From 71435d15cf02adfea2002be4f255d3819c482238 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sun, 27 Jun 2010 17:19:50 +0000 Subject: [PATCH] HGFS: statvfs support --- servers/hgfs/const.h | 2 +- servers/hgfs/inode.h | 1 - servers/hgfs/misc.c | 54 +++++++++++++++++++++++++++++++++++++++++++- servers/hgfs/proto.h | 1 + servers/hgfs/table.c | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/servers/hgfs/const.h b/servers/hgfs/const.h index 937554af0..c757d3c8c 100644 --- a/servers/hgfs/const.h +++ b/servers/hgfs/const.h @@ -6,7 +6,7 @@ /* Number of entries in the name hashtable. */ #define NUM_HASH_SLOTS 1023 -/* Arbitrary block size constant returned by fstatfs. du(1) uses this. +/* Arbitrary block size constant returned by fstatfs and statvfs. * Also used by getdents. This is not the actual HGFS data transfer unit size. */ #define BLOCK_SIZE 4096 diff --git a/servers/hgfs/inode.h b/servers/hgfs/inode.h index 092f4d00f..12f6b4b06 100644 --- a/servers/hgfs/inode.h +++ b/servers/hgfs/inode.h @@ -72,7 +72,6 @@ struct inode { #define i_file i_u.u_file #define i_dir i_u.u_dir - #define I_DIR 0x01 /* this inode represents a directory */ #define I_HANDLE 0x02 /* this inode has an open handle */ diff --git a/servers/hgfs/misc.c b/servers/hgfs/misc.c index b7c4c60c1..9ad1a9c7d 100644 --- a/servers/hgfs/misc.c +++ b/servers/hgfs/misc.c @@ -1,7 +1,8 @@ -/* This file contains miscellaneous file system call handlers. +* This file contains miscellaneous file system call handlers. * * The entry points into this file are: * do_fstatfs perform the FSTATFS file system call + * do_statvfs perform the STATVFS file system call * * Created: * April 2009 (D.C. van Moolenbroek) @@ -10,6 +11,7 @@ #include "inc.h" #include +#include /*===========================================================================* * do_fstatfs * @@ -25,3 +27,53 @@ PUBLIC int do_fstatfs() return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0, (vir_bytes) &statfs, sizeof(statfs), D); } + +/*===========================================================================* + * do_statvfs * + *===========================================================================*/ +PUBLIC int do_statvfs() +{ +/* Retrieve file system statistics. + */ + struct statvfs statvfs; + struct inode *ino; + char path[PATH_MAX]; + u64_t free, total; + int r; + + /* Unfortunately, we cannot be any more specific than this, because we are + * not given an inode number. Statistics of individual shared folders can + * only be obtained by using the "prefix=" option when mounting. + */ + if ((ino = find_inode(ROOT_INODE_NR)) == NULL) + return EINVAL; + + if ((r = verify_inode(ino, path, NULL)) != OK) + return r; + + /* It appears that this call always fails with EACCES ("permission denied") + * on read-only folders. As far as I can tell, this is a VMware bug. + */ + if ((r = hgfs_queryvol(path, &free, &total)) != OK) + return r; + + memset(&statvfs, 0, sizeof(statvfs)); + + /* Returning zero for unknown values seems to be the convention. However, we + * do have to use a nonzero block size, even though it is entirely arbitrary. + */ + statvfs.f_bsize = BLOCK_SIZE; + statvfs.f_frsize = BLOCK_SIZE; + statvfs.f_blocks = div64u(total, BLOCK_SIZE); + statvfs.f_bfree = div64u(free, BLOCK_SIZE); + statvfs.f_bavail = statvfs.f_bfree; + statvfs.f_files = 0; + statvfs.f_ffree = 0; + statvfs.f_favail = 0; + statvfs.f_fsid = state.dev; + statvfs.f_flag = state.read_only ? ST_RDONLY : 0; + statvfs.f_namemax = NAME_MAX; + + return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0, + (vir_bytes) &statvfs, sizeof(statvfs), D); +} diff --git a/servers/hgfs/proto.h b/servers/hgfs/proto.h index 93575c99b..cfc782c3f 100644 --- a/servers/hgfs/proto.h +++ b/servers/hgfs/proto.h @@ -38,6 +38,7 @@ _PROTOTYPE( int main, (int argc, char *argv[]) ); /* misc.c */ _PROTOTYPE( int do_fstatfs, (void) ); +_PROTOTYPE( int do_statvfs, (void) ); /* mount.c */ _PROTOTYPE( int do_readsuper, (void) ); diff --git a/servers/hgfs/table.c b/servers/hgfs/table.c index 9db3dbfc5..487e053ac 100644 --- a/servers/hgfs/table.c +++ b/servers/hgfs/table.c @@ -40,7 +40,7 @@ PUBLIC _PROTOTYPE( int (*call_vec[]), (void) ) = { no_sys, /* 29 newnode */ no_sys, /* 30 rdlink */ do_getdents, /* 31 getdents */ - no_sys, /* 32 statvfs */ + do_statvfs, /* 32 statvfs */ }; /* This should not fail with "array size is negative": */ -- 2.44.0