From a6aca5d6d1313505074ee5b55028d09dece4929a Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 6 Dec 2023 17:17:45 +0100 Subject: [PATCH 1/2] fix struct stat layout linux arm64 --- core/os/os_linux.odin | 61 ++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index aabf42574..2e833da4d 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -263,26 +263,51 @@ Unix_File_Time :: struct { nanoseconds: i64, } -OS_Stat :: struct { - device_id: u64, // ID of device containing file - serial: u64, // File serial number - nlink: u64, // Number of hard links - mode: u32, // Mode of the file - uid: u32, // User ID of the file's owner - gid: u32, // Group ID of the file's group - _padding: i32, // 32 bits of padding - rdev: u64, // Device ID, if device - size: i64, // Size of the file, in bytes - block_size: i64, // Optimal bllocksize for I/O - blocks: i64, // Number of 512-byte blocks allocated +when ODIN_ARCH == .arm64 { + OS_Stat :: struct { + device_id: u64, // ID of device containing file + serial: u64, // File serial number + mode: u32, // Mode of the file + nlink: u32, // Number of hard links + uid: u32, // User ID of the file's owner + gid: u32, // Group ID of the file's group + rdev: u64, // Device ID, if device + _padding: u64, + size: i64, // Size of the file, in bytes + block_size: i32, // Optimal blocksize for I/O + _padding_2: i32, + blocks: i64, // Number of 512-byte blocks allocated - last_access: Unix_File_Time, // Time of last access - modified: Unix_File_Time, // Time of last modification - status_change: Unix_File_Time, // Time of last status change + last_access: Unix_File_Time, // Time of last access + modified: Unix_File_Time, // Time of last modification + status_change: Unix_File_Time, // Time of last status change - _reserve1, - _reserve2, - _reserve3: i64, + _reserve1, + _reserve2: i32, + } + #assert(size_of(OS_Stat) == 128) +} else { + OS_Stat :: struct { + device_id: u64, // ID of device containing file + serial: u64, // File serial number + nlink: u64, // Number of hard links + mode: u32, // Mode of the file + uid: u32, // User ID of the file's owner + gid: u32, // Group ID of the file's group + _padding: i32, // 32 bits of padding + rdev: u64, // Device ID, if device + size: i64, // Size of the file, in bytes + block_size: i64, // Optimal bllocksize for I/O + blocks: i64, // Number of 512-byte blocks allocated + + last_access: Unix_File_Time, // Time of last access + modified: Unix_File_Time, // Time of last modification + status_change: Unix_File_Time, // Time of last status change + + _reserve1, + _reserve2, + _reserve3: i64, + } } // NOTE(laleksic, 2021-01-21): Comment and rename these to match OS_Stat above From d278c852cc4e035581e495357baffbccbfeb6c43 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 8 Dec 2023 23:43:30 +0100 Subject: [PATCH 2/2] clean up field names --- core/os/os_linux.odin | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 2e833da4d..298335ac9 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -272,18 +272,17 @@ when ODIN_ARCH == .arm64 { uid: u32, // User ID of the file's owner gid: u32, // Group ID of the file's group rdev: u64, // Device ID, if device - _padding: u64, + _: u64, // Padding size: i64, // Size of the file, in bytes block_size: i32, // Optimal blocksize for I/O - _padding_2: i32, + _: i32, // Padding blocks: i64, // Number of 512-byte blocks allocated last_access: Unix_File_Time, // Time of last access modified: Unix_File_Time, // Time of last modification status_change: Unix_File_Time, // Time of last status change - _reserve1, - _reserve2: i32, + _reserved: [2]i32, } #assert(size_of(OS_Stat) == 128) } else { @@ -294,7 +293,7 @@ when ODIN_ARCH == .arm64 { mode: u32, // Mode of the file uid: u32, // User ID of the file's owner gid: u32, // Group ID of the file's group - _padding: i32, // 32 bits of padding + _: i32, // 32 bits of padding rdev: u64, // Device ID, if device size: i64, // Size of the file, in bytes block_size: i64, // Optimal bllocksize for I/O @@ -304,9 +303,7 @@ when ODIN_ARCH == .arm64 { modified: Unix_File_Time, // Time of last modification status_change: Unix_File_Time, // Time of last status change - _reserve1, - _reserve2, - _reserve3: i64, + _reserved: [3]i64, } }