xref: /illumos-gate/usr/src/lib/libc/port/gen/posix_fadvise.c (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "lint.h"
30 #include <fcntl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <errno.h>
34 
35 /*
36  * SUSv3 - file advisory information
37  *
38  * This function does nothing, but that's OK because the
39  * Posix specification doesn't require it to do anything
40  * other than return appropriate error numbers.
41  *
42  * In the future, a file system dependent fadvise() or fcntl()
43  * interface, similar to madvise(), should be developed to enable
44  * the kernel to optimize I/O operations based on the given advice.
45  */
46 
47 /* ARGSUSED1 */
48 int
49 posix_fadvise(int fd, off_t offset, off_t len, int advice)
50 {
51 	struct stat64 statb;
52 
53 	switch (advice) {
54 	case POSIX_FADV_NORMAL:
55 	case POSIX_FADV_RANDOM:
56 	case POSIX_FADV_SEQUENTIAL:
57 	case POSIX_FADV_WILLNEED:
58 	case POSIX_FADV_DONTNEED:
59 	case POSIX_FADV_NOREUSE:
60 		break;
61 	default:
62 		return (EINVAL);
63 	}
64 	if (len < 0)
65 		return (EINVAL);
66 	if (fstat64(fd, &statb) != 0)
67 		return (EBADF);
68 	if (S_ISFIFO(statb.st_mode))
69 		return (ESPIPE);
70 	return (0);
71 }
72 
73 #if !defined(_LP64)
74 
75 /* ARGSUSED1 */
76 int
77 posix_fadvise64(int fd, off64_t offset, off64_t len, int advice)
78 {
79 	struct stat64 statb;
80 
81 	switch (advice) {
82 	case POSIX_FADV_NORMAL:
83 	case POSIX_FADV_RANDOM:
84 	case POSIX_FADV_SEQUENTIAL:
85 	case POSIX_FADV_WILLNEED:
86 	case POSIX_FADV_DONTNEED:
87 	case POSIX_FADV_NOREUSE:
88 		break;
89 	default:
90 		return (EINVAL);
91 	}
92 	if (len < 0)
93 		return (EINVAL);
94 	if (fstat64(fd, &statb) != 0)
95 		return (EBADF);
96 	if (S_ISFIFO(statb.st_mode))
97 		return (ESPIPE);
98 	return (0);
99 }
100 
101 #endif
102