Fixes to allow versionless packages on cd
[minix3.git] / servers / hgfs / misc.c
blob0cb80566c0623003ccbddedb4f59011d19aaa498
1 /* This file contains miscellaneous file system call handlers.
3 * The entry points into this file are:
4 * do_fstatfs perform the FSTATFS file system call
5 * do_statvfs perform the STATVFS file system call
7 * Created:
8 * April 2009 (D.C. van Moolenbroek)
9 */
11 #include "inc.h"
13 #include <sys/statfs.h>
14 #include <sys/statvfs.h>
16 /*===========================================================================*
17 * do_fstatfs *
18 *===========================================================================*/
19 PUBLIC int do_fstatfs()
21 /* Retrieve file system statistics.
23 struct statfs statfs;
25 statfs.f_bsize = BLOCK_SIZE; /* arbitrary block size constant */
27 return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0,
28 (vir_bytes) &statfs, sizeof(statfs), D);
31 /*===========================================================================*
32 * do_statvfs *
33 *===========================================================================*/
34 PUBLIC int do_statvfs()
36 /* Retrieve file system statistics.
38 struct statvfs statvfs;
39 struct inode *ino;
40 char path[PATH_MAX];
41 u64_t free, total;
42 int r;
44 /* Unfortunately, we cannot be any more specific than this, because we are
45 * not given an inode number. Statistics of individual shared folders can
46 * only be obtained by using the "prefix=" option when mounting.
48 if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
49 return EINVAL;
51 if ((r = verify_inode(ino, path, NULL)) != OK)
52 return r;
54 /* It appears that this call always fails with EACCES ("permission denied")
55 * on read-only folders. As far as I can tell, this is a VMware bug.
57 if ((r = hgfs_queryvol(path, &free, &total)) != OK)
58 return r;
60 memset(&statvfs, 0, sizeof(statvfs));
62 /* Returning zero for unknown values seems to be the convention. However, we
63 * do have to use a nonzero block size, even though it is entirely arbitrary.
65 statvfs.f_bsize = BLOCK_SIZE;
66 statvfs.f_frsize = BLOCK_SIZE;
67 statvfs.f_blocks = div64u(total, BLOCK_SIZE);
68 statvfs.f_bfree = div64u(free, BLOCK_SIZE);
69 statvfs.f_bavail = statvfs.f_bfree;
70 statvfs.f_files = 0;
71 statvfs.f_ffree = 0;
72 statvfs.f_favail = 0;
73 statvfs.f_fsid = state.dev;
74 statvfs.f_flag = state.read_only ? ST_RDONLY : 0;
75 statvfs.f_flag |= ST_NOTRUNC;
76 statvfs.f_namemax = NAME_MAX;
78 return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0,
79 (vir_bytes) &statvfs, sizeof(statvfs), D);