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