199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1983, 1990, 1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (c) UNIX System Laboratories, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All or some portions of this file are derived from material licensed
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to the University of California by American Telephone and Telegraph
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Co. or Unix System Laboratories, Inc. and are reproduced herein with
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the permission of UNIX System Laboratories, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * @(#)fcntl.h 8.3 (Berkeley) 1/21/94
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_FCNTL_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_FCNTL_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This file includes the definitions for open and fcntl
199767f8919635c4928607450d9e0abb932109ceToomas Soome * described by POSIX for <fcntl.h>; it also includes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * related kernel definitions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _MODE_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __mode_t mode_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _MODE_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _OFF_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __off_t off_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _OFF_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _PID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __pid_t pid_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _PID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * File status flags: these are used by open(2), fcntl(2).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * They are also used (indirectly) in the kernel file structure f_flags,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which is a superset of the open/fcntl flags. Open flags and f_flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* open-only flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_RDONLY 0x0000 /* open for reading only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_WRONLY 0x0001 /* open for writing only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_RDWR 0x0002 /* open for reading and writing */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_ACCMODE 0x0003 /* mask for above modes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Kernel encoding of open mode; separate read and write bits that are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * independently testable: 1 greater than the above.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which was documented to use FREAD/FWRITE, continues to work.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FREAD 0x0001
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FWRITE 0x0002
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_NONBLOCK 0x0004 /* no delay */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_APPEND 0x0008 /* set append mode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_SHLOCK 0x0010 /* open with shared file lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_EXLOCK 0x0020 /* open with exclusive file lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_ASYNC 0x0040 /* signal pgrp when data ready */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_FSYNC 0x0080 /* synchronous writes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_NOFOLLOW 0x0100 /* don't follow symlinks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_CREAT 0x0200 /* create if nonexistent */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_TRUNC 0x0400 /* truncate to zero length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_EXCL 0x0800 /* error if already exists */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FHASLOCK 0x4000 /* descriptor holds advisory lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Attempt to bypass buffer cache */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_DIRECT 0x00010000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_DIRECTORY 0x00020000 /* Fail if not directory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_EXEC 0x00040000 /* Open for execute only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FEXEC O_EXEC
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_TTY_INIT 0x00080000 /* Restore default termios attributes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_CLOEXEC 0x00100000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_VERIFY 0x00200000 /* open only after verification */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX missing O_DSYNC, O_RSYNC.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Only for devfs d_close() flags. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FLASTCLOSE O_DIRECTORY
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FREVOKE O_VERIFY
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Only for fo_close() from half-succeeded open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FOPENFAILED O_TTY_INIT
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FFLAGS(oflags) ((oflags) & O_EXEC ? (oflags) : (oflags) + 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define OFLAGS(fflags) ((fflags) & O_EXEC ? (fflags) : (fflags) - 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* bits to save after open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT|FEXEC)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* bits settable by fcntl(F_SETFL, ...) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FRDAHEAD|O_DIRECT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(COMPAT_FREEBSD7) || defined(COMPAT_FREEBSD6) || \
199767f8919635c4928607450d9e0abb932109ceToomas Soome defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Set by shm_open(3) in older libc's to get automatic MAP_ASYNC
199767f8919635c4928607450d9e0abb932109ceToomas Soome * behavior for POSIX shared memory objects (which are otherwise
199767f8919635c4928607450d9e0abb932109ceToomas Soome * implemented as plain files).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FPOSIXSHM O_NOFOLLOW
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef FCNTLFLAGS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|FRDAHEAD| \
199767f8919635c4928607450d9e0abb932109ceToomas Soome O_DIRECT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The O_* flags used to have only F* names, which were used in the kernel
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and by fcntl. We retain the F* names for the kernel f_flag field
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and for backward compatibility for fcntl. These flags are deprecated.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FAPPEND O_APPEND /* kernel/compat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FASYNC O_ASYNC /* kernel/compat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FFSYNC O_FSYNC /* kernel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FNONBLOCK O_NONBLOCK /* kernel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FNDELAY O_NONBLOCK /* compat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define O_NDELAY O_NONBLOCK /* compat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We are out of bits in f_flag (which is a short). However,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the flag bits not set in FMASK are only meaningful in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * initial open syscall. Those bits can thus be given a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * different meaning for fcntl(2).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Read ahead */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FRDAHEAD O_CREAT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Magic value that specify the use of the current working directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to determine the target of relative file paths in the openat() and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * similar syscalls.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AT_FDCWD -100
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Miscellaneous flags for the *at() syscalls.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AT_EACCESS 0x100 /* Check access using effective user and group ID */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AT_SYMLINK_NOFOLLOW 0x200 /* Do not follow symbolic links */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic link */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AT_REMOVEDIR 0x800 /* Remove directory instead of file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Constants used for fcntl(2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* command values */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_DUPFD 0 /* duplicate file descriptor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_GETFD 1 /* get file descriptor flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETFD 2 /* set file descriptor flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_GETFL 3 /* get file status flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETFL 4 /* set file status flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_OGETLK 7 /* get record locking information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_OSETLK 8 /* set record locking information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_OSETLKW 9 /* F_SETLK; wait if blocked */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_DUP2FD 10 /* duplicate file descriptor to arg */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_GETLK 11 /* get record locking information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETLK 12 /* set record locking information */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETLKW 13 /* F_SETLK; wait if blocked */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_SETLK_REMOTE 14 /* debugging support for remote locks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_READAHEAD 15 /* read ahead */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_RDAHEAD 16 /* Darwin compatible read ahead */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_DUPFD_CLOEXEC 17 /* Like F_DUPFD, but FD_CLOEXEC is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_DUP2FD_CLOEXEC 18 /* Like F_DUP2FD, but FD_CLOEXEC is set */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* file descriptor flags (F_GETFD, F_SETFD) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FD_CLOEXEC 1 /* close-on-exec flag */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_RDLCK 1 /* shared or read lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_UNLCK 2 /* unlock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_WRLCK 3 /* exclusive or write lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_UNLCKSYS 4 /* purge locks for a given system ID */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_CANCEL 5 /* cancel an async lock request */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_WAIT 0x010 /* Wait until lock is granted */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_POSIX 0x040 /* Use POSIX semantics for lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_REMOTE 0x080 /* Lock owner is remote NFS client */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define F_NOINTR 0x100 /* Ignore signals when waiting */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Advisory file segment locking data type -
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information passed to system by user
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct flock {
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t l_start; /* starting offset */
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t l_len; /* len = 0 means until end of file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome pid_t l_pid; /* lock owner */
199767f8919635c4928607450d9e0abb932109ceToomas Soome short l_type; /* lock type: read/write, etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome short l_whence; /* type of l_start */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int l_sysid; /* remote system id or zero for local */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Old advisory file segment locking data type,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * before adding l_sysid.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct __oflock {
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t l_start; /* starting offset */
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t l_len; /* len = 0 means until end of file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome pid_t l_pid; /* lock owner */
199767f8919635c4928607450d9e0abb932109ceToomas Soome short l_type; /* lock type: read/write, etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome short l_whence; /* type of l_start */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* lock operations for flock(2) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOCK_SH 0x01 /* shared file lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOCK_EX 0x02 /* exclusive file lock */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOCK_NB 0x04 /* don't block when locking */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOCK_UN 0x08 /* unlock file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Advice to posix_fadvise
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_NORMAL 0 /* no special treatment */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_RANDOM 1 /* expect random page references */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_SEQUENTIAL 2 /* expect sequential page references */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_WILLNEED 3 /* will need these pages */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_DONTNEED 4 /* dont need these pages */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define POSIX_FADV_NOREUSE 5 /* access data only once */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome__BEGIN_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint open(const char *, int, ...);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint creat(const char *, mode_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint fcntl(int, int, ...);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint flock(int, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint openat(int, const char *, int, ...);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint posix_fadvise(int, off_t, off_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint posix_fallocate(int, off_t, off_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome__END_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_FCNTL_H_ */