2010-01-26 00:18:02 +01:00
|
|
|
/* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
|
|
|
|
|
|
|
|
#include "inc.h"
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* hgfs_opendir *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int hgfs_opendir(char *path, sffs_dir_t *handle)
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Open a directory. Store a directory handle upon success.
|
|
|
|
*/
|
|
|
|
int r;
|
|
|
|
|
|
|
|
RPC_REQUEST(HGFS_REQ_OPENDIR);
|
|
|
|
|
|
|
|
path_put(path);
|
|
|
|
|
|
|
|
if ((r = rpc_query()) != OK)
|
|
|
|
return r;
|
|
|
|
|
2012-04-09 18:08:26 +02:00
|
|
|
*handle = (sffs_dir_t)RPC_NEXT32;
|
2010-01-26 00:18:02 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* hgfs_readdir *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int hgfs_readdir(sffs_dir_t handle, unsigned int index, char *buf,
|
|
|
|
size_t size, struct sffs_attr *attr)
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Read a directory entry from an open directory, using a zero-based index
|
|
|
|
* number. Upon success, the resulting path name is stored in the given buffer
|
|
|
|
* and the given attribute structure is filled selectively as requested. Upon
|
|
|
|
* error, the contents of the path buffer and attribute structure are
|
2012-04-09 17:17:42 +02:00
|
|
|
* undefined. ENOENT is returned upon end of directory.
|
2010-01-26 00:18:02 +01:00
|
|
|
*/
|
|
|
|
int r;
|
|
|
|
|
|
|
|
RPC_REQUEST(HGFS_REQ_READDIR);
|
|
|
|
RPC_NEXT32 = (u32_t)handle;
|
|
|
|
RPC_NEXT32 = index;
|
|
|
|
|
2012-04-09 17:17:42 +02:00
|
|
|
/* EINVAL signifies end of directory. */
|
2010-01-26 00:18:02 +01:00
|
|
|
if ((r = rpc_query()) != OK)
|
2012-04-09 17:17:42 +02:00
|
|
|
return (r == EINVAL) ? ENOENT : OK;
|
2010-01-26 00:18:02 +01:00
|
|
|
|
|
|
|
attr_get(attr);
|
|
|
|
|
2012-04-09 17:17:42 +02:00
|
|
|
if ((r = path_get(buf, size)) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* VMware Player 3 returns an empty name, instead of EINVAL, when reading
|
|
|
|
* from an EOF position right after opening the directory handle. Seems to be
|
|
|
|
* a newly introduced bug..
|
|
|
|
*/
|
|
|
|
return (!buf[0]) ? ENOENT : OK;
|
2010-01-26 00:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* hgfs_closedir *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int hgfs_closedir(sffs_dir_t handle)
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Close an open directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
RPC_REQUEST(HGFS_REQ_CLOSEDIR);
|
|
|
|
RPC_NEXT32 = (u32_t)handle;
|
|
|
|
|
|
|
|
return rpc_query();
|
|
|
|
}
|