xref: /minix3/minix/lib/libvboxfs/info.c (revision 94e65446c4f963450ea94b8becc02cec062675cd)
1433d6423SLionel Sambuc /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
2433d6423SLionel Sambuc 
3433d6423SLionel Sambuc #include "inc.h"
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc /*
6433d6423SLionel Sambuc  * Get or set file information.
7433d6423SLionel Sambuc  */
8433d6423SLionel Sambuc int
vboxfs_getset_info(vboxfs_handle_t handle,u32_t flags,void * data,size_t size)9433d6423SLionel Sambuc vboxfs_getset_info(vboxfs_handle_t handle, u32_t flags, void *data,
10433d6423SLionel Sambuc 	size_t size)
11433d6423SLionel Sambuc {
12433d6423SLionel Sambuc 	vbox_param_t param[5];
13433d6423SLionel Sambuc 
14433d6423SLionel Sambuc 	vbox_set_u32(&param[0], vboxfs_root);
15433d6423SLionel Sambuc 	vbox_set_u64(&param[1], handle);
16433d6423SLionel Sambuc 	vbox_set_u32(&param[2], flags);
17433d6423SLionel Sambuc 	vbox_set_u32(&param[3], size);
18433d6423SLionel Sambuc 	vbox_set_ptr(&param[4], data, size, VBOX_DIR_INOUT);
19433d6423SLionel Sambuc 
20433d6423SLionel Sambuc 	return vbox_call(vboxfs_conn, VBOXFS_CALL_INFO, param, 5, NULL);
21433d6423SLionel Sambuc }
22433d6423SLionel Sambuc 
23433d6423SLionel Sambuc /*
24433d6423SLionel Sambuc  * Query volume information.
25433d6423SLionel Sambuc  */
26433d6423SLionel Sambuc int
vboxfs_query_vol(const char * path,vboxfs_volinfo_t * volinfo)27*94e65446SDavid van Moolenbroek vboxfs_query_vol(const char *path, vboxfs_volinfo_t *volinfo)
28433d6423SLionel Sambuc {
29433d6423SLionel Sambuc 	vboxfs_handle_t h;
30433d6423SLionel Sambuc 	int r;
31433d6423SLionel Sambuc 
32433d6423SLionel Sambuc 	if ((r = vboxfs_open_file(path, O_RDONLY, 0, &h, NULL)) != OK)
33433d6423SLionel Sambuc 		return r;
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc 	r = vboxfs_getset_info(h, VBOXFS_INFO_GET | VBOXFS_INFO_VOLUME,
36433d6423SLionel Sambuc 	    volinfo, sizeof(*volinfo));
37433d6423SLionel Sambuc 
38433d6423SLionel Sambuc 	vboxfs_close_file(h);
39433d6423SLionel Sambuc 
40433d6423SLionel Sambuc 	return r;
41433d6423SLionel Sambuc }
42433d6423SLionel Sambuc 
43433d6423SLionel Sambuc /*
44433d6423SLionel Sambuc  * Query volume information.
45433d6423SLionel Sambuc  */
46433d6423SLionel Sambuc int
vboxfs_queryvol(const char * path,u64_t * free,u64_t * total)47*94e65446SDavid van Moolenbroek vboxfs_queryvol(const char *path, u64_t *free, u64_t *total)
48433d6423SLionel Sambuc {
49433d6423SLionel Sambuc 	vboxfs_volinfo_t volinfo;
50433d6423SLionel Sambuc 	int r;
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc 	if ((r = vboxfs_query_vol(path, &volinfo)) != OK)
53433d6423SLionel Sambuc 		return r;
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc 	*free = volinfo.free;
56433d6423SLionel Sambuc 	*total = volinfo.total;
57433d6423SLionel Sambuc 	return OK;
58433d6423SLionel Sambuc }
59