17c478bd9Sstevel@tonic-gate /* 28fd04b83SRoger A. Faulkner * CDDL HEADER START 38fd04b83SRoger A. Faulkner * 48fd04b83SRoger A. Faulkner * The contents of this file are subject to the terms of the 58fd04b83SRoger A. Faulkner * Common Development and Distribution License (the "License"). 68fd04b83SRoger A. Faulkner * You may not use this file except in compliance with the License. 78fd04b83SRoger A. Faulkner * 88fd04b83SRoger A. Faulkner * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 98fd04b83SRoger A. Faulkner * or http://www.opensolaris.org/os/licensing. 108fd04b83SRoger A. Faulkner * See the License for the specific language governing permissions 118fd04b83SRoger A. Faulkner * and limitations under the License. 128fd04b83SRoger A. Faulkner * 138fd04b83SRoger A. Faulkner * When distributing Covered Code, include this CDDL HEADER in each 148fd04b83SRoger A. Faulkner * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 158fd04b83SRoger A. Faulkner * If applicable, add the following below this CDDL HEADER, with the 168fd04b83SRoger A. Faulkner * fields enclosed by brackets "[]" replaced with your own identifying 178fd04b83SRoger A. Faulkner * information: Portions Copyright [yyyy] [name of copyright owner] 188fd04b83SRoger A. Faulkner * 198fd04b83SRoger A. Faulkner * CDDL HEADER END 208fd04b83SRoger A. Faulkner */ 218fd04b83SRoger A. Faulkner 228fd04b83SRoger A. Faulkner /* 23*f3b6506eSGary Mills * Copyright 2016 Gary Mills 248fd04b83SRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 258fd04b83SRoger A. Faulkner * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 307c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 317c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifndef __SYS_FCNTLCOM_H 357c478bd9Sstevel@tonic-gate #define __SYS_FCNTLCOM_H 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef __cplusplus 387c478bd9Sstevel@tonic-gate extern "C" { 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * Rewack the FXXXXX values as _FXXXX so that _POSIX_SOURCE works. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #define _FOPEN (-1) /* from sys/file.h, kernel use only */ 457c478bd9Sstevel@tonic-gate #define _FREAD 0x0001 /* read enabled */ 467c478bd9Sstevel@tonic-gate #define _FWRITE 0x0002 /* write enabled */ 477c478bd9Sstevel@tonic-gate #define _FNDELAY 0x0004 /* non blocking I/O (4.2 style) */ 487c478bd9Sstevel@tonic-gate #define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ 497c478bd9Sstevel@tonic-gate #define _FMARK 0x0010 /* internal; mark during gc() */ 507c478bd9Sstevel@tonic-gate #define _FDEFER 0x0020 /* internal; defer for next gc pass */ 517c478bd9Sstevel@tonic-gate #define _FASYNC 0x0040 /* signal pgrp when data ready */ 527c478bd9Sstevel@tonic-gate #define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ 537c478bd9Sstevel@tonic-gate #define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ 547c478bd9Sstevel@tonic-gate #define _FCREAT 0x0200 /* open with file create */ 557c478bd9Sstevel@tonic-gate #define _FTRUNC 0x0400 /* open with truncation */ 567c478bd9Sstevel@tonic-gate #define _FEXCL 0x0800 /* error on open if file exists */ 577c478bd9Sstevel@tonic-gate #define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ 587c478bd9Sstevel@tonic-gate #define _FSYNC 0x2000 /* do all writes synchronously */ 597c478bd9Sstevel@tonic-gate #define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ 607c478bd9Sstevel@tonic-gate #define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Flag values for open(2) and fcntl(2) 667c478bd9Sstevel@tonic-gate * The kernel adds 1 to the open modes to turn it into some 677c478bd9Sstevel@tonic-gate * combination of FREAD and FWRITE. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate #define O_RDONLY 0 /* +1 == FREAD */ 707c478bd9Sstevel@tonic-gate #define O_WRONLY 1 /* +1 == FWRITE */ 717c478bd9Sstevel@tonic-gate #define O_RDWR 2 /* +1 == FREAD|FWRITE */ 727c478bd9Sstevel@tonic-gate #define O_APPEND _FAPPEND 737c478bd9Sstevel@tonic-gate #define O_CREAT _FCREAT 747c478bd9Sstevel@tonic-gate #define O_TRUNC _FTRUNC 757c478bd9Sstevel@tonic-gate #define O_EXCL _FEXCL 767c478bd9Sstevel@tonic-gate /* O_SYNC _FSYNC not posix, defined below */ 777c478bd9Sstevel@tonic-gate /* O_NDELAY _FNDELAY set in include/fcntl.h */ 787c478bd9Sstevel@tonic-gate /* O_NDELAY _FNBIO set in 5include/fcntl.h */ 797c478bd9Sstevel@tonic-gate #define O_NONBLOCK _FNONBLOCK 807c478bd9Sstevel@tonic-gate #define O_NOCTTY _FNOCTTY 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #ifndef _POSIX_SOURCE 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #define O_SYNC _FSYNC 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * Flags that work for fcntl(fd, F_SETFL, FXXXX) 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate #define FAPPEND _FAPPEND 907c478bd9Sstevel@tonic-gate #define FSYNC _FSYNC 917c478bd9Sstevel@tonic-gate #define FASYNC _FASYNC 927c478bd9Sstevel@tonic-gate #define FNBIO _FNBIO 937c478bd9Sstevel@tonic-gate #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ 947c478bd9Sstevel@tonic-gate #define FNDELAY _FNDELAY 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * Flags that are disallowed for fcntl's (FCNTLCANT); 987c478bd9Sstevel@tonic-gate * used for opens, internal state, or locking. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate #define FREAD _FREAD 1017c478bd9Sstevel@tonic-gate #define FWRITE _FWRITE 1027c478bd9Sstevel@tonic-gate #define FMARK _FMARK 1037c478bd9Sstevel@tonic-gate #define FDEFER _FDEFER 1047c478bd9Sstevel@tonic-gate #define FSHLOCK _FSHLOCK 1057c478bd9Sstevel@tonic-gate #define FEXLOCK _FEXLOCK 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * The rest of the flags, used only for opens 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate #define FOPEN _FOPEN 1117c478bd9Sstevel@tonic-gate #define FCREAT _FCREAT 1127c478bd9Sstevel@tonic-gate #define FTRUNC _FTRUNC 1137c478bd9Sstevel@tonic-gate #define FEXCL _FEXCL 1147c478bd9Sstevel@tonic-gate #define FNOCTTY _FNOCTTY 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* XXX close on exec request; must match UF_EXCLOSE in user.h */ 1197c478bd9Sstevel@tonic-gate #define FD_CLOEXEC 1 /* posix */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* fcntl(2) requests */ 1227c478bd9Sstevel@tonic-gate #define F_DUPFD 0 /* Duplicate fildes */ 1237c478bd9Sstevel@tonic-gate #define F_GETFD 1 /* Get fildes flags (close on exec) */ 1247c478bd9Sstevel@tonic-gate #define F_SETFD 2 /* Set fildes flags (close on exec) */ 1257c478bd9Sstevel@tonic-gate #define F_GETFL 3 /* Get file flags */ 1267c478bd9Sstevel@tonic-gate #define F_SETFL 4 /* Set file flags */ 1277c478bd9Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1287c478bd9Sstevel@tonic-gate #define F_GETOWN 5 /* Get owner - for ASYNC */ 1297c478bd9Sstevel@tonic-gate #define F_SETOWN 6 /* Set owner - for ASYNC */ 1307c478bd9Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1317c478bd9Sstevel@tonic-gate #define F_GETLK 7 /* Get record-locking information */ 1327c478bd9Sstevel@tonic-gate #define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */ 1337c478bd9Sstevel@tonic-gate #define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */ 1347c478bd9Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1357c478bd9Sstevel@tonic-gate #define F_CNVT 12 /* Convert a fhandle to an open fd */ 1367c478bd9Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1377c478bd9Sstevel@tonic-gate 138*f3b6506eSGary Mills /* Needed by flock.c */ 139*f3b6506eSGary Mills #define F_FLOCKW F_SETLKW 140*f3b6506eSGary Mills #define F_FLOCK F_SETLK 141*f3b6506eSGary Mills 1427c478bd9Sstevel@tonic-gate /* fcntl(2) flags (l_type field of flock structure) */ 1437c478bd9Sstevel@tonic-gate #define F_RDLCK 1 /* read lock */ 1447c478bd9Sstevel@tonic-gate #define F_WRLCK 2 /* write lock */ 1457c478bd9Sstevel@tonic-gate #define F_UNLCK 3 /* remove lock(s) */ 1467c478bd9Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1477c478bd9Sstevel@tonic-gate #define F_UNLKSYS 4 /* remove remote locks for a given system */ 1487c478bd9Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1497c478bd9Sstevel@tonic-gate 1508fd04b83SRoger A. Faulkner /* needed for _syscall(SYS_openat, AT_FDCWD, ...) */ 1518fd04b83SRoger A. Faulkner #define AT_FDCWD 0xffd19553 1528fd04b83SRoger A. Faulkner #define AT_SYMLINK_NOFOLLOW 0x1000 1538fd04b83SRoger A. Faulkner #define AT_REMOVEDIR 0x1 1548fd04b83SRoger A. Faulkner 1557c478bd9Sstevel@tonic-gate #include <sys/stdtypes.h> 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* file segment locking set data type - information passed to system by user */ 1587c478bd9Sstevel@tonic-gate struct flock { 1597c478bd9Sstevel@tonic-gate short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 1607c478bd9Sstevel@tonic-gate short l_whence; /* flag to choose starting offset */ 1617c478bd9Sstevel@tonic-gate long l_start; /* relative offset, in bytes */ 1627c478bd9Sstevel@tonic-gate long l_len; /* length, in bytes; 0 means lock to EOF */ 1637c478bd9Sstevel@tonic-gate short l_pid; /* returned with F_GETLK */ 1647c478bd9Sstevel@tonic-gate short l_xxx; /* reserved for future use */ 1657c478bd9Sstevel@tonic-gate }; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #ifndef _POSIX_SOURCE 1687c478bd9Sstevel@tonic-gate /* extended file segment locking set data type */ 1697c478bd9Sstevel@tonic-gate struct eflock { 1707c478bd9Sstevel@tonic-gate short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 1717c478bd9Sstevel@tonic-gate short l_whence; /* flag to choose starting offset */ 1727c478bd9Sstevel@tonic-gate long l_start; /* relative offset, in bytes */ 1737c478bd9Sstevel@tonic-gate long l_len; /* length, in bytes; 0 means lock to EOF */ 1747c478bd9Sstevel@tonic-gate short l_pid; /* returned with F_GETLK */ 1757c478bd9Sstevel@tonic-gate short l_xxx; /* reserved for future use */ 1767c478bd9Sstevel@tonic-gate long l_rpid; /* Remote process id wanting this lock */ 1777c478bd9Sstevel@tonic-gate long l_rsys; /* Remote system id wanting this lock */ 1787c478bd9Sstevel@tonic-gate }; 1797c478bd9Sstevel@tonic-gate #endif /* !_POSIX_SOURCE */ 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #ifndef KERNEL 1827c478bd9Sstevel@tonic-gate #include <sys/stat.h> /* sigh. for the mode bits for open/creat */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate int open(/* char *path, int flags, mode_t modes */); 1857c478bd9Sstevel@tonic-gate int creat(/* char *path, mode_t modes */); 1867c478bd9Sstevel@tonic-gate int fcntl(/* int fd, cmd, ... */); 1877c478bd9Sstevel@tonic-gate #endif /* !KERNEL */ 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate #endif 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #endif /* __SYS_FCNTLCOM_H */ 194