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 */
38 #ifdef HAVE_SYS_STATVFS_H
40 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
42 struct statvfs *from = _from;
44 to->f_bsize = from->f_bsize;
45 to->f_frsize = from->f_frsize;
46 to->f_blocks = from->f_blocks;
47 to->f_bfree = from->f_bfree;
48 to->f_bavail = from->f_bavail;
49 to->f_files = from->f_files;
50 to->f_ffree = from->f_ffree;
51 to->f_favail = from->f_favail;
52 to->f_fsid = from->f_fsid;
53 to->f_namemax = from->f_namemax;
55 if (Mono_Posix_ToMountFlags (from->f_flag, &to->f_flag) != 0)
62 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
64 struct statvfs *to = _to;
67 to->f_bsize = from->f_bsize;
68 to->f_frsize = from->f_frsize;
69 to->f_blocks = from->f_blocks;
70 to->f_bfree = from->f_bfree;
71 to->f_bavail = from->f_bavail;
72 to->f_files = from->f_files;
73 to->f_ffree = from->f_ffree;
74 to->f_favail = from->f_favail;
75 to->f_fsid = from->f_fsid;
76 to->f_namemax = from->f_namemax;
78 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
84 #endif /* ndef HAVE_SYS_STATVFS_H */
87 * System V-compatible definitions
92 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
102 if ((r = statvfs (path, &s)) == 0)
103 r = Mono_Posix_ToStatvfs (&s, buf);
107 #endif /* ndef HAVA_STATVFS */
111 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
121 if ((r = fstatvfs (fd, &s)) == 0)
122 r = Mono_Posix_ToStatvfs (&s, buf);
126 #endif /* ndef HAVA_FSTATVFS */
129 * BSD-compatible definitions.
131 * Linux also provides these, but are deprecated in favor of (f)statvfs.
134 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
136 Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
138 struct statfs *from = _from;
140 to->f_bsize = from->f_bsize;
141 to->f_frsize = from->f_bsize;
142 to->f_blocks = from->f_blocks;
143 to->f_bfree = from->f_bfree;
144 to->f_bavail = from->f_bavail;
145 to->f_files = from->f_files;
146 to->f_ffree = from->f_ffree;
147 to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */
149 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
150 // so this shouldn't lose anything.
151 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
153 #if HAVE_STRUCT_STATFS_F_FLAGS
154 if (Mono_Posix_ToMountFlags (from->f_flags, &to->f_flag) != 0)
156 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
162 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
164 struct statfs *to = _to;
167 to->f_bsize = from->f_bsize;
168 to->f_blocks = from->f_blocks;
169 to->f_bfree = from->f_bfree;
170 to->f_bavail = from->f_bavail;
171 to->f_files = from->f_files;
172 to->f_ffree = from->f_ffree;
174 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
175 // so this shouldn't lose anything.
176 memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));
178 #if HAVE_STRUCT_STATFS_F_FLAGS
179 if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
182 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
188 set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
190 buf->f_namemax = pathconf (path, _PC_NAME_MAX);
194 set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
196 buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
198 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
200 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
202 Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
212 if ((r = statfs (path, &s)) == 0 &&
213 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
214 set_namemax (path, buf);
219 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
221 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
223 Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
233 if ((r = fstatfs (fd, &s)) == 0 &&
234 (r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
235 set_fnamemax (fd, buf);
240 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */