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