2 * <sys/sendfile.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
16 #ifdef HAVE_SYS_STATVFS_H
17 #include <sys/statvfs.h>
18 #endif /* def HAVE_SYS_STATVFS_H */
21 #include <sys/param.h>
22 #include <sys/ucred.h>
23 #include <sys/mount.h>
24 #include <unistd.h> /* for pathconf */
25 #endif /* def HAVE_GETFSSTAT */
29 struct Mono_Posix_Statvfs {
30 guint64 f_bsize; /* file system block size */
31 guint64 f_frsize; /* fragment size */
32 mph_fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
33 mph_fsblkcnt_t f_bfree; /* # free blocks */
34 mph_fsblkcnt_t f_bavail; /* # free blocks for non-root */
35 mph_fsfilcnt_t f_files; /* # inodes */
36 mph_fsfilcnt_t f_ffree; /* # free inodes */
37 mph_fsfilcnt_t f_favail; /* # free inodes for non-root */
38 guint64 f_fsid; /* file system id */
39 guint64 f_flag; /* mount flags */
40 guint64 f_namemax; /* maximum filename length */
43 #ifdef HAVE_SYS_STATVFS_H
45 copy_statvfs (struct Mono_Posix_Statvfs *to, struct statvfs *from)
47 to->f_bsize = from->f_bsize;
48 to->f_frsize = from->f_frsize;
49 to->f_blocks = from->f_blocks;
50 to->f_bfree = from->f_bfree;
51 to->f_bavail = from->f_bavail;
52 to->f_files = from->f_files;
53 to->f_ffree = from->f_ffree;
54 to->f_favail = from->f_favail;
55 to->f_fsid = from->f_fsid;
56 to->f_flag = from->f_flag;
57 to->f_namemax = from->f_namemax;
59 #endif /* ndef HAVE_SYS_STATVFS_H */
62 * System V-compatible definitions
67 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
77 if ((r = statvfs (path, &s)) == 0)
78 copy_statvfs (buf, &s);
82 #endif /* ndef HAVA_STATVFS */
86 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
96 if ((r = fstatvfs (fd, &s)) == 0)
97 copy_statvfs (buf, &s);
101 #endif /* ndef HAVA_FSTATVFS */
104 * BSD-compatible definitions.
106 * Linux also provides these, but are deprecated in favor of (f)statvfs.
109 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
111 copy_statfs (struct Mono_Posix_Statvfs *to, struct statfs *from)
113 to->f_bsize = from->f_bsize;
114 to->f_frsize = from->f_bsize;
115 to->f_blocks = from->f_blocks;
116 to->f_bfree = from->f_bfree;
117 to->f_bavail = from->f_bavail;
118 to->f_files = from->f_files;
119 to->f_ffree = from->f_ffree;
120 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
121 to->f_flag = from->f_flags;
122 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
123 // so this shouldn't lose anything.
124 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
128 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
130 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
134 set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
136 buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
138 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
140 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
142 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
152 if ((r = statfs (path, &s)) == 0) {
153 copy_statfs (buf, &s);
154 set_namemax (path, buf);
159 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
161 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
163 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
173 if ((r = fstatfs (fd, &s)) == 0) {
174 copy_statfs (buf, &s);
175 set_fnamemax (fd, buf);
180 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */