summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-04-21 15:47:29 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-04-21 15:47:29 +0000
commit631703afd6002f38b0b4e76504c91e3ab397f3f3 (patch)
treee1c92eb0a24aa1d97dc1fa06ef01e3e05d518f58
parent8a8d1486bb7edce317af04782ff5f525856713f9 (diff)
Change kernel-only open flag FNOSYMLINK to userland-visible O_NOFOLLOW;
adapated from FreeBSD. Also change O_FSYNC to the more standard O_SYNC and document it. open(2) needs some real examples for proper usage, to come later.
-rw-r--r--lib/libc/sys/open.239
-rw-r--r--sys/kern/kern_sig.c4
-rw-r--r--sys/kern/vfs_vnops.c21
-rw-r--r--sys/sys/fcntl.h22
4 files changed, 60 insertions, 26 deletions
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index 860340e6b63..062ff002537 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -1,4 +1,4 @@
-.\" $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
@@ -77,8 +77,10 @@ O_APPEND append on each write
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
@@ -97,9 +99,11 @@ exists,
.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
@@ -115,6 +119,9 @@ carrier on a dialup line),
.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
@@ -275,6 +282,32 @@ is already locked.
.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
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 41c7badf86f..de148e69821 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -1199,7 +1199,7 @@ coredump(p)
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);
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index e6ca0a79df3..e45b3d30c30 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -95,8 +95,7 @@ vn_open(ndp, fmode, cmode)
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);
@@ -124,17 +123,11 @@ vn_open(ndp, fmode, cmode)
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;
@@ -143,6 +136,10 @@ vn_open(ndp, fmode, cmode)
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)
@@ -326,7 +323,7 @@ vn_write(fp, poff, uio, cred)
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);
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
index 1acb5a2bb8e..99e18695481 100644
--- a/sys/sys/fcntl.h
+++ b/sys/sys/fcntl.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -85,8 +85,10 @@
#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 */
@@ -94,14 +96,16 @@
#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 */
@@ -127,7 +131,7 @@
#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 */