Skip to content

Commit 4286b2a

Browse files
committed
Merge branch 'main' into chmod-not-update-mtim
2 parents 713d966 + ac676d5 commit 4286b2a

37 files changed

+165
-82
lines changed

src/library_fs.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,29 @@ FS.staticInit();
673673
}
674674
return parent.node_ops.mknod(parent, name, mode, dev);
675675
},
676+
statfs(path) {
677+
678+
// NOTE: None of the defaults here are true. We're just returning safe and
679+
// sane values.
680+
var rtn = {
681+
bsize: 4096,
682+
frsize: 4096,
683+
blocks: 1e6,
684+
bfree: 5e5,
685+
bavail: 5e5,
686+
files: FS.nextInode,
687+
ffree: FS.nextInode - 1,
688+
fsid: 42,
689+
flags: 2,
690+
namelen: 255,
691+
};
692+
693+
var parent = FS.lookupPath(path, {follow: true}).node;
694+
if (parent?.node_ops.statfs) {
695+
Object.assign(rtn, parent.node_ops.statfs(parent.mount.opts.root));
696+
}
697+
return rtn;
698+
},
676699
// helpers to create specific types of nodes
677700
create(path, mode = 0o666) {
678701
mode &= {{{ cDefs.S_IALLUGO }}};
@@ -814,7 +837,7 @@ FS.staticInit();
814837
// do the underlying fs rename
815838
try {
816839
old_dir.node_ops.rename(old_node, new_dir, new_name);
817-
// update old node (we do this here to avoid each backend
840+
// update old node (we do this here to avoid each backend
818841
// needing to)
819842
old_node.parent = new_dir;
820843
} catch (e) {
@@ -909,7 +932,7 @@ FS.staticInit();
909932
if (!link.node_ops.readlink) {
910933
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
911934
}
912-
return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link));
935+
return link.node_ops.readlink(link);
913936
},
914937
stat(path, dontFollow) {
915938
var lookup = FS.lookupPath(path, { follow: !dontFollow });
@@ -1386,7 +1409,7 @@ FS.staticInit();
13861409
FS.mkdir('/proc/self/fd');
13871410
FS.mount({
13881411
mount() {
1389-
var node = FS.createNode(proc_self, 'fd', {{{ cDefs.S_IFDIR }}} | {{{ 0777 }}}, {{{ cDefs.S_IXUGO }}});
1412+
var node = FS.createNode(proc_self, 'fd', {{{ cDefs.S_IFDIR | 0o777 }}}, {{{ cDefs.S_IXUGO }}});
13901413
node.node_ops = {
13911414
lookup(parent, name) {
13921415
var fd = +name;

src/library_lz4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
addToLibrary({
99
$LZ4__deps: ['$FS', '$preloadPlugins'],
1010
$LZ4: {
11-
DIR_MODE: {{{ cDefs.S_IFDIR }}} | 511 /* 0777 */,
12-
FILE_MODE: {{{ cDefs.S_IFREG }}} | 511 /* 0777 */,
11+
DIR_MODE: {{{ cDefs.S_IFDIR | 0o777 }}},
12+
FILE_MODE: {{{ cDefs.S_IFREG | 0o777 }}},
1313
CHUNK_SIZE: -1,
1414
codec: null,
1515
init() {

src/library_memfs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ addToLibrary({
1818
$MEMFS: {
1919
ops_table: null,
2020
mount(mount) {
21-
return MEMFS.createNode(null, '/', {{{ cDefs.S_IFDIR }}} | 511 /* 0777 */, 0);
21+
return MEMFS.createNode(null, '/', {{{ cDefs.S_IFDIR | 0o777 }}}, 0);
2222
},
2323
createNode(parent, name, mode, dev) {
2424
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
@@ -230,7 +230,7 @@ addToLibrary({
230230
return entries;
231231
},
232232
symlink(parent, newname, oldpath) {
233-
var node = MEMFS.createNode(parent, newname, 511 /* 0777 */ | {{{ cDefs.S_IFLNK }}}, 0);
233+
var node = MEMFS.createNode(parent, newname, 0o777 | {{{ cDefs.S_IFLNK }}}, 0);
234234
node.link = oldpath;
235235
return node;
236236
},

src/library_nodefs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ addToLibrary({
220220
var path = NODEFS.realPath(node);
221221
return NODEFS.tryFSOperation(() => fs.readlinkSync(path));
222222
},
223+
statfs(path) {
224+
var stats = NODEFS.tryFSOperation(() => fs.statfsSync(path));
225+
// Node.js doesn't provide frsize (fragment size). Set it to bsize (block size)
226+
// as they're often the same in many file systems. May not be accurate for all.
227+
stats.frsize = stats.bsize;
228+
return stats;
229+
}
223230
},
224231
stream_ops: {
225232
open(stream) {

src/library_pipefs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ addToLibrary({
1212
mount(mount) {
1313
// Do not pollute the real root directory or its child nodes with pipes
1414
// Looks like it is OK to create another pseudo-root node not linked to the FS.root hierarchy this way
15-
return FS.createNode(null, '/', {{{ cDefs.S_IFDIR }}} | 511 /* 0777 */, 0);
15+
return FS.createNode(null, '/', {{{ cDefs.S_IFDIR }}} | 0o777, 0);
1616
},
1717
createPipe() {
1818
var pipe = {

src/library_sockfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ addToLibrary({
4141
SOCKFS.on('close', (fd) => dbg(`websocket: close fd = ${fd}`));
4242
#endif
4343

44-
return FS.createNode(null, '/', {{{ cDefs.S_IFDIR }}} | 511 /* 0777 */, 0);
44+
return FS.createNode(null, '/', {{{ cDefs.S_IFDIR | 0o777 }}}, 0);
4545
},
4646
createSocket(family, type, protocol) {
4747
type &= ~{{{ cDefs.SOCK_CLOEXEC | cDefs.SOCK_NONBLOCK }}}; // Some applications may pass it; it makes no sense for a single process.

src/library_syscall.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -790,22 +790,20 @@ var SyscallsLibrary = {
790790
},
791791
792792
__syscall_statfs64: (path, size, buf) => {
793-
path = SYSCALLS.getStr(path);
794793
#if ASSERTIONS
795794
assert(size === {{{ C_STRUCTS.statfs.__size__ }}});
796795
#endif
797-
// NOTE: None of the constants here are true. We're just returning safe and
798-
// sane values.
799-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bsize, '4096', 'i32') }}};
800-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_frsize, '4096', 'i32') }}};
801-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_blocks, '1000000', 'i32') }}};
802-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bfree, '500000', 'i32') }}};
803-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bavail, '500000', 'i32') }}};
804-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_files, 'FS.nextInode', 'i32') }}};
805-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_ffree, '1000000', 'i32') }}};
806-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_fsid, '42', 'i32') }}};
807-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_flags, '2', 'i32') }}}; // ST_NOSUID
808-
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_namelen, '255', 'i32') }}};
796+
var stats = FS.statfs(SYSCALLS.getStr(path));
797+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bsize, 'stats.bsize', 'i32') }}};
798+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_frsize, 'stats.bsize', 'i32') }}};
799+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_blocks, 'stats.blocks', 'i32') }}};
800+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bfree, 'stats.bfree', 'i32') }}};
801+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_bavail, 'stats.bavail', 'i32') }}};
802+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_files, 'stats.files', 'i32') }}};
803+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_ffree, 'stats.ffree', 'i32') }}};
804+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_fsid, 'stats.fsid', 'i32') }}};
805+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_flags, 'stats.flags', 'i32') }}}; // ST_NOSUID
806+
{{{ makeSetValue('buf', C_STRUCTS.statfs.f_namelen, 'stats.namelen', 'i32') }}};
809807
return 0;
810808
},
811809
__syscall_fstatfs64__deps: ['__syscall_statfs64'],

src/library_wasmfs.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ FS.init();
178178
rmdir: (path) => FS.handleError(
179179
withStackSave(() => __wasmfs_rmdir(stringToUTF8OnStack(path)))
180180
),
181-
open: (path, flags, mode) => withStackSave(() => {
181+
open: (path, flags, mode = 0o666) => withStackSave(() => {
182182
flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
183-
mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode;
184183
var buffer = stringToUTF8OnStack(path);
185184
var fd = FS.handleError(__wasmfs_open(buffer, flags, mode));
186185
return { fd : fd };
@@ -449,7 +448,7 @@ FS.init();
449448
mkdev(path, mode, dev) {
450449
if (typeof dev === 'undefined') {
451450
dev = mode;
452-
mode = 438 /* 0666 */;
451+
mode = 0o666;
453452
}
454453

455454
var deviceBackend = wasmFSDevices[dev];
@@ -517,7 +516,7 @@ FS.init();
517516

518517
$FS_create__deps: ['$FS_mknod'],
519518
// Default settings copied from the legacy JS FS API.
520-
$FS_create: (path, mode = 438 /* 0666 */) => {
519+
$FS_create: (path, mode = 0o666) => {
521520
mode &= {{{ cDefs.S_IALLUGO }}};
522521
mode |= {{{ cDefs.S_IFREG }}};
523522
return FS_mknod(path, mode, 0);
@@ -546,7 +545,7 @@ FS.init();
546545
},
547546

548547
$FS_mkdir__deps: ['_wasmfs_mkdir'],
549-
$FS_mkdir: (path, mode = 511 /* 0777 */) => FS.handleError(withStackSave(() => {
548+
$FS_mkdir: (path, mode = 0o777) => FS.handleError(withStackSave(() => {
550549
var buffer = stringToUTF8OnStack(path);
551550
return __wasmfs_mkdir(buffer, mode);
552551
})),

src/library_workerfs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
addToLibrary({
88
$WORKERFS__deps: ['$FS'],
99
$WORKERFS: {
10-
DIR_MODE: {{{ cDefs.S_IFDIR }}} | 511 /* 0777 */,
11-
FILE_MODE: {{{ cDefs.S_IFREG }}} | 511 /* 0777 */,
10+
DIR_MODE: {{{ cDefs.S_IFDIR | 0o777 }}},
11+
FILE_MODE: {{{ cDefs.S_IFREG | 0o777 }}},
1212
reader: null,
1313
mount(mount) {
1414
assert(ENVIRONMENT_IS_WORKER);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12698,
3-
"a.html.gz": 6901,
4-
"total": 12698,
5-
"total_gz": 6901
2+
"a.html": 12686,
3+
"a.html.gz": 6930,
4+
"total": 12686,
5+
"total_gz": 6930
66
}

0 commit comments

Comments
 (0)