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
;
55 * On AIX with -D_ALL_SOURCE, fsid_t is a struct
56 * See: github.com/python/cpython/pull/4972
58 #if defined(_AIX) && defined(_ALL_SOURCE)
59 to
->f_fsid
= from
->f_fsid
.val
[0];
61 to
->f_fsid
= from
->f_fsid
;
63 to
->f_namemax
= from
->f_namemax
;
65 if (Mono_Posix_ToMountFlags (from
->f_flag
, &to
->f_flag
) != 0)
72 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs
*from
, void *_to
)
74 struct statvfs
*to
= _to
;
77 to
->f_bsize
= from
->f_bsize
;
78 to
->f_frsize
= from
->f_frsize
;
79 to
->f_blocks
= from
->f_blocks
;
80 to
->f_bfree
= from
->f_bfree
;
81 to
->f_bavail
= from
->f_bavail
;
82 to
->f_files
= from
->f_files
;
83 to
->f_ffree
= from
->f_ffree
;
84 to
->f_favail
= from
->f_favail
;
85 #if defined(_AIX) && defined(_ALL_SOURCE)
86 to
->f_fsid
.val
[0] = from
->f_fsid
;
88 to
->f_fsid
= from
->f_fsid
;
90 to
->f_namemax
= from
->f_namemax
;
92 if (Mono_Posix_FromMountFlags (from
->f_flag
, &flag
) != 0)
98 #endif /* ndef HAVE_SYS_STATVFS_H */
101 * System V-compatible definitions
106 Mono_Posix_Syscall_statvfs (const char *path
, struct Mono_Posix_Statvfs
*buf
)
116 if ((r
= statvfs (path
, &s
)) == 0)
117 r
= Mono_Posix_ToStatvfs (&s
, buf
);
121 #endif /* ndef HAVA_STATVFS */
125 Mono_Posix_Syscall_fstatvfs (gint32 fd
, struct Mono_Posix_Statvfs
*buf
)
135 if ((r
= fstatvfs (fd
, &s
)) == 0)
136 r
= Mono_Posix_ToStatvfs (&s
, buf
);
140 #endif /* ndef HAVA_FSTATVFS */
143 * BSD-compatible definitions.
145 * Linux also provides these, but are deprecated in favor of (f)statvfs.
146 * Android NDK unified headers define HAVE_FSTATFS but also HAVE_SYS_STATVFS_H
147 * which makes these duplicates of the functions defined above
150 #if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS) && !defined(ANDROID_UNIFIED_HEADERS)
152 Mono_Posix_ToStatvfs (void *_from
, struct Mono_Posix_Statvfs
*to
)
154 struct statfs
*from
= _from
;
156 to
->f_bsize
= from
->f_bsize
;
157 to
->f_frsize
= 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
;
163 to
->f_favail
= from
->f_ffree
; /* OSX doesn't have f_avail */
165 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
166 // so this shouldn't lose anything.
167 memcpy (&to
->f_fsid
, &from
->f_fsid
, sizeof(to
->f_fsid
));
169 #if HAVE_STRUCT_STATFS_F_FLAGS
170 if (Mono_Posix_ToMountFlags (from
->f_flags
, &to
->f_flag
) != 0)
172 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
178 Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs
*from
, void *_to
)
180 struct statfs
*to
= _to
;
183 to
->f_bsize
= from
->f_bsize
;
184 to
->f_blocks
= from
->f_blocks
;
185 to
->f_bfree
= from
->f_bfree
;
186 to
->f_bavail
= from
->f_bavail
;
187 to
->f_files
= from
->f_files
;
188 to
->f_ffree
= from
->f_ffree
;
190 // from->f_fsid is an int32[2], to->f_fsid is a uint64,
191 // so this shouldn't lose anything.
192 memcpy (&to
->f_fsid
, &from
->f_fsid
, sizeof(to
->f_fsid
));
194 #if HAVE_STRUCT_STATFS_F_FLAGS
195 if (Mono_Posix_FromMountFlags (from
->f_flag
, &flag
) != 0)
198 #endif /* def HAVE_STRUCT_STATFS_F_FLAGS */
204 set_namemax (const char *path
, struct Mono_Posix_Statvfs
*buf
)
206 buf
->f_namemax
= pathconf (path
, _PC_NAME_MAX
);
210 set_fnamemax (int fd
, struct Mono_Posix_Statvfs
*buf
)
212 buf
->f_namemax
= fpathconf (fd
, _PC_NAME_MAX
);
214 #endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */
216 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS) && (!defined(ANDROID_UNIFIED_HEADERS) || __ANDROID_API__ >= 19)
218 Mono_Posix_Syscall_statvfs (const char *path
, struct Mono_Posix_Statvfs
*buf
)
228 if ((r
= statfs (path
, &s
)) == 0 &&
229 (r
= Mono_Posix_ToStatvfs (&s
, buf
)) == 0) {
230 set_namemax (path
, buf
);
235 #endif /* !def HAVE_STATVFS && def HAVE_STATFS */
237 #if !defined (HAVE_STATVFS) && defined (HAVE_STATFS) && (!defined(ANDROID_UNIFIED_HEADERS) || __ANDROID_API__ >= 19)
239 Mono_Posix_Syscall_fstatvfs (gint32 fd
, struct Mono_Posix_Statvfs
*buf
)
249 if ((r
= fstatfs (fd
, &s
)) == 0 &&
250 (r
= Mono_Posix_ToStatvfs (&s
, buf
)) == 0) {
251 set_fnamemax (fd
, buf
);
256 #endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */