Skip to content

Add stat RPC#614

Open
JaewonHur wants to merge 2 commits intoapple:mainfrom
JaewonHur:add-stat-rpc
Open

Add stat RPC#614
JaewonHur wants to merge 2 commits intoapple:mainfrom
JaewonHur:add-stat-rpc

Conversation

@JaewonHur
Copy link
Copy Markdown
Contributor

This PR adds stat RPC to vminitd.


public func stat(
path: URL
) async throws -> Com_Apple_Containerization_Sandbox_V3_Stat {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return a stat_t? And not the protobuf type directly?

result.st_uid = s.uid
result.st_gid = s.gid
result.st_rdev = dev_t(s.rdev)
// result.st_atimespec = timespec(tv_sec: Int(s.atime.seconds), tv_nsec: Int(s.atime.nanos))
Copy link
Copy Markdown
Contributor Author

@JaewonHur JaewonHur Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcantah updated to return Foundation.stat.

But, it doesn't compile when I set timespec fields there. It feels like because they are defined differently depending on the underlying OS.

#define __DARWIN_STRUCT_STAT64_TIMES \
	struct timespec st_atimespec;           /* time of last access */ \
	struct timespec st_mtimespec;           /* time of last data modification */ \
	struct timespec st_ctimespec;           /* time of last status change */ \
	struct timespec st_birthtimespec;       /* time of file creation(birth) */

#else /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */

#define __DARWIN_STRUCT_STAT64_TIMES \
	time_t		st_atime;               /* [XSI] Time of last access */ \
	long		st_atimensec;           /* nsec of last access */ \
	time_t		st_mtime;               /* [XSI] Last data modification time */ \
	long		st_mtimensec;           /* last data modification nsec */ \
	time_t		st_ctime;               /* [XSI] Time of last status change */ \
	long		st_ctimensec;           /* nsec of last status change */ \
	time_t		st_birthtime;           /*  File creation time(birth)  */ \
	long		st_birthtimensec;       /* nsec of File creation time */

#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

/*
 * This structure is used as the second parameter to the fstat64(),
 * lstat64(), and stat64() functions, and for struct stat when
 * __DARWIN_64_BIT_INO_T is set. __DARWIN_STRUCT_STAT64 is defined
 * above, depending on whether we use struct timespec or the direct
 * components.
 *
 * This is simillar to stat except for 64bit inode number
 * number instead of 32bit ino_t and the addition of create(birth) time.
 */
#define __DARWIN_STRUCT_STAT64 { \
	dev_t		st_dev;                 /* [XSI] ID of device containing file */ \
	mode_t		st_mode;                /* [XSI] Mode of file (see below) */ \
	nlink_t		st_nlink;               /* [XSI] Number of hard links */ \
	__darwin_ino64_t st_ino;                /* [XSI] File serial number */ \
	uid_t		st_uid;                 /* [XSI] User ID of the file */ \
	gid_t		st_gid;                 /* [XSI] Group ID of the file */ \
	dev_t		st_rdev;                /* [XSI] Device ID */ \
	__DARWIN_STRUCT_STAT64_TIMES \
	off_t		st_size;                /* [XSI] file size, in bytes */ \
	blkcnt_t	st_blocks;              /* [XSI] blocks allocated for file */ \
	blksize_t	st_blksize;             /* [XSI] optimal blocksize for I/O */ \
	__uint32_t	st_flags;               /* user defined flags for file */ \
	__uint32_t	st_gen;                 /* file generation number */ \
	__int32_t	st_lspare;              /* RESERVED: DO NOT USE! */ \
	__int64_t	st_qspare[2];           /* RESERVED: DO NOT USE! */ \
}

/*
 * [XSI] This structure is used as the second parameter to the fstat(),
 * lstat(), and stat() functions.
 */
#if __DARWIN_64_BIT_INO_T

struct stat __DARWIN_STRUCT_STAT64;

Do you have any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants