1 /* 2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <sys/statvfs.h> 8 #include <sys/stat.h> 9 10 #include <fs_info.h> 11 12 13 static int 14 fill_statvfs(dev_t device, struct statvfs *statvfs) 15 { 16 fs_info info; 17 if (fs_stat_dev(device, &info) < 0) 18 return -1; 19 20 statvfs->f_frsize = statvfs->f_bsize = info.block_size; 21 statvfs->f_blocks = info.total_blocks; 22 statvfs->f_bavail = statvfs->f_bfree = info.free_blocks; 23 statvfs->f_files = info.total_nodes; 24 statvfs->f_favail = statvfs->f_ffree = info.free_nodes; 25 statvfs->f_fsid = device; 26 statvfs->f_flag = info.flags & B_FS_IS_READONLY ? ST_RDONLY : 0; 27 statvfs->f_namemax = B_FILE_NAME_LENGTH; 28 29 return 0; 30 } 31 32 33 // #pragma mark - 34 35 36 int 37 statvfs(const char *path, struct statvfs *statvfs) 38 { 39 dev_t device = dev_for_path(path); 40 if (device < 0) 41 return -1; 42 43 return fill_statvfs(device, statvfs); 44 } 45 46 47 int 48 fstatvfs(int fd, struct statvfs *statvfs) 49 { 50 struct stat stat; 51 if (fstat(fd, &stat) < 0) 52 return -1; 53 54 return fill_statvfs(stat.st_dev, statvfs); 55 } 56 57