summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/amd64/Makefile5
-rw-r--r--usr/src/lib/libc/i386/Makefile.com5
-rw-r--r--usr/src/lib/libc/i386/mapfile-vers1
-rw-r--r--usr/src/lib/libc/port/gen/posix_fadvise.c101
-rw-r--r--usr/src/lib/libc/port/gen/posix_fallocate.c (renamed from usr/src/lib/libc/port/rt/fallocate.c)46
-rw-r--r--usr/src/lib/libc/port/gen/posix_madvise.c58
-rw-r--r--usr/src/lib/libc/port/gen/posix_memalign.c64
-rw-r--r--usr/src/lib/libc/port/gen/sysconf.c4
-rw-r--r--usr/src/lib/libc/port/mapfile-vers3
-rw-r--r--usr/src/lib/libc/sparc/Makefile5
-rw-r--r--usr/src/lib/libc/sparc/mapfile-vers1
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile5
12 files changed, 287 insertions, 11 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index d2db427b4f..63ecf31a34 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -488,6 +488,10 @@ PORTGEN= \
pfmt_print.o \
plock.o \
poll.o \
+ posix_fadvise.o \
+ posix_fallocate.o \
+ posix_madvise.o \
+ posix_memalign.o \
priocntl.o \
privlib.o \
priv_str_xlate.o \
@@ -722,7 +726,6 @@ AIOOBJS= \
RTOBJS= \
clock_timer.o \
- fallocate.o \
mqueue.o \
pos4obj.o \
sched.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 8303dee02d..1cb7299a8c 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -520,6 +520,10 @@ PORTGEN= \
pfmt_print.o \
plock.o \
poll.o \
+ posix_fadvise.o \
+ posix_fallocate.o \
+ posix_madvise.o \
+ posix_memalign.o \
priocntl.o \
privlib.o \
priv_str_xlate.o \
@@ -765,7 +769,6 @@ AIOOBJS= \
RTOBJS= \
clock_timer.o \
- fallocate.o \
mqueue.o \
pos4obj.o \
sched.o \
diff --git a/usr/src/lib/libc/i386/mapfile-vers b/usr/src/lib/libc/i386/mapfile-vers
index 8ac01ff58f..bca5ff395d 100644
--- a/usr/src/lib/libc/i386/mapfile-vers
+++ b/usr/src/lib/libc/i386/mapfile-vers
@@ -40,6 +40,7 @@ SUNW_1.23 {
enable_extended_FILE_stdio;
lio_listio64;
mkstemps64;
+ posix_fadvise64;
posix_fallocate64;
};
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/rt/fallocate.c b/usr/src/lib/libc/port/gen/posix_fallocate.c
index 1f7a627fd9..d82876f1e8 100644
--- a/usr/src/lib/libc/port/rt/fallocate.c
+++ b/usr/src/lib/libc/port/gen/posix_fallocate.c
@@ -27,16 +27,40 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#include "lint.h"
-#include <errno.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;
-#include <stdio.h>
+ 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;
@@ -44,9 +68,12 @@ posix_fallocate(int fd, off_t offset, off_t len)
lck.l_type = F_WRLCK;
if (fcntl(fd, F_ALLOCSP, &lck) == -1) {
- return (-1);
+ if ((error = errno) == EINVAL)
+ error = fallocate_errno(fd);
+ else if (error == EOVERFLOW)
+ error = EFBIG;
+ return (error);
}
-
return (0);
}
@@ -56,6 +83,10 @@ 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;
@@ -63,9 +94,12 @@ posix_fallocate64(int fd, off64_t offset, off64_t len)
lck.l_type = F_WRLCK;
if (fcntl(fd, F_ALLOCSP64, &lck) == -1) {
- return (-1);
+ if ((error = errno) == EINVAL)
+ error = fallocate_errno(fd);
+ else if (error == EOVERFLOW)
+ error = EFBIG;
+ return (error);
}
-
return (0);
}
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:
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 2f164ffeb5..b75a328198 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -100,7 +100,10 @@ SUNW_1.23 { # SunOS 5.11 (Solaris 11)
nanosleep;
ntohl;
ntohs;
+ posix_fadvise;
posix_fallocate;
+ posix_madvise;
+ posix_memalign;
pthread_key_create_once_np;
sched_getparam;
sched_get_priority_max;
diff --git a/usr/src/lib/libc/sparc/Makefile b/usr/src/lib/libc/sparc/Makefile
index 337b5ec720..095ab311e6 100644
--- a/usr/src/lib/libc/sparc/Makefile
+++ b/usr/src/lib/libc/sparc/Makefile
@@ -545,6 +545,10 @@ PORTGEN= \
pfmt_print.o \
plock.o \
poll.o \
+ posix_fadvise.o \
+ posix_fallocate.o \
+ posix_madvise.o \
+ posix_memalign.o \
priocntl.o \
privlib.o \
priv_str_xlate.o \
@@ -791,7 +795,6 @@ AIOOBJS= \
RTOBJS= \
clock_timer.o \
- fallocate.o \
mqueue.o \
pos4obj.o \
sched.o \
diff --git a/usr/src/lib/libc/sparc/mapfile-vers b/usr/src/lib/libc/sparc/mapfile-vers
index 8c01d6d0ac..1bead523f9 100644
--- a/usr/src/lib/libc/sparc/mapfile-vers
+++ b/usr/src/lib/libc/sparc/mapfile-vers
@@ -40,6 +40,7 @@ SUNW_1.23 {
enable_extended_FILE_stdio;
lio_listio64;
mkstemps64;
+ posix_fadvise64;
posix_fallocate64;
};
diff --git a/usr/src/lib/libc/sparcv9/Makefile b/usr/src/lib/libc/sparcv9/Makefile
index 9f7c8d7ef1..2ae43469bf 100644
--- a/usr/src/lib/libc/sparcv9/Makefile
+++ b/usr/src/lib/libc/sparcv9/Makefile
@@ -506,6 +506,10 @@ PORTGEN= \
pfmt_print.o \
plock.o \
poll.o \
+ posix_fadvise.o \
+ posix_fallocate.o \
+ posix_madvise.o \
+ posix_memalign.o \
priocntl.o \
privlib.o \
priv_str_xlate.o \
@@ -737,7 +741,6 @@ AIOOBJS= \
RTOBJS= \
clock_timer.o \
- fallocate.o \
mqueue.o \
pos4obj.o \
sched.o \