1 /* VTreeFS - stadir.c - file and file system status management */ 2 3 #include "inc.h" 4 5 /* 6 * Retrieve file status. 7 */ 8 int 9 fs_stat(ino_t ino_nr, struct stat * buf) 10 { 11 char path[PATH_MAX]; 12 time_t cur_time; 13 struct inode *node; 14 int r; 15 16 if ((node = find_inode(ino_nr)) == NULL) 17 return EINVAL; 18 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; 26 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)); 31 32 if (r == OK) 33 buf->st_size = strlen(path); 34 } 35 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; 41 42 return OK; 43 } 44 45 /* 46 * Change file mode. 47 */ 48 int 49 fs_chmod(ino_t ino_nr, mode_t * mode) 50 { 51 struct inode *node; 52 struct inode_stat istat; 53 int r; 54 55 if ((node = find_inode(ino_nr)) == NULL) 56 return EINVAL; 57 58 if (vtreefs_hooks->chstat_hook == NULL) 59 return ENOSYS; 60 61 get_inode_stat(node, &istat); 62 63 istat.mode = (istat.mode & ~ALL_MODES) | (*mode & ALL_MODES); 64 65 r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node)); 66 67 if (r != OK) 68 return r; 69 70 get_inode_stat(node, &istat); 71 72 *mode = istat.mode; 73 74 return OK; 75 } 76 77 /* 78 * Change file ownership. 79 */ 80 int 81 fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t * mode) 82 { 83 struct inode *node; 84 struct inode_stat istat; 85 int r; 86 87 if ((node = find_inode(ino_nr)) == NULL) 88 return EINVAL; 89 90 if (vtreefs_hooks->chstat_hook == NULL) 91 return ENOSYS; 92 93 get_inode_stat(node, &istat); 94 95 istat.uid = uid; 96 istat.gid = gid; 97 istat.mode &= ~(S_ISUID | S_ISGID); 98 99 r = vtreefs_hooks->chstat_hook(node, &istat, get_inode_cbdata(node)); 100 101 if (r != OK) 102 return r; 103 104 get_inode_stat(node, &istat); 105 106 *mode = istat.mode; 107 108 return OK; 109 } 110 111 /* 112 * Retrieve file system statistics. 113 */ 114 int 115 fs_statvfs(struct statvfs * buf) 116 { 117 118 buf->f_flag = ST_NOTRUNC; 119 buf->f_namemax = NAME_MAX; 120 121 return OK; 122 } 123