Skip to content

Commit

Permalink
Merge pull request #119 from garlick/issue#115
Browse files Browse the repository at this point in the history
fix incorrect fsid in 9P2000.L statfs response
  • Loading branch information
mergify[bot] authored Jan 13, 2025
2 parents 27e81df + dbed88e commit 4e59170
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
15 changes: 1 addition & 14 deletions protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
31 changes: 12 additions & 19 deletions src/daemon/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include <sys/param.h>
#include <sys/mount.h>
#endif
#include <sys/statvfs.h>

#include <sys/socket.h>
#include <sys/time.h>
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4e59170

Please sign in to comment.