diff --git a/headers/posix/sys/statvfs.h b/headers/posix/sys/statvfs.h new file mode 100644 index 0000000000..542add1bdd --- /dev/null +++ b/headers/posix/sys/statvfs.h @@ -0,0 +1,41 @@ +/* + * Copyright 2005, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _STAT_VFS_H_ +#define _STAT_VFS_H_ + + +#include + + +struct statvfs { + unsigned long f_bsize; /* block size */ + unsigned long f_frsize; /* fundamental block size */ + fsblkcnt_t f_blocks; /* number of blocks on file system in units of f_frsize */ + fsblkcnt_t f_bfree; /* number of free blocks */ + fsblkcnt_t f_bavail; /* number of free blocks available to processes */ + fsfilcnt_t f_files; /* number of file serial numbers */ + fsfilcnt_t f_ffree; /* number of free file serial numbers */ + fsfilcnt_t f_favail; /* number of file serial numbers available to processes */ + unsigned long f_fsid; /* file system ID */ + unsigned long f_flag; /* see below */ + unsigned long f_namemax; /* maximum file name length */ +}; + +#define ST_RDONLY 1 +#define ST_NOSUID 2 + + +#ifdef __cplusplus +extern "C" { +#endif + +int statvfs(const char *path, struct statvfs *statvfs); +int fstatvfs(int fd, struct statvfs *statvfs); + +#ifdef __cplusplus +} +#endif + +#endif /* _STAT_VFS_H_ */ diff --git a/src/system/libroot/posix/sys/Jamfile b/src/system/libroot/posix/sys/Jamfile index 71d5e19930..cf7bb055de 100644 --- a/src/system/libroot/posix/sys/Jamfile +++ b/src/system/libroot/posix/sys/Jamfile @@ -10,6 +10,7 @@ KernelMergeObject posix_sys.o : rlimit.c select.c stat.c + statvfs.c sysctl.c times.c uio.c diff --git a/src/system/libroot/posix/sys/statvfs.c b/src/system/libroot/posix/sys/statvfs.c new file mode 100644 index 0000000000..695363fe3b --- /dev/null +++ b/src/system/libroot/posix/sys/statvfs.c @@ -0,0 +1,56 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include + +#include + + +static int +fill_statvfs(dev_t device, struct statvfs *statvfs) +{ + fs_info info; + if (fs_stat_dev(device, &info) < 0) + return -1; + + statvfs->f_frsize = statvfs->f_bsize = info.block_size; + statvfs->f_blocks = info.total_blocks; + statvfs->f_bavail = statvfs->f_bfree = info.free_blocks; + statvfs->f_files = info.total_nodes; + statvfs->f_favail = statvfs->f_ffree = info.free_nodes; + statvfs->f_fsid = device; + statvfs->f_flag = info.flags & B_FS_IS_READONLY ? ST_RDONLY : 0; + statvfs->f_namemax = B_FILE_NAME_LENGTH; + + return 0; +} + + +// #pragma mark - + + +int +statvfs(const char *path, struct statvfs *statvfs) +{ + dev_t device = dev_for_path(path); + if (device < 0) + return -1; + + return fill_statvfs(device, statvfs); +} + + +int +fstatvfs(int fd, struct statvfs *statvfs) +{ + struct stat stat; + if (fstat(fd, &stat) < 0) + return -1; + + return fill_statvfs(stat.st_dev, statvfs); +} +