Remove building with NOCRYPTO option
[minix.git] / minix / lib / libvtreefs / stadir.c
blob51950ae7b3efc4afbff73fc5135bca6d86028a7c
1 /* VTreeFS - stadir.c - file and file system status management */
3 #include "inc.h"
5 /*
6 * Retrieve file status.
7 */
8 int
9 fs_stat(ino_t ino_nr, struct stat * buf)
11 char path[PATH_MAX];
12 time_t cur_time;
13 struct inode *node;
14 int r;
16 if ((node = find_inode(ino_nr)) == NULL)
17 return EINVAL;
19 /* Fill in the basic info. */
20 buf->st_mode = node->i_stat.mode;
21 buf->st_nlink = !is_inode_deleted(node);
22 buf->st_uid = node->i_stat.uid;
23 buf->st_gid = node->i_stat.gid;
24 buf->st_rdev = (dev_t) node->i_stat.dev;
25 buf->st_size = node->i_stat.size;
27 /* If it is a symbolic link, return the size of the link target. */
28 if (S_ISLNK(node->i_stat.mode) && vtreefs_hooks->rdlink_hook != NULL) {
29 r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
30 get_inode_cbdata(node));
32 if (r == OK)
33 buf->st_size = strlen(path);
36 /* Take the current time as file time for all files. */
37 cur_time = clock_time(NULL);
38 buf->st_atime = cur_time;
39 buf->st_mtime = cur_time;
40 buf->st_ctime = cur_time;
42 return OK;
46 * Change file mode.
48 int
49 fs_chmod(ino_t ino_nr, mode_t * mode)
51 struct inode *node;
52 struct inode_stat istat;
53 int r;
55 if ((node = find_inode(ino_nr)) == NULL)
56 return EINVAL;
58 if (vtreefs_hooks->chstat_hook == NULL)
59 return ENOSYS;
61 get_inode_stat(node, &istat);
63 istat.mode = (istat.mode & ~ALL_MODES) | (*mode & ALL_MODES);
65 r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node));
67 if (r != OK)
68 return r;
70 get_inode_stat(node, &istat);
72 *mode = istat.mode;
74 return OK;
78 * Change file ownership.
80 int
81 fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t * mode)
83 struct inode *node;
84 struct inode_stat istat;
85 int r;
87 if ((node = find_inode(ino_nr)) == NULL)
88 return EINVAL;
90 if (vtreefs_hooks->chstat_hook == NULL)
91 return ENOSYS;
93 get_inode_stat(node, &istat);
95 istat.uid = uid;
96 istat.gid = gid;
97 istat.mode &= ~(S_ISUID | S_ISGID);
99 r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node));
101 if (r != OK)
102 return r;
104 get_inode_stat(node, &istat);
106 *mode = istat.mode;
108 return OK;
112 * Retrieve file system statistics.
115 fs_statvfs(struct statvfs * buf)
118 buf->f_flag = ST_NOTRUNC;
119 buf->f_namemax = NAME_MAX;
121 return OK;