kboot: Implement stat(2) and fstat(2) system calls

Implement stat(2) and fstat(2) in terms of newfstatat and newfstat
system calls respectively (assume we have a compat #define when
there's no newfstat and just a regular fstat and do so for ppc).

Snag struct kstat (the Linux kernel stat(2), et al interface) from musl
and attribute properly.

Sponsored by:		Netflix
This commit is contained in:
Warner Losh 2022-07-14 23:19:18 -06:00
parent ae366d5106
commit a647d4a4d1
6 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2005-2020 Rich Felker, et al.
*
* SPDX-Licnse-Identifier: MIT
*
* Note: From the musl project
*/
struct host_kstat {
host_dev_t st_dev;
host_ino_t st_ino;
host_nlink_t st_nlink;
host_mode_t st_mode;
host_uid_t st_uid;
host_gid_t st_gid;
unsigned int __pad0;
host_dev_t st_rdev;
host_off_t st_size;
host_blksize_t st_blksize;
host_blkcnt_t st_blocks;
long st_atime_sec;
long st_atime_nsec;
long st_mtime_sec;
long st_mtime_nsec;
long st_ctime_sec;
long st_ctime_nsec;
long __pad_for_future[3];
};

View File

@ -4,6 +4,8 @@
#define SYS_kexec_load 246
#define SYS_lseek 8
#define SYS_mmap 9
#define SYS_newfstat 5
#define SYS_newfstatat 262
#define SYS_openat 257
#define SYS_pselect6 270
#define SYS_read 0

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2005-2020 Rich Felker, et al.
*
* SPDX-Licnse-Identifier: MIT
*
* Note: From the musl project
*/
struct host_kstat {
host_dev_t st_dev;
host_ino_t st_ino;
host_nlink_t st_nlink;
host_mode_t st_mode;
host_uid_t st_uid;
host_gid_t st_gid;
host_dev_t st_rdev;
host_off_t st_size;
host_blksize_t st_blksize;
host_blkcnt_t st_blocks;
long st_atime_sec;
long st_atime_nsec;
long st_mtime_sec;
long st_mtime_nsec;
long st_ctime_sec;
long st_ctime_nsec;
long __pad_for_future[3];
};

View File

@ -1,9 +1,12 @@
#define SYS_close 6
#define SYS_fstat 108
#define SYS_getdents 141
#define SYS_gettimeofday 78
#define SYS_kexec_load 268
#define SYS_llseek 140
#define SYS_mmap 90
#define SYS_newfstat SYS_fstat
#define SYS_newfstatat 291
#define SYS_openat 286
#define SYS_pselect6 280
#define SYS_read 3

View File

@ -32,6 +32,21 @@
long host_syscall(int number, ...);
/*
* Sizes taken from musl's include/alltypes.h.in and expanded for LP64 hosts
*/
typedef uint64_t host_dev_t;
typedef uint64_t host_ino_t;
typedef int64_t host_nlink_t;
typedef unsigned int host_mode_t;
typedef unsigned int host_uid_t;
typedef unsigned int host_gid_t;
typedef int64_t host_off_t;
typedef long host_blksize_t;
typedef int64_t host_blkcnt_t;
#include "stat_arch.h"
/*
* Constants for open, fcntl, etc
*
@ -75,6 +90,7 @@ struct host_timeval {
* System Calls
*/
int host_close(int fd);
int host_fstat(int fd, struct host_kstat *sb);
int host_getdents(int fd, void *dirp, int count);
int host_gettimeofday(struct host_timeval *a, void *b);
int host_kexec_load(uint32_t start, int nsegs, uint32_t segs, uint32_t flags);
@ -85,6 +101,7 @@ ssize_t host_read(int fd, void *buf, size_t nbyte);
int host_reboot(int, int, int, uintptr_t);
int host_select(int nfds, long *readfds, long *writefds, long *exceptfds,
struct host_timeval *timeout);
int host_stat(const char *path, struct host_kstat *sb);
int host_uname(struct old_utsname *);
ssize_t host_write(int fd, const void *buf, size_t nbyte);

View File

@ -13,6 +13,12 @@ host_close(int fd)
return host_syscall(SYS_close, fd);
}
int
host_fstat(int fd, struct host_kstat *sb)
{
return host_syscall(SYS_newfstat, fd, (uintptr_t)sb);
}
int
host_getdents(int fd, void *dirp, int count)
{
@ -86,6 +92,12 @@ host_select(int nfds, long *readfds, long *writefds, long *exceptfds,
(uintptr_t)exceptfds, (uintptr_t)&ts, (uintptr_t)NULL);
}
int
host_stat(const char *path, struct host_kstat *sb)
{
return host_syscall(SYS_newfstatat, HOST_AT_FDCWD, (uintptr_t)path, (uintptr_t)sb, 0);
}
int
host_uname(struct old_utsname *uts)
{