diff options
author | Fabricio Voznika <fvoznika@google.com> | 2020-03-25 14:44:18 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-03-25 14:49:13 -0700 |
commit | c7f5673529af758c9f7c95523535174c7929dab5 (patch) | |
tree | 84a21d90c5d42a996d69bfdedfaa28a008efac37 /pkg/sentry/fsimpl/tmpfs/device_file.go | |
parent | 2e09f2bdce11d5f303333c68af4272abb62b7885 (diff) |
Set file mode and type to attribute
Makes less error prone to find file type.
Updates #1197
PiperOrigin-RevId: 302974244
Diffstat (limited to 'pkg/sentry/fsimpl/tmpfs/device_file.go')
-rw-r--r-- | pkg/sentry/fsimpl/tmpfs/device_file.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/sentry/fsimpl/tmpfs/device_file.go b/pkg/sentry/fsimpl/tmpfs/device_file.go index 84b181b90..83bf885ee 100644 --- a/pkg/sentry/fsimpl/tmpfs/device_file.go +++ b/pkg/sentry/fsimpl/tmpfs/device_file.go @@ -15,6 +15,8 @@ package tmpfs import ( + "fmt" + "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/sentry/kernel/auth" "gvisor.dev/gvisor/pkg/sentry/vfs" @@ -33,6 +35,14 @@ func (fs *filesystem) newDeviceFile(creds *auth.Credentials, mode linux.FileMode major: major, minor: minor, } + switch kind { + case vfs.BlockDevice: + mode |= linux.S_IFBLK + case vfs.CharDevice: + mode |= linux.S_IFCHR + default: + panic(fmt.Sprintf("invalid DeviceKind: %v", kind)) + } file.inode.init(file, fs, creds, mode) file.inode.nlink = 1 // from parent directory return &file.inode |