@@ -1748,10 +1748,10 @@ pub(super) mod _os {
17481748 #[ cfg( all( unix, not( target_os = "redox" ) ) ) ]
17491749 impl StatvfsResultData {
17501750 fn from_statvfs ( st : libc:: statvfs ) -> Self {
1751- // Handle f_fsid which may be a struct on some platforms
1752- // On most Unix systems, we just use 0 or try to get the value
1751+ // f_fsid is a struct on some platforms (e.g., Linux fsid_t) and a scalar on others.
1752+ // We extract raw bytes and interpret as a native-endian integer.
1753+ // Note: The value may differ across architectures due to endianness.
17531754 let f_fsid = {
1754- // Use pointer cast to get raw bytes from fsid struct
17551755 let ptr = std:: ptr:: addr_of!( st. f_fsid) as * const u8 ;
17561756 let size = std:: mem:: size_of_val ( & st. f_fsid ) ;
17571757 if size >= 8 {
@@ -1790,15 +1790,19 @@ pub(super) mod _os {
17901790 #[ pyfunction( name = "fstatvfs" ) ]
17911791 fn statvfs ( path : OsPathOrFd < ' _ > , vm : & VirtualMachine ) -> PyResult {
17921792 let mut st: libc:: statvfs = unsafe { std:: mem:: zeroed ( ) } ;
1793- let ret = match path {
1794- OsPathOrFd :: Path ( path ) => {
1795- let cpath = path . into_cstring ( vm) ?;
1793+ let ret = match & path {
1794+ OsPathOrFd :: Path ( p ) => {
1795+ let cpath = p . clone ( ) . into_cstring ( vm) ?;
17961796 unsafe { libc:: statvfs ( cpath. as_ptr ( ) , & mut st) }
17971797 }
17981798 OsPathOrFd :: Fd ( fd) => unsafe { libc:: fstatvfs ( fd. as_raw ( ) , & mut st) } ,
17991799 } ;
18001800 if ret != 0 {
1801- return Err ( io:: Error :: last_os_error ( ) . into_pyexception ( vm) ) ;
1801+ return Err ( OSErrorBuilder :: with_filename (
1802+ & io:: Error :: last_os_error ( ) ,
1803+ path,
1804+ vm,
1805+ ) ) ;
18021806 }
18031807 Ok ( StatvfsResultData :: from_statvfs ( st) . to_pyobject ( vm) )
18041808 }
0 commit comments