xref: /illumos-gate/usr/src/lib/libc/port/gen/posix_fadvise.c (revision 4a38094c1dd4980a3761849bfbdf92ae62c568f5)
1019c3c43Sraf /*
2019c3c43Sraf  * CDDL HEADER START
3019c3c43Sraf  *
4019c3c43Sraf  * The contents of this file are subject to the terms of the
5019c3c43Sraf  * Common Development and Distribution License (the "License").
6019c3c43Sraf  * You may not use this file except in compliance with the License.
7019c3c43Sraf  *
8019c3c43Sraf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9019c3c43Sraf  * or http://www.opensolaris.org/os/licensing.
10019c3c43Sraf  * See the License for the specific language governing permissions
11019c3c43Sraf  * and limitations under the License.
12019c3c43Sraf  *
13019c3c43Sraf  * When distributing Covered Code, include this CDDL HEADER in each
14019c3c43Sraf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15019c3c43Sraf  * If applicable, add the following below this CDDL HEADER, with the
16019c3c43Sraf  * fields enclosed by brackets "[]" replaced with your own identifying
17019c3c43Sraf  * information: Portions Copyright [yyyy] [name of copyright owner]
18019c3c43Sraf  *
19019c3c43Sraf  * CDDL HEADER END
20019c3c43Sraf  */
21019c3c43Sraf 
22019c3c43Sraf /*
23019c3c43Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24019c3c43Sraf  * Use is subject to license terms.
25019c3c43Sraf  */
26019c3c43Sraf 
27019c3c43Sraf #include "lint.h"
28019c3c43Sraf #include <fcntl.h>
29019c3c43Sraf #include <sys/types.h>
30019c3c43Sraf #include <sys/stat.h>
31019c3c43Sraf #include <errno.h>
32019c3c43Sraf 
33019c3c43Sraf /*
34019c3c43Sraf  * SUSv3 - file advisory information
35019c3c43Sraf  *
36019c3c43Sraf  * This function does nothing, but that's OK because the
37019c3c43Sraf  * Posix specification doesn't require it to do anything
38019c3c43Sraf  * other than return appropriate error numbers.
39019c3c43Sraf  *
40019c3c43Sraf  * In the future, a file system dependent fadvise() or fcntl()
41019c3c43Sraf  * interface, similar to madvise(), should be developed to enable
42019c3c43Sraf  * the kernel to optimize I/O operations based on the given advice.
43019c3c43Sraf  */
44019c3c43Sraf 
45019c3c43Sraf int
posix_fadvise(int fd,off_t offset __unused,off_t len,int advice)46*4a38094cSToomas Soome posix_fadvise(int fd, off_t offset __unused, off_t len, int advice)
47019c3c43Sraf {
48019c3c43Sraf 	struct stat64 statb;
49019c3c43Sraf 
50019c3c43Sraf 	switch (advice) {
51019c3c43Sraf 	case POSIX_FADV_NORMAL:
52019c3c43Sraf 	case POSIX_FADV_RANDOM:
53019c3c43Sraf 	case POSIX_FADV_SEQUENTIAL:
54019c3c43Sraf 	case POSIX_FADV_WILLNEED:
55019c3c43Sraf 	case POSIX_FADV_DONTNEED:
56019c3c43Sraf 	case POSIX_FADV_NOREUSE:
57019c3c43Sraf 		break;
58019c3c43Sraf 	default:
59019c3c43Sraf 		return (EINVAL);
60019c3c43Sraf 	}
61019c3c43Sraf 	if (len < 0)
62019c3c43Sraf 		return (EINVAL);
63019c3c43Sraf 	if (fstat64(fd, &statb) != 0)
64019c3c43Sraf 		return (EBADF);
65019c3c43Sraf 	if (S_ISFIFO(statb.st_mode))
66019c3c43Sraf 		return (ESPIPE);
67019c3c43Sraf 	return (0);
68019c3c43Sraf }
69019c3c43Sraf 
70019c3c43Sraf #if !defined(_LP64)
71019c3c43Sraf 
72019c3c43Sraf int
posix_fadvise64(int fd,off64_t offset __unused,off64_t len,int advice)73*4a38094cSToomas Soome posix_fadvise64(int fd, off64_t offset __unused, off64_t len, int advice)
74019c3c43Sraf {
75019c3c43Sraf 	struct stat64 statb;
76019c3c43Sraf 
77019c3c43Sraf 	switch (advice) {
78019c3c43Sraf 	case POSIX_FADV_NORMAL:
79019c3c43Sraf 	case POSIX_FADV_RANDOM:
80019c3c43Sraf 	case POSIX_FADV_SEQUENTIAL:
81019c3c43Sraf 	case POSIX_FADV_WILLNEED:
82019c3c43Sraf 	case POSIX_FADV_DONTNEED:
83019c3c43Sraf 	case POSIX_FADV_NOREUSE:
84019c3c43Sraf 		break;
85019c3c43Sraf 	default:
86019c3c43Sraf 		return (EINVAL);
87019c3c43Sraf 	}
88019c3c43Sraf 	if (len < 0)
89019c3c43Sraf 		return (EINVAL);
90019c3c43Sraf 	if (fstat64(fd, &statb) != 0)
91019c3c43Sraf 		return (EBADF);
92019c3c43Sraf 	if (S_ISFIFO(statb.st_mode))
93019c3c43Sraf 		return (ESPIPE);
94019c3c43Sraf 	return (0);
95019c3c43Sraf }
96019c3c43Sraf 
97019c3c43Sraf #endif
98