-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[FS] Make fstat work on file descriptors with no name in memfs #23470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hoodmane
merged 8 commits into
emscripten-core:main
from
hoodmane:anonymous-file-descriptors-memfs
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe1e70e
[FS] Make fstat work on file descriptors with no name in memfs
hoodmane 0ff1aa0
Rebaseline
hoodmane 7869eda
Revert "Rebaseline"
hoodmane ccaff90
Merge branch 'main' into anonymous-file-descriptors-memfs
hoodmane 99207da
Simplify test code
hoodmane db0dcf3
Address review comments
hoodmane 464f80a
Fix some typos
hoodmane 204242e
Automatic rebaseline of codesize expectations. NFC
hoodmane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,6 +487,13 @@ FS.staticInit(); | |
stream.stream_ops?.dup?.(stream); | ||
return stream; | ||
}, | ||
doSetAttr(stream, node, attr) { | ||
var setattr = stream?.stream_ops.setattr; | ||
var arg = setattr ? stream : node; | ||
setattr ??= node.node_ops.setattr; | ||
FS.checkOpExists(setattr, {{{ cDefs.EPERM }}}) | ||
setattr(arg, attr); | ||
}, | ||
|
||
// | ||
// devices | ||
|
@@ -966,11 +973,24 @@ FS.staticInit(); | |
return getattr(node); | ||
}, | ||
fstat(fd) { | ||
return FS.stat(FS.getStreamChecked(fd).path); | ||
var stream = FS.getStreamChecked(fd); | ||
var node = stream.node; | ||
var getattr = stream.stream_ops.getattr; | ||
var arg = getattr ? stream : node; | ||
getattr ??= node.node_ops.getattr; | ||
FS.checkOpExists(getattr, {{{ cDefs.EPERM }}}) | ||
return getattr(arg); | ||
}, | ||
lstat(path) { | ||
return FS.stat(path, true); | ||
}, | ||
doChmod(stream, node, mode, dontFollow) { | ||
FS.doSetAttr(stream, node, { | ||
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}), | ||
ctime: Date.now(), | ||
dontFollow | ||
}); | ||
}, | ||
chmod(path, mode, dontFollow) { | ||
var node; | ||
if (typeof path == 'string') { | ||
|
@@ -979,19 +999,21 @@ FS.staticInit(); | |
} else { | ||
node = path; | ||
} | ||
var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); | ||
setattr(node, { | ||
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}), | ||
ctime: Date.now(), | ||
dontFollow | ||
}); | ||
FS.doChmod(null, node, mode, dontFollow); | ||
}, | ||
lchmod(path, mode) { | ||
FS.chmod(path, mode, true); | ||
}, | ||
fchmod(fd, mode) { | ||
var stream = FS.getStreamChecked(fd); | ||
FS.chmod(stream.node, mode); | ||
FS.doChmod(stream, stream.node, mode, false); | ||
}, | ||
doChown(stream, node, dontFollow) { | ||
FS.doSetAttr(stream, node, { | ||
timestamp: Date.now(), | ||
dontFollow | ||
// we ignore the uid / gid for now | ||
}); | ||
}, | ||
chown(path, uid, gid, dontFollow) { | ||
var node; | ||
|
@@ -1001,31 +1023,16 @@ FS.staticInit(); | |
} else { | ||
node = path; | ||
} | ||
var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); | ||
setattr(node, { | ||
timestamp: Date.now(), | ||
dontFollow | ||
// we ignore the uid / gid for now | ||
}); | ||
FS.doChown(null, node, dontFollow); | ||
}, | ||
lchown(path, uid, gid) { | ||
FS.chown(path, uid, gid, true); | ||
}, | ||
fchown(fd, uid, gid) { | ||
var stream = FS.getStreamChecked(fd); | ||
FS.chown(stream.node, uid, gid); | ||
FS.doChown(stream, stream.node, false); | ||
}, | ||
truncate(path, len) { | ||
if (len < 0) { | ||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
var node; | ||
if (typeof path == 'string') { | ||
var lookup = FS.lookupPath(path, { follow: true }); | ||
node = lookup.node; | ||
} else { | ||
node = path; | ||
} | ||
doTruncate(stream, node, len) { | ||
if (FS.isDir(node.mode)) { | ||
throw new FS.ErrnoError({{{ cDefs.EISDIR }}}); | ||
} | ||
|
@@ -1036,18 +1043,30 @@ FS.staticInit(); | |
if (errCode) { | ||
throw new FS.ErrnoError(errCode); | ||
} | ||
var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); | ||
setattr(node, { | ||
FS.doSetAttr(stream, node, { | ||
size: len, | ||
timestamp: Date.now() | ||
}); | ||
}, | ||
truncate(path, len) { | ||
if (len < 0) { | ||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
var node; | ||
if (typeof path == 'string') { | ||
var lookup = FS.lookupPath(path, { follow: true }); | ||
node = lookup.node; | ||
} else { | ||
node = path; | ||
} | ||
FS.doTruncate(null, node, len); | ||
}, | ||
ftruncate(fd, len) { | ||
var stream = FS.getStreamChecked(fd); | ||
if ((stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { | ||
if (len < 0 || (stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a separate fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah |
||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
FS.truncate(stream.node, len); | ||
FS.doTruncate(stream, stream.node, len); | ||
}, | ||
utime(path, atime, mtime) { | ||
var lookup = FS.lookupPath(path, { follow: true }); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8343 | ||
8359 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20273 | ||
20296 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8327 | ||
8341 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20241 | ||
20264 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
9343 | ||
9358 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
24041 | ||
24064 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8294 | ||
8303 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20166 | ||
20189 |
2 changes: 1 addition & 1 deletion
2
test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8294 | ||
8303 |
2 changes: 1 addition & 1 deletion
2
test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20166 | ||
20189 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8357 | ||
8372 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20348 | ||
20371 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
9349 | ||
9364 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
24041 | ||
24064 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8343 | ||
8359 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20273 | ||
20296 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7647 | ||
7669 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18820 | ||
18843 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.