10Sstevel@tonic-gate /* 2*11798SRoger.Faulkner@Sun.COM * CDDL HEADER START 3*11798SRoger.Faulkner@Sun.COM * 4*11798SRoger.Faulkner@Sun.COM * The contents of this file are subject to the terms of the 5*11798SRoger.Faulkner@Sun.COM * Common Development and Distribution License (the "License"). 6*11798SRoger.Faulkner@Sun.COM * You may not use this file except in compliance with the License. 7*11798SRoger.Faulkner@Sun.COM * 8*11798SRoger.Faulkner@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*11798SRoger.Faulkner@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*11798SRoger.Faulkner@Sun.COM * See the License for the specific language governing permissions 11*11798SRoger.Faulkner@Sun.COM * and limitations under the License. 12*11798SRoger.Faulkner@Sun.COM * 13*11798SRoger.Faulkner@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*11798SRoger.Faulkner@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*11798SRoger.Faulkner@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*11798SRoger.Faulkner@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*11798SRoger.Faulkner@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*11798SRoger.Faulkner@Sun.COM * 19*11798SRoger.Faulkner@Sun.COM * CDDL HEADER END 20*11798SRoger.Faulkner@Sun.COM */ 21*11798SRoger.Faulkner@Sun.COM 22*11798SRoger.Faulkner@Sun.COM /* 23*11798SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24*11798SRoger.Faulkner@Sun.COM * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 290Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 300Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifndef __SYS_FCNTLCOM_H 340Sstevel@tonic-gate #define __SYS_FCNTLCOM_H 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * Rewack the FXXXXX values as _FXXXX so that _POSIX_SOURCE works. 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate #define _FOPEN (-1) /* from sys/file.h, kernel use only */ 440Sstevel@tonic-gate #define _FREAD 0x0001 /* read enabled */ 450Sstevel@tonic-gate #define _FWRITE 0x0002 /* write enabled */ 460Sstevel@tonic-gate #define _FNDELAY 0x0004 /* non blocking I/O (4.2 style) */ 470Sstevel@tonic-gate #define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ 480Sstevel@tonic-gate #define _FMARK 0x0010 /* internal; mark during gc() */ 490Sstevel@tonic-gate #define _FDEFER 0x0020 /* internal; defer for next gc pass */ 500Sstevel@tonic-gate #define _FASYNC 0x0040 /* signal pgrp when data ready */ 510Sstevel@tonic-gate #define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ 520Sstevel@tonic-gate #define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ 530Sstevel@tonic-gate #define _FCREAT 0x0200 /* open with file create */ 540Sstevel@tonic-gate #define _FTRUNC 0x0400 /* open with truncation */ 550Sstevel@tonic-gate #define _FEXCL 0x0800 /* error on open if file exists */ 560Sstevel@tonic-gate #define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ 570Sstevel@tonic-gate #define _FSYNC 0x2000 /* do all writes synchronously */ 580Sstevel@tonic-gate #define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ 590Sstevel@tonic-gate #define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * Flag values for open(2) and fcntl(2) 650Sstevel@tonic-gate * The kernel adds 1 to the open modes to turn it into some 660Sstevel@tonic-gate * combination of FREAD and FWRITE. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate #define O_RDONLY 0 /* +1 == FREAD */ 690Sstevel@tonic-gate #define O_WRONLY 1 /* +1 == FWRITE */ 700Sstevel@tonic-gate #define O_RDWR 2 /* +1 == FREAD|FWRITE */ 710Sstevel@tonic-gate #define O_APPEND _FAPPEND 720Sstevel@tonic-gate #define O_CREAT _FCREAT 730Sstevel@tonic-gate #define O_TRUNC _FTRUNC 740Sstevel@tonic-gate #define O_EXCL _FEXCL 750Sstevel@tonic-gate /* O_SYNC _FSYNC not posix, defined below */ 760Sstevel@tonic-gate /* O_NDELAY _FNDELAY set in include/fcntl.h */ 770Sstevel@tonic-gate /* O_NDELAY _FNBIO set in 5include/fcntl.h */ 780Sstevel@tonic-gate #define O_NONBLOCK _FNONBLOCK 790Sstevel@tonic-gate #define O_NOCTTY _FNOCTTY 800Sstevel@tonic-gate 810Sstevel@tonic-gate #ifndef _POSIX_SOURCE 820Sstevel@tonic-gate 830Sstevel@tonic-gate #define O_SYNC _FSYNC 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Flags that work for fcntl(fd, F_SETFL, FXXXX) 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate #define FAPPEND _FAPPEND 890Sstevel@tonic-gate #define FSYNC _FSYNC 900Sstevel@tonic-gate #define FASYNC _FASYNC 910Sstevel@tonic-gate #define FNBIO _FNBIO 920Sstevel@tonic-gate #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ 930Sstevel@tonic-gate #define FNDELAY _FNDELAY 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Flags that are disallowed for fcntl's (FCNTLCANT); 970Sstevel@tonic-gate * used for opens, internal state, or locking. 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate #define FREAD _FREAD 1000Sstevel@tonic-gate #define FWRITE _FWRITE 1010Sstevel@tonic-gate #define FMARK _FMARK 1020Sstevel@tonic-gate #define FDEFER _FDEFER 1030Sstevel@tonic-gate #define FSHLOCK _FSHLOCK 1040Sstevel@tonic-gate #define FEXLOCK _FEXLOCK 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * The rest of the flags, used only for opens 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate #define FOPEN _FOPEN 1100Sstevel@tonic-gate #define FCREAT _FCREAT 1110Sstevel@tonic-gate #define FTRUNC _FTRUNC 1120Sstevel@tonic-gate #define FEXCL _FEXCL 1130Sstevel@tonic-gate #define FNOCTTY _FNOCTTY 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* XXX close on exec request; must match UF_EXCLOSE in user.h */ 1180Sstevel@tonic-gate #define FD_CLOEXEC 1 /* posix */ 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* fcntl(2) requests */ 1210Sstevel@tonic-gate #define F_DUPFD 0 /* Duplicate fildes */ 1220Sstevel@tonic-gate #define F_GETFD 1 /* Get fildes flags (close on exec) */ 1230Sstevel@tonic-gate #define F_SETFD 2 /* Set fildes flags (close on exec) */ 1240Sstevel@tonic-gate #define F_GETFL 3 /* Get file flags */ 1250Sstevel@tonic-gate #define F_SETFL 4 /* Set file flags */ 1260Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1270Sstevel@tonic-gate #define F_GETOWN 5 /* Get owner - for ASYNC */ 1280Sstevel@tonic-gate #define F_SETOWN 6 /* Set owner - for ASYNC */ 1290Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1300Sstevel@tonic-gate #define F_GETLK 7 /* Get record-locking information */ 1310Sstevel@tonic-gate #define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */ 1320Sstevel@tonic-gate #define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */ 1330Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1340Sstevel@tonic-gate #define F_CNVT 12 /* Convert a fhandle to an open fd */ 1350Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* fcntl(2) flags (l_type field of flock structure) */ 1380Sstevel@tonic-gate #define F_RDLCK 1 /* read lock */ 1390Sstevel@tonic-gate #define F_WRLCK 2 /* write lock */ 1400Sstevel@tonic-gate #define F_UNLCK 3 /* remove lock(s) */ 1410Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1420Sstevel@tonic-gate #define F_UNLKSYS 4 /* remove remote locks for a given system */ 1430Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1440Sstevel@tonic-gate 145*11798SRoger.Faulkner@Sun.COM /* needed for _syscall(SYS_openat, AT_FDCWD, ...) */ 146*11798SRoger.Faulkner@Sun.COM #define AT_FDCWD 0xffd19553 147*11798SRoger.Faulkner@Sun.COM #define AT_SYMLINK_NOFOLLOW 0x1000 148*11798SRoger.Faulkner@Sun.COM #define AT_REMOVEDIR 0x1 149*11798SRoger.Faulkner@Sun.COM 1500Sstevel@tonic-gate #include <sys/stdtypes.h> 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* file segment locking set data type - information passed to system by user */ 1530Sstevel@tonic-gate struct flock { 1540Sstevel@tonic-gate short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 1550Sstevel@tonic-gate short l_whence; /* flag to choose starting offset */ 1560Sstevel@tonic-gate long l_start; /* relative offset, in bytes */ 1570Sstevel@tonic-gate long l_len; /* length, in bytes; 0 means lock to EOF */ 1580Sstevel@tonic-gate short l_pid; /* returned with F_GETLK */ 1590Sstevel@tonic-gate short l_xxx; /* reserved for future use */ 1600Sstevel@tonic-gate }; 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1630Sstevel@tonic-gate /* extended file segment locking set data type */ 1640Sstevel@tonic-gate struct eflock { 1650Sstevel@tonic-gate short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 1660Sstevel@tonic-gate short l_whence; /* flag to choose starting offset */ 1670Sstevel@tonic-gate long l_start; /* relative offset, in bytes */ 1680Sstevel@tonic-gate long l_len; /* length, in bytes; 0 means lock to EOF */ 1690Sstevel@tonic-gate short l_pid; /* returned with F_GETLK */ 1700Sstevel@tonic-gate short l_xxx; /* reserved for future use */ 1710Sstevel@tonic-gate long l_rpid; /* Remote process id wanting this lock */ 1720Sstevel@tonic-gate long l_rsys; /* Remote system id wanting this lock */ 1730Sstevel@tonic-gate }; 1740Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate #ifndef KERNEL 1770Sstevel@tonic-gate #include <sys/stat.h> /* sigh. for the mode bits for open/creat */ 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate int open(/* char *path, int flags, mode_t modes */); 1800Sstevel@tonic-gate int creat(/* char *path, mode_t modes */); 1810Sstevel@tonic-gate int fcntl(/* int fd, cmd, ... */); 1820Sstevel@tonic-gate #endif /* !KERNEL */ 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate #ifdef __cplusplus 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate #endif 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #endif /* __SYS_FCNTLCOM_H */ 189