1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
37 #if _lib_statfs && _mem_f_files_statfs && ( _sys_statfs || _sys_vfs || _sys_mount )
40 #include <sys/statfs.h>
47 #include <sys/param.h> /* expect some macro redefinitions here */
49 #include <sys/mount.h>
55 #define FSTATFS(a,b) fstatfs(a,b,sizeof(struct statfs),0)
56 #define STATFS(a,b) statfs(a,b,sizeof(struct statfs),0)
58 #define FSTATFS(a,b) fstatfs(a,b)
59 #define STATFS(a,b) statfs(a,b)
62 #if defined(__EXPORT__)
63 #define extern __EXPORT__
67 us2v(register struct statfs
* ufs
, register struct stat
* st
, register struct statvfs
* vfs
)
69 memset(vfs
, 0, sizeof(*vfs
));
70 vfs
->f_bsize
= vfs
->f_frsize
= ufs
->f_bsize
;
71 vfs
->f_blocks
= ufs
->f_blocks
;
72 vfs
->f_bfree
= ufs
->f_bfree
;
74 #if _mem_f_bavail_statfs
79 vfs
->f_files
= ufs
->f_files
;
80 vfs
->f_ffree
= ufs
->f_ffree
;
81 vfs
->f_favail
= (ufs
->f_ffree
> 10) ? (ufs
->f_ffree
- 10) : 0;
82 vfs
->f_fsid
= st
->st_dev
;
83 strncpy(vfs
->f_basetype
, FS_default
, sizeof(vfs
->f_basetype
) - 1);
85 strncpy(vfs
->f_fstr
, vfs
->f_basetype
, sizeof(vfs
->f_fstr
) - 1);
89 fstatvfs(int fd
, struct statvfs
* vfs
)
94 if (FSTATFS(fd
, &ufs
) || fstat(fd
, &st
))
101 statvfs(const char* path
, struct statvfs
* vfs
)
106 if (STATFS(path
, &ufs
) || stat(path
, &st
))
108 us2v(&ufs
, &st
, vfs
);
114 #if defined(__EXPORT__)
115 #define extern __EXPORT__
119 s2v(register struct stat
* st
, register struct statvfs
* vfs
)
121 memset(vfs
, 0, sizeof(*vfs
));
122 vfs
->f_bsize
= vfs
->f_frsize
=
123 #if _mem_st_blksize_stat
133 vfs
->f_fsid
= st
->st_dev
;
134 strncpy(vfs
->f_basetype
, FS_default
, sizeof(vfs
->f_basetype
) - 1);
136 strncpy(vfs
->f_fstr
, vfs
->f_basetype
, sizeof(vfs
->f_fstr
) - 1);
140 fstatvfs(int fd
, struct statvfs
* vfs
)
151 statvfs(const char* path
, struct statvfs
* vfs
)