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

View file

@ -122,6 +122,8 @@ int ioprio_set(int, int, int);
int issetugid(void); int issetugid(void);
int kill(int, int); int kill(int, int);
int killpg(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 link(const char *, const char *) dontthrow;
int linkat(int, const char *, int, const char *, int); int linkat(int, const char *, int, const char *, int);
int madvise(void *, uint64_t, int); int madvise(void *, uint64_t, int);

View file

@ -177,7 +177,8 @@ o//libc/calls/fcntl.o: private \
# it's early runtime mandatory and quite huge without it # it's early runtime mandatory and quite huge without it
o//libc/calls/getcwd.greg.o \ o//libc/calls/getcwd.greg.o \
o//libc/calls/getcwd-nt.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 += \ OVERRIDE_CFLAGS += \
-Os -Os

View file

@ -18,6 +18,7 @@
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/struct/fsid.h"
#include "libc/calls/struct/statfs.h" #include "libc/calls/struct/statfs.h"
#include "libc/calls/struct/statfs.internal.h" #include "libc/calls/struct/statfs.internal.h"
#include "libc/calls/syscall_support-nt.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_fstypename[j] = 0;
f->f_type = h; f->f_type = h;
f->f_fsid = VolumeSerialNumber; f->f_fsid = (fsid_t){{VolumeSerialNumber}};
f->f_flags = FileSystemFlags; f->f_flags = FileSystemFlags;
f->f_bsize = fs.BytesPerSector; f->f_bsize = fs.BytesPerSector;
f->f_bsize *= fs.SectorsPerAllocationUnit; f->f_bsize *= fs.SectorsPerAllocationUnit;

View file

@ -27,6 +27,7 @@
/** /**
* Returns information about filesystem. * Returns information about filesystem.
* @return 0 on success, or -1 w/ errno
*/ */
int fstatfs(int fd, struct statfs *sf) { int fstatfs(int fd, struct statfs *sf) {
int rc; int rc;

37
libc/calls/fstatvfs.c Normal file
View file

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

34
libc/calls/lchmod.c Normal file
View file

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

View file

@ -28,6 +28,7 @@
/** /**
* Returns information about filesystem. * Returns information about filesystem.
* @return 0 on success, or -1 w/ errno
*/ */
int statfs(const char *path, struct statfs *sf) { int statfs(const char *path, struct statfs *sf) {
int rc; int rc;

View file

@ -197,7 +197,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
int64_t f_bavail; int64_t f_bavail;
int64_t f_files; int64_t f_files;
int64_t f_ffree; int64_t f_ffree;
int64_t f_fsid; fsid_t f_fsid;
int64_t f_namelen; int64_t f_namelen;
int64_t f_frsize; int64_t f_frsize;
int64_t f_flags; 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_frsize = m->linux.f_frsize;
f_flags = m->linux.f_flags; f_flags = m->linux.f_flags;
f_owner = 0; f_owner = 0;
bzero(f_fstypename, 16);
strcpy(f_fstypename, DescribeStatfsTypeLinux(m->linux.f_type)); strcpy(f_fstypename, DescribeStatfsTypeLinux(m->linux.f_type));
} else if (IsFreebsd()) { } else if (IsFreebsd()) {
@ -232,7 +233,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
f_frsize = m->freebsd.f_bsize; f_frsize = m->freebsd.f_bsize;
f_flags = m->freebsd.f_flags; f_flags = m->freebsd.f_flags;
f_owner = m->freebsd.f_owner; f_owner = m->freebsd.f_owner;
strcpy(f_fstypename, m->freebsd.f_fstypename); memcpy(f_fstypename, m->freebsd.f_fstypename, 16);
} else if (IsXnu()) { } else if (IsXnu()) {
f_type = m->xnu.f_type; 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_frsize = m->xnu.f_bsize;
f_flags = m->xnu.f_flags; f_flags = m->xnu.f_flags;
f_owner = m->xnu.f_owner; f_owner = m->xnu.f_owner;
strcpy(f_fstypename, m->xnu.f_fstypename); memcpy(f_fstypename, m->xnu.f_fstypename, 16);
} else if (IsOpenbsd()) { } else if (IsOpenbsd()) {
f_type = f->f_type; 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_frsize = m->openbsd.f_bsize;
f_flags = m->openbsd.f_flags; f_flags = m->openbsd.f_flags;
f_owner = m->openbsd.f_owner; f_owner = m->openbsd.f_owner;
strcpy(f_fstypename, m->openbsd.f_fstypename); memcpy(f_fstypename, m->openbsd.f_fstypename, 16);
} else if (IsNetbsd()) { } else if (IsNetbsd()) {
f_type = m->netbsd.f_type; 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_frsize = m->netbsd.f_bsize;
f_flags = m->netbsd.f_flags; f_flags = m->netbsd.f_flags;
f_owner = m->netbsd.f_owner; f_owner = m->netbsd.f_owner;
strcpy(f_fstypename, m->netbsd.f_fstypename); memcpy(f_fstypename, m->netbsd.f_fstypename, 16);
} else { } else {
asm("hlt"); asm("hlt");
@ -295,5 +296,5 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
f->f_namelen = f_namelen; f->f_namelen = f_namelen;
f->f_frsize = f_frsize; f->f_frsize = f_frsize;
f->f_flags = f_flags; f->f_flags = f_flags;
strcpy(f->f_fstypename, f_fstypename); memcpy(f->f_fstypename, f_fstypename, 16);
} }

View file

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

37
libc/calls/statvfs.c Normal file
View file

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

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_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
#define 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) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -21,7 +22,7 @@ struct statfs_freebsd {
uint64_t f_spare[10]; /* unused spare */ uint64_t f_spare[10]; /* unused spare */
uint32_t f_namemax; /* maximum filename length */ uint32_t f_namemax; /* maximum filename length */
uint32_t f_owner; /* user that mounted the filesystem */ 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_charspare[80]; /* spare string space */
char f_fstypename[16]; /* filesystem type name */ char f_fstypename[16]; /* filesystem type name */
char f_mntfromname[1024]; /* mounted filesystem */ char f_mntfromname[1024]; /* mounted filesystem */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_
#define 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) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs_linux {
int64_t f_bavail; /* free blocks available to */ int64_t f_bavail; /* free blocks available to */
int64_t f_files; /* total file nodes in filesystem */ int64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free 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_namelen; /* maximum length of filenames */
int64_t f_frsize; /* fragment size */ int64_t f_frsize; /* fragment size */
int64_t f_flags; /* mount flags of filesystem 2.6.36 */ 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_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
#define 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) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -13,7 +14,7 @@ struct statfs_netbsd {
int64_t f_bavail; /* free blocks avail to non-superuser */ int64_t f_bavail; /* free blocks avail to non-superuser */
int64_t f_files; /* total file nodes in file system */ int64_t f_files; /* total file nodes in file system */
int64_t f_ffree; /* free file nodes in fs */ 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 */ uint32_t f_owner; /* user that mounted the file system */
int64_t f_flags; /* copy of mount flags */ int64_t f_flags; /* copy of mount flags */
int64_t f_syncwrites; /* count of sync writes since mount */ int64_t f_syncwrites; /* count of sync writes since mount */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_
#define 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" #include "libc/sock/struct/sockaddr.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -119,7 +120,7 @@ struct statfs_openbsd {
uint64_t f_syncreads; /* count of sync reads since mount */ uint64_t f_syncreads; /* count of sync reads since mount */
uint64_t f_asyncwrites; /* count of async writes 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_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_namemax; /* maximum filename length */
uint32_t f_owner; /* user that mounted the file system */ uint32_t f_owner; /* user that mounted the file system */
uint64_t f_ctime; /* last mount [-u] time */ uint64_t f_ctime; /* last mount [-u] time */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
#define 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) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs_xnu {
uint64_t f_bavail; /* free blocks avail to non-superuser */ uint64_t f_bavail; /* free blocks avail to non-superuser */
uint64_t f_files; /* total file nodes in file system */ uint64_t f_files; /* total file nodes in file system */
uint64_t f_ffree; /* free file nodes in fs */ 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_owner; /* user that mounted the filesystem */
uint32_t f_type; /* type of filesystem */ uint32_t f_type; /* type of filesystem */
uint32_t f_flags; /* copy of mount exported flags */ uint32_t f_flags; /* copy of mount exported flags */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
#include "libc/calls/struct/fsid.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
@ -11,7 +12,7 @@ struct statfs { /* cosmo abi */
int64_t f_bavail; /* free blocks available to unprivileged users */ int64_t f_bavail; /* free blocks available to unprivileged users */
int64_t f_files; /* total file nodes in filesystem */ int64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free 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_namelen; /* maximum length of filenames */
int64_t f_frsize; /* fragment size */ int64_t f_frsize; /* fragment size */
int64_t f_flags; /* mount flags of filesystem 2.6.36 */ 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_ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_
#include "libc/calls/struct/statfs-meta.internal.h" #include "libc/calls/struct/statfs-meta.internal.h"
#include "libc/calls/struct/statfs.h" #include "libc/calls/struct/statfs.h"
#include "libc/calls/struct/statvfs.h"
#include "libc/mem/alloca.h" #include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ 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(int, union statfs_meta *);
int sys_fstatfs_nt(int64_t, struct statfs *); int sys_fstatfs_nt(int64_t, struct statfs *);
int sys_statfs_nt(const char *, 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 *); const char *DescribeStatfs(char[300], int, const struct statfs *);
#define DescribeStatfs(rc, sf) DescribeStatfs(alloca(300), rc, sf) #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_ */

View file

@ -4,7 +4,7 @@
#define MAXSYMLINKS 20 #define MAXSYMLINKS 20
#define MAXHOSTNAMELEN 64 #define MAXHOSTNAMELEN 64
#define MAXNAMLEN 255 #define MAXNAMLEN 255
#define MAXPATHLEN 4096 #define MAXPATHLEN PATH_MAX
#define NBBY 8 #define NBBY 8
#define NGROUPS 32 #define NGROUPS 32
#define CANBSIZ 255 #define CANBSIZ 255

View file

@ -7,6 +7,7 @@
#define L_ctermid 20 #define L_ctermid 20
#define FILENAME_MAX PATH_MAX #define FILENAME_MAX PATH_MAX
#define FOPEN_MAX 1000 #define FOPEN_MAX 1000
#define TMP_MAX 10000
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_

View file

@ -2237,9 +2237,12 @@ static int LuaUnixStatfsFfree(lua_State *L) {
} }
// unix.Statfs:fsid() // unix.Statfs:fsid()
// └─→ fsid:int // └─→ x:int, y:int
static int LuaUnixStatfsFsid(lua_State *L) { 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() // unix.Statfs:namelen()
@ -2314,10 +2317,14 @@ static int LuaUnixStatfsToString(lua_State *L) {
FormatInt64(ibuf, f->f_ffree); FormatInt64(ibuf, f->f_ffree);
luaL_addstring(&b, ibuf); luaL_addstring(&b, ibuf);
} }
if (f->f_fsid) { if (f->f_fsid.__val[0] || f->f_fsid.__val[1]) {
luaL_addstring(&b, ", fsid="); luaL_addstring(&b, ", fsid={");
FormatUint64(ibuf, f->f_fsid); FormatUint64(ibuf, f->f_fsid.__val[0]);
luaL_addstring(&b, ibuf); 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) { if (f->f_namelen) {
luaL_addstring(&b, ", namelen="); luaL_addstring(&b, ", namelen=");

View file

@ -13,12 +13,14 @@
#include "libc/calls/struct/iovec.h" #include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/stat.macros.h" #include "libc/calls/struct/stat.macros.h"
#include "libc/calls/struct/statvfs.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/tms.h" #include "libc/calls/struct/tms.h"
#include "libc/calls/struct/utsname.h" #include "libc/calls/struct/utsname.h"
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/sysparam.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h" #include "libc/calls/weirdtypes.h"
#include "libc/dce.h" #include "libc/dce.h"
@ -49,6 +51,7 @@
#include "libc/sysv/consts/prio.h" #include "libc/sysv/consts/prio.h"
#include "libc/sysv/consts/s.h" #include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/sched.h" #include "libc/sysv/consts/sched.h"
#include "libc/sysv/consts/seek.h"
#include "libc/sysv/consts/sf.h" #include "libc/sysv/consts/sf.h"
#include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/st.h" #include "libc/sysv/consts/st.h"
@ -122,14 +125,6 @@ module os
#define NAMLEN(dirent) strlen((dirent)->d_name) #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 #ifdef UNION_WAIT
/* Emulate some macros on systems that have a union instead of macros */ /* Emulate some macros on systems that have a union instead of macros */

View file

@ -142,8 +142,8 @@
#define HAVE_FSYNC 1 #define HAVE_FSYNC 1
#define HAVE_GETENTROPY 1 #define HAVE_GETENTROPY 1
#define HAVE_GETLOADAVG 1 #define HAVE_GETLOADAVG 1
#define HAVE_FSTATVFS 1
/* #undef HAVE_FEXECVE */ /* #undef HAVE_FEXECVE */
/* #undef HAVE_FSTATVFS */
/* #undef HAVE_FTIME */ /* #undef HAVE_FTIME */
/* #define HAVE_GETGROUPS 1 */ /* #define HAVE_GETGROUPS 1 */
/* #define HAVE_SETGROUPS 1 */ /* #define HAVE_SETGROUPS 1 */
@ -205,8 +205,8 @@
#define HAVE_GETLOGIN 1 #define HAVE_GETLOGIN 1
#define HAVE_LCHOWN 1 #define HAVE_LCHOWN 1
#define HAVE_LCHMOD 1
/* #undef HAVE_LCHFLAGS */ /* #undef HAVE_LCHFLAGS */
/* #undef HAVE_LCHMOD */
/* Define to 1 if you have the `dl' library (-ldl). */ /* Define to 1 if you have the `dl' library (-ldl). */
/* #undef HAVE_LIBDL */ /* #undef HAVE_LIBDL */
@ -311,6 +311,7 @@
#define HAVE_WAIT3 1 #define HAVE_WAIT3 1
#define HAVE_WAIT4 1 #define HAVE_WAIT4 1
#define HAVE_WAITPID 1 #define HAVE_WAITPID 1
#define HAVE_STATVFS 1
/* #define HAVE_MREMAP 1 */ /* #define HAVE_MREMAP 1 */
/* #undef HAVE_PLOCK */ /* #undef HAVE_PLOCK */
@ -320,7 +321,6 @@
/* #undef HAVE_TMPNAM */ /* #undef HAVE_TMPNAM */
/* #undef HAVE_TMPNAM_R */ /* #undef HAVE_TMPNAM_R */
/* #undef HAVE_SETPGRP */ /* #undef HAVE_SETPGRP */
/* #undef HAVE_STATVFS */
/* #undef HAVE_STAT_TV_NSEC2 */ /* #undef HAVE_STAT_TV_NSEC2 */
/* #undef HAVE_SIGPENDING */ /* #undef HAVE_SIGPENDING */
/* #undef HAVE_SIGRELSE */ /* #undef HAVE_SIGRELSE */
@ -513,7 +513,7 @@
/* #define _Py_MEMORY_SANITIZER */ /* #define _Py_MEMORY_SANITIZER */
/* #define HAVE_DEV_PTMX 1 */ /* #define HAVE_DEV_PTMX 1 */
/* #define HAVE_OPENPTY 1 */ /* #define HAVE_OPENPTY 1 */
/* #undef HAVE__GETPTY */ /* #undef HAVE__GETPTY */
/* #undef HAVE_DEV_PTC */ /* #undef HAVE_DEV_PTC */
/* #define HAVE_FORKPTY 1 */ /* #define HAVE_FORKPTY 1 */