custom message type for VM_INFO
[minix3.git] / lib / libhgfs / dir.c
blob3782b920f5ba51427fb70321cfc53e9700db0a99
1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
3 #include "inc.h"
5 /*===========================================================================*
6 * hgfs_opendir *
7 *===========================================================================*/
8 int hgfs_opendir(char *path, sffs_dir_t *handle)
10 /* Open a directory. Store a directory handle upon success.
12 int r;
14 RPC_REQUEST(HGFS_REQ_OPENDIR);
16 path_put(path);
18 if ((r = rpc_query()) != OK)
19 return r;
21 *handle = (sffs_dir_t)RPC_NEXT32;
23 return OK;
26 /*===========================================================================*
27 * hgfs_readdir *
28 *===========================================================================*/
29 int hgfs_readdir(sffs_dir_t handle, unsigned int index, char *buf,
30 size_t size, struct sffs_attr *attr)
32 /* Read a directory entry from an open directory, using a zero-based index
33 * number. Upon success, the resulting path name is stored in the given buffer
34 * and the given attribute structure is filled selectively as requested. Upon
35 * error, the contents of the path buffer and attribute structure are
36 * undefined. ENOENT is returned upon end of directory.
38 int r;
40 RPC_REQUEST(HGFS_REQ_READDIR);
41 RPC_NEXT32 = (u32_t)handle;
42 RPC_NEXT32 = index;
44 /* EINVAL signifies end of directory. */
45 if ((r = rpc_query()) != OK)
46 return (r == EINVAL) ? ENOENT : OK;
48 attr_get(attr);
50 if ((r = path_get(buf, size)) != OK)
51 return r;
53 /* VMware Player 3 returns an empty name, instead of EINVAL, when reading
54 * from an EOF position right after opening the directory handle. Seems to be
55 * a newly introduced bug..
57 return (!buf[0]) ? ENOENT : OK;
60 /*===========================================================================*
61 * hgfs_closedir *
62 *===========================================================================*/
63 int hgfs_closedir(sffs_dir_t handle)
65 /* Close an open directory.
68 RPC_REQUEST(HGFS_REQ_CLOSEDIR);
69 RPC_NEXT32 = (u32_t)handle;
71 return rpc_query();