Skip to content
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

fix incorrect fsid in 9P2000.L statfs response #119

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading