Skip to content

Commit 2a35eb7

Browse files
Linux: Re-add statx -> stat conversion
Also: - `statx_timestamp` gets a function to convert into a `timestamp`. - The empty lines in the `Statx` struct have been removed.
1 parent 1d9db8f commit 2a35eb7

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

lib/std/os/linux.zig

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,24 @@ pub const Stat = struct {
514514
.ctime = st.ctime(),
515515
};
516516
}
517+
518+
fn fromStatx(stx: Statx) @This() {
519+
return .{
520+
.dev = makedev(stx.dev_major, stx.dev_minor),
521+
.ino = stx.ino,
522+
.mode = stx.mode,
523+
.nlink = stx.nlink,
524+
.uid = stx.uid,
525+
.gid = stx.gid,
526+
.rdev = makedev(stx.rdev_major, stx.rdev_minor),
527+
.size = stx.size,
528+
.blksize = stx.blksize,
529+
.blocks = @intCast(stx.blocks),
530+
.atime = stx.atime.toTimespec(),
531+
.mtime = stx.mtime.toTimespec(),
532+
.ctime = stx.ctime.toTimespec(),
533+
};
534+
}
517535
};
518536

519537
// The 64-bit `stat` definition used by the Linux kernel,
@@ -6496,68 +6514,56 @@ pub const statx_timestamp = extern struct {
64966514
sec: i64,
64976515
nsec: u32,
64986516
__pad1: u32,
6517+
6518+
fn toTimespec(self: @This()) timespec {
6519+
return .{
6520+
.sec = self.sec,
6521+
.nsec = @as(i32, @bitCast(self.nsec)),
6522+
};
6523+
}
64996524
};
65006525

65016526
/// Renamed to `Statx` to not conflict with the `statx` function.
65026527
pub const Statx = extern struct {
65036528
/// Mask of bits indicating filled fields
65046529
mask: u32,
6505-
65066530
/// Block size for filesystem I/O
65076531
blksize: u32,
6508-
65096532
/// Extra file attribute indicators
65106533
attributes: u64,
6511-
65126534
/// Number of hard links
65136535
nlink: u32,
6514-
65156536
/// User ID of owner
65166537
uid: uid_t,
6517-
65186538
/// Group ID of owner
65196539
gid: gid_t,
6520-
65216540
/// File type and mode
65226541
mode: u16,
65236542
__pad1: u16,
6524-
65256543
/// Inode number
65266544
ino: u64,
6527-
65286545
/// Total size in bytes
65296546
size: u64,
6530-
65316547
/// Number of 512B blocks allocated
65326548
blocks: u64,
6533-
65346549
/// Mask to show what's supported in `attributes`.
65356550
attributes_mask: u64,
6536-
65376551
/// Last access file timestamp
65386552
atime: statx_timestamp,
6539-
65406553
/// Creation file timestamp
65416554
btime: statx_timestamp,
6542-
65436555
/// Last status change file timestamp
65446556
ctime: statx_timestamp,
6545-
65466557
/// Last modification file timestamp
65476558
mtime: statx_timestamp,
6548-
65496559
/// Major ID, if this file represents a device.
65506560
rdev_major: u32,
6551-
65526561
/// Minor ID, if this file represents a device.
65536562
rdev_minor: u32,
6554-
65556563
/// Major ID of the device containing the filesystem where this file resides.
65566564
dev_major: u32,
6557-
65586565
/// Minor ID of the device containing the filesystem where this file resides.
65596566
dev_minor: u32,
6560-
65616567
__pad2: [14]u64,
65626568
};
65636569

0 commit comments

Comments
 (0)