p9: fix lcreate to respect the open mode

lcreate is not just used for creat(2), but open(2) as well. So it is
possible that the read/write mode is specified manually.

BUG=chromium:1105484
TEST=Run the test program in the bug. Read returns 0 like on other
     filesystem.

Change-Id: I4fb642deb09831f00d3bd83e973e8a42c54ec5d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2297228
Tested-by: Victor Hsieh <victorhsieh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Victor Hsieh <victorhsieh@chromium.org>
Commit-Queue: Victor Hsieh <victorhsieh@chromium.org>
This commit is contained in:
Victor Hsieh 2020-07-14 08:51:24 -07:00 committed by Commit Bot
parent e43468f066
commit fe863ad1bc

View file

@ -540,8 +540,8 @@ impl Server {
} }
let file = fs::OpenOptions::new() let file = fs::OpenOptions::new()
.read(false) .read((lcreate.flags & P9_NOACCESS) == 0 || (lcreate.flags & P9_RDWR) != 0)
.write(true) .write((lcreate.flags & P9_WRONLY) != 0 || (lcreate.flags & P9_RDWR) != 0)
.truncate(true) .truncate(true)
.create(true) .create(true)
.append((lcreate.flags & P9_APPEND) != 0) .append((lcreate.flags & P9_APPEND) != 0)