vfs_syscalls.c (ef6ea91593ebff73e2fc201efd9f848b71c5a125) vfs_syscalls.c (dd81cc2bc5f25fb2c58bb59bf585deeeae196345)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

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

4309 return (error);
4310 if ((fp->f_flag & FREAD) == 0) {
4311 fdrop(fp, td);
4312 return (EBADF);
4313 }
4314 vp = fp->f_vnode;
4315 foffset = foffset_lock(fp, 0);
4316unionread:
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

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

4309 return (error);
4310 if ((fp->f_flag & FREAD) == 0) {
4311 fdrop(fp, td);
4312 return (EBADF);
4313 }
4314 vp = fp->f_vnode;
4315 foffset = foffset_lock(fp, 0);
4316unionread:
4317 if (vp->v_type != VDIR) {
4318 error = EINVAL;
4319 goto fail;
4320 }
4321 if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) {
4322 error = ENOENT;
4323 goto fail;
4324 }
4325 aiov.iov_base = buf;
4326 aiov.iov_len = count;
4327 auio.uio_iov = &aiov;
4328 auio.uio_iovcnt = 1;
4329 auio.uio_rw = UIO_READ;
4330 auio.uio_segflg = bufseg;
4331 auio.uio_td = td;
4332 vn_lock(vp, LK_SHARED | LK_RETRY);
4317 if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) {
4318 error = ENOENT;
4319 goto fail;
4320 }
4321 aiov.iov_base = buf;
4322 aiov.iov_len = count;
4323 auio.uio_iov = &aiov;
4324 auio.uio_iovcnt = 1;
4325 auio.uio_rw = UIO_READ;
4326 auio.uio_segflg = bufseg;
4327 auio.uio_td = td;
4328 vn_lock(vp, LK_SHARED | LK_RETRY);
4329 /*
4330 * We want to return ENOTDIR for anything that is not VDIR, but
4331 * not for VBAD, and we can't check for VBAD while the vnode is
4332 * unlocked.
4333 */
4334 if (vp->v_type != VDIR) {
4335 if (vp->v_type == VBAD)
4336 error = EBADF;
4337 else
4338 error = ENOTDIR;
4339 VOP_UNLOCK(vp);
4340 goto fail;
4341 }
4333 AUDIT_ARG_VNODE1(vp);
4334 loff = auio.uio_offset = foffset;
4335#ifdef MAC
4336 error = mac_vnode_check_readdir(td->td_ucred, vp);
4337 if (error == 0)
4338#endif
4339 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL,
4340 NULL);

--- 877 unchanged lines hidden ---
4342 AUDIT_ARG_VNODE1(vp);
4343 loff = auio.uio_offset = foffset;
4344#ifdef MAC
4345 error = mac_vnode_check_readdir(td->td_ucred, vp);
4346 if (error == 0)
4347#endif
4348 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL,
4349 NULL);

--- 877 unchanged lines hidden ---