summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/gofer/file_state.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/gofer/file_state.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/gofer/file_state.go')
-rw-r--r--pkg/sentry/fs/gofer/file_state.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/pkg/sentry/fs/gofer/file_state.go b/pkg/sentry/fs/gofer/file_state.go
index c2fbb4be9..bb8312849 100644
--- a/pkg/sentry/fs/gofer/file_state.go
+++ b/pkg/sentry/fs/gofer/file_state.go
@@ -28,8 +28,14 @@ func (f *fileOperations) afterLoad() {
// Manually load the open handles.
var err error
+
+ // The file may have been opened with Truncate, but we don't
+ // want to re-open it with Truncate or we will lose data.
+ flags := f.flags
+ flags.Truncate = false
+
// TODO(b/38173783): Context is not plumbed to save/restore.
- f.handles, err = f.inodeOperations.fileState.getHandles(context.Background(), f.flags, f.inodeOperations.cachingInodeOps)
+ f.handles, err = f.inodeOperations.fileState.getHandles(context.Background(), flags, f.inodeOperations.cachingInodeOps)
if err != nil {
return fmt.Errorf("failed to re-open handle: %v", err)
}