Skip to content

Commit 86b7ceb

Browse files
authored
[WasmFS] Do not change the type bits in the mode (#16973)
The mode has permission bits, like read/write, which can be changed, but the type bits like "is file" or "is directory" can never be changed in POSIX. Or at least so the docs I can find seem to say, and I confirmed it on Linux. It is also how the old FS works. This is a necessary fix for a future PR's test to pass, so a test is not included in this PR.
1 parent 864a234 commit 86b7ceb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

system/lib/wasmfs/file.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ class File::Handle {
258258
: file(file), lock(file->mutex, std::defer_lock) {}
259259
size_t getSize() { return file->getSize(); }
260260
mode_t getMode() { return file->mode; }
261-
void setMode(mode_t mode) { file->mode = mode; }
261+
void setMode(mode_t mode) {
262+
// The type bits can never be changed (whether something is a file or a
263+
// directory, for example).
264+
file->mode = (file->mode & S_IFMT) | (mode & ~S_IFMT);
265+
}
262266
time_t getCTime() { return file->ctime; }
263267
void setCTime(time_t time) { file->ctime = time; }
264268
time_t getMTime() { return file->mtime; }

0 commit comments

Comments
 (0)