xref: /minix3/minix/lib/libsffs/misc.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1 /* This file contains miscellaneous file system call handlers.
2  *
3  * The entry points into this file are:
4  *   do_statvfs		perform the STATVFS file system call
5  *
6  * Created:
7  *   April 2009 (D.C. van Moolenbroek)
8  */
9 
10 #include "inc.h"
11 
12 #include <sys/statvfs.h>
13 
14 /*===========================================================================*
15  *				do_statvfs				     *
16  *===========================================================================*/
17 int do_statvfs(void)
18 {
19 /* Retrieve file system statistics.
20  */
21   struct statvfs statvfs;
22   struct inode *ino;
23   char path[PATH_MAX];
24   u64_t free, total;
25   int r;
26 
27   /* Unfortunately, we cannot be any more specific than this, because we are
28    * not given an inode number. Statistics of individual shared folders can
29    * only be obtained by making sure that the root of the file system is an
30    * actual share, and not a list of available shares.
31    */
32   if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
33 	return EINVAL;
34 
35   if ((r = verify_inode(ino, path, NULL)) != OK)
36 	return r;
37 
38   if ((r = sffs_table->t_queryvol(path, &free, &total)) != OK)
39 	return r;
40 
41   memset(&statvfs, 0, sizeof(statvfs));
42 
43   /* Returning zero for unknown values seems to be the convention. However, we
44    * do have to use a nonzero block size, even though it is entirely arbitrary.
45    */
46   statvfs.f_flag = ST_NOTRUNC;
47   statvfs.f_bsize = BLOCK_SIZE;
48   statvfs.f_frsize = BLOCK_SIZE;
49   statvfs.f_iosize = BLOCK_SIZE;
50   statvfs.f_blocks = (unsigned long)(total / BLOCK_SIZE);
51   statvfs.f_bfree = (unsigned long)(free / BLOCK_SIZE);
52   statvfs.f_bavail = statvfs.f_bfree;
53   statvfs.f_namemax = NAME_MAX;
54 
55   return sys_safecopyto(m_in.m_source, m_in.m_vfs_fs_statvfs.grant, 0,
56 			(vir_bytes) &statvfs, sizeof(statvfs));
57 }
58