1 /* Created (MFS based): 2 * February 2010 (Evgeniy Ivanov) 3 */ 4 5 #include "fs.h" 6 #include <string.h> 7 #include <sys/stat.h> 8 #include <sys/statvfs.h> 9 #include "inode.h" 10 #include "super.h" 11 12 13 /*===========================================================================* 14 * fs_stat * 15 *===========================================================================*/ 16 int fs_stat(ino_t ino_nr, struct stat *statbuf) 17 { 18 struct inode *rip; 19 mode_t mo; 20 int s; 21 22 if ((rip = get_inode(fs_dev, ino_nr)) == NULL) 23 return(EINVAL); 24 25 /* Update the atime, ctime, and mtime fields in the inode, if need be. */ 26 if (rip->i_update) update_times(rip); 27 28 /* Fill in the statbuf struct. */ 29 mo = rip->i_mode & I_TYPE; 30 31 /* true iff special */ 32 s = (mo == I_CHAR_SPECIAL || mo == I_BLOCK_SPECIAL); 33 34 statbuf->st_dev = rip->i_dev; 35 statbuf->st_ino = rip->i_num; 36 statbuf->st_mode = rip->i_mode; 37 statbuf->st_nlink = rip->i_links_count; 38 statbuf->st_uid = rip->i_uid; 39 statbuf->st_gid = rip->i_gid; 40 statbuf->st_rdev = (s ? (dev_t)rip->i_block[0] : NO_DEV); 41 statbuf->st_size = rip->i_size; 42 statbuf->st_atime = rip->i_atime; 43 statbuf->st_mtime = rip->i_mtime; 44 statbuf->st_ctime = rip->i_ctime; 45 statbuf->st_blksize = rip->i_sp->s_block_size; 46 statbuf->st_blocks = rip->i_blocks; 47 48 put_inode(rip); /* release the inode */ 49 50 return(OK); 51 } 52 53 /*===========================================================================* 54 * fs_statvfs * 55 *===========================================================================*/ 56 int fs_statvfs(struct statvfs *st) 57 { 58 struct super_block *sp; 59 60 sp = get_super(fs_dev); 61 62 st->f_flag = ST_NOTRUNC; 63 st->f_bsize = sp->s_block_size; 64 st->f_frsize = sp->s_block_size; 65 st->f_iosize = sp->s_block_size; 66 st->f_blocks = sp->s_blocks_count; 67 st->f_bfree = sp->s_free_blocks_count; 68 st->f_bavail = sp->s_free_blocks_count - sp->s_r_blocks_count; 69 st->f_files = sp->s_inodes_count; 70 st->f_ffree = sp->s_free_inodes_count; 71 st->f_favail = sp->s_free_inodes_count; 72 st->f_namemax = EXT2_NAME_MAX; 73 74 return(OK); 75 } 76 77 /*===========================================================================* 78 * blockstats * 79 *===========================================================================*/ 80 void fs_blockstats(u64_t *blocks, u64_t *free, u64_t *used) 81 { 82 struct super_block *sp = get_super(fs_dev); 83 84 *blocks = sp->s_blocks_count; 85 *free = sp->s_free_blocks_count; 86 *used = *blocks - *free; 87 } 88 89