2 * <sys/sendfile.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
17 #ifdef HAVE_PATHCONF_H
21 #ifdef HAVE_SYS_STATVFS_H
22 #include <sys/statvfs.h>
23 #elif defined (HAVE_STATFS) || defined (HAVE_FSTATFS)
25 #endif /* def HAVE_SYS_STATVFS_H */
28 #include <sys/param.h>
29 #include <sys/ucred.h>
30 #include <sys/mount.h>
31 #include <unistd.h> /* for pathconf */
32 #endif /* def HAVE_GETFSSTAT */
36 #ifdef HAVE_SYS_STATVFS_H
38 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
40 struct statvfs *from = _from;
42 to->f_bsize = from->f_bsize;
43 to->f_frsize = from->f_frsize;
44 to->f_blocks = from->f_blocks;
45 to->f_bfree = from->f_bfree;
46 to->f_bavail = from->f_bavail;
47 to->f_files = from->f_files;
48 to->f_ffree = from->f_ffree;
49 to->f_favail = from->f_favail;
50 to->f_fsid = from->f_fsid;
51 to->f_namemax = from->f_namemax;
53 if (Mono_Posix_ToMountFlags (from->f_flag, &to->f_flag) != 0)
60 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
62 struct statvfs *to = _to;
65 to->f_bsize = from->f_bsize;
66 to->f_frsize = from->f_frsize;
67 to->f_blocks = from->f_blocks;
68 to->f_bfree = from->f_bfree;
69 to->f_bavail = from->f_bavail;
70 to->f_files = from->f_files;
71 to->f_ffree = from->f_ffree;
72 to->f_favail = from->f_favail;
73 to->f_fsid = from->f_fsid;
74 to->f_namemax = from->f_namemax;
76 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
82 #endif /* ndef HAVE_SYS_STATVFS_H */
85 * System V-compatible definitions
90 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
100 if ((r = statvfs (path, &s)) == 0)
101 r = Mono_Posix_ToStatvfs (&s, buf);
105 #endif /* ndef HAVA_STATVFS */
109 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
119 if ((r = fstatvfs (fd, &s)) == 0)
120 r = Mono_Posix_ToStatvfs (&s, buf);
124 #endif /* ndef HAVA_FSTATVFS */
127 * BSD-compatible definitions.
129 * Linux also provides these, but are deprecated in favor of (f)statvfs.
132 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
134 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
136 struct statfs *from = _from;
138 to->f_bsize = from->f_bsize;
139 to->f_frsize = from->f_bsize;
140 to->f_blocks = from->f_blocks;
141 to->f_bfree = from->f_bfree;
142 to->f_bavail = from->f_bavail;
143 to->f_files = from->f_files;
144 to->f_ffree = from->f_ffree;
145 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
147 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
148 // so this shouldn't lose anything.
149 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
151 #if HAVE_STRUCT_STATFS_F_FLAGS
152 if (Mono_Posix_ToMountFlags (from->f_flags, &to->f_flag) != 0)
154 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
160 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
162 struct statfs *to = _to;
165 to->f_bsize = from->f_bsize;
166 to->f_blocks = from->f_blocks;
167 to->f_bfree = from->f_bfree;
168 to->f_bavail = from->f_bavail;
169 to->f_files = from->f_files;
170 to->f_ffree = from->f_ffree;
172 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
173 // so this shouldn't lose anything.
174 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
176 #if HAVE_STRUCT_STATFS_F_FLAGS
177 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
180 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
186 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
188 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
192 set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
194 buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
196 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
198 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
200 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
210 if ((r = statfs (path, &s)) == 0 &&
211 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
212 set_namemax (path, buf);
217 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
219 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
221 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
231 if ((r = fstatfs (fd, &s)) == 0 &&
232 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
233 set_fnamemax (fd, buf);
238 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */