patch(1) problems workaround
[minix3.git] / lib / libhgfs / attr.c
blobd87fb6084758d731e506e7391dbc18bddee87c4d
1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
3 #include "inc.h"
5 #include <sys/stat.h>
7 /*===========================================================================*
8 * attr_get *
9 *===========================================================================*/
10 void attr_get(struct sffs_attr *attr)
12 /* Get attribute information from the RPC buffer, storing the requested parts
13 * in the given attr structure.
15 mode_t mode;
16 u32_t size_lo, size_hi;
18 mode = (RPC_NEXT32) ? S_IFDIR : S_IFREG;
20 size_lo = RPC_NEXT32;
21 size_hi = RPC_NEXT32;
22 if (attr->a_mask & SFFS_ATTR_SIZE)
23 attr->a_size = make64(size_lo, size_hi);
25 time_get((attr->a_mask & SFFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
26 time_get((attr->a_mask & SFFS_ATTR_ATIME) ? &attr->a_atime : NULL);
27 time_get((attr->a_mask & SFFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
28 time_get((attr->a_mask & SFFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
30 mode |= HGFS_PERM_TO_MODE(RPC_NEXT8);
31 if (attr->a_mask & SFFS_ATTR_MODE) attr->a_mode = mode;
34 /*===========================================================================*
35 * hgfs_getattr *
36 *===========================================================================*/
37 int hgfs_getattr(char *path, struct sffs_attr *attr)
39 /* Get selected attributes of a file by path name.
41 int r;
43 RPC_REQUEST(HGFS_REQ_GETATTR);
45 path_put(path);
47 if ((r = rpc_query()) != OK)
48 return r;
50 attr_get(attr);
52 return OK;
55 /*===========================================================================*
56 * hgfs_setattr *
57 *===========================================================================*/
58 int hgfs_setattr(char *path, struct sffs_attr *attr)
60 /* Set selected attributes of a file by path name.
62 u8_t mask;
64 RPC_REQUEST(HGFS_REQ_SETATTR);
66 /* This library implements the HGFS v1 protocol, which is largely
67 * path-oriented. This is the only method to set the file size, and thus,
68 * truncating a deleted file is not possible. This has been fixed in later
69 * HGFS protocol version (v2/v3).
71 mask = 0;
72 if (attr->a_mask & SFFS_ATTR_MODE) mask |= HGFS_ATTR_MODE;
73 if (attr->a_mask & SFFS_ATTR_SIZE) mask |= HGFS_ATTR_SIZE;
74 if (attr->a_mask & SFFS_ATTR_CRTIME) mask |= HGFS_ATTR_CRTIME;
75 if (attr->a_mask & SFFS_ATTR_ATIME)
76 mask |= HGFS_ATTR_ATIME | HGFS_ATTR_ATIME_SET;
77 if (attr->a_mask & SFFS_ATTR_MTIME)
78 mask |= HGFS_ATTR_MTIME | HGFS_ATTR_MTIME_SET;
79 if (attr->a_mask & SFFS_ATTR_CTIME) mask |= HGFS_ATTR_CTIME;
81 RPC_NEXT8 = mask;
83 RPC_NEXT32 = !!(S_ISDIR(attr->a_mode));
84 RPC_NEXT32 = ex64lo(attr->a_size);
85 RPC_NEXT32 = ex64hi(attr->a_size);
87 time_put((attr->a_mask & HGFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
88 time_put((attr->a_mask & HGFS_ATTR_ATIME) ? &attr->a_atime : NULL);
89 time_put((attr->a_mask & HGFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
90 time_put((attr->a_mask & HGFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
92 RPC_NEXT8 = HGFS_MODE_TO_PERM(attr->a_mode);
94 path_put(path);
96 return rpc_query();