Repository navigation
Expand file tree
/
Copy pathmisc.c
More file actions
80 lines (68 loc) · 2.38 KB
/
Copy pathmisc.c
File metadata and controls
80 lines (68 loc) · 2.38 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This file contains miscellaneous file system call handlers.
*
* The entry points into this file are:
* do_fstatfs perform the FSTATFS file system call
* do_statvfs perform the STATVFS file system call
*
* Created:
* April 2009 (D.C. van Moolenbroek)
*/
#include "inc.h"
#include <sys/statfs.h>
#include <sys/statvfs.h>
/*===========================================================================*
* do_fstatfs *
*===========================================================================*/
PUBLIC int do_fstatfs()
{
/* Retrieve file system statistics.
*/
struct statfs statfs;
statfs.f_bsize = BLOCK_SIZE; /* arbitrary block size constant */
return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0,
(vir_bytes) &statfs, sizeof(statfs), D);
}
/*===========================================================================*
* do_statvfs *
*===========================================================================*/
PUBLIC int do_statvfs()
{
/* Retrieve file system statistics.
*/
struct statvfs statvfs;
struct inode *ino;
char path[PATH_MAX];
u64_t free, total;
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 using the "prefix=" option when mounting.
*/
if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_inode(ino, path, NULL)) != OK)
return r;
/* It appears that this call always fails with EACCES ("permission denied")
* on read-only folders. As far as I can tell, this is a VMware bug.
*/
if ((r = hgfs_queryvol(path, &free, &total)) != OK)
return r;
memset(&statvfs, 0, sizeof(statvfs));
/* 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.
*/
statvfs.f_bsize = BLOCK_SIZE;
statvfs.f_frsize = BLOCK_SIZE;
statvfs.f_blocks = div64u(total, BLOCK_SIZE);
statvfs.f_bfree = div64u(free, BLOCK_SIZE);
statvfs.f_bavail = statvfs.f_bfree;
statvfs.f_files = 0;
statvfs.f_ffree = 0;
statvfs.f_favail = 0;
statvfs.f_fsid = state.dev;
statvfs.f_flag = state.read_only ? ST_RDONLY : 0;
statvfs.f_flag |= ST_NOTRUNC;
statvfs.f_namemax = NAME_MAX;
return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0,
(vir_bytes) &statvfs, sizeof(statvfs), D);
}