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 #include "lint.h" 28 #include <fcntl.h> 29 #include <sys/types.h> 30 #include <sys/stat.h> 31 #include <errno.h> 32 33 /* 34 * SUSv3 - file advisory information 35 * 36 * This function does nothing, but that's OK because the 37 * Posix specification doesn't require it to do anything 38 * other than return appropriate error numbers. 39 * 40 * In the future, a file system dependent fadvise() or fcntl() 41 * interface, similar to madvise(), should be developed to enable 42 * the kernel to optimize I/O operations based on the given advice. 43 */ 44 45 int 46 posix_fadvise(int fd, off_t offset __unused, off_t len, int advice) 47 { 48 struct stat64 statb; 49 50 switch (advice) { 51 case POSIX_FADV_NORMAL: 52 case POSIX_FADV_RANDOM: 53 case POSIX_FADV_SEQUENTIAL: 54 case POSIX_FADV_WILLNEED: 55 case POSIX_FADV_DONTNEED: 56 case POSIX_FADV_NOREUSE: 57 break; 58 default: 59 return (EINVAL); 60 } 61 if (len < 0) 62 return (EINVAL); 63 if (fstat64(fd, &statb) != 0) 64 return (EBADF); 65 if (S_ISFIFO(statb.st_mode)) 66 return (ESPIPE); 67 return (0); 68 } 69 70 #if !defined(_LP64) 71 72 int 73 posix_fadvise64(int fd, off64_t offset __unused, off64_t len, int advice) 74 { 75 struct stat64 statb; 76 77 switch (advice) { 78 case POSIX_FADV_NORMAL: 79 case POSIX_FADV_RANDOM: 80 case POSIX_FADV_SEQUENTIAL: 81 case POSIX_FADV_WILLNEED: 82 case POSIX_FADV_DONTNEED: 83 case POSIX_FADV_NOREUSE: 84 break; 85 default: 86 return (EINVAL); 87 } 88 if (len < 0) 89 return (EINVAL); 90 if (fstat64(fd, &statb) != 0) 91 return (EBADF); 92 if (S_ISFIFO(statb.st_mode)) 93 return (ESPIPE); 94 return (0); 95 } 96 97 #endif 98