2010-01-26 00:18:02 +01:00
|
|
|
/* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
|
|
|
|
|
|
|
|
#include "inc.h"
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* attr_get *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void attr_get(attr)
|
2012-04-09 18:08:26 +02:00
|
|
|
struct sffs_attr *attr;
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Get attribute information from the RPC buffer, storing the requested parts
|
|
|
|
* in the given attr structure.
|
|
|
|
*/
|
|
|
|
mode_t mode;
|
|
|
|
u32_t size_lo, size_hi;
|
|
|
|
|
|
|
|
mode = (RPC_NEXT32) ? S_IFDIR : S_IFREG;
|
|
|
|
|
|
|
|
size_lo = RPC_NEXT32;
|
|
|
|
size_hi = RPC_NEXT32;
|
2012-04-09 18:08:26 +02:00
|
|
|
if (attr->a_mask & SFFS_ATTR_SIZE)
|
2010-01-26 00:18:02 +01:00
|
|
|
attr->a_size = make64(size_lo, size_hi);
|
|
|
|
|
2012-04-09 18:08:26 +02:00
|
|
|
time_get((attr->a_mask & SFFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
|
|
|
|
time_get((attr->a_mask & SFFS_ATTR_ATIME) ? &attr->a_atime : NULL);
|
|
|
|
time_get((attr->a_mask & SFFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
|
|
|
|
time_get((attr->a_mask & SFFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
|
2010-01-26 00:18:02 +01:00
|
|
|
|
|
|
|
mode |= HGFS_PERM_TO_MODE(RPC_NEXT8);
|
2012-04-09 18:08:26 +02:00
|
|
|
if (attr->a_mask & SFFS_ATTR_MODE) attr->a_mode = mode;
|
2010-01-26 00:18:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* hgfs_getattr *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int hgfs_getattr(path, attr)
|
2010-01-26 00:18:02 +01:00
|
|
|
char *path;
|
2012-04-09 18:08:26 +02:00
|
|
|
struct sffs_attr *attr;
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Get selected attributes of a file by path name.
|
|
|
|
*/
|
|
|
|
int r;
|
|
|
|
|
|
|
|
RPC_REQUEST(HGFS_REQ_GETATTR);
|
|
|
|
|
|
|
|
path_put(path);
|
|
|
|
|
|
|
|
if ((r = rpc_query()) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
attr_get(attr);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* hgfs_setattr *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int hgfs_setattr(path, attr)
|
2010-01-26 00:18:02 +01:00
|
|
|
char *path;
|
2012-04-09 18:08:26 +02:00
|
|
|
struct sffs_attr *attr;
|
2010-01-26 00:18:02 +01:00
|
|
|
{
|
|
|
|
/* Set selected attributes of a file by path name.
|
|
|
|
*/
|
2012-04-09 17:17:42 +02:00
|
|
|
u8_t mask;
|
2010-01-26 00:18:02 +01:00
|
|
|
|
|
|
|
RPC_REQUEST(HGFS_REQ_SETATTR);
|
|
|
|
|
2012-04-09 17:17:42 +02:00
|
|
|
/* This library implements the HGFS v1 protocol, which is largely
|
|
|
|
* path-oriented. This is the only method to set the file size, and thus,
|
|
|
|
* truncating a deleted file is not possible. This has been fixed in later
|
|
|
|
* HGFS protocol version (v2/v3).
|
|
|
|
*/
|
|
|
|
mask = 0;
|
2012-04-09 18:08:26 +02:00
|
|
|
if (attr->a_mask & SFFS_ATTR_MODE) mask |= HGFS_ATTR_MODE;
|
|
|
|
if (attr->a_mask & SFFS_ATTR_SIZE) mask |= HGFS_ATTR_SIZE;
|
|
|
|
if (attr->a_mask & SFFS_ATTR_CRTIME) mask |= HGFS_ATTR_CRTIME;
|
|
|
|
if (attr->a_mask & SFFS_ATTR_ATIME)
|
2012-04-09 17:17:42 +02:00
|
|
|
mask |= HGFS_ATTR_ATIME | HGFS_ATTR_ATIME_SET;
|
2012-04-09 18:08:26 +02:00
|
|
|
if (attr->a_mask & SFFS_ATTR_MTIME)
|
2012-04-09 17:17:42 +02:00
|
|
|
mask |= HGFS_ATTR_MTIME | HGFS_ATTR_MTIME_SET;
|
2012-04-09 18:08:26 +02:00
|
|
|
if (attr->a_mask & SFFS_ATTR_CTIME) mask |= HGFS_ATTR_CTIME;
|
2012-04-09 17:17:42 +02:00
|
|
|
|
|
|
|
RPC_NEXT8 = mask;
|
2010-01-26 00:18:02 +01:00
|
|
|
|
|
|
|
RPC_NEXT32 = !!(S_ISDIR(attr->a_mode));
|
|
|
|
RPC_NEXT32 = ex64lo(attr->a_size);
|
|
|
|
RPC_NEXT32 = ex64hi(attr->a_size);
|
|
|
|
|
|
|
|
time_put((attr->a_mask & HGFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
|
2012-04-09 17:17:42 +02:00
|
|
|
time_put((attr->a_mask & HGFS_ATTR_ATIME) ? &attr->a_atime : NULL);
|
|
|
|
time_put((attr->a_mask & HGFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
|
2010-01-26 00:18:02 +01:00
|
|
|
time_put((attr->a_mask & HGFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
|
|
|
|
|
|
|
|
RPC_NEXT8 = HGFS_MODE_TO_PERM(attr->a_mode);
|
|
|
|
|
|
|
|
path_put(path);
|
|
|
|
|
|
|
|
return rpc_query();
|
|
|
|
}
|