From d2b311f0ac1f97325e0e5afa6742e2cf556189bd Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Sun, 12 Jan 2025 13:47:14 -0800 Subject: [PATCH 1/2] doc: update Rstatfs description Problem: the description of Rstatfs suggests that an implementation should call statfs(2), but it can now be satisfied with statvfs(3) in a more portable manner. Just refer to statvfs(3). Don't quote structs as that's available elsewhere. --- protocol.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/protocol.md b/protocol.md index 9cc333c6..bcced899 100644 --- a/protocol.md +++ b/protocol.md @@ -145,20 +145,7 @@ size[4] Tstatfs tag[2] fid[4] size[4] Rstatfs tag[2] type[4] bsize[4] blocks[8] bfree[8] bavail[8] files[8] ffree[8] fsid[8] namelen[4] ``` -statfs is used to request file system information of the file system containing fid. The Rstatfs response corresponds to the fields returned by the statfs(2) system call, e.g.: -``` -struct statfs { - long f_type; /* type of file system (see below) */ - long f_bsize; /* optimal transfer block size */ - long f_blocks; /* total data blocks in file system */ - long f_bfree; /* free blocks in fs */ - long f_bavail; /* free blocks avail to non-superuser */ - long f_files; /* total file nodes in file system */ - long f_ffree; /* free file nodes in fs */ - fsid_t f_fsid; /* file system id */ - long f_namelen; /* maximum length of filenames */ -}; -``` +statfs is used to request file system information of the file system containing fid. See statvfs(3). #### lopen -- open a file ``` From dbed88e638c587059b1dfa7491c8f6e627207a63 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Sun, 12 Jan 2025 14:05:12 -0800 Subject: [PATCH 2/2] fix fsid in Rstatfs result Problem: the remote fsid returned by Tstatfs is incorrect. I botched the construction of fsid from fsid_t (an array of two variable size integers) when building the response to Tstatfs. Just use statvfs(3) instead, which returns the fsid as a single number. It's more portable than statfs(2) so some ifdefs that cover BSD/linux differences can go away. Note that statfs(2) still has to be called to get the file system type if the "statfs-passthrough" option is configured, but f_type seems to be portable across platforms. Fixes #32 Fixes #115 --- src/daemon/ops.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/daemon/ops.c b/src/daemon/ops.c index f3de61d0..ce71a299 100644 --- a/src/daemon/ops.c +++ b/src/daemon/ops.c @@ -73,6 +73,7 @@ #include #include #endif +#include #include #include @@ -584,34 +585,26 @@ Npfcall* diod_statfs (Npfid *fid) { Fid *f = fid->aux; - struct statfs sb; + struct statvfs sb; Npfcall *ret; - u64 fsid; u32 type = V9FS_MAGIC; - if (statfs (path_s (f->path), &sb) < 0) { + if (statvfs (path_s (f->path), &sb) < 0) { np_uerror (errno); goto error; } - -#ifdef __FreeBSD__ - fsid = (u64)sb.f_fsid.val[0] | ((u64)sb.f_fsid.val[1] << 32); -#else - fsid = (u64)sb.f_fsid.__val[0] | ((u64)sb.f_fsid.__val[1] << 32); -#endif - if (diod_conf_get_statfs_passthru ()) - type = sb.f_type; -#ifdef __FreeBSD__ + if (diod_conf_get_statfs_passthru ()) { + struct statfs sb2; + if (statfs (path_s (f->path), &sb2) < 0) { + np_uerror (errno); + goto error; + } + type = sb2.f_type; + } if (!(ret = np_create_rstatfs(type, sb.f_bsize, sb.f_blocks, sb.f_bfree, sb.f_bavail, sb.f_files, - sb.f_ffree, fsid, + sb.f_ffree, sb.f_fsid, sb.f_namemax))) { -#else - if (!(ret = np_create_rstatfs(type, sb.f_bsize, sb.f_blocks, - sb.f_bfree, sb.f_bavail, sb.f_files, - sb.f_ffree, fsid, - sb.f_namelen))) { -#endif np_uerror (ENOMEM); goto error; }