Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src implement lchflags(2), which does the chflags(2) dance witho...
details: https://anonhg.NetBSD.org/src/rev/8e83cf286439
branches: trunk
changeset: 485047:8e83cf286439
user: mrg <mrg%NetBSD.org@localhost>
date: Mon Apr 17 14:31:21 2000 +0000
description:
implement lchflags(2), which does the chflags(2) dance without following
symlinks, and thus can operate on symlinks. remove a bogus comment in
chflags(1) that claims symlinks do not have file flags.
XXX: todo -- make chflags(1) use lchflags(2) when given the right options.
diffstat:
lib/libc/sys/Makefile.inc | 4 ++--
lib/libc/sys/chflags.2 | 12 +++++++++++-
sys/kern/syscalls.master | 3 ++-
sys/kern/vfs_syscalls.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
sys/sys/stat.h | 3 ++-
usr.bin/chflags/chflags.1 | 9 +--------
6 files changed, 62 insertions(+), 14 deletions(-)
diffs (168 lines):
diff -r c8b865d42f33 -r 8e83cf286439 lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Mon Apr 17 12:25:45 2000 +0000
+++ b/lib/libc/sys/Makefile.inc Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.98 2000/01/31 15:14:19 christos Exp $
+# $NetBSD: Makefile.inc,v 1.99 2000/04/17 14:31:21 mrg Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@@ -46,7 +46,7 @@
__getlogin.o getpeername.o getpgid.o getpgrp.o \
getpriority.o getrlimit.o getrusage.o getsid.o getsockname.o \
getsockopt.o gettimeofday.o ioctl.o kill.o ktrace.o \
- lchmod.o lchown.o __lstat13.o lfs_bmapv.o lfs_markv.o \
+ lchflags.o lchmod.o lchown.o __lstat13.o lfs_bmapv.o lfs_markv.o \
lfs_segclean.o lfs_segwait.o link.o listen.o lutimes.o \
madvise.o mincore.o minherit.o mkdir.o mkfifo.o mknod.o \
mlock.o mlockall.o mount.o mprotect.o __msgctl13.o msgget.o msgrcv.o \
diff -r c8b865d42f33 -r 8e83cf286439 lib/libc/sys/chflags.2
--- a/lib/libc/sys/chflags.2 Mon Apr 17 12:25:45 2000 +0000
+++ b/lib/libc/sys/chflags.2 Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: chflags.2,v 1.15 1999/12/02 21:42:36 kleink Exp $
+.\" $NetBSD: chflags.2,v 1.16 2000/04/17 14:31:21 mrg Exp $
.\"
.\" Copyright (c) 1989, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -48,6 +48,8 @@
.Ft int
.Fn chflags "const char *path" "u_long flags"
.Ft int
+.Fn lchflags "const char *path" "u_long flags"
+.Ft int
.Fn fchflags "int fd" "u_long flags"
.Sh DESCRIPTION
The file whose name
@@ -57,6 +59,10 @@
.Fa fd
has its flags changed to
.Fa flags .
+For
+.Fn lchflags ,
+symbolic links are not traversed and thus their modes may be changed with
+this call.
.Pp
The flags specified are formed by
.Em or Ns 'ing
@@ -179,3 +185,7 @@
.Fn fchflags
functions first appeared in
.Bx 4.4 .
+The
+.Fn lchflags
+function first appeared in
+.Nx 1.5 .
diff -r c8b865d42f33 -r 8e83cf286439 sys/kern/syscalls.master
--- a/sys/kern/syscalls.master Mon Apr 17 12:25:45 2000 +0000
+++ b/sys/kern/syscalls.master Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
- $NetBSD: syscalls.master,v 1.99 2000/01/31 15:12:30 christos Exp $
+ $NetBSD: syscalls.master,v 1.100 2000/04/17 14:31:22 mrg Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -583,3 +583,4 @@
#else
303 EXCL __shmctl13
#endif
+304 STD { int sys_lchflags(const char *path, u_long flags); }
diff -r c8b865d42f33 -r 8e83cf286439 sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c Mon Apr 17 12:25:45 2000 +0000
+++ b/sys/kern/vfs_syscalls.c Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_syscalls.c,v 1.155 2000/03/30 09:27:15 augustss Exp $ */
+/* $NetBSD: vfs_syscalls.c,v 1.156 2000/04/17 14:31:22 mrg Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -2132,6 +2132,49 @@
}
/*
+ * Change flags of a file given a file descriptor; this version does
+ * not follow links.
+ */
+int
+sys_lchflags(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_chflags_args /* {
+ syscallarg(const char *) path;
+ syscallarg(u_long) flags;
+ } */ *uap = v;
+ register struct vnode *vp;
+ struct vattr vattr;
+ int error;
+ struct nameidata nd;
+
+ NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+ if ((error = namei(&nd)) != 0)
+ return (error);
+ vp = nd.ni_vp;
+ VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ /* Non-superusers cannot change the flags on devices, even if they
+ own them. */
+ if (suser(p->p_ucred, &p->p_acflag)) {
+ if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0)
+ goto out;
+ if (vattr.va_type == VCHR || vattr.va_type == VBLK) {
+ error = EINVAL;
+ goto out;
+ }
+ }
+ VATTR_NULL(&vattr);
+ vattr.va_flags = SCARG(uap, flags);
+ error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
+out:
+ vput(vp);
+ return (error);
+}
+
+/*
* Change mode of a file given path name; this version follows links.
*/
/* ARGSUSED */
diff -r c8b865d42f33 -r 8e83cf286439 sys/sys/stat.h
--- a/sys/sys/stat.h Mon Apr 17 12:25:45 2000 +0000
+++ b/sys/sys/stat.h Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: stat.h,v 1.39 2000/02/03 02:01:53 cgd Exp $ */
+/* $NetBSD: stat.h,v 1.40 2000/04/17 14:31:23 mrg Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -288,6 +288,7 @@
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
int chflags __P((const char *, unsigned long));
int fchflags __P((int, unsigned long));
+int lchflags __P((const char *, unsigned long));
int lchmod __P((const char *, mode_t));
#endif /* !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) */
__END_DECLS
diff -r c8b865d42f33 -r 8e83cf286439 usr.bin/chflags/chflags.1
--- a/usr.bin/chflags/chflags.1 Mon Apr 17 12:25:45 2000 +0000
+++ b/usr.bin/chflags/chflags.1 Mon Apr 17 14:31:21 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: chflags.1,v 1.9 1999/07/31 03:24:46 christos Exp $
+.\" $NetBSD: chflags.1,v 1.10 2000/04/17 14:31:23 mrg Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -98,13 +98,6 @@
nouchg the immutable bit should be cleared
.Ed
.Pp
-Symbolic links do not have flags, so unless the
-.Fl H
-or
-.Fl L
-option is set,
-.Nm
-on a symbolic link always succeeds and has no effect.
The
.Fl H ,
.Fl L
Home |
Main Index |
Thread Index |
Old Index