add opendir alias
[minix.git] / lib / libvboxfs / link.c
blobb525d3d6e25f42d4e34e4d8ef850ffd2af352786
1 /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
3 #include "inc.h"
5 /*
6 * Create a directory.
7 */
8 int
9 vboxfs_mkdir(char *path, int mode)
11 vboxfs_handle_t h;
12 int r;
14 assert(S_ISDIR(mode));
16 if ((r = vboxfs_open_file(path, O_CREAT | O_EXCL | O_WRONLY, mode, &h,
17 NULL)) != OK)
18 return r;
20 vboxfs_close_file(h);
22 return r;
26 * Remove a file or directory.
28 static int
29 remove_file(char *path, int dir)
31 vbox_param_t param[3];
32 vboxfs_path_t pathbuf;
33 int r;
35 if ((r = vboxfs_set_path(&pathbuf, path)) != OK)
36 return r;
38 /* FIXME: symbolic links are not supported at all yet */
39 vbox_set_u32(&param[0], vboxfs_root);
40 vbox_set_ptr(&param[1], &pathbuf, vboxfs_get_path_size(&pathbuf),
41 VBOX_DIR_OUT);
42 vbox_set_u32(&param[2], dir ? VBOXFS_REMOVE_DIR : VBOXFS_REMOVE_FILE);
44 return vbox_call(vboxfs_conn, VBOXFS_CALL_REMOVE, param, 3, NULL);
48 * Unlink a file.
50 int
51 vboxfs_unlink(char *path)
54 return remove_file(path, FALSE /*dir*/);
58 * Remove a directory.
60 int
61 vboxfs_rmdir(char *path)
64 return remove_file(path, TRUE /*dir*/);
68 * Rename a file or directory.
70 static int
71 rename_file(char *opath, char *npath, int dir)
73 vbox_param_t param[4];
74 vboxfs_path_t opathbuf, npathbuf;
75 u32_t flags;
76 int r;
78 if ((r = vboxfs_set_path(&opathbuf, opath)) != OK)
79 return r;
81 if ((r = vboxfs_set_path(&npathbuf, npath)) != OK)
82 return r;
84 flags = dir ? VBOXFS_RENAME_DIR : VBOXFS_RENAME_FILE;
85 flags |= VBOXFS_RENAME_REPLACE;
87 vbox_set_u32(&param[0], vboxfs_root);
88 vbox_set_ptr(&param[1], &opathbuf, vboxfs_get_path_size(&opathbuf),
89 VBOX_DIR_OUT);
90 vbox_set_ptr(&param[2], &npathbuf, vboxfs_get_path_size(&npathbuf),
91 VBOX_DIR_OUT);
92 vbox_set_u32(&param[3], flags);
94 return vbox_call(vboxfs_conn, VBOXFS_CALL_RENAME, param, 4, NULL);
98 * Rename a file or directory.
101 vboxfs_rename(char *opath, char *npath)
103 int r;
105 if ((r = rename_file(opath, npath, FALSE /*dir*/)) != EISDIR)
106 return r;
108 return rename_file(opath, npath, TRUE /*dir*/);