Deleted Added
full compact
vfs_extattr.c (89173) vfs_extattr.c (89306)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
39 * $FreeBSD: head/sys/kern/vfs_extattr.c 89173 2002-01-10 01:59:30Z iedowse $
39 * $FreeBSD: head/sys/kern/vfs_extattr.c 89306 2002-01-13 11:58:06Z alfred $
40 */
41
42/* For 4.3 integer FS ID compatibility */
43#include "opt_compat.h"
44#include "opt_ffs.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>

--- 401 unchanged lines hidden (view full) ---

449
450 if (olddp->v_usecount == 1)
451 return;
452 sx_slock(&allproc_lock);
453 LIST_FOREACH(p, &allproc, p_list) {
454 fdp = p->p_fd;
455 if (fdp == NULL)
456 continue;
40 */
41
42/* For 4.3 integer FS ID compatibility */
43#include "opt_compat.h"
44#include "opt_ffs.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>

--- 401 unchanged lines hidden (view full) ---

449
450 if (olddp->v_usecount == 1)
451 return;
452 sx_slock(&allproc_lock);
453 LIST_FOREACH(p, &allproc, p_list) {
454 fdp = p->p_fd;
455 if (fdp == NULL)
456 continue;
457 FILEDESC_LOCK(fdp);
457 if (fdp->fd_cdir == olddp) {
458 if (fdp->fd_cdir == olddp) {
458 vrele(fdp->fd_cdir);
459 VREF(newdp);
460 fdp->fd_cdir = newdp;
459 VREF(newdp);
460 fdp->fd_cdir = newdp;
461 FILEDESC_UNLOCK(fdp);
462 vrele(olddp);
463 FILEDESC_LOCK(fdp);
461 }
462 if (fdp->fd_rdir == olddp) {
464 }
465 if (fdp->fd_rdir == olddp) {
463 vrele(fdp->fd_rdir);
464 VREF(newdp);
465 fdp->fd_rdir = newdp;
466 VREF(newdp);
467 fdp->fd_rdir = newdp;
466 }
468 FILEDESC_UNLOCK(fdp);
469 vrele(olddp);
470 } else
471 FILEDESC_UNLOCK(fdp);
467 }
468 sx_sunlock(&allproc_lock);
469 if (rootvnode == olddp) {
470 vrele(rootvnode);
471 VREF(newdp);
472 rootvnode = newdp;
473 }
474}

--- 322 unchanged lines hidden (view full) ---

797 struct mount *mp;
798 register struct statfs *sp;
799 int error;
800 struct statfs sb;
801
802 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
803 return (error);
804 mp = ((struct vnode *)fp->f_data)->v_mount;
472 }
473 sx_sunlock(&allproc_lock);
474 if (rootvnode == olddp) {
475 vrele(rootvnode);
476 VREF(newdp);
477 rootvnode = newdp;
478 }
479}

--- 322 unchanged lines hidden (view full) ---

802 struct mount *mp;
803 register struct statfs *sp;
804 int error;
805 struct statfs sb;
806
807 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
808 return (error);
809 mp = ((struct vnode *)fp->f_data)->v_mount;
810 fdrop(fp, td);
805 if (mp == NULL)
806 return (EBADF);
807 sp = &mp->mnt_stat;
808 error = VFS_STATFS(mp, sp, td);
809 if (error)
810 return (error);
811 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
812 if (suser_xxx(td->td_proc->p_ucred, 0, 0)) {

--- 85 unchanged lines hidden (view full) ---

898int
899fchdir(td, uap)
900 struct thread *td;
901 struct fchdir_args /* {
902 syscallarg(int) fd;
903 } */ *uap;
904{
905 register struct filedesc *fdp = td->td_proc->p_fd;
811 if (mp == NULL)
812 return (EBADF);
813 sp = &mp->mnt_stat;
814 error = VFS_STATFS(mp, sp, td);
815 if (error)
816 return (error);
817 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
818 if (suser_xxx(td->td_proc->p_ucred, 0, 0)) {

--- 85 unchanged lines hidden (view full) ---

904int
905fchdir(td, uap)
906 struct thread *td;
907 struct fchdir_args /* {
908 syscallarg(int) fd;
909 } */ *uap;
910{
911 register struct filedesc *fdp = td->td_proc->p_fd;
906 struct vnode *vp, *tdp;
912 struct vnode *vp, *tdp, *vpold;
907 struct mount *mp;
908 struct file *fp;
909 int error;
910
911 if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
912 return (error);
913 vp = (struct vnode *)fp->f_data;
914 VREF(vp);
913 struct mount *mp;
914 struct file *fp;
915 int error;
916
917 if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
918 return (error);
919 vp = (struct vnode *)fp->f_data;
920 VREF(vp);
921 fdrop(fp, td);
915 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
916 if (vp->v_type != VDIR)
917 error = ENOTDIR;
918 else
919 error = VOP_ACCESS(vp, VEXEC, td->td_proc->p_ucred, td);
920 while (!error && (mp = vp->v_mountedhere) != NULL) {
921 if (vfs_busy(mp, 0, 0, td))
922 continue;

--- 4 unchanged lines hidden (view full) ---

927 vput(vp);
928 vp = tdp;
929 }
930 if (error) {
931 vput(vp);
932 return (error);
933 }
934 VOP_UNLOCK(vp, 0, td);
922 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
923 if (vp->v_type != VDIR)
924 error = ENOTDIR;
925 else
926 error = VOP_ACCESS(vp, VEXEC, td->td_proc->p_ucred, td);
927 while (!error && (mp = vp->v_mountedhere) != NULL) {
928 if (vfs_busy(mp, 0, 0, td))
929 continue;

--- 4 unchanged lines hidden (view full) ---

934 vput(vp);
935 vp = tdp;
936 }
937 if (error) {
938 vput(vp);
939 return (error);
940 }
941 VOP_UNLOCK(vp, 0, td);
935 vrele(fdp->fd_cdir);
942 FILEDESC_LOCK(fdp);
943 vpold = fdp->fd_cdir;
936 fdp->fd_cdir = vp;
944 fdp->fd_cdir = vp;
945 FILEDESC_UNLOCK(fdp);
946 vrele(vpold);
937 return (0);
938}
939
940/*
941 * Change current working directory (``.'').
942 */
943#ifndef _SYS_SYSPROTO_H_
944struct chdir_args {

--- 6 unchanged lines hidden (view full) ---

951 struct thread *td;
952 struct chdir_args /* {
953 syscallarg(char *) path;
954 } */ *uap;
955{
956 register struct filedesc *fdp = td->td_proc->p_fd;
957 int error;
958 struct nameidata nd;
947 return (0);
948}
949
950/*
951 * Change current working directory (``.'').
952 */
953#ifndef _SYS_SYSPROTO_H_
954struct chdir_args {

--- 6 unchanged lines hidden (view full) ---

961 struct thread *td;
962 struct chdir_args /* {
963 syscallarg(char *) path;
964 } */ *uap;
965{
966 register struct filedesc *fdp = td->td_proc->p_fd;
967 int error;
968 struct nameidata nd;
969 struct vnode *vp;
959
960 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
961 SCARG(uap, path), td);
962 if ((error = change_dir(&nd, td)) != 0)
963 return (error);
964 NDFREE(&nd, NDF_ONLY_PNBUF);
970
971 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
972 SCARG(uap, path), td);
973 if ((error = change_dir(&nd, td)) != 0)
974 return (error);
975 NDFREE(&nd, NDF_ONLY_PNBUF);
965 vrele(fdp->fd_cdir);
976 FILEDESC_LOCK(fdp);
977 vp = fdp->fd_cdir;
966 fdp->fd_cdir = nd.ni_vp;
978 fdp->fd_cdir = nd.ni_vp;
979 FILEDESC_UNLOCK(fdp);
980 vrele(vp);
967 return (0);
968}
969
970/*
971 * Helper function for raised chroot(2) security function: Refuse if
972 * any filedescriptors are open directories.
973 */
974static int
975chroot_refuse_vdir_fds(fdp)
976 struct filedesc *fdp;
977{
978 struct vnode *vp;
979 struct file *fp;
981 return (0);
982}
983
984/*
985 * Helper function for raised chroot(2) security function: Refuse if
986 * any filedescriptors are open directories.
987 */
988static int
989chroot_refuse_vdir_fds(fdp)
990 struct filedesc *fdp;
991{
992 struct vnode *vp;
993 struct file *fp;
994 struct thread *td = curthread;
980 int error;
981 int fd;
982
995 int error;
996 int fd;
997
998 FILEDESC_LOCK(fdp);
983 for (fd = 0; fd < fdp->fd_nfiles ; fd++) {
984 error = getvnode(fdp, fd, &fp);
985 if (error)
986 continue;
987 vp = (struct vnode *)fp->f_data;
999 for (fd = 0; fd < fdp->fd_nfiles ; fd++) {
1000 error = getvnode(fdp, fd, &fp);
1001 if (error)
1002 continue;
1003 vp = (struct vnode *)fp->f_data;
1004 fdrop(fp, td);
988 if (vp->v_type != VDIR)
989 continue;
1005 if (vp->v_type != VDIR)
1006 continue;
1007 FILEDESC_UNLOCK(fdp);
990 return(EPERM);
991 }
1008 return(EPERM);
1009 }
1010 FILEDESC_UNLOCK(fdp);
992 return (0);
993}
994
995/*
996 * This sysctl determines if we will allow a process to chroot(2) if it
997 * has a directory open:
998 * 0: disallowed for all processes.
999 * 1: allowed for processes that were not already chroot(2)'ed.

--- 19 unchanged lines hidden (view full) ---

1019 struct thread *td;
1020 struct chroot_args /* {
1021 syscallarg(char *) path;
1022 } */ *uap;
1023{
1024 register struct filedesc *fdp = td->td_proc->p_fd;
1025 int error;
1026 struct nameidata nd;
1011 return (0);
1012}
1013
1014/*
1015 * This sysctl determines if we will allow a process to chroot(2) if it
1016 * has a directory open:
1017 * 0: disallowed for all processes.
1018 * 1: allowed for processes that were not already chroot(2)'ed.

--- 19 unchanged lines hidden (view full) ---

1038 struct thread *td;
1039 struct chroot_args /* {
1040 syscallarg(char *) path;
1041 } */ *uap;
1042{
1043 register struct filedesc *fdp = td->td_proc->p_fd;
1044 int error;
1045 struct nameidata nd;
1046 struct vnode *vp;
1027
1028 error = suser_xxx(0, td->td_proc, PRISON_ROOT);
1029 if (error)
1030 return (error);
1047
1048 error = suser_xxx(0, td->td_proc, PRISON_ROOT);
1049 if (error)
1050 return (error);
1051 FILEDESC_LOCK(fdp);
1031 if (chroot_allow_open_directories == 0 ||
1052 if (chroot_allow_open_directories == 0 ||
1032 (chroot_allow_open_directories == 1 && fdp->fd_rdir != rootvnode))
1053 (chroot_allow_open_directories == 1 && fdp->fd_rdir != rootvnode)) {
1054 FILEDESC_UNLOCK(fdp);
1033 error = chroot_refuse_vdir_fds(fdp);
1055 error = chroot_refuse_vdir_fds(fdp);
1056 } else
1057 FILEDESC_UNLOCK(fdp);
1034 if (error)
1035 return (error);
1036 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
1037 SCARG(uap, path), td);
1038 if ((error = change_dir(&nd, td)) != 0)
1039 return (error);
1040 NDFREE(&nd, NDF_ONLY_PNBUF);
1058 if (error)
1059 return (error);
1060 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
1061 SCARG(uap, path), td);
1062 if ((error = change_dir(&nd, td)) != 0)
1063 return (error);
1064 NDFREE(&nd, NDF_ONLY_PNBUF);
1041 vrele(fdp->fd_rdir);
1065 FILEDESC_LOCK(fdp);
1066 vp = fdp->fd_rdir;
1042 fdp->fd_rdir = nd.ni_vp;
1043 if (!fdp->fd_jdir) {
1044 fdp->fd_jdir = nd.ni_vp;
1045 VREF(fdp->fd_jdir);
1046 }
1067 fdp->fd_rdir = nd.ni_vp;
1068 if (!fdp->fd_jdir) {
1069 fdp->fd_jdir = nd.ni_vp;
1070 VREF(fdp->fd_jdir);
1071 }
1072 FILEDESC_UNLOCK(fdp);
1073 vrele(vp);
1047 return (0);
1048}
1049
1050/*
1051 * Common routine for chroot and chdir.
1052 */
1053static int
1054change_dir(ndp, td)

--- 53 unchanged lines hidden (view full) ---

1108 oflags = SCARG(uap, flags);
1109 if ((oflags & O_ACCMODE) == O_ACCMODE)
1110 return (EINVAL);
1111 flags = FFLAGS(oflags);
1112 error = falloc(td, &nfp, &indx);
1113 if (error)
1114 return (error);
1115 fp = nfp;
1074 return (0);
1075}
1076
1077/*
1078 * Common routine for chroot and chdir.
1079 */
1080static int
1081change_dir(ndp, td)

--- 53 unchanged lines hidden (view full) ---

1135 oflags = SCARG(uap, flags);
1136 if ((oflags & O_ACCMODE) == O_ACCMODE)
1137 return (EINVAL);
1138 flags = FFLAGS(oflags);
1139 error = falloc(td, &nfp, &indx);
1140 if (error)
1141 return (error);
1142 fp = nfp;
1143 FILEDESC_LOCK(fdp);
1116 cmode = ((SCARG(uap, mode) &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT;
1144 cmode = ((SCARG(uap, mode) &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT;
1145 FILEDESC_UNLOCK(fdp);
1117 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), td);
1118 td->td_dupfd = -indx - 1; /* XXX check for fdopen */
1119 /*
1120 * Bump the ref count to prevent another process from closing
1121 * the descriptor while we are blocked in vn_open()
1122 */
1123 fhold(fp);
1124 error = vn_open(&nd, &flags, cmode);

--- 14 unchanged lines hidden (view full) ---

1139 dupfdopen(td, fdp, indx, td->td_dupfd, flags, error)) == 0) {
1140 td->td_retval[0] = indx;
1141 return (0);
1142 }
1143 /*
1144 * Clean up the descriptor, but only if another thread hadn't
1145 * replaced or closed it.
1146 */
1146 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), td);
1147 td->td_dupfd = -indx - 1; /* XXX check for fdopen */
1148 /*
1149 * Bump the ref count to prevent another process from closing
1150 * the descriptor while we are blocked in vn_open()
1151 */
1152 fhold(fp);
1153 error = vn_open(&nd, &flags, cmode);

--- 14 unchanged lines hidden (view full) ---

1168 dupfdopen(td, fdp, indx, td->td_dupfd, flags, error)) == 0) {
1169 td->td_retval[0] = indx;
1170 return (0);
1171 }
1172 /*
1173 * Clean up the descriptor, but only if another thread hadn't
1174 * replaced or closed it.
1175 */
1176 FILEDESC_LOCK(fdp);
1147 if (fdp->fd_ofiles[indx] == fp) {
1148 fdp->fd_ofiles[indx] = NULL;
1177 if (fdp->fd_ofiles[indx] == fp) {
1178 fdp->fd_ofiles[indx] = NULL;
1179 FILEDESC_UNLOCK(fdp);
1149 fdrop(fp, td);
1180 fdrop(fp, td);
1150 }
1181 } else
1182 FILEDESC_UNLOCK(fdp);
1151
1152 if (error == ERESTART)
1153 error = EINTR;
1154 return (error);
1155 }
1156 td->td_dupfd = 0;
1157 NDFREE(&nd, NDF_ONLY_PNBUF);
1158 vp = nd.ni_vp;
1159
1160 /*
1161 * There should be 2 references on the file, one from the descriptor
1162 * table, and one for us.
1163 *
1164 * Handle the case where someone closed the file (via its file
1165 * descriptor) while we were blocked. The end result should look
1166 * like opening the file succeeded but it was immediately closed.
1167 */
1183
1184 if (error == ERESTART)
1185 error = EINTR;
1186 return (error);
1187 }
1188 td->td_dupfd = 0;
1189 NDFREE(&nd, NDF_ONLY_PNBUF);
1190 vp = nd.ni_vp;
1191
1192 /*
1193 * There should be 2 references on the file, one from the descriptor
1194 * table, and one for us.
1195 *
1196 * Handle the case where someone closed the file (via its file
1197 * descriptor) while we were blocked. The end result should look
1198 * like opening the file succeeded but it was immediately closed.
1199 */
1200 FILEDESC_LOCK(fdp);
1201 FILE_LOCK(fp);
1168 if (fp->f_count == 1) {
1169 KASSERT(fdp->fd_ofiles[indx] != fp,
1170 ("Open file descriptor lost all refs"));
1202 if (fp->f_count == 1) {
1203 KASSERT(fdp->fd_ofiles[indx] != fp,
1204 ("Open file descriptor lost all refs"));
1205 FILEDESC_UNLOCK(fdp);
1206 FILE_UNLOCK(fp);
1171 VOP_UNLOCK(vp, 0, td);
1172 vn_close(vp, flags & FMASK, fp->f_cred, td);
1173 fdrop(fp, td);
1174 td->td_retval[0] = indx;
1175 return 0;
1176 }
1177
1178 fp->f_data = (caddr_t)vp;
1179 fp->f_flag = flags & FMASK;
1180 fp->f_ops = &vnops;
1181 fp->f_type = (vp->v_type == VFIFO ? DTYPE_FIFO : DTYPE_VNODE);
1207 VOP_UNLOCK(vp, 0, td);
1208 vn_close(vp, flags & FMASK, fp->f_cred, td);
1209 fdrop(fp, td);
1210 td->td_retval[0] = indx;
1211 return 0;
1212 }
1213
1214 fp->f_data = (caddr_t)vp;
1215 fp->f_flag = flags & FMASK;
1216 fp->f_ops = &vnops;
1217 fp->f_type = (vp->v_type == VFIFO ? DTYPE_FIFO : DTYPE_VNODE);
1218 FILEDESC_UNLOCK(fdp);
1219 FILE_UNLOCK(fp);
1182 VOP_UNLOCK(vp, 0, td);
1183 if (flags & (O_EXLOCK | O_SHLOCK)) {
1184 lf.l_whence = SEEK_SET;
1185 lf.l_start = 0;
1186 lf.l_len = 0;
1187 if (flags & O_EXLOCK)
1188 lf.l_type = F_WRLCK;
1189 else

--- 24 unchanged lines hidden (view full) ---

1214 /*
1215 * Release our private reference, leaving the one associated with
1216 * the descriptor table intact.
1217 */
1218 fdrop(fp, td);
1219 td->td_retval[0] = indx;
1220 return (0);
1221bad:
1220 VOP_UNLOCK(vp, 0, td);
1221 if (flags & (O_EXLOCK | O_SHLOCK)) {
1222 lf.l_whence = SEEK_SET;
1223 lf.l_start = 0;
1224 lf.l_len = 0;
1225 if (flags & O_EXLOCK)
1226 lf.l_type = F_WRLCK;
1227 else

--- 24 unchanged lines hidden (view full) ---

1252 /*
1253 * Release our private reference, leaving the one associated with
1254 * the descriptor table intact.
1255 */
1256 fdrop(fp, td);
1257 td->td_retval[0] = indx;
1258 return (0);
1259bad:
1260 FILEDESC_LOCK(fdp);
1222 if (fdp->fd_ofiles[indx] == fp) {
1223 fdp->fd_ofiles[indx] = NULL;
1261 if (fdp->fd_ofiles[indx] == fp) {
1262 fdp->fd_ofiles[indx] = NULL;
1263 FILEDESC_UNLOCK(fdp);
1224 fdrop(fp, td);
1264 fdrop(fp, td);
1225 }
1226 fdrop(fp, td);
1265 } else
1266 FILEDESC_UNLOCK(fdp);
1227 return (error);
1228}
1229
1230#ifdef COMPAT_43
1231/*
1232 * Create a file.
1233 */
1234#ifndef _SYS_SYSPROTO_H_

--- 67 unchanged lines hidden (view full) ---

1302 if ((error = namei(&nd)) != 0)
1303 return (error);
1304 vp = nd.ni_vp;
1305 if (vp != NULL) {
1306 vrele(vp);
1307 error = EEXIST;
1308 } else {
1309 VATTR_NULL(&vattr);
1267 return (error);
1268}
1269
1270#ifdef COMPAT_43
1271/*
1272 * Create a file.
1273 */
1274#ifndef _SYS_SYSPROTO_H_

--- 67 unchanged lines hidden (view full) ---

1342 if ((error = namei(&nd)) != 0)
1343 return (error);
1344 vp = nd.ni_vp;
1345 if (vp != NULL) {
1346 vrele(vp);
1347 error = EEXIST;
1348 } else {
1349 VATTR_NULL(&vattr);
1350 FILEDESC_LOCK(td->td_proc->p_fd);
1310 vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ td->td_proc->p_fd->fd_cmask;
1351 vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ td->td_proc->p_fd->fd_cmask;
1352 FILEDESC_UNLOCK(td->td_proc->p_fd);
1311 vattr.va_rdev = SCARG(uap, dev);
1312 whiteout = 0;
1313
1314 switch (SCARG(uap, mode) & S_IFMT) {
1315 case S_IFMT: /* used by badsect to flag bad sectors */
1316 vattr.va_type = VBAD;
1317 break;
1318 case S_IFCHR:

--- 74 unchanged lines hidden (view full) ---

1393 NDFREE(&nd, NDF_ONLY_PNBUF);
1394 vput(nd.ni_dvp);
1395 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
1396 return (error);
1397 goto restart;
1398 }
1399 VATTR_NULL(&vattr);
1400 vattr.va_type = VFIFO;
1353 vattr.va_rdev = SCARG(uap, dev);
1354 whiteout = 0;
1355
1356 switch (SCARG(uap, mode) & S_IFMT) {
1357 case S_IFMT: /* used by badsect to flag bad sectors */
1358 vattr.va_type = VBAD;
1359 break;
1360 case S_IFCHR:

--- 74 unchanged lines hidden (view full) ---

1435 NDFREE(&nd, NDF_ONLY_PNBUF);
1436 vput(nd.ni_dvp);
1437 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
1438 return (error);
1439 goto restart;
1440 }
1441 VATTR_NULL(&vattr);
1442 vattr.va_type = VFIFO;
1443 FILEDESC_LOCK(td->td_proc->p_fd);
1401 vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ td->td_proc->p_fd->fd_cmask;
1444 vattr.va_mode = (SCARG(uap, mode) & ALLPERMS) &~ td->td_proc->p_fd->fd_cmask;
1445 FILEDESC_UNLOCK(td->td_proc->p_fd);
1402 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
1403 error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
1404 if (error == 0)
1405 vput(nd.ni_vp);
1406 NDFREE(&nd, NDF_ONLY_PNBUF);
1407 vput(nd.ni_dvp);
1408 vn_finished_write(mp);
1409 return (error);

--- 98 unchanged lines hidden (view full) ---

1508 if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
1509 NDFREE(&nd, NDF_ONLY_PNBUF);
1510 vput(nd.ni_dvp);
1511 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
1512 return (error);
1513 goto restart;
1514 }
1515 VATTR_NULL(&vattr);
1446 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
1447 error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
1448 if (error == 0)
1449 vput(nd.ni_vp);
1450 NDFREE(&nd, NDF_ONLY_PNBUF);
1451 vput(nd.ni_dvp);
1452 vn_finished_write(mp);
1453 return (error);

--- 98 unchanged lines hidden (view full) ---

1552 if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
1553 NDFREE(&nd, NDF_ONLY_PNBUF);
1554 vput(nd.ni_dvp);
1555 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
1556 return (error);
1557 goto restart;
1558 }
1559 VATTR_NULL(&vattr);
1560 FILEDESC_LOCK(td->td_proc->p_fd);
1516 vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_fd->fd_cmask;
1561 vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_fd->fd_cmask;
1562 FILEDESC_UNLOCK(td->td_proc->p_fd);
1517 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
1518 error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, path);
1519 NDFREE(&nd, NDF_ONLY_PNBUF);
1520 if (error == 0)
1521 vput(nd.ni_vp);
1522 vput(nd.ni_dvp);
1523 vn_finished_write(mp);
1524 ASSERT_VOP_UNLOCKED(nd.ni_dvp, "symlink");

--- 128 unchanged lines hidden (view full) ---

1653 register struct lseek_args /* {
1654 syscallarg(int) fd;
1655 syscallarg(int) pad;
1656 syscallarg(off_t) offset;
1657 syscallarg(int) whence;
1658 } */ *uap;
1659{
1660 struct ucred *cred = td->td_proc->p_ucred;
1563 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
1564 error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, path);
1565 NDFREE(&nd, NDF_ONLY_PNBUF);
1566 if (error == 0)
1567 vput(nd.ni_vp);
1568 vput(nd.ni_dvp);
1569 vn_finished_write(mp);
1570 ASSERT_VOP_UNLOCKED(nd.ni_dvp, "symlink");

--- 128 unchanged lines hidden (view full) ---

1699 register struct lseek_args /* {
1700 syscallarg(int) fd;
1701 syscallarg(int) pad;
1702 syscallarg(off_t) offset;
1703 syscallarg(int) whence;
1704 } */ *uap;
1705{
1706 struct ucred *cred = td->td_proc->p_ucred;
1661 register struct filedesc *fdp = td->td_proc->p_fd;
1662 register struct file *fp;
1707 register struct file *fp;
1663 struct vattr vattr;
1664 struct vnode *vp;
1708 struct vnode *vp;
1709 struct vattr vattr;
1665 off_t offset;
1666 int error, noneg;
1667
1710 off_t offset;
1711 int error, noneg;
1712
1668 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
1669 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
1713 fp = ffind_hold(td, uap->fd);
1714 if (fp == NULL)
1670 return (EBADF);
1715 return (EBADF);
1671 if (fp->f_type != DTYPE_VNODE)
1716 if (fp->f_type != DTYPE_VNODE) {
1717 fdrop(fp, td);
1672 return (ESPIPE);
1718 return (ESPIPE);
1719 }
1673 vp = (struct vnode *)fp->f_data;
1674 noneg = (vp->v_type != VCHR);
1675 offset = SCARG(uap, offset);
1676 switch (SCARG(uap, whence)) {
1677 case L_INCR:
1678 if (noneg &&
1679 (fp->f_offset < 0 ||
1680 (offset > 0 && fp->f_offset > OFF_MAX - offset)))

--- 8 unchanged lines hidden (view full) ---

1689 (vattr.va_size > OFF_MAX ||
1690 (offset > 0 && vattr.va_size > OFF_MAX - offset)))
1691 return (EOVERFLOW);
1692 offset += vattr.va_size;
1693 break;
1694 case L_SET:
1695 break;
1696 default:
1720 vp = (struct vnode *)fp->f_data;
1721 noneg = (vp->v_type != VCHR);
1722 offset = SCARG(uap, offset);
1723 switch (SCARG(uap, whence)) {
1724 case L_INCR:
1725 if (noneg &&
1726 (fp->f_offset < 0 ||
1727 (offset > 0 && fp->f_offset > OFF_MAX - offset)))

--- 8 unchanged lines hidden (view full) ---

1736 (vattr.va_size > OFF_MAX ||
1737 (offset > 0 && vattr.va_size > OFF_MAX - offset)))
1738 return (EOVERFLOW);
1739 offset += vattr.va_size;
1740 break;
1741 case L_SET:
1742 break;
1743 default:
1744 fdrop(fp, td);
1697 return (EINVAL);
1698 }
1699 if (noneg && offset < 0)
1700 return (EINVAL);
1701 fp->f_offset = offset;
1702 *(off_t *)(td->td_retval) = fp->f_offset;
1745 return (EINVAL);
1746 }
1747 if (noneg && offset < 0)
1748 return (EINVAL);
1749 fp->f_offset = offset;
1750 *(off_t *)(td->td_retval) = fp->f_offset;
1751 fdrop(fp, td);
1703 return (0);
1704}
1705
1706#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1707/*
1708 * Reposition read/write file offset.
1709 */
1710#ifndef _SYS_SYSPROTO_H_

--- 591 unchanged lines hidden (view full) ---

2302 syscallarg(int) flags;
2303 } */ *uap;
2304{
2305 struct file *fp;
2306 int error;
2307
2308 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2309 return (error);
1752 return (0);
1753}
1754
1755#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1756/*
1757 * Reposition read/write file offset.
1758 */
1759#ifndef _SYS_SYSPROTO_H_

--- 591 unchanged lines hidden (view full) ---

2351 syscallarg(int) flags;
2352 } */ *uap;
2353{
2354 struct file *fp;
2355 int error;
2356
2357 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2358 return (error);
2310 return setfflags(td, (struct vnode *) fp->f_data, SCARG(uap, flags));
2359 error = setfflags(td, (struct vnode *) fp->f_data, SCARG(uap, flags));
2360 fdrop(fp, td);
2361 return (error);
2311}
2312
2313/*
2314 * Common implementation code for chmod(), lchmod() and fchmod().
2315 */
2316static int
2317setfmode(td, vp, mode)
2318 struct thread *td;

--- 90 unchanged lines hidden (view full) ---

2409fchmod(td, uap)
2410 struct thread *td;
2411 register struct fchmod_args /* {
2412 syscallarg(int) fd;
2413 syscallarg(int) mode;
2414 } */ *uap;
2415{
2416 struct file *fp;
2362}
2363
2364/*
2365 * Common implementation code for chmod(), lchmod() and fchmod().
2366 */
2367static int
2368setfmode(td, vp, mode)
2369 struct thread *td;

--- 90 unchanged lines hidden (view full) ---

2460fchmod(td, uap)
2461 struct thread *td;
2462 register struct fchmod_args /* {
2463 syscallarg(int) fd;
2464 syscallarg(int) mode;
2465 } */ *uap;
2466{
2467 struct file *fp;
2468 struct vnode *vp;
2417 int error;
2418
2419 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2420 return (error);
2469 int error;
2470
2471 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2472 return (error);
2421 return setfmode(td, (struct vnode *)fp->f_data, SCARG(uap, mode));
2473 vp = (struct vnode *)fp->f_data;
2474 error = setfmode(td, (struct vnode *)fp->f_data, SCARG(uap, mode));
2475 fdrop(fp, td);
2476 return (error);
2422}
2423
2424/*
2425 * Common implementation for chown(), lchown(), and fchown()
2426 */
2427static int
2428setfown(td, vp, uid, gid)
2429 struct thread *td;

--- 98 unchanged lines hidden (view full) ---

2528 struct thread *td;
2529 register struct fchown_args /* {
2530 syscallarg(int) fd;
2531 syscallarg(int) uid;
2532 syscallarg(int) gid;
2533 } */ *uap;
2534{
2535 struct file *fp;
2477}
2478
2479/*
2480 * Common implementation for chown(), lchown(), and fchown()
2481 */
2482static int
2483setfown(td, vp, uid, gid)
2484 struct thread *td;

--- 98 unchanged lines hidden (view full) ---

2583 struct thread *td;
2584 register struct fchown_args /* {
2585 syscallarg(int) fd;
2586 syscallarg(int) uid;
2587 syscallarg(int) gid;
2588 } */ *uap;
2589{
2590 struct file *fp;
2591 struct vnode *vp;
2536 int error;
2537
2538 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2539 return (error);
2592 int error;
2593
2594 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2595 return (error);
2540 return setfown(td, (struct vnode *)fp->f_data,
2596 vp = (struct vnode *)fp->f_data;
2597 error = setfown(td, (struct vnode *)fp->f_data,
2541 SCARG(uap, uid), SCARG(uap, gid));
2598 SCARG(uap, uid), SCARG(uap, gid));
2599 fdrop(fp, td);
2600 return (error);
2542}
2543
2544/*
2545 * Common implementation code for utimes(), lutimes(), and futimes().
2546 */
2547static int
2548getutimes(usrtvp, tsp)
2549 const struct timeval *usrtvp;

--- 137 unchanged lines hidden (view full) ---

2687 struct timeval *usrtvp;
2688 int error;
2689
2690 usrtvp = SCARG(uap, tptr);
2691 if ((error = getutimes(usrtvp, ts)) != 0)
2692 return (error);
2693 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2694 return (error);
2601}
2602
2603/*
2604 * Common implementation code for utimes(), lutimes(), and futimes().
2605 */
2606static int
2607getutimes(usrtvp, tsp)
2608 const struct timeval *usrtvp;

--- 137 unchanged lines hidden (view full) ---

2746 struct timeval *usrtvp;
2747 int error;
2748
2749 usrtvp = SCARG(uap, tptr);
2750 if ((error = getutimes(usrtvp, ts)) != 0)
2751 return (error);
2752 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2753 return (error);
2695 return setutimes(td, (struct vnode *)fp->f_data, ts, usrtvp == NULL);
2754 error = setutimes(td, (struct vnode *)fp->f_data, ts, usrtvp == NULL);
2755 fdrop(fp, td);
2756 return (error);
2696}
2697
2698/*
2699 * Truncate a file given its path name.
2700 */
2701#ifndef _SYS_SYSPROTO_H_
2702struct truncate_args {
2703 char *path;

--- 68 unchanged lines hidden (view full) ---

2772 struct vnode *vp;
2773 struct file *fp;
2774 int error;
2775
2776 if (uap->length < 0)
2777 return(EINVAL);
2778 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2779 return (error);
2757}
2758
2759/*
2760 * Truncate a file given its path name.
2761 */
2762#ifndef _SYS_SYSPROTO_H_
2763struct truncate_args {
2764 char *path;

--- 68 unchanged lines hidden (view full) ---

2833 struct vnode *vp;
2834 struct file *fp;
2835 int error;
2836
2837 if (uap->length < 0)
2838 return(EINVAL);
2839 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2840 return (error);
2780 if ((fp->f_flag & FWRITE) == 0)
2841 if ((fp->f_flag & FWRITE) == 0) {
2842 fdrop(fp, td);
2781 return (EINVAL);
2843 return (EINVAL);
2844 }
2782 vp = (struct vnode *)fp->f_data;
2845 vp = (struct vnode *)fp->f_data;
2783 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
2846 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
2847 fdrop(fp, td);
2784 return (error);
2848 return (error);
2849 }
2785 VOP_LEASE(vp, td, td->td_proc->p_ucred, LEASE_WRITE);
2786 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2787 if (vp->v_type == VDIR)
2788 error = EISDIR;
2789 else if ((error = vn_writechk(vp)) == 0) {
2790 VATTR_NULL(&vattr);
2791 vattr.va_size = SCARG(uap, length);
2792 error = VOP_SETATTR(vp, &vattr, fp->f_cred, td);
2793 }
2794 VOP_UNLOCK(vp, 0, td);
2795 vn_finished_write(mp);
2850 VOP_LEASE(vp, td, td->td_proc->p_ucred, LEASE_WRITE);
2851 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2852 if (vp->v_type == VDIR)
2853 error = EISDIR;
2854 else if ((error = vn_writechk(vp)) == 0) {
2855 VATTR_NULL(&vattr);
2856 vattr.va_size = SCARG(uap, length);
2857 error = VOP_SETATTR(vp, &vattr, fp->f_cred, td);
2858 }
2859 VOP_UNLOCK(vp, 0, td);
2860 vn_finished_write(mp);
2861 fdrop(fp, td);
2796 return (error);
2797}
2798
2799#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2800/*
2801 * Truncate a file given its path name.
2802 */
2803#ifndef _SYS_SYSPROTO_H_

--- 74 unchanged lines hidden (view full) ---

2878 vm_object_t obj;
2879 int error;
2880
2881 GIANT_REQUIRED;
2882
2883 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2884 return (error);
2885 vp = (struct vnode *)fp->f_data;
2862 return (error);
2863}
2864
2865#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2866/*
2867 * Truncate a file given its path name.
2868 */
2869#ifndef _SYS_SYSPROTO_H_

--- 74 unchanged lines hidden (view full) ---

2944 vm_object_t obj;
2945 int error;
2946
2947 GIANT_REQUIRED;
2948
2949 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
2950 return (error);
2951 vp = (struct vnode *)fp->f_data;
2886 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
2952 if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) {
2953 fdrop(fp, td);
2887 return (error);
2954 return (error);
2955 }
2888 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2889 if (VOP_GETVOBJECT(vp, &obj) == 0) {
2890 vm_object_page_clean(obj, 0, 0, 0);
2891 }
2892 error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, td);
2893#ifdef SOFTUPDATES
2894 if (error == 0 && vp->v_mount && (vp->v_mount->mnt_flag & MNT_SOFTDEP))
2895 error = softdep_fsync(vp);
2896#endif
2897
2898 VOP_UNLOCK(vp, 0, td);
2899 vn_finished_write(mp);
2956 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2957 if (VOP_GETVOBJECT(vp, &obj) == 0) {
2958 vm_object_page_clean(obj, 0, 0, 0);
2959 }
2960 error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, td);
2961#ifdef SOFTUPDATES
2962 if (error == 0 && vp->v_mount && (vp->v_mount->mnt_flag & MNT_SOFTDEP))
2963 error = softdep_fsync(vp);
2964#endif
2965
2966 VOP_UNLOCK(vp, 0, td);
2967 vn_finished_write(mp);
2968 fdrop(fp, td);
2900 return (error);
2901}
2902
2903/*
2904 * Rename files. Source and destination must either both be directories,
2905 * or both not be directories. If target is a directory, it must be empty.
2906 */
2907#ifndef _SYS_SYSPROTO_H_

--- 155 unchanged lines hidden (view full) ---

3063 NDFREE(&nd, NDF_ONLY_PNBUF);
3064 vput(nd.ni_dvp);
3065 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
3066 return (error);
3067 goto restart;
3068 }
3069 VATTR_NULL(&vattr);
3070 vattr.va_type = VDIR;
2969 return (error);
2970}
2971
2972/*
2973 * Rename files. Source and destination must either both be directories,
2974 * or both not be directories. If target is a directory, it must be empty.
2975 */
2976#ifndef _SYS_SYSPROTO_H_

--- 155 unchanged lines hidden (view full) ---

3132 NDFREE(&nd, NDF_ONLY_PNBUF);
3133 vput(nd.ni_dvp);
3134 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
3135 return (error);
3136 goto restart;
3137 }
3138 VATTR_NULL(&vattr);
3139 vattr.va_type = VDIR;
3140 FILEDESC_LOCK(td->td_proc->p_fd);
3071 vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_fd->fd_cmask;
3141 vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_fd->fd_cmask;
3142 FILEDESC_UNLOCK(td->td_proc->p_fd);
3072 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
3073 error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
3074 NDFREE(&nd, NDF_ONLY_PNBUF);
3075 vput(nd.ni_dvp);
3076 if (!error)
3077 vput(nd.ni_vp);
3078 vn_finished_write(mp);
3079 ASSERT_VOP_UNLOCKED(nd.ni_dvp, "mkdir");

--- 105 unchanged lines hidden (view full) ---

3185 int error, eofflag, readcnt;
3186 long loff;
3187
3188 /* XXX arbitrary sanity limit on `count'. */
3189 if (SCARG(uap, count) > 64 * 1024)
3190 return (EINVAL);
3191 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
3192 return (error);
3143 VOP_LEASE(nd.ni_dvp, td, td->td_proc->p_ucred, LEASE_WRITE);
3144 error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
3145 NDFREE(&nd, NDF_ONLY_PNBUF);
3146 vput(nd.ni_dvp);
3147 if (!error)
3148 vput(nd.ni_vp);
3149 vn_finished_write(mp);
3150 ASSERT_VOP_UNLOCKED(nd.ni_dvp, "mkdir");

--- 105 unchanged lines hidden (view full) ---

3256 int error, eofflag, readcnt;
3257 long loff;
3258
3259 /* XXX arbitrary sanity limit on `count'. */
3260 if (SCARG(uap, count) > 64 * 1024)
3261 return (EINVAL);
3262 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
3263 return (error);
3193 if ((fp->f_flag & FREAD) == 0)
3264 if ((fp->f_flag & FREAD) == 0) {
3265 fdrop(fp, td);
3194 return (EBADF);
3266 return (EBADF);
3267 }
3195 vp = (struct vnode *)fp->f_data;
3196unionread:
3268 vp = (struct vnode *)fp->f_data;
3269unionread:
3197 if (vp->v_type != VDIR)
3270 if (vp->v_type != VDIR) {
3271 fdrop(fp, td);
3198 return (EINVAL);
3272 return (EINVAL);
3273 }
3199 aiov.iov_base = SCARG(uap, buf);
3200 aiov.iov_len = SCARG(uap, count);
3201 auio.uio_iov = &aiov;
3202 auio.uio_iovcnt = 1;
3203 auio.uio_rw = UIO_READ;
3204 auio.uio_segflg = UIO_USERSPACE;
3205 auio.uio_td = td;
3206 auio.uio_resid = SCARG(uap, count);

--- 46 unchanged lines hidden (view full) ---

3253 }
3254 }
3255 if (dp >= edp)
3256 error = uiomove(dirbuf, readcnt, &auio);
3257 }
3258 FREE(dirbuf, M_TEMP);
3259 }
3260 VOP_UNLOCK(vp, 0, td);
3274 aiov.iov_base = SCARG(uap, buf);
3275 aiov.iov_len = SCARG(uap, count);
3276 auio.uio_iov = &aiov;
3277 auio.uio_iovcnt = 1;
3278 auio.uio_rw = UIO_READ;
3279 auio.uio_segflg = UIO_USERSPACE;
3280 auio.uio_td = td;
3281 auio.uio_resid = SCARG(uap, count);

--- 46 unchanged lines hidden (view full) ---

3328 }
3329 }
3330 if (dp >= edp)
3331 error = uiomove(dirbuf, readcnt, &auio);
3332 }
3333 FREE(dirbuf, M_TEMP);
3334 }
3335 VOP_UNLOCK(vp, 0, td);
3261 if (error)
3336 if (error) {
3337 fdrop(fp, td);
3262 return (error);
3338 return (error);
3339 }
3263 if (SCARG(uap, count) == auio.uio_resid) {
3264 if (union_dircheckp) {
3265 error = union_dircheckp(td, &vp, fp);
3266 if (error == -1)
3267 goto unionread;
3340 if (SCARG(uap, count) == auio.uio_resid) {
3341 if (union_dircheckp) {
3342 error = union_dircheckp(td, &vp, fp);
3343 if (error == -1)
3344 goto unionread;
3268 if (error)
3345 if (error) {
3346 fdrop(fp, td);
3269 return (error);
3347 return (error);
3348 }
3270 }
3271 if ((vp->v_flag & VROOT) &&
3272 (vp->v_mount->mnt_flag & MNT_UNION)) {
3273 struct vnode *tvp = vp;
3274 vp = vp->v_mount->mnt_vnodecovered;
3275 VREF(vp);
3276 fp->f_data = (caddr_t) vp;
3277 fp->f_offset = 0;
3278 vrele(tvp);
3279 goto unionread;
3280 }
3281 }
3282 error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
3283 sizeof(long));
3349 }
3350 if ((vp->v_flag & VROOT) &&
3351 (vp->v_mount->mnt_flag & MNT_UNION)) {
3352 struct vnode *tvp = vp;
3353 vp = vp->v_mount->mnt_vnodecovered;
3354 VREF(vp);
3355 fp->f_data = (caddr_t) vp;
3356 fp->f_offset = 0;
3357 vrele(tvp);
3358 goto unionread;
3359 }
3360 }
3361 error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
3362 sizeof(long));
3363 fdrop(fp, td);
3284 td->td_retval[0] = SCARG(uap, count) - auio.uio_resid;
3285 return (error);
3286}
3287#endif /* COMPAT_43 */
3288
3289/*
3290 * Read a block of directory entries in a file system independent format.
3291 */

--- 19 unchanged lines hidden (view full) ---

3311 struct file *fp;
3312 struct uio auio;
3313 struct iovec aiov;
3314 long loff;
3315 int error, eofflag;
3316
3317 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
3318 return (error);
3364 td->td_retval[0] = SCARG(uap, count) - auio.uio_resid;
3365 return (error);
3366}
3367#endif /* COMPAT_43 */
3368
3369/*
3370 * Read a block of directory entries in a file system independent format.
3371 */

--- 19 unchanged lines hidden (view full) ---

3391 struct file *fp;
3392 struct uio auio;
3393 struct iovec aiov;
3394 long loff;
3395 int error, eofflag;
3396
3397 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
3398 return (error);
3319 if ((fp->f_flag & FREAD) == 0)
3399 if ((fp->f_flag & FREAD) == 0) {
3400 fdrop(fp, td);
3320 return (EBADF);
3401 return (EBADF);
3402 }
3321 vp = (struct vnode *)fp->f_data;
3322unionread:
3403 vp = (struct vnode *)fp->f_data;
3404unionread:
3323 if (vp->v_type != VDIR)
3405 if (vp->v_type != VDIR) {
3406 fdrop(fp, td);
3324 return (EINVAL);
3407 return (EINVAL);
3408 }
3325 aiov.iov_base = SCARG(uap, buf);
3326 aiov.iov_len = SCARG(uap, count);
3327 auio.uio_iov = &aiov;
3328 auio.uio_iovcnt = 1;
3329 auio.uio_rw = UIO_READ;
3330 auio.uio_segflg = UIO_USERSPACE;
3331 auio.uio_td = td;
3332 auio.uio_resid = SCARG(uap, count);
3333 /* vn_lock(vp, LK_SHARED | LK_RETRY, td); */
3334 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3335 loff = auio.uio_offset = fp->f_offset;
3336 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL, NULL);
3337 fp->f_offset = auio.uio_offset;
3338 VOP_UNLOCK(vp, 0, td);
3409 aiov.iov_base = SCARG(uap, buf);
3410 aiov.iov_len = SCARG(uap, count);
3411 auio.uio_iov = &aiov;
3412 auio.uio_iovcnt = 1;
3413 auio.uio_rw = UIO_READ;
3414 auio.uio_segflg = UIO_USERSPACE;
3415 auio.uio_td = td;
3416 auio.uio_resid = SCARG(uap, count);
3417 /* vn_lock(vp, LK_SHARED | LK_RETRY, td); */
3418 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3419 loff = auio.uio_offset = fp->f_offset;
3420 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL, NULL);
3421 fp->f_offset = auio.uio_offset;
3422 VOP_UNLOCK(vp, 0, td);
3339 if (error)
3423 if (error) {
3424 fdrop(fp, td);
3340 return (error);
3425 return (error);
3426 }
3341 if (SCARG(uap, count) == auio.uio_resid) {
3342 if (union_dircheckp) {
3343 error = union_dircheckp(td, &vp, fp);
3344 if (error == -1)
3345 goto unionread;
3427 if (SCARG(uap, count) == auio.uio_resid) {
3428 if (union_dircheckp) {
3429 error = union_dircheckp(td, &vp, fp);
3430 if (error == -1)
3431 goto unionread;
3346 if (error)
3432 if (error) {
3433 fdrop(fp, td);
3347 return (error);
3434 return (error);
3435 }
3348 }
3349 if ((vp->v_flag & VROOT) &&
3350 (vp->v_mount->mnt_flag & MNT_UNION)) {
3351 struct vnode *tvp = vp;
3352 vp = vp->v_mount->mnt_vnodecovered;
3353 VREF(vp);
3354 fp->f_data = (caddr_t) vp;
3355 fp->f_offset = 0;
3356 vrele(tvp);
3357 goto unionread;
3358 }
3359 }
3360 if (SCARG(uap, basep) != NULL) {
3361 error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
3362 sizeof(long));
3363 }
3364 td->td_retval[0] = SCARG(uap, count) - auio.uio_resid;
3436 }
3437 if ((vp->v_flag & VROOT) &&
3438 (vp->v_mount->mnt_flag & MNT_UNION)) {
3439 struct vnode *tvp = vp;
3440 vp = vp->v_mount->mnt_vnodecovered;
3441 VREF(vp);
3442 fp->f_data = (caddr_t) vp;
3443 fp->f_offset = 0;
3444 vrele(tvp);
3445 goto unionread;
3446 }
3447 }
3448 if (SCARG(uap, basep) != NULL) {
3449 error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
3450 sizeof(long));
3451 }
3452 td->td_retval[0] = SCARG(uap, count) - auio.uio_resid;
3453 fdrop(fp, td);
3365 return (error);
3366}
3367#ifndef _SYS_SYSPROTO_H_
3368struct getdents_args {
3369 int fd;
3370 char *buf;
3371 size_t count;
3372};

--- 29 unchanged lines hidden (view full) ---

3402umask(td, uap)
3403 struct thread *td;
3404 struct umask_args /* {
3405 syscallarg(int) newmask;
3406 } */ *uap;
3407{
3408 register struct filedesc *fdp;
3409
3454 return (error);
3455}
3456#ifndef _SYS_SYSPROTO_H_
3457struct getdents_args {
3458 int fd;
3459 char *buf;
3460 size_t count;
3461};

--- 29 unchanged lines hidden (view full) ---

3491umask(td, uap)
3492 struct thread *td;
3493 struct umask_args /* {
3494 syscallarg(int) newmask;
3495 } */ *uap;
3496{
3497 register struct filedesc *fdp;
3498
3499 FILEDESC_LOCK(td->td_proc->p_fd);
3410 fdp = td->td_proc->p_fd;
3411 td->td_retval[0] = fdp->fd_cmask;
3412 fdp->fd_cmask = SCARG(uap, newmask) & ALLPERMS;
3500 fdp = td->td_proc->p_fd;
3501 td->td_retval[0] = fdp->fd_cmask;
3502 fdp->fd_cmask = SCARG(uap, newmask) & ALLPERMS;
3503 FILEDESC_UNLOCK(td->td_proc->p_fd);
3413 return (0);
3414}
3415
3416/*
3417 * Void all references to file by ripping underlying filesystem
3418 * away from vnode.
3419 */
3420#ifndef _SYS_SYSPROTO_H_

--- 39 unchanged lines hidden (view full) ---

3460 vn_finished_write(mp);
3461out:
3462 vrele(vp);
3463 return (error);
3464}
3465
3466/*
3467 * Convert a user file descriptor to a kernel file entry.
3504 return (0);
3505}
3506
3507/*
3508 * Void all references to file by ripping underlying filesystem
3509 * away from vnode.
3510 */
3511#ifndef _SYS_SYSPROTO_H_

--- 39 unchanged lines hidden (view full) ---

3551 vn_finished_write(mp);
3552out:
3553 vrele(vp);
3554 return (error);
3555}
3556
3557/*
3558 * Convert a user file descriptor to a kernel file entry.
3559 * The file entry is locked upon returning.
3468 */
3469int
3470getvnode(fdp, fd, fpp)
3471 struct filedesc *fdp;
3472 int fd;
3473 struct file **fpp;
3474{
3560 */
3561int
3562getvnode(fdp, fd, fpp)
3563 struct filedesc *fdp;
3564 int fd;
3565 struct file **fpp;
3566{
3567 int error;
3475 struct file *fp;
3476
3568 struct file *fp;
3569
3477 if ((u_int)fd >= fdp->fd_nfiles ||
3478 (fp = fdp->fd_ofiles[fd]) == NULL)
3479 return (EBADF);
3480 if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO)
3481 return (EINVAL);
3570 fp = NULL;
3571 if (fdp == NULL)
3572 error = EBADF;
3573 else {
3574 FILEDESC_LOCK(fdp);
3575 if ((u_int)fd >= fdp->fd_nfiles ||
3576 (fp = fdp->fd_ofiles[fd]) == NULL)
3577 error = EBADF;
3578 else if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) {
3579 fp = NULL;
3580 error = EINVAL;
3581 } else {
3582 fhold(fp);
3583 error = 0;
3584 }
3585 FILEDESC_UNLOCK(fdp);
3586 }
3482 *fpp = fp;
3587 *fpp = fp;
3483 return (0);
3588 return (error);
3484}
3485/*
3486 * Get (NFS) file handle
3487 */
3488#ifndef _SYS_SYSPROTO_H_
3489struct getfh_args {
3490 char *fname;
3491 fhandle_t *fhp;

--- 184 unchanged lines hidden (view full) ---

3676 type |= F_WAIT;
3677 VOP_UNLOCK(vp, 0, td);
3678 if ((error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type)) != 0) {
3679 /*
3680 * The lock request failed. Normally close the
3681 * descriptor but handle the case where someone might
3682 * have dup()d or close()d it when we weren't looking.
3683 */
3589}
3590/*
3591 * Get (NFS) file handle
3592 */
3593#ifndef _SYS_SYSPROTO_H_
3594struct getfh_args {
3595 char *fname;
3596 fhandle_t *fhp;

--- 184 unchanged lines hidden (view full) ---

3781 type |= F_WAIT;
3782 VOP_UNLOCK(vp, 0, td);
3783 if ((error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type)) != 0) {
3784 /*
3785 * The lock request failed. Normally close the
3786 * descriptor but handle the case where someone might
3787 * have dup()d or close()d it when we weren't looking.
3788 */
3789 FILEDESC_LOCK(fdp);
3684 if (fdp->fd_ofiles[indx] == fp) {
3685 fdp->fd_ofiles[indx] = NULL;
3790 if (fdp->fd_ofiles[indx] == fp) {
3791 fdp->fd_ofiles[indx] = NULL;
3792 FILEDESC_UNLOCK(fdp);
3686 fdrop(fp, td);
3793 fdrop(fp, td);
3687 }
3794 } else
3795 FILEDESC_UNLOCK(fdp);
3688 /*
3689 * release our private reference
3690 */
3691 fdrop(fp, td);
3692 return(error);
3693 }
3694 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3695 fp->f_flag |= FHASLOCK;

--- 294 unchanged lines hidden (view full) ---

3990 return (error);
3991
3992 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
3993 return (error);
3994
3995 error = extattr_set_vp((struct vnode *)fp->f_data,
3996 SCARG(uap, attrnamespace), attrname, SCARG(uap, iovp),
3997 SCARG(uap, iovcnt), td);
3796 /*
3797 * release our private reference
3798 */
3799 fdrop(fp, td);
3800 return(error);
3801 }
3802 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
3803 fp->f_flag |= FHASLOCK;

--- 294 unchanged lines hidden (view full) ---

4098 return (error);
4099
4100 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
4101 return (error);
4102
4103 error = extattr_set_vp((struct vnode *)fp->f_data,
4104 SCARG(uap, attrnamespace), attrname, SCARG(uap, iovp),
4105 SCARG(uap, iovcnt), td);
4106 fdrop(fp, td);
3998
3999 return (error);
4000}
4001
4002/*
4003 * extattr_get_vp(): Get a named extended attribute on a file or directory
4004 *
4005 * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",

--- 97 unchanged lines hidden (view full) ---

4103
4104 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
4105 return (error);
4106
4107 error = extattr_get_vp((struct vnode *)fp->f_data,
4108 SCARG(uap, attrnamespace), attrname, SCARG(uap, iovp),
4109 SCARG(uap, iovcnt), td);
4110
4107
4108 return (error);
4109}
4110
4111/*
4112 * extattr_get_vp(): Get a named extended attribute on a file or directory
4113 *
4114 * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",

--- 97 unchanged lines hidden (view full) ---

4212
4213 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
4214 return (error);
4215
4216 error = extattr_get_vp((struct vnode *)fp->f_data,
4217 SCARG(uap, attrnamespace), attrname, SCARG(uap, iovp),
4218 SCARG(uap, iovcnt), td);
4219
4220 fdrop(fp, td);
4111 return (error);
4112}
4113
4114/*
4115 * extattr_delete_vp(): Delete a named extended attribute on a file or
4116 * directory
4117 *
4118 * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",

--- 49 unchanged lines hidden (view full) ---

4168}
4169
4170int
4171extattr_delete_fd(td, uap)
4172 struct thread *td;
4173 struct extattr_delete_fd_args *uap;
4174{
4175 struct file *fp;
4221 return (error);
4222}
4223
4224/*
4225 * extattr_delete_vp(): Delete a named extended attribute on a file or
4226 * directory
4227 *
4228 * Arguments: unlocked vnode "vp", attribute namespace "attrnamespace",

--- 49 unchanged lines hidden (view full) ---

4278}
4279
4280int
4281extattr_delete_fd(td, uap)
4282 struct thread *td;
4283 struct extattr_delete_fd_args *uap;
4284{
4285 struct file *fp;
4286 struct vnode *vp;
4176 char attrname[EXTATTR_MAXNAMELEN];
4177 int error;
4178
4179 error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN,
4180 NULL);
4181 if (error)
4182 return (error);
4183
4184 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
4185 return (error);
4287 char attrname[EXTATTR_MAXNAMELEN];
4288 int error;
4289
4290 error = copyinstr(SCARG(uap, attrname), attrname, EXTATTR_MAXNAMELEN,
4291 NULL);
4292 if (error)
4293 return (error);
4294
4295 if ((error = getvnode(td->td_proc->p_fd, SCARG(uap, fd), &fp)) != 0)
4296 return (error);
4297 vp = (struct vnode *)fp->f_data;
4186
4187 error = extattr_delete_vp((struct vnode *)fp->f_data,
4188 SCARG(uap, attrnamespace), attrname, td);
4189
4298
4299 error = extattr_delete_vp((struct vnode *)fp->f_data,
4300 SCARG(uap, attrnamespace), attrname, td);
4301
4302 fdrop(fp, td);
4190 return (error);
4191}
4303 return (error);
4304}