1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
7 /*===========================================================================*
9 *===========================================================================*/
11 struct sffs_attr
*attr
;
13 /* Get attribute information from the RPC buffer, storing the requested parts
14 * in the given attr structure.
17 u32_t size_lo
, size_hi
;
19 mode
= (RPC_NEXT32
) ? S_IFDIR
: S_IFREG
;
23 if (attr
->a_mask
& SFFS_ATTR_SIZE
)
24 attr
->a_size
= make64(size_lo
, size_hi
);
26 time_get((attr
->a_mask
& SFFS_ATTR_CRTIME
) ? &attr
->a_crtime
: NULL
);
27 time_get((attr
->a_mask
& SFFS_ATTR_ATIME
) ? &attr
->a_atime
: NULL
);
28 time_get((attr
->a_mask
& SFFS_ATTR_MTIME
) ? &attr
->a_mtime
: NULL
);
29 time_get((attr
->a_mask
& SFFS_ATTR_CTIME
) ? &attr
->a_ctime
: NULL
);
31 mode
|= HGFS_PERM_TO_MODE(RPC_NEXT8
);
32 if (attr
->a_mask
& SFFS_ATTR_MODE
) attr
->a_mode
= mode
;
35 /*===========================================================================*
37 *===========================================================================*/
38 int hgfs_getattr(path
, attr
)
40 struct sffs_attr
*attr
;
42 /* Get selected attributes of a file by path name.
46 RPC_REQUEST(HGFS_REQ_GETATTR
);
50 if ((r
= rpc_query()) != OK
)
58 /*===========================================================================*
60 *===========================================================================*/
61 int hgfs_setattr(path
, attr
)
63 struct sffs_attr
*attr
;
65 /* Set selected attributes of a file by path name.
69 RPC_REQUEST(HGFS_REQ_SETATTR
);
71 /* This library implements the HGFS v1 protocol, which is largely
72 * path-oriented. This is the only method to set the file size, and thus,
73 * truncating a deleted file is not possible. This has been fixed in later
74 * HGFS protocol version (v2/v3).
77 if (attr
->a_mask
& SFFS_ATTR_MODE
) mask
|= HGFS_ATTR_MODE
;
78 if (attr
->a_mask
& SFFS_ATTR_SIZE
) mask
|= HGFS_ATTR_SIZE
;
79 if (attr
->a_mask
& SFFS_ATTR_CRTIME
) mask
|= HGFS_ATTR_CRTIME
;
80 if (attr
->a_mask
& SFFS_ATTR_ATIME
)
81 mask
|= HGFS_ATTR_ATIME
| HGFS_ATTR_ATIME_SET
;
82 if (attr
->a_mask
& SFFS_ATTR_MTIME
)
83 mask
|= HGFS_ATTR_MTIME
| HGFS_ATTR_MTIME_SET
;
84 if (attr
->a_mask
& SFFS_ATTR_CTIME
) mask
|= HGFS_ATTR_CTIME
;
88 RPC_NEXT32
= !!(S_ISDIR(attr
->a_mode
));
89 RPC_NEXT32
= ex64lo(attr
->a_size
);
90 RPC_NEXT32
= ex64hi(attr
->a_size
);
92 time_put((attr
->a_mask
& HGFS_ATTR_CRTIME
) ? &attr
->a_crtime
: NULL
);
93 time_put((attr
->a_mask
& HGFS_ATTR_ATIME
) ? &attr
->a_atime
: NULL
);
94 time_put((attr
->a_mask
& HGFS_ATTR_MTIME
) ? &attr
->a_mtime
: NULL
);
95 time_put((attr
->a_mask
& HGFS_ATTR_CTIME
) ? &attr
->a_ctime
: NULL
);
97 RPC_NEXT8
= HGFS_MODE_TO_PERM(attr
->a_mode
);