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