From 8b3af37da0c2e16d9733886fa0b193239fbfa6ad Mon Sep 17 00:00:00 2001 From: Yage Hu Date: Tue, 11 Jun 2024 09:02:47 -0700 Subject: [PATCH] wasi: `path_open` should accept a dir with RIGHT_FD_WRITE (#2244) Signed-off-by: Yage Hu --- imports/wasi_snapshot_preview1/fs.go | 1 - imports/wasi_snapshot_preview1/fs_test.go | 24 +++++++++++++++++++++++ internal/sysfs/file.go | 3 --- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/imports/wasi_snapshot_preview1/fs.go b/imports/wasi_snapshot_preview1/fs.go index 7575d77fe7..1ec0d81b37 100644 --- a/imports/wasi_snapshot_preview1/fs.go +++ b/imports/wasi_snapshot_preview1/fs.go @@ -1708,7 +1708,6 @@ func openFlags(dirflags, oflags, fdflags uint16, rights uint32) (openFlags exper } if oflags&wasip1.O_DIRECTORY != 0 { openFlags |= experimentalsys.O_DIRECTORY - return // Early return for directories as the rest of flags doesn't make sense for it. } else if oflags&wasip1.O_EXCL != 0 { openFlags |= experimentalsys.O_EXCL } diff --git a/imports/wasi_snapshot_preview1/fs_test.go b/imports/wasi_snapshot_preview1/fs_test.go index 03c324f915..b87212f49b 100644 --- a/imports/wasi_snapshot_preview1/fs_test.go +++ b/imports/wasi_snapshot_preview1/fs_test.go @@ -3937,6 +3937,30 @@ func Test_pathOpen(t *testing.T) { expectedLog: ` ==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=,fs_rights_base=FD_READ|FD_WRITE,fs_rights_inheriting=,fdflags=) <== (opened_fd=4,errno=ESUCCESS) +`, + }, + { + name: "sysfs.DirFS file O_DIRECTORY RIGHTS_FD_WRITE", + fs: writeFS, + path: func(*testing.T) string { return fileName }, + oflags: wasip1.O_DIRECTORY, + rights: wasip1.RIGHT_FD_WRITE, + expectedErrno: wasip1.ErrnoNotdir, + expectedLog: ` +==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=file,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=) +<== (opened_fd=,errno=ENOTDIR) +`, + }, + { + name: "sysfs.DirFS dir O_DIRECTORY RIGHTS_FD_WRITE", + fs: writeFS, + path: func(*testing.T) string { return dirName }, + oflags: wasip1.O_DIRECTORY, + rights: wasip1.RIGHT_FD_WRITE, + expectedErrno: wasip1.ErrnoIsdir, + expectedLog: ` +==> wasi_snapshot_preview1.path_open(fd=3,dirflags=,path=dir,oflags=DIRECTORY,fs_rights_base=FD_WRITE,fs_rights_inheriting=,fdflags=) +<== (opened_fd=,errno=EISDIR) `, }, } diff --git a/internal/sysfs/file.go b/internal/sysfs/file.go index 9a77205bb5..fdbf1fde0d 100644 --- a/internal/sysfs/file.go +++ b/internal/sysfs/file.go @@ -38,9 +38,6 @@ func NewStdioFile(stdin bool, f fs.File) (fsapi.File, error) { } func OpenFile(path string, flag experimentalsys.Oflag, perm fs.FileMode) (*os.File, experimentalsys.Errno) { - if flag&experimentalsys.O_DIRECTORY != 0 && flag&(experimentalsys.O_WRONLY|experimentalsys.O_RDWR) != 0 { - return nil, experimentalsys.EISDIR // invalid to open a directory writeable - } return openFile(path, flag, perm) }