summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/flags.go
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-11-20 14:54:03 -0800
committergVisor bot <gvisor-bot@google.com>2019-11-20 15:07:16 -0800
commit012102eefd2b145ddee774cba28e4fa889fadd49 (patch)
tree8150e163ee3ba161370194d2bdd00642faa820c1 /pkg/sentry/fs/flags.go
parentef6f93625457c166628fc9de57c15d986ae83159 (diff)
Pass OpenTruncate to gofer in Open call when opening file with O_TRUNC.
Note that the Sentry still calls Truncate() on the file before calling Open. A new p9 version check was added to ensure that the p9 server can handle the the OpenTruncate flag. If not, then the flag is stripped before sending. PiperOrigin-RevId: 281609112
Diffstat (limited to 'pkg/sentry/fs/flags.go')
-rw-r--r--pkg/sentry/fs/flags.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/pkg/sentry/fs/flags.go b/pkg/sentry/fs/flags.go
index 0fab876a9..4338ae1fa 100644
--- a/pkg/sentry/fs/flags.go
+++ b/pkg/sentry/fs/flags.go
@@ -64,6 +64,10 @@ type FileFlags struct {
// NonSeekable indicates that file.offset isn't used.
NonSeekable bool
+
+ // Truncate indicates that the file should be truncated before opened.
+ // This is only applicable if the file is regular.
+ Truncate bool
}
// SettableFileFlags is a subset of FileFlags above that can be changed
@@ -118,6 +122,9 @@ func (f FileFlags) ToLinux() (mask uint) {
if f.LargeFile {
mask |= linux.O_LARGEFILE
}
+ if f.Truncate {
+ mask |= linux.O_TRUNC
+ }
switch {
case f.Read && f.Write: