2 * <sys/sendfile.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
17 #ifdef HAVE_SYS_STATVFS_H
18 #include <sys/statvfs.h>
19 #endif /* def HAVE_SYS_STATVFS_H */
22 #include <sys/param.h>
23 #include <sys/ucred.h>
24 #include <sys/mount.h>
25 #include <unistd.h> /* for pathconf */
26 #endif /* def HAVE_GETFSSTAT */
30 struct Mono_Posix_Statvfs {
31 guint64 f_bsize; /* file system block size */
32 guint64 f_frsize; /* fragment size */
33 mph_fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
34 mph_fsblkcnt_t f_bfree; /* # free blocks */
35 mph_fsblkcnt_t f_bavail; /* # free blocks for non-root */
36 mph_fsfilcnt_t f_files; /* # inodes */
37 mph_fsfilcnt_t f_ffree; /* # free inodes */
38 mph_fsfilcnt_t f_favail; /* # free inodes for non-root */
39 guint64 f_fsid; /* file system id */
40 guint64 f_flag; /* mount flags */
41 guint64 f_namemax; /* maximum filename length */
44 #ifdef HAVE_SYS_STATVFS_H
46 copy_statvfs (struct Mono_Posix_Statvfs *to, struct statvfs *from)
48 to->f_bsize = from->f_bsize;
49 to->f_frsize = from->f_frsize;
50 to->f_blocks = from->f_blocks;
51 to->f_bfree = from->f_bfree;
52 to->f_bavail = from->f_bavail;
53 to->f_files = from->f_files;
54 to->f_ffree = from->f_ffree;
55 to->f_favail = from->f_favail;
56 to->f_fsid = from->f_fsid;
57 Mono_Posix_ToMountFlags (from->f_flag, &to->f_flag);
58 to->f_namemax = from->f_namemax;
60 #endif /* ndef HAVE_SYS_STATVFS_H */
63 * System V-compatible definitions
68 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
78 if ((r = statvfs (path, &s)) == 0)
79 copy_statvfs (buf, &s);
83 #endif /* ndef HAVA_STATVFS */
87 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
97 if ((r = fstatvfs (fd, &s)) == 0)
98 copy_statvfs (buf, &s);
102 #endif /* ndef HAVA_FSTATVFS */
105 * BSD-compatible definitions.
107 * Linux also provides these, but are deprecated in favor of (f)statvfs.
110 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
112 copy_statfs (struct Mono_Posix_Statvfs *to, struct statfs *from)
114 to->f_bsize = from->f_bsize;
115 to->f_frsize = from->f_bsize;
116 to->f_blocks = from->f_blocks;
117 to->f_bfree = from->f_bfree;
118 to->f_bavail = from->f_bavail;
119 to->f_files = from->f_files;
120 to->f_ffree = from->f_ffree;
121 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
122 Mono_Posix_ToMountFlags (from->f_flags, &to->f_flag);
123 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
124 // so this shouldn't lose anything.
125 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
129 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
131 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
135 set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
137 buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
139 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
141 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
143 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
153 if ((r = statfs (path, &s)) == 0) {
154 copy_statfs (buf, &s);
155 set_namemax (path, buf);
160 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
162 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
164 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
174 if ((r = fstatfs (fd, &s)) == 0) {
175 copy_statfs (buf, &s);
176 set_fnamemax (fd, buf);
181 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */