2 * <sys/sendfile.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
14 #ifdef HAVE_SYS_STATVFS_H
15 #include <sys/statvfs.h>
16 #endif /* def HAVE_SYS_STATVFS_H */
19 #include <sys/param.h>
20 #include <sys/ucred.h>
21 #include <sys/mount.h>
22 #include <unistd.h> /* for pathconf */
23 #endif /* def HAVE_GETFSSTAT */
27 struct Mono_Posix_Statvfs {
28 guint64 f_bsize; /* file system block size */
29 guint64 f_frsize; /* fragment size */
30 mph_fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
31 mph_fsblkcnt_t f_bfree; /* # free blocks */
32 mph_fsblkcnt_t f_bavail; /* # free blocks for non-root */
33 mph_fsfilcnt_t f_files; /* # inodes */
34 mph_fsfilcnt_t f_ffree; /* # free inodes */
35 mph_fsfilcnt_t f_favail; /* # free inodes for non-root */
36 guint64 f_fsid; /* file system id */
37 guint64 f_flag; /* mount flags */
38 guint64 f_namemax; /* maximum filename length */
41 #ifdef HAVE_SYS_STATVFS_H
43 copy_statvfs (struct Mono_Posix_Statvfs *to, struct statvfs *from)
45 to->f_bsize = from->f_bsize;
46 to->f_frsize = from->f_frsize;
47 to->f_blocks = from->f_blocks;
48 to->f_bfree = from->f_bfree;
49 to->f_bavail = from->f_bavail;
50 to->f_files = from->f_files;
51 to->f_ffree = from->f_ffree;
52 to->f_favail = from->f_favail;
53 to->f_fsid = from->f_fsid;
54 to->f_flag = from->f_flag;
55 to->f_namemax = from->f_namemax;
57 #endif /* ndef HAVE_SYS_STATVFS_H */
60 * System V-compatible definitions
65 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
75 if ((r = statvfs (path, &s)) == 0)
76 copy_statvfs (buf, &s);
80 #endif /* ndef HAVA_STATVFS */
84 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
94 if ((r = fstatvfs (fd, &s)) == 0)
95 copy_statvfs (buf, &s);
99 #endif /* ndef HAVA_FSTATVFS */
102 * BSD-compatible definitions.
104 * Linux also provides these, but are deprecated in favor of (f)statvfs.
107 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
109 copy_statfs (struct Mono_Posix_Statvfs *to, struct statfs *from)
111 to->f_bsize = from->f_bsize;
112 to->f_frsize = from->f_frsize;
113 to->f_blocks = from->f_blocks;
114 to->f_bfree = from->f_bfree;
115 to->f_bavail = from->f_bavail;
116 to->f_files = from->f_files;
117 to->f_ffree = from->f_ffree;
118 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
119 to->f_fsid = from->f_fsid;
120 to->f_flag = from->f_flags;
124 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
126 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
128 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
130 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
132 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
142 if ((r = statfs (path, &s)) == 0) {
143 copy_statfs (buf, &s);
144 set_namemax (path, buf);
149 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
151 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
153 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
163 if ((r = fstatfs (fd, &s)) == 0) {
164 copy_statvfs (buf, &s);
165 set_namemax (path, buf);
170 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */