@@ -208,3 +208,60 @@ unsafe extern "C" fn statfs(path: *const c_char, stat_: *mut libc::statfs) -> c_
208
208
None => -1 ,
209
209
}
210
210
}
211
+
212
+ #[ no_mangle]
213
+ unsafe extern "C" fn fstatfs64 ( fd : c_int , stat_ : * mut libc:: statfs64 ) -> c_int {
214
+ libc ! ( libc:: fstatfs64( fd, stat_) ) ;
215
+ let stat_: * mut rustix:: fs:: StatFs = checked_cast ! ( stat_) ;
216
+
217
+ match convert_res ( rustix:: fs:: fstatfs ( BorrowedFd :: borrow_raw ( fd) ) ) {
218
+ Some ( r) => {
219
+ * stat_ = r;
220
+ 0
221
+ }
222
+ None => -1 ,
223
+ }
224
+ }
225
+
226
+ #[ no_mangle]
227
+ unsafe extern "C" fn fstatfs ( fd : c_int , stat_ : * mut libc:: statfs ) -> c_int {
228
+ libc ! ( libc:: fstatfs( fd, stat_) ) ;
229
+
230
+ match convert_res ( rustix:: fs:: fstatfs ( BorrowedFd :: borrow_raw ( fd) ) ) {
231
+ Some ( r) => {
232
+ #[ cfg( target_os = "linux" ) ]
233
+ {
234
+ let mut converted = core:: mem:: zeroed :: < libc:: statfs > ( ) ;
235
+ converted. f_type = r. f_type . try_into ( ) . unwrap ( ) ;
236
+ converted. f_bsize = r. f_bsize . try_into ( ) . unwrap ( ) ;
237
+ converted. f_blocks = r. f_blocks . try_into ( ) . unwrap ( ) ;
238
+ converted. f_bfree = r. f_bfree . try_into ( ) . unwrap ( ) ;
239
+ converted. f_bavail = r. f_bavail . try_into ( ) . unwrap ( ) ;
240
+ converted. f_files = r. f_files . try_into ( ) . unwrap ( ) ;
241
+ converted. f_ffree = r. f_ffree . try_into ( ) . unwrap ( ) ;
242
+ converted. f_namelen = r. f_namelen . try_into ( ) . unwrap ( ) ;
243
+ converted. f_frsize = r. f_frsize . try_into ( ) . unwrap ( ) ;
244
+
245
+ // The libc crate declares `f_fsid` with private fields,
246
+ // perhaps because who even knows what this field means,
247
+ // but understanding is not required for the job here.
248
+ assert_eq ! ( size_of_val( & r. f_fsid) , size_of_val( & converted. f_fsid) ) ;
249
+ copy_nonoverlapping (
250
+ addr_of ! ( r. f_fsid) . cast :: < u8 > ( ) ,
251
+ addr_of_mut ! ( converted. f_fsid) . cast :: < u8 > ( ) ,
252
+ size_of_val ( & r. f_fsid ) ,
253
+ ) ;
254
+
255
+ * stat_ = converted;
256
+ }
257
+
258
+ #[ cfg( not( target_os = "linux" ) ) ]
259
+ {
260
+ * stat_ = r;
261
+ }
262
+
263
+ 0
264
+ }
265
+ None => -1 ,
266
+ }
267
+ }
0 commit comments