2 * <sys/sendfile.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 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 #ifdef HAVE_SYS_STATVFS_H
32 Mono_Posix_ToStatvfs (void *_from
, struct Mono_Posix_Statvfs
*to
)
34 struct statvfs
*from
= _from
;
36 to
->f_bsize
= from
->f_bsize
;
37 to
->f_frsize
= from
->f_frsize
;
38 to
->f_blocks
= from
->f_blocks
;
39 to
->f_bfree
= from
->f_bfree
;
40 to
->f_bavail
= from
->f_bavail
;
41 to
->f_files
= from
->f_files
;
42 to
->f_ffree
= from
->f_ffree
;
43 to
->f_favail
= from
->f_favail
;
44 to
->f_fsid
= from
->f_fsid
;
45 to
->f_namemax
= from
->f_namemax
;
47 if (Mono_Posix_ToMountFlags (from
->f_flag
, &to
->f_flag
) != 0)
54 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs
*from
, void *_to
)
56 struct statvfs
*to
= _to
;
59 to
->f_bsize
= from
->f_bsize
;
60 to
->f_frsize
= from
->f_frsize
;
61 to
->f_blocks
= from
->f_blocks
;
62 to
->f_bfree
= from
->f_bfree
;
63 to
->f_bavail
= from
->f_bavail
;
64 to
->f_files
= from
->f_files
;
65 to
->f_ffree
= from
->f_ffree
;
66 to
->f_favail
= from
->f_favail
;
67 to
->f_fsid
= from
->f_fsid
;
68 to
->f_namemax
= from
->f_namemax
;
70 if (Mono_Posix_FromMountFlags (from
->f_flag
, &flag
) != 0)
76 #endif /* ndef HAVE_SYS_STATVFS_H */
79 * System V-compatible definitions
84 Mono_Posix_Syscall_statvfs (const char *path
, struct Mono_Posix_Statvfs
*buf
)
94 if ((r
= statvfs (path
, &s
)) == 0)
95 r
= Mono_Posix_ToStatvfs (&s
, buf
);
99 #endif /* ndef HAVA_STATVFS */
103 Mono_Posix_Syscall_fstatvfs (gint32 fd
, struct Mono_Posix_Statvfs
*buf
)
113 if ((r
= fstatvfs (fd
, &s
)) == 0)
114 r
= Mono_Posix_ToStatvfs (&s
, buf
);
118 #endif /* ndef HAVA_FSTATVFS */
121 * BSD-compatible definitions.
123 * Linux also provides these, but are deprecated in favor of (f)statvfs.
126 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
128 Mono_Posix_ToStatvfs (void *_from
, struct Mono_Posix_Statvfs
*to
)
130 struct statfs
*from
= _from
;
132 to
->f_bsize
= from
->f_bsize
;
133 to
->f_frsize
= from
->f_bsize
;
134 to
->f_blocks
= from
->f_blocks
;
135 to
->f_bfree
= from
->f_bfree
;
136 to
->f_bavail
= from
->f_bavail
;
137 to
->f_files
= from
->f_files
;
138 to
->f_ffree
= from
->f_ffree
;
139 to
->f_favail
= from
->f_ffree
; /* OSX doesn't have f_avail */
141 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
142 // so this shouldn't lose anything.
143 memcpy (&to
->f_fsid
, &from
->f_fsid
, sizeof(to
->f_fsid
));
145 if (Mono_Posix_ToMountFlags (from
->f_flags
, &to
->f_flag
) != 0)
152 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs
*from
, void *_to
)
154 struct statfs
*to
= _to
;
157 to
->f_bsize
= from
->f_bsize
;
158 to
->f_blocks
= from
->f_blocks
;
159 to
->f_bfree
= from
->f_bfree
;
160 to
->f_bavail
= from
->f_bavail
;
161 to
->f_files
= from
->f_files
;
162 to
->f_ffree
= from
->f_ffree
;
164 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
165 // so this shouldn't lose anything.
166 memcpy (&to
->f_fsid
, &from
->f_fsid
, sizeof(to
->f_fsid
));
168 if (Mono_Posix_FromMountFlags (from
->f_flag
, &flag
) != 0)
176 set_namemax (const char *path
, struct Mono_Posix_Statvfs
*buf
)
178 buf
->f_namemax
= pathconf (path
, _PC_NAME_MAX
);
182 set_fnamemax (int fd
, struct Mono_Posix_Statvfs
*buf
)
184 buf
->f_namemax
= fpathconf (fd
, _PC_NAME_MAX
);
186 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
188 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
190 Mono_Posix_Syscall_statvfs (const char *path
, struct Mono_Posix_Statvfs
*buf
)
200 if ((r
= statfs (path
, &s
)) == 0 &&
201 (r
= Mono_Posix_ToStatvfs (&s
, buf
)) == 0) {
202 set_namemax (path
, buf
);
207 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
209 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
211 Mono_Posix_Syscall_fstatvfs (gint32 fd
, struct Mono_Posix_Statvfs
*buf
)
221 if ((r
= fstatfs (fd
, &s
)) == 0 &&
222 (r
= Mono_Posix_ToStatvfs (&s
, buf
)) == 0) {
223 set_fnamemax (fd
, buf
);
228 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */