Add lchown, lchmod, statvfs, fstatvfs

This commit is contained in:
Justine Tunney 2022-08-22 20:49:33 -07:00
parent 7b74f6e20e
commit 5a632cf72d
24 changed files with 231 additions and 32 deletions

12
libc/calls/struct/fsid.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef struct fsid_t {
uint32_t __val[2];
} fsid_t;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_ */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -21,7 +22,7 @@ struct statfs_freebsd {
uint64_t f_spare[10]; /* unused spare */
uint32_t f_namemax; /* maximum filename length */
uint32_t f_owner; /* user that mounted the filesystem */
uint64_t f_fsid; /* filesystem id (endian 32 matters) */
fsid_t f_fsid; /* filesystem id */
char f_charspare[80]; /* spare string space */
char f_fstypename[16]; /* filesystem type name */
char f_mntfromname[1024]; /* mounted filesystem */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs_linux {
int64_t f_bavail; /* free blocks available to */
int64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free file nodes in filesystem */
int64_t f_fsid; /* filesystem id */
fsid_t f_fsid; /* filesystem id */
int64_t f_namelen; /* maximum length of filenames */
int64_t f_frsize; /* fragment size */
int64_t f_flags; /* mount flags of filesystem 2.6.36 */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -13,7 +14,7 @@ struct statfs_netbsd {
int64_t f_bavail; /* free blocks avail to non-superuser */
int64_t f_files; /* total file nodes in file system */
int64_t f_ffree; /* free file nodes in fs */
uint64_t f_fsid; /* file system id (endian 32 matters) */
fsid_t f_fsid; /* file system id */
uint32_t f_owner; /* user that mounted the file system */
int64_t f_flags; /* copy of mount flags */
int64_t f_syncwrites; /* count of sync writes since mount */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_
#include "libc/calls/struct/fsid.h"
#include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -119,7 +120,7 @@ struct statfs_openbsd {
uint64_t f_syncreads; /* count of sync reads since mount */
uint64_t f_asyncwrites; /* count of async writes since mount */
uint64_t f_asyncreads; /* count of async reads since mount */
uint64_t f_fsid; /* file system id (endian 32 matters) */
fsid_t f_fsid; /* file system id */
uint32_t f_namemax; /* maximum filename length */
uint32_t f_owner; /* user that mounted the file system */
uint64_t f_ctime; /* last mount [-u] time */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs_xnu {
uint64_t f_bavail; /* free blocks avail to non-superuser */
uint64_t f_files; /* total file nodes in file system */
uint64_t f_ffree; /* free file nodes in fs */
uint64_t f_fsid; /* file system id (endian 32 matters) */
fsid_t f_fsid; /* file system id */
uint32_t f_owner; /* user that mounted the filesystem */
uint32_t f_type; /* type of filesystem */
uint32_t f_flags; /* copy of mount exported flags */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs { /* cosmo abi */
int64_t f_bavail; /* free blocks available to unprivileged users */
int64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free file nodes in filesystem */
int64_t f_fsid; /* filesystem id */
fsid_t f_fsid; /* filesystem id */
int64_t f_namelen; /* maximum length of filenames */
int64_t f_frsize; /* fragment size */
int64_t f_flags; /* mount flags of filesystem 2.6.36 */

View file

@ -2,6 +2,7 @@
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_
#include "libc/calls/struct/statfs-meta.internal.h"
#include "libc/calls/struct/statfs.h"
#include "libc/calls/struct/statvfs.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -10,6 +11,7 @@ int sys_statfs(const char *, union statfs_meta *);
int sys_fstatfs(int, union statfs_meta *);
int sys_fstatfs_nt(int64_t, struct statfs *);
int sys_statfs_nt(const char *, struct statfs *);
void statfs2statvfs(struct statvfs *, const struct statfs *);
const char *DescribeStatfs(char[300], int, const struct statfs *);
#define DescribeStatfs(rc, sf) DescribeStatfs(alloca(300), rc, sf)

View file

@ -0,0 +1,25 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct statvfs {
unsigned long f_bsize; /* Filesystem block size */
unsigned long f_frsize; /* Fragment size */
uint64_t f_blocks; /* Size of fs in f_frsize units */
uint64_t f_bfree; /* Number of free blocks */
uint64_t f_bavail; /* Number of free blocks for unprivileged users */
uint64_t f_files; /* Number of inodes */
uint64_t f_ffree; /* Number of free inodes */
uint64_t f_favail; /* Number of free inodes for unprivileged users */
unsigned long f_fsid; /* Filesystem ID */
unsigned long f_flag; /* Mount flags */
unsigned long f_namemax; /* Maximum filename length */
};
int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_ */