summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/attr.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2019-08-07 21:32:48 +0000
committergVisor bot <gvisor-bot@google.com>2019-08-07 21:32:48 +0000
commit3d4b6ad4b210d4a09fcf7ad91e39e60a55012fe1 (patch)
tree739b4b3f2e514e593fecb46f54417c5a4a508f2b /pkg/sentry/fs/attr.go
parentabdd9fb7c165e6aae38d2af1bd83657ae4988caf (diff)
parent1c9781a4edce5fa9688f868149a2506f2ec5fa86 (diff)
Merge 1c9781a4 (automated)
Diffstat (limited to 'pkg/sentry/fs/attr.go')
-rw-r--r--pkg/sentry/fs/attr.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/sentry/fs/attr.go b/pkg/sentry/fs/attr.go
index 9fc6a5bc2..4f3d6410e 100644
--- a/pkg/sentry/fs/attr.go
+++ b/pkg/sentry/fs/attr.go
@@ -111,6 +111,50 @@ func (n InodeType) LinuxType() uint32 {
}
}
+// ToDirentType converts an InodeType to a linux dirent type field.
+func ToDirentType(nodeType InodeType) uint8 {
+ switch nodeType {
+ case RegularFile, SpecialFile:
+ return linux.DT_REG
+ case Symlink:
+ return linux.DT_LNK
+ case Directory, SpecialDirectory:
+ return linux.DT_DIR
+ case Pipe:
+ return linux.DT_FIFO
+ case CharacterDevice:
+ return linux.DT_CHR
+ case BlockDevice:
+ return linux.DT_BLK
+ case Socket:
+ return linux.DT_SOCK
+ default:
+ return linux.DT_UNKNOWN
+ }
+}
+
+// ToInodeType coverts a linux file type to InodeType.
+func ToInodeType(linuxFileType linux.FileMode) InodeType {
+ switch linuxFileType {
+ case linux.ModeRegular:
+ return RegularFile
+ case linux.ModeDirectory:
+ return Directory
+ case linux.ModeSymlink:
+ return Symlink
+ case linux.ModeNamedPipe:
+ return Pipe
+ case linux.ModeCharacterDevice:
+ return CharacterDevice
+ case linux.ModeBlockDevice:
+ return BlockDevice
+ case linux.ModeSocket:
+ return Socket
+ default:
+ panic(fmt.Sprintf("unknown file mode: %d", linuxFileType))
+ }
+}
+
// StableAttr contains Inode attributes that will be stable throughout the
// lifetime of the Inode.
//