diff options
Diffstat (limited to 'usr/src/lib/libc/port/gen')
| -rw-r--r-- | usr/src/lib/libc/port/gen/posix_fadvise.c | 101 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/gen/posix_fallocate.c | 106 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/gen/posix_madvise.c | 58 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/gen/posix_memalign.c | 64 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/gen/sysconf.c | 4 |
5 files changed, 332 insertions, 1 deletions
diff --git a/usr/src/lib/libc/port/gen/posix_fadvise.c b/usr/src/lib/libc/port/gen/posix_fadvise.c new file mode 100644 index 0000000000..a42d1a9e88 --- /dev/null +++ b/usr/src/lib/libc/port/gen/posix_fadvise.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "lint.h" +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +/* + * SUSv3 - file advisory information + * + * This function does nothing, but that's OK because the + * Posix specification doesn't require it to do anything + * other than return appropriate error numbers. + * + * In the future, a file system dependent fadvise() or fcntl() + * interface, similar to madvise(), should be developed to enable + * the kernel to optimize I/O operations based on the given advice. + */ + +/* ARGSUSED1 */ +int +posix_fadvise(int fd, off_t offset, off_t len, int advice) +{ + struct stat64 statb; + + switch (advice) { + case POSIX_FADV_NORMAL: + case POSIX_FADV_RANDOM: + case POSIX_FADV_SEQUENTIAL: + case POSIX_FADV_WILLNEED: + case POSIX_FADV_DONTNEED: + case POSIX_FADV_NOREUSE: + break; + default: + return (EINVAL); + } + if (len < 0) + return (EINVAL); + if (fstat64(fd, &statb) != 0) + return (EBADF); + if (S_ISFIFO(statb.st_mode)) + return (ESPIPE); + return (0); +} + +#if !defined(_LP64) + +/* ARGSUSED1 */ +int +posix_fadvise64(int fd, off64_t offset, off64_t len, int advice) +{ + struct stat64 statb; + + switch (advice) { + case POSIX_FADV_NORMAL: + case POSIX_FADV_RANDOM: + case POSIX_FADV_SEQUENTIAL: + case POSIX_FADV_WILLNEED: + case POSIX_FADV_DONTNEED: + case POSIX_FADV_NOREUSE: + break; + default: + return (EINVAL); + } + if (len < 0) + return (EINVAL); + if (fstat64(fd, &statb) != 0) + return (EBADF); + if (S_ISFIFO(statb.st_mode)) + return (ESPIPE); + return (0); +} + +#endif diff --git a/usr/src/lib/libc/port/gen/posix_fallocate.c b/usr/src/lib/libc/port/gen/posix_fallocate.c new file mode 100644 index 0000000000..d82876f1e8 --- /dev/null +++ b/usr/src/lib/libc/port/gen/posix_fallocate.c @@ -0,0 +1,106 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "lint.h" +#include <fcntl.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> + +/* + * Return the proper Posix error number for a failed (EINVAL) fcntl() operation. + */ +static int +fallocate_errno(int fd) +{ + struct stat64 statb; + int error; + + if (fstat64(fd, &statb) != 0) /* can't happen? */ + error = EBADF; + else if (S_ISFIFO(statb.st_mode)) /* pipe or FIFO */ + error = ESPIPE; + else if (!S_ISREG(statb.st_mode)) /* not a regular file */ + error = ENODEV; + else /* the file system doesn't support F_ALLOCSP */ + error = EINVAL; + + return (error); +} + +int +posix_fallocate(int fd, off_t offset, off_t len) +{ + struct flock lck; + int error; + + if (offset < 0 || len <= 0) + return (EINVAL); + + lck.l_whence = 0; + lck.l_start = offset; + lck.l_len = len; + lck.l_type = F_WRLCK; + + if (fcntl(fd, F_ALLOCSP, &lck) == -1) { + if ((error = errno) == EINVAL) + error = fallocate_errno(fd); + else if (error == EOVERFLOW) + error = EFBIG; + return (error); + } + return (0); +} + +#if !defined(_LP64) + +int +posix_fallocate64(int fd, off64_t offset, off64_t len) +{ + struct flock64 lck; + int error; + + if (offset < 0 || len <= 0) + return (EINVAL); + + lck.l_whence = 0; + lck.l_start = offset; + lck.l_len = len; + lck.l_type = F_WRLCK; + + if (fcntl(fd, F_ALLOCSP64, &lck) == -1) { + if ((error = errno) == EINVAL) + error = fallocate_errno(fd); + else if (error == EOVERFLOW) + error = EFBIG; + return (error); + } + return (0); +} + +#endif diff --git a/usr/src/lib/libc/port/gen/posix_madvise.c b/usr/src/lib/libc/port/gen/posix_madvise.c new file mode 100644 index 0000000000..a065746a64 --- /dev/null +++ b/usr/src/lib/libc/port/gen/posix_madvise.c @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "lint.h" +#include <sys/types.h> +#include <sys/mman.h> +#include <errno.h> + +/* + * SUSv3 - memory advisory information and alignment control + * + * The POSIX_MADV_* constants below are defined in <sys/mman.h> + * to have the same values as the corresponding MADV_* constants, + * also defined in <sys/mman.h>, so a direct call to madvise() + * can be made here without further ado. + */ +int +posix_madvise(void *addr, size_t len, int advice) +{ + switch (advice) { + case POSIX_MADV_NORMAL: + case POSIX_MADV_SEQUENTIAL: + case POSIX_MADV_RANDOM: + case POSIX_MADV_WILLNEED: + case POSIX_MADV_DONTNEED: + break; + default: + return (EINVAL); + } + if (madvise(addr, len, advice) == 0) + return (0); + return (errno); +} diff --git a/usr/src/lib/libc/port/gen/posix_memalign.c b/usr/src/lib/libc/port/gen/posix_memalign.c new file mode 100644 index 0000000000..d05ac2d9ea --- /dev/null +++ b/usr/src/lib/libc/port/gen/posix_memalign.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "lint.h" +#include <stdlib.h> +#include <errno.h> + +/* + * SUSv3 - aligned memory allocation + * + * From the SUSv3 specification: + * The value of alignment shall be a power + * of two multiple of sizeof (void *). + * This is enforced below. + * + * From the SUSv3 specification: + * If the size of the space requested is 0, the behavior + * is implementation-defined; the value returned in memptr + * shall be either a null pointer or a unique pointer. + * We choose always to return a null pointer in this case. + * (Not all implementations of memalign() behave this way.) + */ +int +posix_memalign(void **memptr, size_t alignment, size_t size) +{ + void *ptr = NULL; + int error = 0; + + if (alignment == 0 || + (alignment & (sizeof (void *) - 1)) != 0 || + (alignment & (alignment - 1)) != 0) + error = EINVAL; + else if (size != 0 && + (ptr = memalign(alignment, size)) == NULL) + error = ENOMEM; + + *memptr = ptr; + return (error); +} diff --git a/usr/src/lib/libc/port/gen/sysconf.c b/usr/src/lib/libc/port/gen/sysconf.c index 2599bfa4d0..26415015c3 100644 --- a/usr/src/lib/libc/port/gen/sysconf.c +++ b/usr/src/lib/libc/port/gen/sysconf.c @@ -469,6 +469,9 @@ sysconf(int name) case _SC_SHELL: return ((long)_POSIX_SHELL); + case _SC_ADVISORY_INFO: + return ((long)_POSIX_ADVISORY_INFO); + case _SC_HOST_NAME_MAX: return ((long)_POSIX_HOST_NAME_MAX); @@ -506,7 +509,6 @@ sysconf(int name) case _SC_2_PBS_LOCATE: case _SC_2_PBS_MESSAGE: case _SC_2_PBS_TRACK: - case _SC_ADVISORY_INFO: case _SC_CPUTIME: case _SC_SPORADIC_SERVER: case _SC_SS_REPL_MAX: |
