From 5a632cf72d5c6116a5c62ae0b9730476900b4df7 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 22 Aug 2022 20:49:33 -0700 Subject: [PATCH] Add lchown, lchmod, statvfs, fstatvfs --- libc/calls/calls.h | 2 ++ libc/calls/calls.mk | 3 +- libc/calls/fstatfs-nt.c | 3 +- libc/calls/fstatfs.c | 1 + libc/calls/fstatvfs.c | 37 +++++++++++++++++++++ libc/calls/lchmod.c | 34 +++++++++++++++++++ libc/calls/statfs.c | 1 + libc/calls/statfs2cosmo.c | 13 ++++---- libc/calls/statfs2statvfs.c | 36 ++++++++++++++++++++ libc/calls/statvfs.c | 37 +++++++++++++++++++++ libc/calls/struct/fsid.h | 12 +++++++ libc/calls/struct/statfs-freebsd.internal.h | 3 +- libc/calls/struct/statfs-linux.internal.h | 3 +- libc/calls/struct/statfs-netbsd.internal.h | 3 +- libc/calls/struct/statfs-openbsd.internal.h | 3 +- libc/calls/struct/statfs-xnu.internal.h | 3 +- libc/calls/struct/statfs.h | 3 +- libc/calls/struct/statfs.internal.h | 2 ++ libc/calls/struct/statvfs.h | 25 ++++++++++++++ libc/calls/sysparam.h | 2 +- libc/stdio/stdio.h | 1 + third_party/lua/lunix.c | 17 +++++++--- third_party/python/Modules/posixmodule.c | 11 ++---- third_party/python/pyconfig.h | 8 ++--- 24 files changed, 231 insertions(+), 32 deletions(-) create mode 100644 libc/calls/fstatvfs.c create mode 100644 libc/calls/lchmod.c create mode 100644 libc/calls/statfs2statvfs.c create mode 100644 libc/calls/statvfs.c create mode 100644 libc/calls/struct/fsid.h create mode 100644 libc/calls/struct/statvfs.h diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 23437afa1..e15ff85a8 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -122,6 +122,8 @@ int ioprio_set(int, int, int); int issetugid(void); int kill(int, int); int killpg(int, int); +int lchmod(const char *, uint32_t); +int lchown(const char *, uint32_t, uint32_t); int link(const char *, const char *) dontthrow; int linkat(int, const char *, int, const char *, int); int madvise(void *, uint64_t, int); diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index c097156fb..2708a40bd 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -177,7 +177,8 @@ o//libc/calls/fcntl.o: private \ # it's early runtime mandatory and quite huge without it o//libc/calls/getcwd.greg.o \ o//libc/calls/getcwd-nt.greg.o \ -o//libc/calls/getcwd-xnu.greg.o: private \ +o//libc/calls/getcwd-xnu.greg.o \ +o//libc/calls/statfs2cosmo.o: private \ OVERRIDE_CFLAGS += \ -Os diff --git a/libc/calls/fstatfs-nt.c b/libc/calls/fstatfs-nt.c index 0d6e3b5b4..022c8687e 100644 --- a/libc/calls/fstatfs-nt.c +++ b/libc/calls/fstatfs-nt.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" +#include "libc/calls/struct/fsid.h" #include "libc/calls/struct/statfs.h" #include "libc/calls/struct/statfs.internal.h" #include "libc/calls/syscall_support-nt.internal.h" @@ -69,7 +70,7 @@ textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) { } f->f_fstypename[j] = 0; f->f_type = h; - f->f_fsid = VolumeSerialNumber; + f->f_fsid = (fsid_t){{VolumeSerialNumber}}; f->f_flags = FileSystemFlags; f->f_bsize = fs.BytesPerSector; f->f_bsize *= fs.SectorsPerAllocationUnit; diff --git a/libc/calls/fstatfs.c b/libc/calls/fstatfs.c index ca053c808..76d53dc6c 100644 --- a/libc/calls/fstatfs.c +++ b/libc/calls/fstatfs.c @@ -27,6 +27,7 @@ /** * Returns information about filesystem. + * @return 0 on success, or -1 w/ errno */ int fstatfs(int fd, struct statfs *sf) { int rc; diff --git a/libc/calls/fstatvfs.c b/libc/calls/fstatvfs.c new file mode 100644 index 000000000..91503ab2a --- /dev/null +++ b/libc/calls/fstatvfs.c @@ -0,0 +1,37 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/calls/struct/statfs.h" +#include "libc/calls/struct/statfs.internal.h" +#include "libc/calls/struct/statvfs.h" + +/** + * Returns information about filesystem. + * @return 0 on success, or -1 w/ errno + * @note consider using fstatfs() + */ +int fstatvfs(int fd, struct statvfs *sv) { + struct statfs sf; + if (fstatfs(fd, &sf) != -1) { + statfs2statvfs(sv, &sf); + return 0; + } else { + return -1; + } +} diff --git a/libc/calls/lchmod.c b/libc/calls/lchmod.c new file mode 100644 index 000000000..b421de792 --- /dev/null +++ b/libc/calls/lchmod.c @@ -0,0 +1,34 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/sysv/consts/at.h" + +/** + * Changes mode of pathname, w/o dereferencing symlinks. + * + * @param uid is user id, or -1u to not change + * @param gid is group id, or -1u to not change + * @return 0 on success, or -1 w/ errno + * @see chown() which dereferences symbolic links + * @see /etc/passwd for user ids + * @see /etc/group for group ids + */ +int lchmod(const char *pathname, uint32_t mode) { + return fchmodat(AT_FDCWD, pathname, mode, AT_SYMLINK_NOFOLLOW); +} diff --git a/libc/calls/statfs.c b/libc/calls/statfs.c index e54324bdd..294040b56 100644 --- a/libc/calls/statfs.c +++ b/libc/calls/statfs.c @@ -28,6 +28,7 @@ /** * Returns information about filesystem. + * @return 0 on success, or -1 w/ errno */ int statfs(const char *path, struct statfs *sf) { int rc; diff --git a/libc/calls/statfs2cosmo.c b/libc/calls/statfs2cosmo.c index 33150a148..8669d031d 100644 --- a/libc/calls/statfs2cosmo.c +++ b/libc/calls/statfs2cosmo.c @@ -197,7 +197,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { int64_t f_bavail; int64_t f_files; int64_t f_ffree; - int64_t f_fsid; + fsid_t f_fsid; int64_t f_namelen; int64_t f_frsize; int64_t f_flags; @@ -217,6 +217,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f_frsize = m->linux.f_frsize; f_flags = m->linux.f_flags; f_owner = 0; + bzero(f_fstypename, 16); strcpy(f_fstypename, DescribeStatfsTypeLinux(m->linux.f_type)); } else if (IsFreebsd()) { @@ -232,7 +233,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f_frsize = m->freebsd.f_bsize; f_flags = m->freebsd.f_flags; f_owner = m->freebsd.f_owner; - strcpy(f_fstypename, m->freebsd.f_fstypename); + memcpy(f_fstypename, m->freebsd.f_fstypename, 16); } else if (IsXnu()) { f_type = m->xnu.f_type; @@ -247,7 +248,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f_frsize = m->xnu.f_bsize; f_flags = m->xnu.f_flags; f_owner = m->xnu.f_owner; - strcpy(f_fstypename, m->xnu.f_fstypename); + memcpy(f_fstypename, m->xnu.f_fstypename, 16); } else if (IsOpenbsd()) { f_type = f->f_type; @@ -262,7 +263,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f_frsize = m->openbsd.f_bsize; f_flags = m->openbsd.f_flags; f_owner = m->openbsd.f_owner; - strcpy(f_fstypename, m->openbsd.f_fstypename); + memcpy(f_fstypename, m->openbsd.f_fstypename, 16); } else if (IsNetbsd()) { f_type = m->netbsd.f_type; @@ -277,7 +278,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f_frsize = m->netbsd.f_bsize; f_flags = m->netbsd.f_flags; f_owner = m->netbsd.f_owner; - strcpy(f_fstypename, m->netbsd.f_fstypename); + memcpy(f_fstypename, m->netbsd.f_fstypename, 16); } else { asm("hlt"); @@ -295,5 +296,5 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f->f_namelen = f_namelen; f->f_frsize = f_frsize; f->f_flags = f_flags; - strcpy(f->f_fstypename, f_fstypename); + memcpy(f->f_fstypename, f_fstypename, 16); } diff --git a/libc/calls/statfs2statvfs.c b/libc/calls/statfs2statvfs.c new file mode 100644 index 000000000..69d8e9b2f --- /dev/null +++ b/libc/calls/statfs2statvfs.c @@ -0,0 +1,36 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/struct/statfs.h" +#include "libc/calls/struct/statvfs.h" +#include "libc/str/str.h" + +void statfs2statvfs(struct statvfs *sv, const struct statfs *sf) { + bzero(sv, sizeof(*sv)); + sv->f_bsize = sf->f_bsize; + sv->f_frsize = sf->f_frsize ? sf->f_frsize : sf->f_bsize; + sv->f_blocks = sf->f_blocks; + sv->f_bfree = sf->f_bfree; + sv->f_bavail = sf->f_bavail; + sv->f_files = sf->f_files; + sv->f_ffree = sf->f_ffree; + sv->f_favail = sf->f_ffree; + sv->f_fsid = sf->f_fsid.__val[0]; + sv->f_flag = sf->f_flags; + sv->f_namemax = sf->f_namelen; +} diff --git a/libc/calls/statvfs.c b/libc/calls/statvfs.c new file mode 100644 index 000000000..773ec8f97 --- /dev/null +++ b/libc/calls/statvfs.c @@ -0,0 +1,37 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/calls/struct/statfs.h" +#include "libc/calls/struct/statfs.internal.h" +#include "libc/calls/struct/statvfs.h" + +/** + * Returns information about filesystem. + * @return 0 on success, or -1 w/ errno + * @note consider using statfs() + */ +int statvfs(const char *path, struct statvfs *sv) { + struct statfs sf; + if (statfs(path, &sf) != -1) { + statfs2statvfs(sv, &sf); + return 0; + } else { + return -1; + } +} diff --git a/libc/calls/struct/fsid.h b/libc/calls/struct/fsid.h new file mode 100644 index 000000000..9bf3ac1bb --- /dev/null +++ b/libc/calls/struct/fsid.h @@ -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_ */ diff --git a/libc/calls/struct/statfs-freebsd.internal.h b/libc/calls/struct/statfs-freebsd.internal.h index 95d7f4b8b..050b7bfa8 100644 --- a/libc/calls/struct/statfs-freebsd.internal.h +++ b/libc/calls/struct/statfs-freebsd.internal.h @@ -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 */ diff --git a/libc/calls/struct/statfs-linux.internal.h b/libc/calls/struct/statfs-linux.internal.h index 487c48410..90839dce9 100644 --- a/libc/calls/struct/statfs-linux.internal.h +++ b/libc/calls/struct/statfs-linux.internal.h @@ -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 */ diff --git a/libc/calls/struct/statfs-netbsd.internal.h b/libc/calls/struct/statfs-netbsd.internal.h index edca612e5..7e8e3cf0f 100644 --- a/libc/calls/struct/statfs-netbsd.internal.h +++ b/libc/calls/struct/statfs-netbsd.internal.h @@ -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 */ diff --git a/libc/calls/struct/statfs-openbsd.internal.h b/libc/calls/struct/statfs-openbsd.internal.h index 04684eb4d..e1795f48c 100644 --- a/libc/calls/struct/statfs-openbsd.internal.h +++ b/libc/calls/struct/statfs-openbsd.internal.h @@ -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 */ diff --git a/libc/calls/struct/statfs-xnu.internal.h b/libc/calls/struct/statfs-xnu.internal.h index cc3ad3867..eaf3e922f 100644 --- a/libc/calls/struct/statfs-xnu.internal.h +++ b/libc/calls/struct/statfs-xnu.internal.h @@ -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 */ diff --git a/libc/calls/struct/statfs.h b/libc/calls/struct/statfs.h index 0f52b0916..1e7c9a9ed 100644 --- a/libc/calls/struct/statfs.h +++ b/libc/calls/struct/statfs.h @@ -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 */ diff --git a/libc/calls/struct/statfs.internal.h b/libc/calls/struct/statfs.internal.h index e0d5f2e52..bba93de72 100644 --- a/libc/calls/struct/statfs.internal.h +++ b/libc/calls/struct/statfs.internal.h @@ -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) diff --git a/libc/calls/struct/statvfs.h b/libc/calls/struct/statvfs.h new file mode 100644 index 000000000..9c75266c6 --- /dev/null +++ b/libc/calls/struct/statvfs.h @@ -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_ */ diff --git a/libc/calls/sysparam.h b/libc/calls/sysparam.h index 3f2425dbf..865a53bf5 100644 --- a/libc/calls/sysparam.h +++ b/libc/calls/sysparam.h @@ -4,7 +4,7 @@ #define MAXSYMLINKS 20 #define MAXHOSTNAMELEN 64 #define MAXNAMLEN 255 -#define MAXPATHLEN 4096 +#define MAXPATHLEN PATH_MAX #define NBBY 8 #define NGROUPS 32 #define CANBSIZ 255 diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index cc2f56733..7180a1457 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -7,6 +7,7 @@ #define L_ctermid 20 #define FILENAME_MAX PATH_MAX #define FOPEN_MAX 1000 +#define TMP_MAX 10000 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index b70272d47..9c4f4d431 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -2237,9 +2237,12 @@ static int LuaUnixStatfsFfree(lua_State *L) { } // unix.Statfs:fsid() -// └─→ fsid:int +// └─→ x:int, y:int static int LuaUnixStatfsFsid(lua_State *L) { - return ReturnInteger(L, GetUnixStatfs(L)->f_fsid); + struct statfs *f = GetUnixStatfs(L); + lua_pushinteger(L, f->f_fsid.__val[0]); + lua_pushinteger(L, f->f_fsid.__val[1]); + return 2; } // unix.Statfs:namelen() @@ -2314,10 +2317,14 @@ static int LuaUnixStatfsToString(lua_State *L) { FormatInt64(ibuf, f->f_ffree); luaL_addstring(&b, ibuf); } - if (f->f_fsid) { - luaL_addstring(&b, ", fsid="); - FormatUint64(ibuf, f->f_fsid); + if (f->f_fsid.__val[0] || f->f_fsid.__val[1]) { + luaL_addstring(&b, ", fsid={"); + FormatUint64(ibuf, f->f_fsid.__val[0]); luaL_addstring(&b, ibuf); + luaL_addstring(&b, ", "); + FormatUint64(ibuf, f->f_fsid.__val[1]); + luaL_addstring(&b, ibuf); + luaL_addstring(&b, "}"); } if (f->f_namelen) { luaL_addstring(&b, ", namelen="); diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index bf4c0a2dc..ea15baef8 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -13,12 +13,14 @@ #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/stat.macros.h" +#include "libc/calls/struct/statvfs.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/struct/tms.h" #include "libc/calls/struct/utsname.h" #include "libc/calls/struct/winsize.h" #include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/sysparam.h" #include "libc/calls/termios.h" #include "libc/calls/weirdtypes.h" #include "libc/dce.h" @@ -49,6 +51,7 @@ #include "libc/sysv/consts/prio.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/consts/sched.h" +#include "libc/sysv/consts/seek.h" #include "libc/sysv/consts/sf.h" #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/st.h" @@ -122,14 +125,6 @@ module os #define NAMLEN(dirent) strlen((dirent)->d_name) -#ifndef MAXPATHLEN -#if defined(PATH_MAX) && PATH_MAX > 1024 /* TODO: wut? */ -#define MAXPATHLEN PATH_MAX -#else -#define MAXPATHLEN 1024 -#endif -#endif /* MAXPATHLEN */ - #ifdef UNION_WAIT /* Emulate some macros on systems that have a union instead of macros */ diff --git a/third_party/python/pyconfig.h b/third_party/python/pyconfig.h index 651757392..5eca36725 100644 --- a/third_party/python/pyconfig.h +++ b/third_party/python/pyconfig.h @@ -142,8 +142,8 @@ #define HAVE_FSYNC 1 #define HAVE_GETENTROPY 1 #define HAVE_GETLOADAVG 1 +#define HAVE_FSTATVFS 1 /* #undef HAVE_FEXECVE */ -/* #undef HAVE_FSTATVFS */ /* #undef HAVE_FTIME */ /* #define HAVE_GETGROUPS 1 */ /* #define HAVE_SETGROUPS 1 */ @@ -205,8 +205,8 @@ #define HAVE_GETLOGIN 1 #define HAVE_LCHOWN 1 +#define HAVE_LCHMOD 1 /* #undef HAVE_LCHFLAGS */ -/* #undef HAVE_LCHMOD */ /* Define to 1 if you have the `dl' library (-ldl). */ /* #undef HAVE_LIBDL */ @@ -311,6 +311,7 @@ #define HAVE_WAIT3 1 #define HAVE_WAIT4 1 #define HAVE_WAITPID 1 +#define HAVE_STATVFS 1 /* #define HAVE_MREMAP 1 */ /* #undef HAVE_PLOCK */ @@ -320,7 +321,6 @@ /* #undef HAVE_TMPNAM */ /* #undef HAVE_TMPNAM_R */ /* #undef HAVE_SETPGRP */ -/* #undef HAVE_STATVFS */ /* #undef HAVE_STAT_TV_NSEC2 */ /* #undef HAVE_SIGPENDING */ /* #undef HAVE_SIGRELSE */ @@ -513,7 +513,7 @@ /* #define _Py_MEMORY_SANITIZER */ /* #define HAVE_DEV_PTMX 1 */ -/* #define HAVE_OPENPTY 1 */ +/* #define HAVE_OPENPTY 1 */ /* #undef HAVE__GETPTY */ /* #undef HAVE_DEV_PTC */ /* #define HAVE_FORKPTY 1 */