From a7a0167716d71895919021692b15bd000f63b24f Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 31 Jul 2018 11:18:02 -0700 Subject: proc: show file flags in fdinfo Currently, there is an attempt to print FD flags, but they are not decoded into a number, so we see something like this: /criu # cat /proc/self/fdinfo/0 flags: {%!o(bool=000false)} Actually, fdinfo has to contain file flags. Change-Id: Idcbb7db908067447eb9ae6f2c3cfb861f2be1a97 PiperOrigin-RevId: 206794498 --- pkg/sentry/fs/flags.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'pkg/sentry/fs/flags.go') diff --git a/pkg/sentry/fs/flags.go b/pkg/sentry/fs/flags.go index 810452584..da0ff58af 100644 --- a/pkg/sentry/fs/flags.go +++ b/pkg/sentry/fs/flags.go @@ -14,6 +14,10 @@ package fs +import ( + "gvisor.googlesource.com/gvisor/pkg/abi/linux" +) + // FileFlags encodes file flags. type FileFlags struct { // Direct indicates that I/O should be done directly. @@ -78,3 +82,38 @@ func (f FileFlags) Settable() SettableFileFlags { Async: f.Async, } } + +// ToLinux converts a FileFlags object to a Linux representation. +func (f FileFlags) ToLinux() (mask uint) { + if f.Direct { + mask |= linux.O_DIRECT + } + if f.NonBlocking { + mask |= linux.O_NONBLOCK + } + if f.Sync { + mask |= linux.O_SYNC + } + if f.Append { + mask |= linux.O_APPEND + } + if f.Directory { + mask |= linux.O_DIRECTORY + } + if f.Async { + mask |= linux.O_ASYNC + } + if f.LargeFile { + mask |= linux.O_LARGEFILE + } + + switch { + case f.Read && f.Write: + mask |= linux.O_RDWR + case f.Write: + mask |= linux.O_WRONLY + case f.Read: + mask |= linux.O_RDONLY + } + return +} -- cgit v1.2.3