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