summaryrefslogtreecommitdiff
path: root/minix/lib/libsffs/misc.c
blob: 566ddb3506cbf0ffcef8331f1728f64ca9cd0d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This file contains miscellaneous file system call handlers.
 *
 * The entry points into this file are:
 *   do_statvfs		perform the STATVFS file system call
 *
 * Created:
 *   April 2009 (D.C. van Moolenbroek)
 */

#include "inc.h"

#include <sys/statvfs.h>

/*===========================================================================*
 *				do_statvfs				     *
 *===========================================================================*/
int do_statvfs(struct statvfs *st)
{
/* Retrieve file system statistics.
 */
  struct inode *ino;
  char path[PATH_MAX];
  u64_t bfree, btotal;
  int r;

  /* Unfortunately, we cannot be any more specific than this, because we are
   * not given an inode number. Statistics of individual shared folders can
   * only be obtained by making sure that the root of the file system is an
   * actual share, and not a list of available shares.
   */
  if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
	return EINVAL;

  if ((r = verify_inode(ino, path, NULL)) != OK)
	return r;

  if ((r = sffs_table->t_queryvol(path, &bfree, &btotal)) != OK)
	return r;

  /* Returning zero for unknown values seems to be the convention. However, we
   * do have to use a nonzero block size, even though it is entirely arbitrary.
   */
  st->f_flag = ST_NOTRUNC;
  st->f_bsize = BLOCK_SIZE;
  st->f_frsize = BLOCK_SIZE;
  st->f_iosize = BLOCK_SIZE;
  st->f_blocks = (fsblkcnt_t)(btotal / BLOCK_SIZE);
  st->f_bfree = (fsblkcnt_t)(bfree / BLOCK_SIZE);
  st->f_bavail = st->f_bfree;
  st->f_namemax = NAME_MAX;

  return OK;
}