Added statvfs.h header and implemented statvfs() and fstatvfs() - both untested, though.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14746 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-07 13:47:55 +00:00
parent 7a0b14b7ab
commit 6efb3f085f
3 changed files with 98 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ KernelMergeObject posix_sys.o :
rlimit.c
select.c
stat.c
statvfs.c
sysctl.c
times.c
uio.c
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2005, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <fs_info.h>
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);
}