csu: restore crt1.o symlink
[minix.git] / lib / libvboxfs / vboxfs.c
blob28f60d6802ca72c1517c941c2b286f4fc29dc25b
1 /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
3 #include "inc.h"
5 vbox_conn_t vboxfs_conn;
6 vboxfs_root_t vboxfs_root;
8 static struct sffs_table vboxfs_table = {
9 .t_open = vboxfs_open,
10 .t_read = vboxfs_read,
11 .t_write = vboxfs_write,
12 .t_close = vboxfs_close,
14 .t_readbuf = vboxfs_buffer,
15 .t_writebuf = vboxfs_buffer,
17 .t_opendir = vboxfs_opendir,
18 .t_readdir = vboxfs_readdir,
19 .t_closedir = vboxfs_closedir,
21 .t_getattr = vboxfs_getattr,
22 .t_setattr = vboxfs_setattr,
24 .t_mkdir = vboxfs_mkdir,
25 .t_unlink = vboxfs_unlink,
26 .t_rmdir = vboxfs_rmdir,
27 .t_rename = vboxfs_rename,
29 .t_queryvol = vboxfs_queryvol
33 * Initialize communication with the VBOX driver, and map the given share.
35 int
36 vboxfs_init(char *share, const struct sffs_table **tablep, int *case_insens,
37 int *read_only)
39 vbox_param_t param[4];
40 vboxfs_path_t path;
41 vboxfs_volinfo_t volinfo;
42 int r;
44 if ((r = vboxfs_set_path(&path, share)) != OK)
45 return r;
47 if ((r = vbox_init()) != OK)
48 return r;
50 if ((vboxfs_conn = r = vbox_open("VBoxSharedFolders")) < 0)
51 return r;
53 r = vbox_call(vboxfs_conn, VBOXFS_CALL_SET_UTF8, NULL, 0, NULL);
54 if (r != OK) {
55 vbox_close(vboxfs_conn);
57 return r;
60 vbox_set_ptr(&param[0], &path, vboxfs_get_path_size(&path),
61 VBOX_DIR_OUT);
62 vbox_set_u32(&param[1], 0);
63 vbox_set_u32(&param[2], '/'); /* path separator */
64 vbox_set_u32(&param[3], TRUE); /* case sensitivity - no effect? */
66 r = vbox_call(vboxfs_conn, VBOXFS_CALL_MAP_FOLDER, param, 4, NULL);
67 if (r != OK) {
68 vbox_close(vboxfs_conn);
70 return r;
73 vboxfs_root = vbox_get_u32(&param[1]);
75 /* Gather extra information about the mapped shared. */
76 if (vboxfs_query_vol("", &volinfo) == OK) {
77 *case_insens = !volinfo.props.casesens;
78 *read_only = !!volinfo.props.readonly;
81 *tablep = &vboxfs_table;
82 return OK;
86 * Unmap the share, and disconnect from the VBOX driver.
88 void
89 vboxfs_cleanup(void)
91 vbox_param_t param[1];
93 vbox_set_u32(&param[0], vboxfs_root);
95 vbox_call(vboxfs_conn, VBOXFS_CALL_UNMAP_FOLDER, param, 1, NULL);
97 vbox_close(vboxfs_conn);