filesystem_posix.c (1733B)
1 #include "../filesystem.h" 2 3 #include <errno.h> 4 #include <string.h> 5 #include <sys/statvfs.h> 6 #include <sys/types.h> 7 8 #if !defined(__linux__) || defined(ARUU_FORCE_POSIX) 9 int 10 fs_get_status(const char *path, struct FilesystemStatus *status) 11 { 12 (void)path; 13 memset(status, 0, sizeof(*status)); 14 errno = ENOTSUP; 15 return -1; 16 } 17 18 int 19 fs_get_mounts(struct FilesystemMount **mounts, size_t *count) 20 { 21 *mounts = NULL; 22 *count = 0; 23 errno = ENOTSUP; 24 return -1; 25 } 26 27 void 28 fs_free_mounts(struct FilesystemMount *mounts, size_t count) 29 { 30 (void)mounts; 31 (void)count; 32 } 33 34 /* sys/types.h has them on most systems. without them, the split of 35 * the first unixes: 8 bits each */ 36 unsigned int 37 fs_devmajor(dev_t dev) 38 { 39 #if defined(major) 40 return major(dev); 41 #else 42 return ((unsigned int)dev >> 8) & 0xff; 43 #endif 44 } 45 46 unsigned int 47 fs_devminor(dev_t dev) 48 { 49 #if defined(minor) 50 return minor(dev); 51 #else 52 return (unsigned int)dev & 0xff; 53 #endif 54 } 55 56 dev_t 57 fs_makedev(unsigned int ma, unsigned int mi) 58 { 59 #if defined(makedev) 60 return makedev(ma, mi); 61 #else 62 return (dev_t)((ma & 0xff) << 8 | (mi & 0xff)); 63 #endif 64 } 65 66 /* statvfs is what posix has: no number for the kind of filesystem */ 67 int 68 fs_get_info(const char *path, int fd, struct FilesystemInfo *info) 69 { 70 struct statvfs st; 71 72 if ((path ? statvfs(path, &st) : fstatvfs(fd, &st)) < 0) 73 return -1; 74 info->id = st.f_fsid; 75 info->namelen = st.f_namemax; 76 info->type = 0; 77 info->bsize = st.f_bsize; 78 info->frsize = st.f_frsize; 79 info->blocks = st.f_blocks; 80 info->bfree = st.f_bfree; 81 info->bavail = st.f_bavail; 82 info->files = st.f_files; 83 info->ffree = st.f_ffree; 84 return 0; 85 } 86 87 const char * 88 fs_type_name(long type) 89 { 90 (void)type; 91 return "unknown"; 92 } 93 #endif