1*7088Sraf /*
2*7088Sraf * CDDL HEADER START
3*7088Sraf *
4*7088Sraf * The contents of this file are subject to the terms of the
5*7088Sraf * Common Development and Distribution License (the "License").
6*7088Sraf * You may not use this file except in compliance with the License.
7*7088Sraf *
8*7088Sraf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7088Sraf * or http://www.opensolaris.org/os/licensing.
10*7088Sraf * See the License for the specific language governing permissions
11*7088Sraf * and limitations under the License.
12*7088Sraf *
13*7088Sraf * When distributing Covered Code, include this CDDL HEADER in each
14*7088Sraf * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7088Sraf * If applicable, add the following below this CDDL HEADER, with the
16*7088Sraf * fields enclosed by brackets "[]" replaced with your own identifying
17*7088Sraf * information: Portions Copyright [yyyy] [name of copyright owner]
18*7088Sraf *
19*7088Sraf * CDDL HEADER END
20*7088Sraf */
21*7088Sraf
22*7088Sraf /*
23*7088Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*7088Sraf * Use is subject to license terms.
25*7088Sraf */
26*7088Sraf
27*7088Sraf #pragma ident "%Z%%M% %I% %E% SMI"
28*7088Sraf
29*7088Sraf #include "lint.h"
30*7088Sraf #include <fcntl.h>
31*7088Sraf #include <sys/types.h>
32*7088Sraf #include <sys/stat.h>
33*7088Sraf #include <errno.h>
34*7088Sraf
35*7088Sraf /*
36*7088Sraf * SUSv3 - file advisory information
37*7088Sraf *
38*7088Sraf * This function does nothing, but that's OK because the
39*7088Sraf * Posix specification doesn't require it to do anything
40*7088Sraf * other than return appropriate error numbers.
41*7088Sraf *
42*7088Sraf * In the future, a file system dependent fadvise() or fcntl()
43*7088Sraf * interface, similar to madvise(), should be developed to enable
44*7088Sraf * the kernel to optimize I/O operations based on the given advice.
45*7088Sraf */
46*7088Sraf
47*7088Sraf /* ARGSUSED1 */
48*7088Sraf int
posix_fadvise(int fd,off_t offset,off_t len,int advice)49*7088Sraf posix_fadvise(int fd, off_t offset, off_t len, int advice)
50*7088Sraf {
51*7088Sraf struct stat64 statb;
52*7088Sraf
53*7088Sraf switch (advice) {
54*7088Sraf case POSIX_FADV_NORMAL:
55*7088Sraf case POSIX_FADV_RANDOM:
56*7088Sraf case POSIX_FADV_SEQUENTIAL:
57*7088Sraf case POSIX_FADV_WILLNEED:
58*7088Sraf case POSIX_FADV_DONTNEED:
59*7088Sraf case POSIX_FADV_NOREUSE:
60*7088Sraf break;
61*7088Sraf default:
62*7088Sraf return (EINVAL);
63*7088Sraf }
64*7088Sraf if (len < 0)
65*7088Sraf return (EINVAL);
66*7088Sraf if (fstat64(fd, &statb) != 0)
67*7088Sraf return (EBADF);
68*7088Sraf if (S_ISFIFO(statb.st_mode))
69*7088Sraf return (ESPIPE);
70*7088Sraf return (0);
71*7088Sraf }
72*7088Sraf
73*7088Sraf #if !defined(_LP64)
74*7088Sraf
75*7088Sraf /* ARGSUSED1 */
76*7088Sraf int
posix_fadvise64(int fd,off64_t offset,off64_t len,int advice)77*7088Sraf posix_fadvise64(int fd, off64_t offset, off64_t len, int advice)
78*7088Sraf {
79*7088Sraf struct stat64 statb;
80*7088Sraf
81*7088Sraf switch (advice) {
82*7088Sraf case POSIX_FADV_NORMAL:
83*7088Sraf case POSIX_FADV_RANDOM:
84*7088Sraf case POSIX_FADV_SEQUENTIAL:
85*7088Sraf case POSIX_FADV_WILLNEED:
86*7088Sraf case POSIX_FADV_DONTNEED:
87*7088Sraf case POSIX_FADV_NOREUSE:
88*7088Sraf break;
89*7088Sraf default:
90*7088Sraf return (EINVAL);
91*7088Sraf }
92*7088Sraf if (len < 0)
93*7088Sraf return (EINVAL);
94*7088Sraf if (fstat64(fd, &statb) != 0)
95*7088Sraf return (EBADF);
96*7088Sraf if (S_ISFIFO(statb.st_mode))
97*7088Sraf return (ESPIPE);
98*7088Sraf return (0);
99*7088Sraf }
100*7088Sraf
101*7088Sraf #endif
102