xref: /minix3/minix/lib/libsffs/misc.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
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(struct statvfs *st)
18  {
19  /* Retrieve file system statistics.
20   */
21    struct inode *ino;
22    char path[PATH_MAX];
23    u64_t bfree, btotal;
24    int r;
25  
26    /* Unfortunately, we cannot be any more specific than this, because we are
27     * not given an inode number. Statistics of individual shared folders can
28     * only be obtained by making sure that the root of the file system is an
29     * actual share, and not a list of available shares.
30     */
31    if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
32  	return EINVAL;
33  
34    if ((r = verify_inode(ino, path, NULL)) != OK)
35  	return r;
36  
37    if ((r = sffs_table->t_queryvol(path, &bfree, &btotal)) != OK)
38  	return r;
39  
40    /* Returning zero for unknown values seems to be the convention. However, we
41     * do have to use a nonzero block size, even though it is entirely arbitrary.
42     */
43    st->f_flag = ST_NOTRUNC;
44    st->f_bsize = BLOCK_SIZE;
45    st->f_frsize = BLOCK_SIZE;
46    st->f_iosize = BLOCK_SIZE;
47    st->f_blocks = (fsblkcnt_t)(btotal / BLOCK_SIZE);
48    st->f_bfree = (fsblkcnt_t)(bfree / BLOCK_SIZE);
49    st->f_bavail = st->f_bfree;
50    st->f_namemax = NAME_MAX;
51  
52    return OK;
53  }
54