mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
Polyfill statfs() and fstatfs() on BSD distros
This commit is contained in:
parent
e3fe127ccd
commit
f7ee9d7d99
42 changed files with 968 additions and 287 deletions
|
@ -118,6 +118,8 @@ o/$(MODE)/libc/calls/ntcontext2linux.o: private \
|
|||
o/$(MODE)/libc/calls/execl.o \
|
||||
o/$(MODE)/libc/calls/execle.o \
|
||||
o/$(MODE)/libc/calls/execlp.o \
|
||||
o/$(MODE)/libc/calls/statfs.o \
|
||||
o/$(MODE)/libc/calls/fstatfs.o \
|
||||
o/$(MODE)/libc/calls/execve-sysv.o \
|
||||
o/$(MODE)/libc/calls/execve-nt.greg.o \
|
||||
o/$(MODE)/libc/calls/mkntenvblock.o: private \
|
||||
|
|
37
libc/calls/fstatfs.c
Normal file
37
libc/calls/fstatfs.c
Normal 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/strace.internal.h"
|
||||
#include "libc/calls/struct/statfs-meta.internal.h"
|
||||
#include "libc/calls/struct/statfs.internal.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
|
||||
/**
|
||||
* Returns information about filesystem.
|
||||
*/
|
||||
int fstatfs(int fd, struct statfs *sf) {
|
||||
int rc;
|
||||
union statfs_meta m;
|
||||
CheckLargeStackAllocation(&m, sizeof(m));
|
||||
if ((rc = sys_fstatfs(fd, &m)) != -1) {
|
||||
statfs2cosmo(sf, &m);
|
||||
}
|
||||
STRACE("fstatfs(%d, [%s]) → %d% m", fd, DescribeStatfs(rc, sf));
|
||||
return rc;
|
||||
}
|
37
libc/calls/statfs.c
Normal file
37
libc/calls/statfs.c
Normal 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/strace.internal.h"
|
||||
#include "libc/calls/struct/statfs-meta.internal.h"
|
||||
#include "libc/calls/struct/statfs.internal.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
|
||||
/**
|
||||
* Returns information about filesystem.
|
||||
*/
|
||||
int statfs(const char *path, struct statfs *sf) {
|
||||
int rc;
|
||||
union statfs_meta m;
|
||||
CheckLargeStackAllocation(&m, sizeof(m));
|
||||
if ((rc = sys_statfs(path, &m)) != -1) {
|
||||
statfs2cosmo(sf, &m);
|
||||
}
|
||||
STRACE("statfs(%#s, [%s]) → %d% m", path, DescribeStatfs(rc, sf));
|
||||
return rc;
|
||||
}
|
299
libc/calls/statfs2cosmo.c
Normal file
299
libc/calls/statfs2cosmo.c
Normal file
|
@ -0,0 +1,299 @@
|
|||
/*-*- 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-meta.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static const char *DescribeStatfsTypeLinux(int64_t x) {
|
||||
switch (x) {
|
||||
case 0xadf5:
|
||||
return "adfs";
|
||||
case 0xadff:
|
||||
return "affs";
|
||||
case 0x0187:
|
||||
return "autofs";
|
||||
case 0x1373:
|
||||
return "devfs";
|
||||
case 0x1cd1:
|
||||
return "devpts";
|
||||
case 0xf15f:
|
||||
return "ecryptfs";
|
||||
case 0x137d:
|
||||
return "ext1";
|
||||
case 0xef51:
|
||||
return "ext2_old";
|
||||
case 0xef53:
|
||||
return "ext"; // ext2, ext3, ext4
|
||||
case 0x4244:
|
||||
return "hfs";
|
||||
case 0x9660:
|
||||
return "isofs";
|
||||
case 0x72b6:
|
||||
return "jffs2";
|
||||
case 0x137f:
|
||||
return "minix";
|
||||
case 0x138f:
|
||||
return "minix2";
|
||||
case 0x2468:
|
||||
return "minix2";
|
||||
case 0x2478:
|
||||
return "minix22";
|
||||
case 0x4d5a:
|
||||
return "minix3";
|
||||
case 0x4d44:
|
||||
return "msdos";
|
||||
case 0x564c:
|
||||
return "ncp";
|
||||
case 0x6969:
|
||||
return "nfs";
|
||||
case 0x3434:
|
||||
return "nilfs";
|
||||
case 0x9fa1:
|
||||
return "openprom";
|
||||
case 0x9fa0:
|
||||
return "proc";
|
||||
case 0x002f:
|
||||
return "qnx4";
|
||||
case 0x7275:
|
||||
return "romfs";
|
||||
case 0x517b:
|
||||
return "smb";
|
||||
case 0x9fa2:
|
||||
return "usbdevice";
|
||||
case 0x27e0eb:
|
||||
return "cgroup";
|
||||
case 0xbad1dea:
|
||||
return "futexfs";
|
||||
case 0x5346414f:
|
||||
return "afs";
|
||||
case 0x09041934:
|
||||
return "anon_inode_fs";
|
||||
case 0x62646576:
|
||||
return "bdevfs";
|
||||
case 0x42465331:
|
||||
return "befs";
|
||||
case 0x1badface:
|
||||
return "bfs";
|
||||
case 0x42494e4d:
|
||||
return "binfmtfs";
|
||||
case 0xcafe4a11:
|
||||
return "bpf_fs";
|
||||
case 0x9123683e:
|
||||
return "btrfs";
|
||||
case 0x73727279:
|
||||
return "btrfs_test";
|
||||
case 0x63677270:
|
||||
return "cgroup2";
|
||||
case 0xff534d42:
|
||||
return "cifs_number";
|
||||
case 0x73757245:
|
||||
return "coda";
|
||||
case 0x012ff7b7:
|
||||
return "coh";
|
||||
case 0x28cd3d45:
|
||||
return "cramfs";
|
||||
case 0x64626720:
|
||||
return "debugfs";
|
||||
case 0xde5e81e4:
|
||||
return "efivarfs";
|
||||
case 0x00414a53:
|
||||
return "efs";
|
||||
case 0xf2f52010:
|
||||
return "f2fs";
|
||||
case 0x65735546:
|
||||
return "fuse";
|
||||
case 0x00c0ffee:
|
||||
return "hostfs";
|
||||
case 0xf995e849:
|
||||
return "hpfs";
|
||||
case 0x958458f6:
|
||||
return "hugetlbfs";
|
||||
case 0x3153464a:
|
||||
return "jfs";
|
||||
case 0x19800202:
|
||||
return "mqueue";
|
||||
case 0x11307854:
|
||||
return "mtd_inode_fs";
|
||||
case 0x6e736673:
|
||||
return "nsfs";
|
||||
case 0x5346544e:
|
||||
return "ntfs_sb";
|
||||
case 0x7461636f:
|
||||
return "ocfs2";
|
||||
case 0x794c7630:
|
||||
return "overlayfs";
|
||||
case 0x50495045:
|
||||
return "pipefs";
|
||||
case 0x6165676c:
|
||||
return "pstorefs";
|
||||
case 0x68191122:
|
||||
return "qnx6";
|
||||
case 0x858458f6:
|
||||
return "ramfs";
|
||||
case 0x52654973:
|
||||
return "reiserfs";
|
||||
case 0x73636673:
|
||||
return "securityfs";
|
||||
case 0xf97cff8c:
|
||||
return "selinux";
|
||||
case 0x43415d53:
|
||||
return "smack";
|
||||
case 0x534f434b:
|
||||
return "sockfs";
|
||||
case 0x73717368:
|
||||
return "squashfs";
|
||||
case 0x62656572:
|
||||
return "sysfs";
|
||||
case 0x012ff7b6:
|
||||
return "sysv2";
|
||||
case 0x012ff7b5:
|
||||
return "sysv4";
|
||||
case 0x01021994:
|
||||
return "tmpfs";
|
||||
case 0x74726163:
|
||||
return "tracefs";
|
||||
case 0x15013346:
|
||||
return "udf";
|
||||
case 0x00011954:
|
||||
return "ufs";
|
||||
case 0x01021997:
|
||||
return "v9fs";
|
||||
case 0xa501fcf5:
|
||||
return "vxfs";
|
||||
case 0xabba1974:
|
||||
return "xenfs";
|
||||
case 0x012ff7b4:
|
||||
return "xenix";
|
||||
case 0x58465342:
|
||||
return "xfs";
|
||||
case 0x012fd16d:
|
||||
return "_xiafs";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
|
||||
int64_t f_type;
|
||||
int64_t f_bsize;
|
||||
int64_t f_blocks;
|
||||
int64_t f_bfree;
|
||||
int64_t f_bavail;
|
||||
int64_t f_files;
|
||||
int64_t f_ffree;
|
||||
int64_t f_fsid;
|
||||
int64_t f_namelen;
|
||||
int64_t f_frsize;
|
||||
int64_t f_flags;
|
||||
int32_t f_owner;
|
||||
char f_fstypename[16];
|
||||
|
||||
if (IsLinux()) {
|
||||
f_type = m->linux.f_type;
|
||||
f_bsize = m->linux.f_bsize;
|
||||
f_blocks = m->linux.f_blocks;
|
||||
f_bfree = m->linux.f_bfree;
|
||||
f_bavail = m->linux.f_bavail;
|
||||
f_files = m->linux.f_files;
|
||||
f_ffree = m->linux.f_ffree;
|
||||
f_fsid = m->linux.f_fsid;
|
||||
f_namelen = m->linux.f_namelen;
|
||||
f_frsize = m->linux.f_frsize;
|
||||
f_flags = m->linux.f_flags;
|
||||
f_owner = 0;
|
||||
strcpy(f_fstypename, DescribeStatfsTypeLinux(m->linux.f_type));
|
||||
|
||||
} else if (IsFreebsd()) {
|
||||
f_type = m->freebsd.f_type;
|
||||
f_bsize = m->freebsd.f_bsize;
|
||||
f_blocks = m->freebsd.f_blocks;
|
||||
f_bfree = m->freebsd.f_bfree;
|
||||
f_bavail = m->freebsd.f_bavail;
|
||||
f_files = m->freebsd.f_files;
|
||||
f_ffree = m->freebsd.f_ffree;
|
||||
f_fsid = m->freebsd.f_fsid;
|
||||
f_namelen = m->freebsd.f_namemax;
|
||||
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);
|
||||
|
||||
} else if (IsXnu()) {
|
||||
f_type = m->xnu.f_type;
|
||||
f_bsize = m->xnu.f_bsize;
|
||||
f_blocks = m->xnu.f_blocks;
|
||||
f_bfree = m->xnu.f_bfree;
|
||||
f_bavail = m->xnu.f_bavail;
|
||||
f_files = m->xnu.f_files;
|
||||
f_ffree = m->xnu.f_ffree;
|
||||
f_fsid = m->xnu.f_fsid;
|
||||
f_namelen = 4096;
|
||||
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);
|
||||
|
||||
} else if (IsOpenbsd()) {
|
||||
f_type = f->f_type;
|
||||
f_bsize = m->openbsd.f_bsize;
|
||||
f_blocks = m->openbsd.f_blocks;
|
||||
f_bfree = m->openbsd.f_bfree;
|
||||
f_bavail = m->openbsd.f_bavail;
|
||||
f_files = m->openbsd.f_files;
|
||||
f_ffree = m->openbsd.f_ffree;
|
||||
f_fsid = m->openbsd.f_fsid;
|
||||
f_namelen = m->openbsd.f_namemax;
|
||||
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);
|
||||
|
||||
} else if (IsNetbsd()) {
|
||||
f_type = m->netbsd.f_type;
|
||||
f_bsize = m->netbsd.f_bsize;
|
||||
f_blocks = m->netbsd.f_blocks;
|
||||
f_bfree = m->netbsd.f_bfree;
|
||||
f_bavail = m->netbsd.f_bavail;
|
||||
f_files = m->netbsd.f_files;
|
||||
f_ffree = m->netbsd.f_ffree;
|
||||
f_fsid = m->netbsd.f_fsid;
|
||||
f_namelen = f->f_namelen;
|
||||
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);
|
||||
|
||||
} else {
|
||||
asm("hlt");
|
||||
unreachable;
|
||||
}
|
||||
|
||||
f->f_type = f_type;
|
||||
f->f_bsize = f_bsize;
|
||||
f->f_blocks = f_blocks;
|
||||
f->f_bfree = f_bfree;
|
||||
f->f_bavail = f_bavail;
|
||||
f->f_files = f_files;
|
||||
f->f_ffree = f_ffree;
|
||||
f->f_fsid = f_fsid;
|
||||
f->f_namelen = f_namelen;
|
||||
f->f_frsize = f_frsize;
|
||||
f->f_flags = f_flags;
|
||||
strcpy(f->f_fstypename, f_fstypename);
|
||||
}
|
33
libc/calls/struct/statfs-freebsd.internal.h
Normal file
33
libc/calls/struct/statfs-freebsd.internal.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct statfs_freebsd {
|
||||
uint32_t f_version; /* structure version number */
|
||||
uint32_t f_type; /* type of filesystem */
|
||||
uint64_t f_flags; /* copy of mount exported flags */
|
||||
uint64_t f_bsize; /* filesystem fragment size */
|
||||
uint64_t f_iosize; /* optimal transfer block size */
|
||||
uint64_t f_blocks; /* total data blocks in filesystem */
|
||||
uint64_t f_bfree; /* free blocks in filesystem */
|
||||
int64_t f_bavail; /* free blocks avail to non-superuser */
|
||||
uint64_t f_files; /* total file nodes in filesystem */
|
||||
int64_t f_ffree; /* free nodes avail to non-superuser */
|
||||
uint64_t f_syncwrites; /* count of sync writes since mount */
|
||||
uint64_t f_asyncwrites; /* count of async writes since mount */
|
||||
uint64_t f_syncreads; /* count of sync reads since mount */
|
||||
uint64_t f_asyncreads; /* count of async reads since mount */
|
||||
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) */
|
||||
char f_charspare[80]; /* spare string space */
|
||||
char f_fstypename[16]; /* filesystem type name */
|
||||
char f_mntfromname[1024]; /* mounted filesystem */
|
||||
char f_mntonname[1024]; /* directory on which mounted */
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_FREEBSD_INTERNAL_H_ */
|
23
libc/calls/struct/statfs-linux.internal.h
Normal file
23
libc/calls/struct/statfs-linux.internal.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct statfs_linux {
|
||||
int64_t f_type; /* type of filesystem */
|
||||
int64_t f_bsize; /* optimal transfer block size */
|
||||
int64_t f_blocks; /* total data blocks in filesystem */
|
||||
int64_t f_bfree; /* free blocks in filesystem */
|
||||
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 */
|
||||
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 */
|
||||
int64_t f_spare[4];
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_LINUX_INTERNAL_H_ */
|
24
libc/calls/struct/statfs-meta.internal.h
Normal file
24
libc/calls/struct/statfs-meta.internal.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_
|
||||
#include "libc/calls/struct/statfs-freebsd.internal.h"
|
||||
#include "libc/calls/struct/statfs-linux.internal.h"
|
||||
#include "libc/calls/struct/statfs-netbsd.internal.h"
|
||||
#include "libc/calls/struct/statfs-openbsd.internal.h"
|
||||
#include "libc/calls/struct/statfs-xnu.internal.h"
|
||||
#include "libc/calls/struct/statfs.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
union statfs_meta {
|
||||
struct statfs_linux linux;
|
||||
struct statfs_xnu xnu;
|
||||
struct statfs_freebsd freebsd;
|
||||
struct statfs_openbsd openbsd;
|
||||
struct statfs_netbsd netbsd;
|
||||
};
|
||||
|
||||
void statfs2cosmo(struct statfs *, const union statfs_meta *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_META_INTERNAL_H_ */
|
29
libc/calls/struct/statfs-netbsd.internal.h
Normal file
29
libc/calls/struct/statfs-netbsd.internal.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct statfs_netbsd {
|
||||
int16_t f_type; /* type of file system */
|
||||
uint16_t f_oflags; /* deprecated copy of mount flags */
|
||||
int64_t f_bsize; /* fundamental file system block size */
|
||||
int64_t f_iosize; /* optimal transfer block size */
|
||||
int64_t f_blocks; /* total data blocks in file system */
|
||||
int64_t f_bfree; /* free blocks in fs */
|
||||
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) */
|
||||
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 */
|
||||
int64_t f_asyncwrites; /* count of async writes since mount */
|
||||
int64_t f_spare[1]; /* spare for later */
|
||||
char f_fstypename[16]; /* fs type name */
|
||||
char f_mntonname[90]; /* directory on which mounted */
|
||||
char f_mntfromname[90]; /* mounted file system */
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_NETBSD_H_ */
|
135
libc/calls/struct/statfs-openbsd.internal.h
Normal file
135
libc/calls/struct/statfs-openbsd.internal.h
Normal file
|
@ -0,0 +1,135 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct xucred_openbsd {
|
||||
uint32_t cr_uid; /* user id */
|
||||
uint32_t cr_gid; /* group id */
|
||||
int16_t cr_ngroups; /* number of groups */
|
||||
uint32_t cr_groups[16]; /* groups */
|
||||
};
|
||||
|
||||
struct export_args_openbsd {
|
||||
int32_t ex_flags; /* export related flags */
|
||||
uint32_t ex_root; /* mapping for root uid */
|
||||
struct xucred_openbsd ex_anon; /* mapping for anonymous user */
|
||||
struct sockaddr *ex_addr; /* net address to which exported */
|
||||
int32_t ex_addrlen; /* and the net address length */
|
||||
struct sockaddr *ex_mask; /* mask of valid bits in saddr */
|
||||
int32_t ex_masklen; /* and the smask length */
|
||||
};
|
||||
|
||||
struct ufs_args_openbsd {
|
||||
char *fspec; /* block special device to mount */
|
||||
struct export_args_openbsd export_info; /* network export information */
|
||||
};
|
||||
|
||||
struct mfs_args_openbsd {
|
||||
char *fspec; /* name to export for statfs */
|
||||
struct export_args_openbsd export_info; /* if exported MFSes are supported */
|
||||
char *base; /* base of file system in memory */
|
||||
uint64_t size; /* size of file system */
|
||||
};
|
||||
|
||||
struct iso_args_openbsd {
|
||||
char *fspec; /* block special device to mount */
|
||||
struct export_args_openbsd export_info; /* network export info */
|
||||
int32_t flags; /* mounting flags, see below */
|
||||
int32_t sess; /* start sector of session */
|
||||
};
|
||||
|
||||
struct nfs_args_openbsd {
|
||||
int32_t version; /* args structure version number */
|
||||
struct sockaddr *addr; /* file server address */
|
||||
int32_t addrlen; /* length of address */
|
||||
int32_t sotype; /* Socket type */
|
||||
int32_t proto; /* and Protocol */
|
||||
unsigned char *fh; /* File handle to be mounted */
|
||||
int32_t fhsize; /* Size, in bytes, of fh */
|
||||
int32_t flags; /* flags */
|
||||
int32_t wsize; /* write size in bytes */
|
||||
int32_t rsize; /* read size in bytes */
|
||||
int32_t readdirsize; /* readdir size in bytes */
|
||||
int32_t timeo; /* initial timeout in .1 secs */
|
||||
int32_t retrans; /* times to retry send */
|
||||
int32_t maxgrouplist; /* Max. size of group list */
|
||||
int32_t readahead; /* # of blocks to readahead */
|
||||
int32_t leaseterm; /* Term (sec) of lease */
|
||||
int32_t deadthresh; /* Retrans threshold */
|
||||
char *hostname; /* server's name */
|
||||
int32_t acregmin; /* Attr cache file recently modified */
|
||||
int32_t acregmax; /* ac file not recently modified */
|
||||
int32_t acdirmin; /* ac for dir recently modified */
|
||||
int32_t acdirmax; /* ac for dir not recently modified */
|
||||
};
|
||||
|
||||
struct msdosfs_args_openbsd {
|
||||
char *fspec; /* blocks special holding the fs to mount */
|
||||
struct export_args_openbsd export_info; /* network export information */
|
||||
uint32_t uid; /* uid that owns msdosfs files */
|
||||
uint32_t gid; /* gid that owns msdosfs files */
|
||||
uint32_t mask; /* mask to be applied for msdosfs perms */
|
||||
int32_t flags; /* see below */
|
||||
};
|
||||
|
||||
struct ntfs_args_openbsd {
|
||||
char *fspec; /* block special device to mount */
|
||||
struct export_args_openbsd export_info; /* network export information */
|
||||
uint32_t uid; /* uid that owns ntfs files */
|
||||
uint32_t gid; /* gid that owns ntfs files */
|
||||
uint32_t mode; /* mask to be applied for ntfs perms */
|
||||
uint64_t flag; /* additional flags */
|
||||
};
|
||||
|
||||
struct tmpfs_args_openbsd {
|
||||
int32_t ta_version;
|
||||
/* Size counters. */
|
||||
uint64_t ta_nodes_max;
|
||||
int64_t ta_size_max;
|
||||
/* Root node attributes. */
|
||||
uint32_t ta_root_uid;
|
||||
uint32_t ta_root_gid;
|
||||
uint32_t ta_root_mode;
|
||||
};
|
||||
|
||||
union mount_info_openbsd {
|
||||
struct ufs_args_openbsd ufs_args;
|
||||
struct mfs_args_openbsd mfs_args;
|
||||
struct nfs_args_openbsd nfs_args;
|
||||
struct iso_args_openbsd iso_args;
|
||||
struct msdosfs_args_openbsd msdosfs_args;
|
||||
struct ntfs_args_openbsd ntfs_args;
|
||||
struct tmpfs_args_openbsd tmpfs_args;
|
||||
char __align[160]; /* 64-bit alignment and room to grow */
|
||||
};
|
||||
|
||||
struct statfs_openbsd {
|
||||
uint32_t f_flags; /* copy of mount flags */
|
||||
uint32_t f_bsize; /* file system block size */
|
||||
uint32_t f_iosize; /* optimal transfer block size */
|
||||
uint64_t f_blocks; /* total data blocks in file system */
|
||||
uint64_t f_bfree; /* free blocks in fs */
|
||||
int64_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 */
|
||||
int64_t f_favail; /* free file nodes avail to non-root */
|
||||
uint64_t f_syncwrites; /* count of sync writes 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_asyncreads; /* count of async reads since mount */
|
||||
uint64_t f_fsid; /* file system id (endian 32 matters) */
|
||||
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 */
|
||||
char f_fstypename[16]; /* fs type name */
|
||||
char f_mntonname[90]; /* directory on which mounted */
|
||||
char f_mntfromname[90]; /* mounted file system */
|
||||
char f_mntfromspec[90]; /* special for mount request */
|
||||
union mount_info_openbsd mount_info; /* per-filesystem mount options */
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_OPENBSD_H_ */
|
28
libc/calls/struct/statfs-xnu.internal.h
Normal file
28
libc/calls/struct/statfs-xnu.internal.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct statfs_xnu {
|
||||
uint32_t f_bsize; /* fundamental file system block size */
|
||||
int32_t f_iosize; /* optimal transfer block size */
|
||||
uint64_t f_blocks; /* total data blocks in file system */
|
||||
uint64_t f_bfree; /* free blocks in fs */
|
||||
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) */
|
||||
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 */
|
||||
uint32_t f_fssubtype; /* fs sub-type (flavor) */
|
||||
char f_fstypename[16]; /* fs type name */
|
||||
char f_mntonname[4096]; /* directory on which mounted */
|
||||
char f_mntfromname[4096]; /* mounted filesystem */
|
||||
uint32_t f_flags_ext; /* extended flags */
|
||||
uint32_t f_reserved[7]; /* For future use */
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_XNU_INTERNAL_H_ */
|
|
@ -3,19 +3,21 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct statfs {
|
||||
int64_t f_type; /* type of filesystem */
|
||||
int64_t f_bsize; /* optimal transfer block size */
|
||||
int64_t f_blocks; /* total data blocks in filesystem */
|
||||
int64_t f_bfree; /* free blocks in filesystem */
|
||||
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 */
|
||||
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 */
|
||||
int64_t f_spare[4];
|
||||
struct statfs { /* cosmo abi */
|
||||
int64_t f_type; /* type of filesystem */
|
||||
int64_t f_bsize; /* optimal transfer block size */
|
||||
int64_t f_blocks; /* total data blocks in filesystem */
|
||||
int64_t f_bfree; /* free blocks in filesystem */
|
||||
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 */
|
||||
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 */
|
||||
int64_t f_spare[4]; /* end of linux abi */
|
||||
uint32_t f_owner;
|
||||
char f_fstypename[16];
|
||||
};
|
||||
|
||||
int statfs(const char *, struct statfs *);
|
||||
|
|
17
libc/calls/struct/statfs.internal.h
Normal file
17
libc/calls/struct/statfs.internal.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef 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.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sys_statfs(const char *, union statfs_meta *);
|
||||
int sys_fstatfs(int, union statfs_meta *);
|
||||
|
||||
const char *DescribeStatfs(char[300], int, const struct statfs *);
|
||||
#define DescribeStatfs(rc, sf) DescribeStatfs(alloca(300), rc, sf)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_INTERNAL_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue