kernel debug: priv can be NULL early on
[minix.git] / lib / libhgfs / attr.c
blob4814c7b40fec7d23ff1a4fe7c4c3695c1932199e
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(attr)
11 struct sffs_attr *attr;
13 /* Get attribute information from the RPC buffer, storing the requested parts
14 * in the given attr structure.
16 mode_t mode;
17 u32_t size_lo, size_hi;
19 mode = (RPC_NEXT32) ? S_IFDIR : S_IFREG;
21 size_lo = RPC_NEXT32;
22 size_hi = RPC_NEXT32;
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 /*===========================================================================*
36 * hgfs_getattr *
37 *===========================================================================*/
38 int hgfs_getattr(path, attr)
39 char *path;
40 struct sffs_attr *attr;
42 /* Get selected attributes of a file by path name.
44 int r;
46 RPC_REQUEST(HGFS_REQ_GETATTR);
48 path_put(path);
50 if ((r = rpc_query()) != OK)
51 return r;
53 attr_get(attr);
55 return OK;
58 /*===========================================================================*
59 * hgfs_setattr *
60 *===========================================================================*/
61 int hgfs_setattr(path, attr)
62 char *path;
63 struct sffs_attr *attr;
65 /* Set selected attributes of a file by path name.
67 u8_t mask;
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).
76 mask = 0;
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;
86 RPC_NEXT8 = mask;
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);
99 path_put(path);
101 return rpc_query();