diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index 5b51f19f41..8f7a46ad3e 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -145,6 +145,16 @@ pub const File = struct { } pub const Stat = struct { + /// A number that the system uses to point to the file metadata. This number is not guaranteed to be + /// unique across time, as some file systems may reuse an inode after it's file has been deleted. + /// Some systems may change the inode of a file over time. + /// + /// On Linux, the inode _is_ structure that stores the metadata, and the inode _number_ is what + /// you see here: the index number of the inode. + /// + /// The FileIndex on Windows is similar. It is a number for a file that is unique to each filesystem. + inode: os.ino_t, + size: u64, mode: Mode, @@ -174,6 +184,7 @@ pub const File = struct { else => return windows.unexpectedStatus(rc), } return Stat{ + .inode = info.InternalInformation.IndexNumber, .size = @bitCast(u64, info.StandardInformation.EndOfFile), .mode = 0, .atime = windows.fromSysTime(info.BasicInformation.LastAccessTime), @@ -187,6 +198,7 @@ pub const File = struct { const mtime = st.mtime(); const ctime = st.ctime(); return Stat{ + .inode = st.ino, .size = @bitCast(u64, st.size), .mode = st.mode, .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index fb933c6698..6808af0315 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -53,6 +53,7 @@ pub const mach_timebase_info_data = extern struct { }; pub const off_t = i64; +pub const ino_t = u64; /// Renamed to Stat to not conflict with the stat function. /// atime, mtime, and ctime have functions to return `timespec`, @@ -64,7 +65,7 @@ pub const Stat = extern struct { dev: i32, mode: u16, nlink: u16, - ino: u64, + ino: ino_t, uid: u32, gid: u32, rdev: i32, diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index c6c23affa7..27b2733b76 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -138,8 +138,10 @@ pub const MAP_SIZEALIGN = 262144; pub const PATH_MAX = 1024; +pub const ino_t = c_ulong; + pub const Stat = extern struct { - ino: c_ulong, + ino: ino_t, nlink: c_uint, dev: c_uint, mode: c_ushort, diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index b7d14934f5..02fe7e75b3 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -98,6 +98,7 @@ pub const msghdr_const = extern struct { }; pub const off_t = i64; +pub const ino_t = u64; /// Renamed to Stat to not conflict with the stat function. /// atime, mtime, and ctime have functions to return `timespec`, @@ -107,7 +108,7 @@ pub const off_t = i64; /// methods to accomplish this. pub const Stat = extern struct { dev: u64, - ino: u64, + ino: ino_t, nlink: usize, mode: u16, diff --git a/lib/std/os/bits/linux/x86_64.zig b/lib/std/os/bits/linux/x86_64.zig index 608f74e2d3..e92591d94e 100644 --- a/lib/std/os/bits/linux/x86_64.zig +++ b/lib/std/os/bits/linux/x86_64.zig @@ -481,6 +481,7 @@ pub const msghdr_const = extern struct { }; pub const off_t = i64; +pub const ino_t = u64; /// Renamed to Stat to not conflict with the stat function. /// atime, mtime, and ctime have functions to return `timespec`, @@ -490,7 +491,7 @@ pub const off_t = i64; /// methods to accomplish this. pub const Stat = extern struct { dev: u64, - ino: u64, + ino: ino_t, nlink: usize, mode: u32, diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 89e0998d6d..735485695a 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -69,6 +69,7 @@ pub const msghdr_const = extern struct { }; pub const off_t = i64; +pub const ino_t = u64; /// Renamed to Stat to not conflict with the stat function. /// atime, mtime, and ctime have functions to return `timespec`, @@ -79,7 +80,7 @@ pub const off_t = i64; pub const Stat = extern struct { dev: u64, mode: u32, - ino: u64, + ino: ino_t, nlink: usize, uid: u32, diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index f56e53504e..8fb85e1fcd 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -178,6 +178,7 @@ pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004; pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008; pub const inode_t = u64; +pub const ino_t = inode_t; pub const linkcount_t = u32; diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig index ba2725e0a9..05486c8f7b 100644 --- a/lib/std/os/bits/windows.zig +++ b/lib/std/os/bits/windows.zig @@ -4,6 +4,7 @@ usingnamespace @import("../windows/bits.zig"); const ws2_32 = @import("../windows/ws2_32.zig"); pub const fd_t = HANDLE; +pub const ino_t = LARGE_INTEGER; pub const pid_t = HANDLE; pub const mode_t = u0;