VM: full munmap
[minix.git] / lib / libsffs / misc.c
blobfe48d84cf0edc3e7097d2a44e06891f21aacf80e
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 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));
31 /*===========================================================================*
32 * do_statvfs *
33 *===========================================================================*/
34 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 making sure that the root of the file system is an
47 * actual share, and not a list of available shares.
49 if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
50 return EINVAL;
52 if ((r = verify_inode(ino, path, NULL)) != OK)
53 return r;
55 if ((r = sffs_table->t_queryvol(path, &free, &total)) != OK)
56 return r;
58 memset(&statvfs, 0, sizeof(statvfs));
60 /* Returning zero for unknown values seems to be the convention. However, we
61 * do have to use a nonzero block size, even though it is entirely arbitrary.
63 statvfs.f_bsize = BLOCK_SIZE;
64 statvfs.f_frsize = BLOCK_SIZE;
65 statvfs.f_blocks = div64u(total, BLOCK_SIZE);
66 statvfs.f_bfree = div64u(free, BLOCK_SIZE);
67 statvfs.f_bavail = statvfs.f_bfree;
68 statvfs.f_files = 0;
69 statvfs.f_ffree = 0;
70 statvfs.f_favail = 0;
71 statvfs.f_fsid = state.s_dev;
72 statvfs.f_flag = state.s_read_only ? ST_RDONLY : 0;
73 statvfs.f_flag |= ST_NOTRUNC;
74 statvfs.f_namemax = NAME_MAX;
76 return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0,
77 (vir_bytes) &statvfs, sizeof(statvfs));