1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
5 /*===========================================================================*
7 *===========================================================================*/
8 int hgfs_opendir(char *path
, sffs_dir_t
*handle
)
10 /* Open a directory. Store a directory handle upon success.
14 RPC_REQUEST(HGFS_REQ_OPENDIR
);
18 if ((r
= rpc_query()) != OK
)
21 *handle
= (sffs_dir_t
)RPC_NEXT32
;
26 /*===========================================================================*
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.
40 RPC_REQUEST(HGFS_REQ_READDIR
);
41 RPC_NEXT32
= (u32_t
)handle
;
44 /* EINVAL signifies end of directory. */
45 if ((r
= rpc_query()) != OK
)
46 return (r
== EINVAL
) ? ENOENT
: OK
;
50 if ((r
= path_get(buf
, size
)) != OK
)
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 /*===========================================================================*
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
;