xref: /minix3/minix/lib/libsffs/misc.c (revision 7c48de6cc4c6d56f2277d378dba01dbac8a8c3b9)
1433d6423SLionel Sambuc /* This file contains miscellaneous file system call handlers.
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * The entry points into this file are:
4433d6423SLionel Sambuc  *   do_statvfs		perform the STATVFS file system call
5433d6423SLionel Sambuc  *
6433d6423SLionel Sambuc  * Created:
7433d6423SLionel Sambuc  *   April 2009 (D.C. van Moolenbroek)
8433d6423SLionel Sambuc  */
9433d6423SLionel Sambuc 
10433d6423SLionel Sambuc #include "inc.h"
11433d6423SLionel Sambuc 
12433d6423SLionel Sambuc #include <sys/statvfs.h>
13433d6423SLionel Sambuc 
14433d6423SLionel Sambuc /*===========================================================================*
15433d6423SLionel Sambuc  *				do_statvfs				     *
16433d6423SLionel Sambuc  *===========================================================================*/
do_statvfs(struct statvfs * st)17*7c48de6cSDavid van Moolenbroek int do_statvfs(struct statvfs *st)
18433d6423SLionel Sambuc {
19433d6423SLionel Sambuc /* Retrieve file system statistics.
20433d6423SLionel Sambuc  */
21433d6423SLionel Sambuc   struct inode *ino;
22433d6423SLionel Sambuc   char path[PATH_MAX];
23*7c48de6cSDavid van Moolenbroek   u64_t bfree, btotal;
24433d6423SLionel Sambuc   int r;
25433d6423SLionel Sambuc 
26433d6423SLionel Sambuc   /* Unfortunately, we cannot be any more specific than this, because we are
27433d6423SLionel Sambuc    * not given an inode number. Statistics of individual shared folders can
28433d6423SLionel Sambuc    * only be obtained by making sure that the root of the file system is an
29433d6423SLionel Sambuc    * actual share, and not a list of available shares.
30433d6423SLionel Sambuc    */
31433d6423SLionel Sambuc   if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
32433d6423SLionel Sambuc 	return EINVAL;
33433d6423SLionel Sambuc 
34433d6423SLionel Sambuc   if ((r = verify_inode(ino, path, NULL)) != OK)
35433d6423SLionel Sambuc 	return r;
36433d6423SLionel Sambuc 
37*7c48de6cSDavid van Moolenbroek   if ((r = sffs_table->t_queryvol(path, &bfree, &btotal)) != OK)
38433d6423SLionel Sambuc 	return r;
39433d6423SLionel Sambuc 
40433d6423SLionel Sambuc   /* Returning zero for unknown values seems to be the convention. However, we
41433d6423SLionel Sambuc    * do have to use a nonzero block size, even though it is entirely arbitrary.
42433d6423SLionel Sambuc    */
43*7c48de6cSDavid van Moolenbroek   st->f_flag = ST_NOTRUNC;
44*7c48de6cSDavid van Moolenbroek   st->f_bsize = BLOCK_SIZE;
45*7c48de6cSDavid van Moolenbroek   st->f_frsize = BLOCK_SIZE;
46*7c48de6cSDavid van Moolenbroek   st->f_iosize = BLOCK_SIZE;
47*7c48de6cSDavid van Moolenbroek   st->f_blocks = (fsblkcnt_t)(btotal / BLOCK_SIZE);
48*7c48de6cSDavid van Moolenbroek   st->f_bfree = (fsblkcnt_t)(bfree / BLOCK_SIZE);
49*7c48de6cSDavid van Moolenbroek   st->f_bavail = st->f_bfree;
50*7c48de6cSDavid van Moolenbroek   st->f_namemax = NAME_MAX;
51433d6423SLionel Sambuc 
52a99c939dSDavid van Moolenbroek   return OK;
53433d6423SLionel Sambuc }
54