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 #ifdef HAVE_SYS_PARAM_H
29 #include <sys/param.h>
31 #include <sys/ucred.h>
32 #include <sys/mount.h>
33 #include <unistd.h> /* for pathconf */
34 #endif /* def HAVE_GETFSSTAT */
36 #include "mono/utils/mono-compiler.h"
40 #ifdef HAVE_SYS_STATVFS_H
42 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
44 struct statvfs *from = _from;
46 to->f_bsize = from->f_bsize;
47 to->f_frsize = from->f_frsize;
48 to->f_blocks = from->f_blocks;
49 to->f_bfree = from->f_bfree;
50 to->f_bavail = from->f_bavail;
51 to->f_files = from->f_files;
52 to->f_ffree = from->f_ffree;
53 to->f_favail = from->f_favail;
54 to->f_fsid = from->f_fsid;
55 to->f_namemax = from->f_namemax;
57 if (Mono_Posix_ToMountFlags (from->f_flag, &to->f_flag) != 0)
64 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
66 struct statvfs *to = _to;
69 to->f_bsize = from->f_bsize;
70 to->f_frsize = from->f_frsize;
71 to->f_blocks = from->f_blocks;
72 to->f_bfree = from->f_bfree;
73 to->f_bavail = from->f_bavail;
74 to->f_files = from->f_files;
75 to->f_ffree = from->f_ffree;
76 to->f_favail = from->f_favail;
77 to->f_fsid = from->f_fsid;
78 to->f_namemax = from->f_namemax;
80 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
86 #endif /* ndef HAVE_SYS_STATVFS_H */
89 * System V-compatible definitions
94 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
104 if ((r = statvfs (path, &s)) == 0)
105 r = Mono_Posix_ToStatvfs (&s, buf);
109 #endif /* ndef HAVA_STATVFS */
113 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
123 if ((r = fstatvfs (fd, &s)) == 0)
124 r = Mono_Posix_ToStatvfs (&s, buf);
128 #endif /* ndef HAVA_FSTATVFS */
131 * BSD-compatible definitions.
133 * Linux also provides these, but are deprecated in favor of (f)statvfs.
134 * Android NDK unified headers define HAVE_FSTATFS but also HAVE_SYS_STATVFS_H
135 * which makes these duplicates of the functions defined above
138 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS) && !defined(ANDROID_UNIFIED_HEADERS)
140 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
142 struct statfs *from = _from;
144 to->f_bsize = from->f_bsize;
145 to->f_frsize = from->f_bsize;
146 to->f_blocks = from->f_blocks;
147 to->f_bfree = from->f_bfree;
148 to->f_bavail = from->f_bavail;
149 to->f_files = from->f_files;
150 to->f_ffree = from->f_ffree;
151 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
153 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
154 // so this shouldn't lose anything.
155 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
157 #if HAVE_STRUCT_STATFS_F_FLAGS
158 if (Mono_Posix_ToMountFlags (from->f_flags, &to->f_flag) != 0)
160 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
166 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
168 struct statfs *to = _to;
171 to->f_bsize = from->f_bsize;
172 to->f_blocks = from->f_blocks;
173 to->f_bfree = from->f_bfree;
174 to->f_bavail = from->f_bavail;
175 to->f_files = from->f_files;
176 to->f_ffree = from->f_ffree;
178 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
179 // so this shouldn't lose anything.
180 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
182 #if HAVE_STRUCT_STATFS_F_FLAGS
183 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
186 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
192 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
194 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
198 set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
200 buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
202 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
204 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS) && (!defined(ANDROID_UNIFIED_HEADERS) || __ANDROID_API__ >= 19)
206 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
216 if ((r = statfs (path, &s)) == 0 &&
217 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
218 set_namemax (path, buf);
223 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
225 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS) && (!defined(ANDROID_UNIFIED_HEADERS) || __ANDROID_API__ >= 19)
227 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
237 if ((r = fstatfs (fd, &s)) == 0 &&
238 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
239 set_fnamemax (fd, buf);
244 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */