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 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* 28 * Copyright (c) 1983 Regents of the University of California. 29 * All rights reserved. The Berkeley software License Agreement 30 * specifies the terms and conditions for redistribution. 31 */ 32 33#ifndef __SYS_FCNTLCOM_H 34#define __SYS_FCNTLCOM_H 35 36#ifdef __cplusplus 37extern "C" { 38#endif 39 40/* 41 * Rewack the FXXXXX values as _FXXXX so that _POSIX_SOURCE works. 42 */ 43#define _FOPEN (-1) /* from sys/file.h, kernel use only */ 44#define _FREAD 0x0001 /* read enabled */ 45#define _FWRITE 0x0002 /* write enabled */ 46#define _FNDELAY 0x0004 /* non blocking I/O (4.2 style) */ 47#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ 48#define _FMARK 0x0010 /* internal; mark during gc() */ 49#define _FDEFER 0x0020 /* internal; defer for next gc pass */ 50#define _FASYNC 0x0040 /* signal pgrp when data ready */ 51#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ 52#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ 53#define _FCREAT 0x0200 /* open with file create */ 54#define _FTRUNC 0x0400 /* open with truncation */ 55#define _FEXCL 0x0800 /* error on open if file exists */ 56#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ 57#define _FSYNC 0x2000 /* do all writes synchronously */ 58#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ 59#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ 60 61#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 62 63/* 64 * Flag values for open(2) and fcntl(2) 65 * The kernel adds 1 to the open modes to turn it into some 66 * combination of FREAD and FWRITE. 67 */ 68#define O_RDONLY 0 /* +1 == FREAD */ 69#define O_WRONLY 1 /* +1 == FWRITE */ 70#define O_RDWR 2 /* +1 == FREAD|FWRITE */ 71#define O_APPEND _FAPPEND 72#define O_CREAT _FCREAT 73#define O_TRUNC _FTRUNC 74#define O_EXCL _FEXCL 75/* O_SYNC _FSYNC not posix, defined below */ 76/* O_NDELAY _FNDELAY set in include/fcntl.h */ 77/* O_NDELAY _FNBIO set in 5include/fcntl.h */ 78#define O_NONBLOCK _FNONBLOCK 79#define O_NOCTTY _FNOCTTY 80 81#ifndef _POSIX_SOURCE 82 83#define O_SYNC _FSYNC 84 85/* 86 * Flags that work for fcntl(fd, F_SETFL, FXXXX) 87 */ 88#define FAPPEND _FAPPEND 89#define FSYNC _FSYNC 90#define FASYNC _FASYNC 91#define FNBIO _FNBIO 92#define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ 93#define FNDELAY _FNDELAY 94 95/* 96 * Flags that are disallowed for fcntl's (FCNTLCANT); 97 * used for opens, internal state, or locking. 98 */ 99#define FREAD _FREAD 100#define FWRITE _FWRITE 101#define FMARK _FMARK 102#define FDEFER _FDEFER 103#define FSHLOCK _FSHLOCK 104#define FEXLOCK _FEXLOCK 105 106/* 107 * The rest of the flags, used only for opens 108 */ 109#define FOPEN _FOPEN 110#define FCREAT _FCREAT 111#define FTRUNC _FTRUNC 112#define FEXCL _FEXCL 113#define FNOCTTY _FNOCTTY 114 115#endif /* !_POSIX_SOURCE */ 116 117/* XXX close on exec request; must match UF_EXCLOSE in user.h */ 118#define FD_CLOEXEC 1 /* posix */ 119 120/* fcntl(2) requests */ 121#define F_DUPFD 0 /* Duplicate fildes */ 122#define F_GETFD 1 /* Get fildes flags (close on exec) */ 123#define F_SETFD 2 /* Set fildes flags (close on exec) */ 124#define F_GETFL 3 /* Get file flags */ 125#define F_SETFL 4 /* Set file flags */ 126#ifndef _POSIX_SOURCE 127#define F_GETOWN 5 /* Get owner - for ASYNC */ 128#define F_SETOWN 6 /* Set owner - for ASYNC */ 129#endif /* !_POSIX_SOURCE */ 130#define F_GETLK 7 /* Get record-locking information */ 131#define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */ 132#define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */ 133#ifndef _POSIX_SOURCE 134#define F_CNVT 12 /* Convert a fhandle to an open fd */ 135#endif /* !_POSIX_SOURCE */ 136 137/* fcntl(2) flags (l_type field of flock structure) */ 138#define F_RDLCK 1 /* read lock */ 139#define F_WRLCK 2 /* write lock */ 140#define F_UNLCK 3 /* remove lock(s) */ 141#ifndef _POSIX_SOURCE 142#define F_UNLKSYS 4 /* remove remote locks for a given system */ 143#endif /* !_POSIX_SOURCE */ 144 145/* needed for _syscall(SYS_openat, AT_FDCWD, ...) */ 146#define AT_FDCWD 0xffd19553 147#define AT_SYMLINK_NOFOLLOW 0x1000 148#define AT_REMOVEDIR 0x1 149 150#include <sys/stdtypes.h> 151 152/* file segment locking set data type - information passed to system by user */ 153struct flock { 154 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 155 short l_whence; /* flag to choose starting offset */ 156 long l_start; /* relative offset, in bytes */ 157 long l_len; /* length, in bytes; 0 means lock to EOF */ 158 short l_pid; /* returned with F_GETLK */ 159 short l_xxx; /* reserved for future use */ 160}; 161 162#ifndef _POSIX_SOURCE 163/* extended file segment locking set data type */ 164struct eflock { 165 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 166 short l_whence; /* flag to choose starting offset */ 167 long l_start; /* relative offset, in bytes */ 168 long l_len; /* length, in bytes; 0 means lock to EOF */ 169 short l_pid; /* returned with F_GETLK */ 170 short l_xxx; /* reserved for future use */ 171 long l_rpid; /* Remote process id wanting this lock */ 172 long l_rsys; /* Remote system id wanting this lock */ 173}; 174#endif /* !_POSIX_SOURCE */ 175 176#ifndef KERNEL 177#include <sys/stat.h> /* sigh. for the mode bits for open/creat */ 178 179int open(/* char *path, int flags, mode_t modes */); 180int creat(/* char *path, mode_t modes */); 181int fcntl(/* int fd, cmd, ... */); 182#endif /* !KERNEL */ 183 184#ifdef __cplusplus 185} 186#endif 187 188#endif /* __SYS_FCNTLCOM_H */ 189