17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 1998 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7a5aac98SJerry Jelinek * Copyright 2015 Joyent, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 337c478bd9Sstevel@tonic-gate * The Regents of the University of California 347c478bd9Sstevel@tonic-gate * All Rights Reserved 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 377c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 387c478bd9Sstevel@tonic-gate * contributors. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #ifndef _SYS_FCNTL_H 427c478bd9Sstevel@tonic-gate #define _SYS_FCNTL_H 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifndef _SYS_TYPES_H 457c478bd9Sstevel@tonic-gate #include <sys/types.h> 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef __cplusplus 497c478bd9Sstevel@tonic-gate extern "C" { 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* Flag values accessible to open(2) and fcntl(2) */ 537c478bd9Sstevel@tonic-gate /* (The first three can only be set by open) */ 547c478bd9Sstevel@tonic-gate #define O_RDONLY 0 557c478bd9Sstevel@tonic-gate #define O_WRONLY 1 567c478bd9Sstevel@tonic-gate #define O_RDWR 2 577c478bd9Sstevel@tonic-gate #define O_NDELAY 04 /* Non-blocking I/O */ 587c478bd9Sstevel@tonic-gate #define O_APPEND 010 /* append (writes guaranteed at the end) */ 597c478bd9Sstevel@tonic-gate #define O_SYNC 020 /* synchronous write option */ 607c478bd9Sstevel@tonic-gate #define O_NONBLOCK 0200 /* Non-blocking I/O (POSIX) */ 617c478bd9Sstevel@tonic-gate #define O_PRIV 010000 /* Private access to file */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #ifdef _LARGEFILE_SOURCE 647c478bd9Sstevel@tonic-gate #define O_LARGEFILE 0x2000 657c478bd9Sstevel@tonic-gate #endif 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* Flag values accessible only to open(2) */ 687c478bd9Sstevel@tonic-gate #define O_CREAT 00400 /* open with file create (uses third open arg) */ 697c478bd9Sstevel@tonic-gate #define O_TRUNC 01000 /* open with truncation */ 707c478bd9Sstevel@tonic-gate #define O_EXCL 02000 /* exclusive open */ 717c478bd9Sstevel@tonic-gate #define O_NOCTTY 04000 /* don't allocate controlling tty (POSIX) */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* fcntl(2) requests */ 747c478bd9Sstevel@tonic-gate #define F_DUPFD 0 /* Duplicate fildes */ 757c478bd9Sstevel@tonic-gate #define F_GETFD 1 /* Get fildes flags */ 767c478bd9Sstevel@tonic-gate #define F_SETFD 2 /* Set fildes flags */ 777c478bd9Sstevel@tonic-gate #define F_GETFL 3 /* Get file flags */ 787c478bd9Sstevel@tonic-gate #define F_SETFL 4 /* Set file flags */ 797c478bd9Sstevel@tonic-gate #define F_SETLK 6 /* Set file lock */ 807c478bd9Sstevel@tonic-gate #define F_SETLKW 7 /* Set file lock and wait */ 81*7a5aac98SJerry Jelinek #define F_FLOCK 53 /* private - flock */ 82*7a5aac98SJerry Jelinek #define F_FLOCKW 54 /* private - flock wait */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Applications that read /dev/mem must be built like the kernel. A new 867c478bd9Sstevel@tonic-gate * symbol "_KMEMUSER" is defined for this purpose. 877c478bd9Sstevel@tonic-gate * Applications that read /dev/mem will migrate with the kernel 887c478bd9Sstevel@tonic-gate * to an "_LTYPES" definition. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 927c478bd9Sstevel@tonic-gate #define F_GETLK 14 /* Get file lock */ 937c478bd9Sstevel@tonic-gate #define F_O_GETLK 5 /* SVR3 Get file lock */ 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate #else /* user definition */ 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #if defined(_LTYPES) /* EFT definition */ 987c478bd9Sstevel@tonic-gate #define F_GETLK 14 /* Get file lock */ 997c478bd9Sstevel@tonic-gate #else 1007c478bd9Sstevel@tonic-gate #define F_GETLK 5 /* Get file lock */ 1017c478bd9Sstevel@tonic-gate #endif /* defined(_LTYPES) */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define F_SETLK 6 /* Set file lock */ 1067c478bd9Sstevel@tonic-gate #define F_SETLKW 7 /* Set file lock and wait */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #define F_CHKFL 8 /* Reserved */ 1107c478bd9Sstevel@tonic-gate #define F_ALLOCSP 10 /* Reserved */ 1117c478bd9Sstevel@tonic-gate #define F_FREESP 11 /* Free file space */ 1127c478bd9Sstevel@tonic-gate #define F_ISSTREAM 13 /* Is the file desc. a stream ? */ 1137c478bd9Sstevel@tonic-gate #define F_PRIV 15 /* Turn on private access to file */ 1147c478bd9Sstevel@tonic-gate #define F_NPRIV 16 /* Turn off private access to file */ 1157c478bd9Sstevel@tonic-gate #define F_QUOTACTL 17 /* UFS quota call */ 1167c478bd9Sstevel@tonic-gate #define F_BLOCKS 18 /* Get number of BLKSIZE blocks allocated */ 1177c478bd9Sstevel@tonic-gate #define F_BLKSIZE 19 /* Get optimal I/O block size */ 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate #define F_GETOWN 23 /* Get owner */ 1207c478bd9Sstevel@tonic-gate #define F_SETOWN 24 /* Set owner */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* flags for F_GETFL, F_SETFL-- copied from <sys/file.h> */ 1237c478bd9Sstevel@tonic-gate #ifndef FOPEN 1247c478bd9Sstevel@tonic-gate #define FOPEN 0xFFFFFFFF 1257c478bd9Sstevel@tonic-gate #define FREAD 0x01 1267c478bd9Sstevel@tonic-gate #define FWRITE 0x02 1277c478bd9Sstevel@tonic-gate #define FNDELAY 0x04 1287c478bd9Sstevel@tonic-gate #define FAPPEND 0x08 1297c478bd9Sstevel@tonic-gate #define FSYNC 0x10 1307c478bd9Sstevel@tonic-gate #define FNONBLOCK 0x80 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define FMASK 0xFF /* should be disjoint from FASYNC */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* open-only modes */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #define FCREAT 0x0100 1377c478bd9Sstevel@tonic-gate #define FTRUNC 0x0200 1387c478bd9Sstevel@tonic-gate #define FEXCL 0x0400 1397c478bd9Sstevel@tonic-gate #define FNOCTTY 0x0800 1407c478bd9Sstevel@tonic-gate #define FASYNC 0x1000 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* file descriptor flags */ 1437c478bd9Sstevel@tonic-gate #define FCLOSEXEC 001 /* close on exec */ 1447c478bd9Sstevel@tonic-gate #endif 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * File segment locking set data type - information passed to system by user. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 1507c478bd9Sstevel@tonic-gate /* EFT definition */ 1517c478bd9Sstevel@tonic-gate typedef struct flock { 1527c478bd9Sstevel@tonic-gate short l_type; 1537c478bd9Sstevel@tonic-gate short l_whence; 1547c478bd9Sstevel@tonic-gate off_t l_start; 1557c478bd9Sstevel@tonic-gate off_t l_len; /* len == 0 means until end of file */ 1567c478bd9Sstevel@tonic-gate int l_sysid; 1577c478bd9Sstevel@tonic-gate pid_t l_pid; 1587c478bd9Sstevel@tonic-gate long pad[4]; /* reserve area */ 1597c478bd9Sstevel@tonic-gate } flock_t; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate typedef struct o_flock { 1627c478bd9Sstevel@tonic-gate short l_type; 1637c478bd9Sstevel@tonic-gate short l_whence; 1647c478bd9Sstevel@tonic-gate int l_start; 1657c478bd9Sstevel@tonic-gate int l_len; /* len == 0 means until end of file */ 1667c478bd9Sstevel@tonic-gate short l_sysid; 1677c478bd9Sstevel@tonic-gate o_pid_t l_pid; 1687c478bd9Sstevel@tonic-gate } o_flock_t; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #else /* user level definition */ 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #if defined(_STYPES) 1737c478bd9Sstevel@tonic-gate /* SVR3 definition */ 1747c478bd9Sstevel@tonic-gate typedef struct flock { 1757c478bd9Sstevel@tonic-gate short l_type; 1767c478bd9Sstevel@tonic-gate short l_whence; 1777c478bd9Sstevel@tonic-gate off_t l_start; 1787c478bd9Sstevel@tonic-gate off_t l_len; /* len == 0 means until end of file */ 1797c478bd9Sstevel@tonic-gate short l_sysid; 1807c478bd9Sstevel@tonic-gate o-pid_t l_pid; 1817c478bd9Sstevel@tonic-gate } flock_t; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate #else 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate typedef struct flock { 1867c478bd9Sstevel@tonic-gate short l_type; 1877c478bd9Sstevel@tonic-gate short l_whence; 1887c478bd9Sstevel@tonic-gate off_t l_start; 1897c478bd9Sstevel@tonic-gate off_t l_len; /* len == 0 means until end of file */ 1907c478bd9Sstevel@tonic-gate int l_sysid; 1917c478bd9Sstevel@tonic-gate pid_t l_pid; 1927c478bd9Sstevel@tonic-gate long pad[4]; /* reserve area */ 1937c478bd9Sstevel@tonic-gate } flock_t; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #endif /* define(_STYPES) */ 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * File segment locking types. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate #define F_RDLCK 01 /* Read lock */ 2037c478bd9Sstevel@tonic-gate #define F_WRLCK 02 /* Write lock */ 2047c478bd9Sstevel@tonic-gate #define F_UNLCK 03 /* Remove lock(s) */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * POSIX constants 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #define O_ACCMODE 3 /* Mask for file access modes */ 2117c478bd9Sstevel@tonic-gate #define FD_CLOEXEC 1 /* close on exec flag */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* large file compilation environment setup */ 2147c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 2157c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 2167c478bd9Sstevel@tonic-gate #pragma redefine_extname open open64 2177c478bd9Sstevel@tonic-gate #pragma redefine_extname creat creat64 2187c478bd9Sstevel@tonic-gate #else 2197c478bd9Sstevel@tonic-gate #define open open64 2207c478bd9Sstevel@tonic-gate #define creat creat64 2217c478bd9Sstevel@tonic-gate #endif 2227c478bd9Sstevel@tonic-gate #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */ 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 2257c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 2267c478bd9Sstevel@tonic-gate #pragma redefine_extname open64 open 2277c478bd9Sstevel@tonic-gate #pragma redefine_extname creat64 creat 2287c478bd9Sstevel@tonic-gate #else 2297c478bd9Sstevel@tonic-gate #define open64 open 2307c478bd9Sstevel@tonic-gate #define creat64 creat 2317c478bd9Sstevel@tonic-gate #endif 2327c478bd9Sstevel@tonic-gate #endif /* _LP64 && _LARGEFILE64_SOURCE */ 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate #if defined(__STDC__) 2357c478bd9Sstevel@tonic-gate extern int fcntl(int, int, ...); 2367c478bd9Sstevel@tonic-gate extern int open(const char *, int, ...); 2377c478bd9Sstevel@tonic-gate extern int creat(const char *, mode_t); 2387c478bd9Sstevel@tonic-gate #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 2397c478bd9Sstevel@tonic-gate !defined(__PRAGMA_REDEFINE_EXTNAME)) 2407c478bd9Sstevel@tonic-gate extern int open64(const char *, int, ...); 2417c478bd9Sstevel@tonic-gate extern int creat64(const char *, mode_t); 2427c478bd9Sstevel@tonic-gate #endif 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate #endif 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate #endif 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate #endif /* _SYS_FCNTL_H */ 251