-.\" $OpenBSD: open.2,v 1.14 2000/04/10 19:36:02 deraadt Exp $
+.\" $OpenBSD: open.2,v 1.15 2000/04/21 15:47:27 millert Exp $
.\" $NetBSD: open.2,v 1.8 1995/02/27 12:35:14 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
O_CREAT create file if it does not exist
O_TRUNC truncate size to 0
O_EXCL error if create and file exists
+O_SYNC perform syncronous I/O operations
O_SHLOCK atomically obtain a shared lock
O_EXLOCK atomically obtain an exclusive lock
+O_NOFOLLOW if last path element is a symlink, don't follow it
.Ed
.Pp
Opening a file with
.Fn open
returns an error. This may be used to
implement a simple exclusive access locking mechanism.
-If
+If either of
.Dv O_EXCL
-is set and the last component of the pathname is
+or
+.Dv O_NOFOLLOW
+are set and the last component of the pathname is
a symbolic link,
.Fn open
will fail even if the symbolic
.Fn open
returns immediately.
This flag also has the effect of making all subsequent I/O on the open file non-blocking.
+If the
+.Dv O_SYNC
+flag is set, all I/O operations on the file will be done syncronously.
.Pp
When opening a file, a lock with
.Xr flock 2
.Xr umask 2 ,
.Xr write 2 ,
.Xr getdtablesize 3
+.Sh STANDARDS
+The
+.Fn open
+function conforms to
+.St -ansiC ,
+.St -p1003.1-90
+and
+.St -xpg4.2 .
+.Pp
+.Dv POSIX
+specifies three different flavors for syncronous I/O:
+.Dv O_SYNC ,
+.Dv O_DSYNC
+and
+.Dv O_RSYNC .
+In
+.Ox ,
+these are all equivalent.
+.Pp
+The
+.Dv O_SHLOCK ,
+.Dv O_EXLOCK
+and
+.Dv O_NOFOLLOW
+flags are non-standard extensions and should not be used if portability
+is of concern.
.Sh HISTORY
An
.Fn open
-/* $OpenBSD: kern_sig.c,v 1.36 2000/03/03 11:31:43 art Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.37 2000/04/21 15:47:27 millert Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
sprintf(name, "%s.core", p->p_comm);
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p);
- error = vn_open(&nd, O_CREAT | FWRITE | FNOSYMLINK, S_IRUSR | S_IWUSR);
+ error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW, S_IRUSR | S_IWUSR);
if (error) {
crfree(cred);
-/* $OpenBSD: vfs_vnops.c,v 1.24 2000/04/19 08:34:53 csapuntz Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.25 2000/04/21 15:47:28 millert Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
if (fmode & O_CREAT) {
ndp->ni_cnd.cn_nameiop = CREATE;
ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
- if (((fmode & O_EXCL) == 0) &&
- ((fmode & FNOSYMLINK) == 0))
+ if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
ndp->ni_cnd.cn_flags |= FOLLOW;
if ((error = namei(ndp)) != 0)
return (error);
error = EEXIST;
goto bad;
}
- if ((ndp->ni_vp->v_type == VLNK) &&
- ((fmode & FNOSYMLINK) != 0)) {
- error = EFTYPE;
- goto bad;
- }
-
- fmode &= ~O_CREAT;
}
} else {
ndp->ni_cnd.cn_nameiop = LOOKUP;
- ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF;
+ ndp->ni_cnd.cn_flags =
+ ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
if ((error = namei(ndp)) != 0)
return (error);
vp = ndp->ni_vp;
error = EOPNOTSUPP;
goto bad;
}
+ if (vp->v_type == VLNK) {
+ error = EMLINK;
+ goto bad;
+ }
if ((fmode & O_CREAT) == 0) {
if (fmode & FREAD) {
if ((error = VOP_ACCESS(vp, VREAD, cred, p)) != 0)
ioflag |= IO_APPEND;
if (fp->f_flag & FNONBLOCK)
ioflag |= IO_NDELAY;
- if ((fp->f_flag & O_FSYNC) ||
+ if ((fp->f_flag & FFSYNC) ||
(vp->v_mount && (vp->v_mount->mnt_flag & MNT_SYNCHRONOUS)))
ioflag |= IO_SYNC;
VOP_LEASE(vp, uio->uio_procp, cred, LEASE_WRITE);
-/* $OpenBSD: fcntl.h,v 1.5 1998/01/09 16:33:47 csapuntz Exp $ */
+/* $OpenBSD: fcntl.h,v 1.6 2000/04/21 15:47:27 millert Exp $ */
/* $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */
/*-
#define O_SHLOCK 0x0010 /* open with shared file lock */
#define O_EXLOCK 0x0020 /* open with exclusive file lock */
#define O_ASYNC 0x0040 /* signal pgrp when data ready */
-#define O_FSYNC 0x0080 /* synchronous writes */
+#define O_FSYNC O_SYNC /* backwards compatibility */
+#define O_NOFOLLOW 0x0100 /* if path is a symlink, don't follow */
#endif
+#define O_SYNC 0x0080 /* synchronous writes */
#define O_CREAT 0x0200 /* create if nonexistant */
#define O_TRUNC 0x0400 /* truncate to zero length */
#define O_EXCL 0x0800 /* error if already exists */
#define FMARK 0x1000 /* mark during gc() */
#define FDEFER 0x2000 /* defer for next gc pass */
#define FHASLOCK 0x4000 /* descriptor holds advisory lock */
-
-/* Note: The below is not a flag that can be used in the struct file.
- It's an option that can be passed to vn_open to make sure it doesn't
- follow a symlink on the last lookup */
-#define FNOSYMLINK 0x10000 /* Don't follow symlink for last
- component */
#endif
+/*
+ * POSIX 1003.1 specifies a higher granularity for syncronous operations
+ * than we support. Since synchronicity is all or nothing in OpenBSD
+ * we just define these to be the same as O_SYNC.
+ */
+#define O_DSYNC O_SYNC /* synchronous data writes */
+#define O_RSYNC O_SYNC /* synchronous reads */
+
/* defined by POSIX 1003.1; BSD default, this bit is not required */
#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
#ifndef _POSIX_SOURCE
#define FAPPEND O_APPEND /* kernel/compat */
#define FASYNC O_ASYNC /* kernel/compat */
-#define FFSYNC O_FSYNC /* kernel */
+#define FFSYNC O_SYNC /* kernel */
#define FNONBLOCK O_NONBLOCK /* kernel */
#define FNDELAY O_NONBLOCK /* compat */
#define O_NDELAY O_NONBLOCK /* compat */