1 /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
2
3 #include "inc.h"
4
5 /*
6 * Get or set file information.
7 */
8 int
vboxfs_getset_info(vboxfs_handle_t handle,u32_t flags,void * data,size_t size)9 vboxfs_getset_info(vboxfs_handle_t handle, u32_t flags, void *data,
10 size_t size)
11 {
12 vbox_param_t param[5];
13
14 vbox_set_u32(¶m[0], vboxfs_root);
15 vbox_set_u64(¶m[1], handle);
16 vbox_set_u32(¶m[2], flags);
17 vbox_set_u32(¶m[3], size);
18 vbox_set_ptr(¶m[4], data, size, VBOX_DIR_INOUT);
19
20 return vbox_call(vboxfs_conn, VBOXFS_CALL_INFO, param, 5, NULL);
21 }
22
23 /*
24 * Query volume information.
25 */
26 int
vboxfs_query_vol(const char * path,vboxfs_volinfo_t * volinfo)27 vboxfs_query_vol(const char *path, vboxfs_volinfo_t *volinfo)
28 {
29 vboxfs_handle_t h;
30 int r;
31
32 if ((r = vboxfs_open_file(path, O_RDONLY, 0, &h, NULL)) != OK)
33 return r;
34
35 r = vboxfs_getset_info(h, VBOXFS_INFO_GET | VBOXFS_INFO_VOLUME,
36 volinfo, sizeof(*volinfo));
37
38 vboxfs_close_file(h);
39
40 return r;
41 }
42
43 /*
44 * Query volume information.
45 */
46 int
vboxfs_queryvol(const char * path,u64_t * free,u64_t * total)47 vboxfs_queryvol(const char *path, u64_t *free, u64_t *total)
48 {
49 vboxfs_volinfo_t volinfo;
50 int r;
51
52 if ((r = vboxfs_query_vol(path, &volinfo)) != OK)
53 return r;
54
55 *free = volinfo.free;
56 *total = volinfo.total;
57 return OK;
58 }
59