Merge pull request #4695 from leroycep/feature-inode-stat

Expose file inode number on posix and file index on windows
This commit is contained in:
Andrew Kelley 2020-03-09 13:01:26 -04:00 committed by GitHub
commit 6ab156ce7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 5 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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;