1 /* VTreeFS - stadir.c - by Alen Stojanov and David van Moolenbroek */ 2 3 #include "inc.h" 4 5 #include <time.h> 6 #include <sys/statvfs.h> 7 #include <string.h> 8 9 /*===========================================================================* 10 * fs_stat * 11 *===========================================================================*/ 12 int fs_stat(void) 13 { 14 /* Retrieve file status. 15 */ 16 char path[PATH_MAX]; 17 struct stat statbuf; 18 time_t cur_time; 19 struct inode *node; 20 int r; 21 22 if ((node = find_inode(fs_m_in.m_vfs_fs_stat.inode)) == NULL) 23 return EINVAL; 24 25 memset(&statbuf, 0, sizeof(struct stat)); 26 27 /* Fill in the basic info. */ 28 statbuf.st_dev = fs_dev; 29 statbuf.st_ino = get_inode_number(node); 30 statbuf.st_mode = node->i_stat.mode; 31 statbuf.st_nlink = !is_inode_deleted(node); 32 statbuf.st_uid = node->i_stat.uid; 33 statbuf.st_gid = node->i_stat.gid; 34 statbuf.st_rdev = (dev_t) node->i_stat.dev; 35 statbuf.st_size = node->i_stat.size; 36 37 /* If it is a symbolic link, return the size of the link target. */ 38 if (S_ISLNK(node->i_stat.mode) && vtreefs_hooks->rdlink_hook != NULL) { 39 r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path), 40 get_inode_cbdata(node)); 41 42 if (r == OK) 43 statbuf.st_size = strlen(path); 44 } 45 46 /* Take the current time as file time for all files. */ 47 cur_time = time(NULL); 48 statbuf.st_atime = cur_time; 49 statbuf.st_mtime = cur_time; 50 statbuf.st_ctime = cur_time; 51 52 /* Copy the struct to user space. */ 53 return sys_safecopyto(fs_m_in.m_source, fs_m_in.m_vfs_fs_stat.grant, 0, 54 (vir_bytes) &statbuf, (phys_bytes) sizeof(statbuf)); 55 } 56 57 /*===========================================================================* 58 * fs_statvfs * 59 *===========================================================================*/ 60 int fs_statvfs(void) 61 { 62 /* Retrieve file system statistics. 63 */ 64 struct statvfs statvfs; 65 66 memset(&statvfs, 0, sizeof(statvfs)); 67 68 statvfs.f_flag = ST_NOTRUNC; 69 statvfs.f_namemax = PNAME_MAX; 70 71 return sys_safecopyto(fs_m_in.m_source, fs_m_in.m_vfs_fs_statvfs.grant, 72 0, (vir_bytes) &statvfs, sizeof(statvfs)); 73 } 74