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:
parent
7a0b14b7ab
commit
6efb3f085f
41
headers/posix/sys/statvfs.h
Normal file
41
headers/posix/sys/statvfs.h
Normal file
@ -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 <sys/types.h>
|
||||
|
||||
|
||||
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_ */
|
@ -10,6 +10,7 @@ KernelMergeObject posix_sys.o :
|
||||
rlimit.c
|
||||
select.c
|
||||
stat.c
|
||||
statvfs.c
|
||||
sysctl.c
|
||||
times.c
|
||||
uio.c
|
||||
|
56
src/system/libroot/posix/sys/statvfs.c
Normal file
56
src/system/libroot/posix/sys/statvfs.c
Normal file
@ -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 <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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user