4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
36 * Return the proper Posix error number for a failed (EINVAL) fcntl() operation.
39 fallocate_errno(int fd
)
44 if (fstat64(fd
, &statb
) != 0) /* can't happen? */
46 else if (S_ISFIFO(statb
.st_mode
)) /* pipe or FIFO */
48 else if (!S_ISREG(statb
.st_mode
)) /* not a regular file */
50 else /* the file system doesn't support F_ALLOCSP */
57 posix_fallocate(int fd
, off_t offset
, off_t len
)
62 if (offset
< 0 || len
<= 0)
70 if (fcntl(fd
, F_ALLOCSP
, &lck
) == -1) {
71 if ((error
= errno
) == EINVAL
)
72 error
= fallocate_errno(fd
);
73 else if (error
== EOVERFLOW
)
83 posix_fallocate64(int fd
, off64_t offset
, off64_t len
)
88 if (offset
< 0 || len
<= 0)
96 if (fcntl(fd
, F_ALLOCSP64
, &lck
) == -1) {
97 if ((error
= errno
) == EINVAL
)
98 error
= fallocate_errno(fd
);
99 else if (error
== EOVERFLOW
)