Fixing O_TRUNC behavior to match Linux.

PiperOrigin-RevId: 224351139
Change-Id: I9453bd75e5a8d38db406bb47fdc01038ac60922e
This commit is contained in:
Zach Koopmans
2018-12-06 09:26:49 -08:00
committed by Shentubot
parent 7f35daddd2
commit 4d8c7ae869
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -22,6 +22,9 @@ import (
// flagsToPermissions returns a Permissions object from Linux flags.
// This includes truncate permission if O_TRUNC is set in the mask.
func flagsToPermissions(mask uint) (p fs.PermMask) {
if mask&linux.O_TRUNC != 0 {
p.Write = true
}
switch mask & linux.O_ACCMODE {
case linux.O_WRONLY:
p.Write = true
+1 -1
View File
@@ -170,7 +170,7 @@ func openAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint) (fd u
if dirPath {
return syserror.ENOTDIR
}
if fileFlags.Write && flags&linux.O_TRUNC != 0 {
if flags&linux.O_TRUNC != 0 {
if err := d.Inode.Truncate(t, d, 0); err != nil {
return err
}