diff options
Diffstat (limited to 'libc/bionic')
| -rw-r--r-- | libc/bionic/pathconf.c | 267 | ||||
| -rw-r--r-- | libc/bionic/pathconf.cpp | 152 | ||||
| -rw-r--r-- | libc/bionic/sysconf.cpp | 8 |
3 files changed, 153 insertions, 274 deletions
diff --git a/libc/bionic/pathconf.c b/libc/bionic/pathconf.c deleted file mode 100644 index cf81272..0000000 --- a/libc/bionic/pathconf.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <pathconf.h> -#include <sys/vfs.h> -#include <sys/limits.h> -#include <errno.h> - -/* these may not be defined yet by our headers */ -#ifndef _POSIX_VDISABLE -#define _POSIX_VDISABLE -1 -#endif - -#ifndef _POSIX_SYNC_IO -#define _POSIX_SYNC_IO -1 -#endif - -#ifndef _POSIX_PRIO_IO -#define _POSIX_PRIO_IO -1 -#endif - -#ifndef _POSIX_ASYNC_IO -#define _POSIX_ASYNC_IO -1 -#endif - - -static long -__filesizebits( struct statfs* s ) -{ -#define EOL_MAGIC 0x0000U - - /* list of known 64-bit aware filesystems */ - static const uint32_t known64[] = { - EXT2_SUPER_MAGIC, - UFS_MAGIC, - REISERFS_SUPER_MAGIC, - XFS_SUPER_MAGIC, - SMB_SUPER_MAGIC, - UDF_SUPER_MAGIC, - JFS_SUPER_MAGIC, - NTFS_SB_MAGIC, - VXFS_SUPER_MAGIC, - EOL_MAGIC - }; - int nn = 0; - - for (; known64[nn] != EOL_MAGIC; ++nn) { - if (known64[nn] == s->f_type) { - return 64; - } - } - return 32; -} - - -static long -__link_max( struct statfs* s ) -{ - // These constant values were taken from kernel headers. - // They're not available in uapi headers. - static const struct { uint32_t type; int max; } knownMax[] = - { - { EXT2_SUPER_MAGIC, 32000 }, - { EXT3_SUPER_MAGIC, 32000 }, - { MINIX_SUPER_MAGIC, 250 }, - { MINIX2_SUPER_MAGIC, 65530 }, - { REISERFS_SUPER_MAGIC, 0xffff - 1000 }, - { UFS_MAGIC, 32000 }, - { EOL_MAGIC, 0 } - }; - int nn = 0; - - for (; knownMax[nn].type != EOL_MAGIC; ++nn) { - if (knownMax[nn].type == s->f_type) { - return knownMax[nn].max; - } - } - return LINK_MAX; -} - -static long -__2_symlinks( struct statfs* s ) -{ - /* list of know filesystems that don't support symlinks */ - static const uint32_t knownNoSymlinks[] = { - ADFS_SUPER_MAGIC, BFS_MAGIC, CRAMFS_MAGIC, - EFS_SUPER_MAGIC, MSDOS_SUPER_MAGIC, NTFS_SB_MAGIC, - QNX4_SUPER_MAGIC, - EOL_MAGIC - }; - int nn = 0; - - for (; knownNoSymlinks[nn] != EOL_MAGIC; ++nn) { - if (knownNoSymlinks[nn] == s->f_type) { - return 0; - } - } - return 1; -} - -static long -__name_max( struct statfs* s ) -{ - return s->f_namelen; -} - -long -pathconf(const char *path, int name) -{ - struct statfs buf; - int ret = statfs( path, &buf ); - - if (ret < 0) - return -1; - - switch (name) { - case _PC_FILESIZEBITS: - return __filesizebits(&buf); - - case _PC_LINK_MAX: - return __link_max(&buf); - - case _PC_MAX_CANON: - return MAX_CANON; - - case _PC_MAX_INPUT: - return MAX_INPUT; - - case _PC_NAME_MAX: - return __name_max(&buf); - - case _PC_PATH_MAX: - return PATH_MAX; - - case _PC_PIPE_BUF: - return PIPE_BUF; - - case _PC_2_SYMLINKS: - return __2_symlinks(&buf); - -#if 0 /* don't know what to do there, the specs are really weird */ - case _PC_ALLOC_SIZE_MIN: - case _PC_REC_INCR_XFER_SIZE: - case _PC_REC_MAX_XFER_SIZE: - case _PC_REC_MIN_XFER_SIZE: - case _PC_REC_XFER_ALIGN: -#endif - - case _PC_SYMLINK_MAX: - return -1; /* no limit */ - - case _PC_CHOWN_RESTRICTED: - return _POSIX_CHOWN_RESTRICTED; - - case _PC_NO_TRUNC: - return _POSIX_NO_TRUNC; - - case _PC_VDISABLE: - return _POSIX_VDISABLE; - - case _PC_ASYNC_IO: - return _POSIX_ASYNC_IO; - - case _PC_PRIO_IO: - return _POSIX_PRIO_IO; - - case _PC_SYNC_IO: - return _POSIX_SYNC_IO; - - default: - errno = EINVAL; - return -1; - } -} - -long fpathconf(int fildes, int name) -{ - struct statfs buf; - int ret = fstatfs(fildes, &buf); - - if (ret < 0) - return -1; - - switch (name) { - case _PC_FILESIZEBITS: - return __filesizebits(&buf); - - case _PC_LINK_MAX: - return __link_max(&buf); - - case _PC_MAX_CANON: - return MAX_CANON; - - case _PC_MAX_INPUT: - return MAX_INPUT; - - case _PC_NAME_MAX: - return __name_max(&buf); - - case _PC_PATH_MAX: - return PATH_MAX; - - case _PC_PIPE_BUF: - return PIPE_BUF; - - case _PC_2_SYMLINKS: - return __2_symlinks(&buf); - -#if 0 /* don't know what to do there, the specs are really weird */ - case _PC_ALLOC_SIZE_MIN: - case _PC_REC_INCR_XFER_SIZE: - case _PC_REC_MAX_XFER_SIZE: - case _PC_REC_MIN_XFER_SIZE: - case _PC_REC_XFER_ALIGN: -#endif - - case _PC_SYMLINK_MAX: - return -1; /* no limit */ - - case _PC_CHOWN_RESTRICTED: - return _POSIX_CHOWN_RESTRICTED; - - case _PC_NO_TRUNC: - return _POSIX_NO_TRUNC; - - case _PC_VDISABLE: - return _POSIX_VDISABLE; - - case _PC_ASYNC_IO: - return _POSIX_ASYNC_IO; - - case _PC_PRIO_IO: - return _POSIX_PRIO_IO; - - case _PC_SYNC_IO: - return _POSIX_SYNC_IO; - - default: - errno = EINVAL; - return -1; - } -} diff --git a/libc/bionic/pathconf.cpp b/libc/bionic/pathconf.cpp new file mode 100644 index 0000000..de9e022 --- /dev/null +++ b/libc/bionic/pathconf.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <unistd.h> + +#include <errno.h> +#include <sys/limits.h> +#include <sys/vfs.h> + +static long __filesizebits(const struct statfs& s) { + switch (s.f_type) { + case JFFS2_SUPER_MAGIC: + case MSDOS_SUPER_MAGIC: + case NCP_SUPER_MAGIC: + return 32; + } + // There won't be any new 32-bit file systems. + return 64; +} + +static long __link_max(const struct statfs& s) { + // These constant values were taken from kernel headers. + // They're not available in uapi headers. + switch (s.f_type) { + case EXT2_SUPER_MAGIC: + return 32000; + case MINIX_SUPER_MAGIC: + return 250; + case MINIX2_SUPER_MAGIC: + return 65530; + case REISERFS_SUPER_MAGIC: + return 0xffff - 1000; + case UFS_MAGIC: + return 32000; + } + return LINK_MAX; +} + +static long __2_symlinks(const struct statfs& s) { + switch (s.f_type) { + case ADFS_SUPER_MAGIC: + case BFS_MAGIC: + case CRAMFS_MAGIC: + case EFS_SUPER_MAGIC: + case MSDOS_SUPER_MAGIC: + case QNX4_SUPER_MAGIC: + return 0; + } + return 1; +} + +static long __pathconf(const struct statfs& s, int name) { + switch (name) { + case _PC_FILESIZEBITS: + return __filesizebits(s); + + case _PC_LINK_MAX: + return __link_max(s); + + case _PC_MAX_CANON: + return MAX_CANON; + + case _PC_MAX_INPUT: + return MAX_INPUT; + + case _PC_NAME_MAX: + return s.f_namelen; + + case _PC_PATH_MAX: + return PATH_MAX; + + case _PC_PIPE_BUF: + return PIPE_BUF; + + case _PC_2_SYMLINKS: + return __2_symlinks(s); + +#if 0 + case _PC_ALLOC_SIZE_MIN: + case _PC_REC_INCR_XFER_SIZE: + case _PC_REC_MAX_XFER_SIZE: + case _PC_REC_MIN_XFER_SIZE: + case _PC_REC_XFER_ALIGN: +#endif + + case _PC_SYMLINK_MAX: + return -1; /* no limit */ + + case _PC_CHOWN_RESTRICTED: + return _POSIX_CHOWN_RESTRICTED; + + case _PC_NO_TRUNC: + return _POSIX_NO_TRUNC; + + case _PC_VDISABLE: + return _POSIX_VDISABLE; + + case _PC_ASYNC_IO: + return -1; + + case _PC_PRIO_IO: + return -1; + + case _PC_SYNC_IO: + return -1; + + default: + errno = EINVAL; + return -1; + } +} + +long pathconf(const char* path, int name) { + struct statfs sb; + if (statfs(path, &sb) == -1) { + return -1; + } + return __pathconf(sb, name); +} + +long fpathconf(int fd, int name) { + struct statfs sb; + if (fstatfs(fd, &sb) == -1) { + return -1; + } + return __pathconf(sb, name); +} diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp index 24a1ae7..951860d 100644 --- a/libc/bionic/sysconf.cpp +++ b/libc/bionic/sysconf.cpp @@ -152,18 +152,12 @@ static int __sysconf_monotonic_clock() { int sysconf(int name) { switch (name) { case _SC_ARG_MAX: return _POSIX_ARG_MAX; - case _SC_BC_BASE_MAX: return _POSIX2_BC_BASE_MAX; - case _SC_BC_DIM_MAX: return _POSIX2_BC_DIM_MAX; - case _SC_BC_SCALE_MAX: return _POSIX2_BC_SCALE_MAX; - case _SC_BC_STRING_MAX: return _POSIX2_BC_STRING_MAX; case _SC_CHILD_MAX: return CHILD_MAX; case _SC_CLK_TCK: return SYSTEM_CLK_TCK; - case _SC_COLL_WEIGHTS_MAX: return _POSIX2_COLL_WEIGHTS_MAX; - case _SC_EXPR_NEST_MAX: return _POSIX2_EXPR_NEST_MAX; case _SC_LINE_MAX: return _POSIX2_LINE_MAX; case _SC_NGROUPS_MAX: return NGROUPS_MAX; case _SC_OPEN_MAX: return OPEN_MAX; - //case _SC_PASS_MAX: return PASS_MAX; + case _SC_PASS_MAX: return PASS_MAX; case _SC_2_C_BIND: return SYSTEM_2_C_BIND; case _SC_2_C_DEV: return SYSTEM_2_C_DEV; case _SC_2_C_VERSION: return SYSTEM_2_C_VER; |
