Lines Matching +full:vref +full:- +full:half

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
146 if ((mp->mnt_flag & MNT_RDONLY) == 0 && in kern_sync()
197 AUDIT_ARG_CMD(uap->cmd); in sys_quotactl()
198 AUDIT_ARG_UID(uap->uid); in sys_quotactl()
199 if (!prison_allow(td->td_ucred, PR_ALLOW_QUOTAS)) in sys_quotactl()
202 uap->path); in sys_quotactl()
206 mp = nd.ni_vp->v_mount; in sys_quotactl()
215 error = VFS_QUOTACTL(mp, uap->cmd, uap->uid, uap->arg, &mp_busy); in sys_quotactl()
222 * second is from mount point cross-walk code in lookup()), in sys_quotactl()
237 * that 'max_size' should be a bitmask, i.e. 2^n - 1 for some non-zero
254 if (sf->f_bavail < 0) in statfs_scale_blocks()
255 count = -sf->f_bavail; in statfs_scale_blocks()
257 count = sf->f_bavail; in statfs_scale_blocks()
258 count = MAX(sf->f_blocks, MAX(sf->f_bfree, count)); in statfs_scale_blocks()
269 sf->f_bsize <<= shift; in statfs_scale_blocks()
270 sf->f_blocks >>= shift; in statfs_scale_blocks()
271 sf->f_bfree >>= shift; in statfs_scale_blocks()
272 sf->f_bavail >>= shift; in statfs_scale_blocks()
287 error = mac_mount_check_stat(td->td_ucred, mp); in kern_do_statfs()
294 if (priv_check_cred_vfs_generation(td->td_ucred)) { in kern_do_statfs()
295 buf->f_fsid.val[0] = buf->f_fsid.val[1] = 0; in kern_do_statfs()
296 prison_enforce_statfs(td->td_ucred, mp, buf); in kern_do_statfs()
319 error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp); in sys_statfs()
321 error = copyout(sfp, uap->buf, sizeof(struct statfs)); in sys_statfs()
360 error = kern_fstatfs(td, uap->fd, sfp); in sys_fstatfs()
362 error = copyout(sfp, uap->buf, sizeof(struct statfs)); in sys_fstatfs()
379 vp = fp->f_vnode; in kern_fstatfs()
408 if (uap->bufsize < 0 || uap->bufsize > SIZE_MAX) in sys_getfsstat()
410 error = kern_getfsstat(td, &uap->buf, uap->bufsize, &count, in sys_getfsstat()
411 UIO_USERSPACE, uap->mode); in sys_getfsstat()
413 td->td_retval[0] = count; in sys_getfsstat()
466 * This could be TAILQ_FOREACH but it is open-coded to match the original in kern_getfsstat()
472 if (prison_canseemount(td->td_ucred, mp) != 0) { in kern_getfsstat()
477 if (mac_mount_check_stat(td->td_ucred, mp) != 0) { in kern_getfsstat()
493 * Short-circuit the corner case of no room for anything, avoids in kern_getfsstat()
502 if (prison_canseemount(td->td_ucred, mp) != 0) { in kern_getfsstat()
507 if (mac_mount_check_stat(td->td_ucred, mp) != 0) { in kern_getfsstat()
531 sp = &mp->mnt_stat; in kern_getfsstat()
545 if (priv_check_cred_vfs_generation(td->td_ucred)) { in kern_getfsstat()
549 sptmp->f_fsid.val[0] = sptmp->f_fsid.val[1] = 0; in kern_getfsstat()
550 prison_enforce_statfs(td->td_ucred, mp, sptmp); in kern_getfsstat()
603 error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp); in freebsd4_statfs()
606 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd4_statfs()
629 error = kern_fstatfs(td, uap->fd, sfp); in freebsd4_fstatfs()
632 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd4_fstatfs()
656 if (uap->bufsize < 0) in freebsd4_getfsstat()
658 count = uap->bufsize / sizeof(struct ostatfs); in freebsd4_getfsstat()
663 uap->mode); in freebsd4_getfsstat()
665 td->td_retval[0] = count; in freebsd4_getfsstat()
670 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd4_getfsstat()
672 uap->buf++; in freebsd4_getfsstat()
673 count--; in freebsd4_getfsstat()
697 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t)); in freebsd4_fhstatfs()
704 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd4_fhstatfs()
719 osp->f_bsize = nsp->f_bsize; in freebsd4_cvtstatfs()
720 osp->f_iosize = MIN(nsp->f_iosize, LONG_MAX); in freebsd4_cvtstatfs()
721 osp->f_blocks = nsp->f_blocks; in freebsd4_cvtstatfs()
722 osp->f_bfree = nsp->f_bfree; in freebsd4_cvtstatfs()
723 osp->f_bavail = nsp->f_bavail; in freebsd4_cvtstatfs()
724 osp->f_files = MIN(nsp->f_files, LONG_MAX); in freebsd4_cvtstatfs()
725 osp->f_ffree = MIN(nsp->f_ffree, LONG_MAX); in freebsd4_cvtstatfs()
726 osp->f_owner = nsp->f_owner; in freebsd4_cvtstatfs()
727 osp->f_type = nsp->f_type; in freebsd4_cvtstatfs()
728 osp->f_flags = nsp->f_flags; in freebsd4_cvtstatfs()
729 osp->f_syncwrites = MIN(nsp->f_syncwrites, LONG_MAX); in freebsd4_cvtstatfs()
730 osp->f_asyncwrites = MIN(nsp->f_asyncwrites, LONG_MAX); in freebsd4_cvtstatfs()
731 osp->f_syncreads = MIN(nsp->f_syncreads, LONG_MAX); in freebsd4_cvtstatfs()
732 osp->f_asyncreads = MIN(nsp->f_asyncreads, LONG_MAX); in freebsd4_cvtstatfs()
733 strlcpy(osp->f_fstypename, nsp->f_fstypename, in freebsd4_cvtstatfs()
735 strlcpy(osp->f_mntonname, nsp->f_mntonname, in freebsd4_cvtstatfs()
737 strlcpy(osp->f_mntfromname, nsp->f_mntfromname, in freebsd4_cvtstatfs()
739 osp->f_fsid = nsp->f_fsid; in freebsd4_cvtstatfs()
757 error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp); in freebsd11_statfs()
760 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd11_statfs()
777 error = kern_fstatfs(td, uap->fd, sfp); in freebsd11_fstatfs()
780 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd11_fstatfs()
792 return (kern_freebsd11_getfsstat(td, uap->buf, uap->bufsize, uap->mode)); in freebsd11_getfsstat()
811 td->td_retval[0] = count; in kern_freebsd11_getfsstat()
819 count--; in kern_freebsd11_getfsstat()
837 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t)); in freebsd11_fhstatfs()
844 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd11_fhstatfs()
858 osp->f_version = FREEBSD11_STATFS_VERSION; in freebsd11_cvtstatfs()
859 osp->f_type = nsp->f_type; in freebsd11_cvtstatfs()
860 osp->f_flags = nsp->f_flags; in freebsd11_cvtstatfs()
861 osp->f_bsize = nsp->f_bsize; in freebsd11_cvtstatfs()
862 osp->f_iosize = nsp->f_iosize; in freebsd11_cvtstatfs()
863 osp->f_blocks = nsp->f_blocks; in freebsd11_cvtstatfs()
864 osp->f_bfree = nsp->f_bfree; in freebsd11_cvtstatfs()
865 osp->f_bavail = nsp->f_bavail; in freebsd11_cvtstatfs()
866 osp->f_files = nsp->f_files; in freebsd11_cvtstatfs()
867 osp->f_ffree = nsp->f_ffree; in freebsd11_cvtstatfs()
868 osp->f_syncwrites = nsp->f_syncwrites; in freebsd11_cvtstatfs()
869 osp->f_asyncwrites = nsp->f_asyncwrites; in freebsd11_cvtstatfs()
870 osp->f_syncreads = nsp->f_syncreads; in freebsd11_cvtstatfs()
871 osp->f_asyncreads = nsp->f_asyncreads; in freebsd11_cvtstatfs()
872 osp->f_namemax = nsp->f_namemax; in freebsd11_cvtstatfs()
873 osp->f_owner = nsp->f_owner; in freebsd11_cvtstatfs()
874 osp->f_fsid = nsp->f_fsid; in freebsd11_cvtstatfs()
875 strlcpy(osp->f_fstypename, nsp->f_fstypename, in freebsd11_cvtstatfs()
876 MIN(MFSNAMELEN, sizeof(osp->f_fstypename))); in freebsd11_cvtstatfs()
877 strlcpy(osp->f_mntonname, nsp->f_mntonname, in freebsd11_cvtstatfs()
878 MIN(MNAMELEN, sizeof(osp->f_mntonname))); in freebsd11_cvtstatfs()
879 strlcpy(osp->f_mntfromname, nsp->f_mntfromname, in freebsd11_cvtstatfs()
880 MIN(MNAMELEN, sizeof(osp->f_mntfromname))); in freebsd11_cvtstatfs()
900 AUDIT_ARG_FD(uap->fd); in sys_fchdir()
901 error = getvnode_path(td, uap->fd, &cap_fchdir_rights, in sys_fchdir()
905 vp = fp->f_vnode; in sys_fchdir()
911 while (!error && (mp = vp->v_mountedhere) != NULL) { in sys_fchdir()
942 return (kern_chdir(td, uap->path, UIO_USERSPACE)); in sys_chdir()
987 p = td->td_proc; in sys_chroot()
990 (p->p_flag2 & P2_NO_NEW_PRIVS) == 0) { in sys_chroot()
997 UIO_USERSPACE, uap->path); in sys_chroot()
1006 error = mac_vnode_check_chroot(td->td_ucred, nd.ni_vp); in sys_chroot()
1031 if (vp->v_type != VDIR) in change_dir()
1034 error = mac_vnode_check_chdir(td->td_ucred, vp); in change_dir()
1038 return (VOP_ACCESS(vp, VEXEC, td->td_ucred, td)); in change_dir()
1092 return (kern_openat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_open()
1093 uap->flags, uap->mode)); in sys_open()
1108 AUDIT_ARG_FD(uap->fd); in sys_openat()
1109 return (kern_openat(td, uap->fd, uap->path, UIO_USERSPACE, uap->flag, in sys_openat()
1110 uap->mode)); in sys_openat()
1132 indx = -1; in openatfp()
1133 p = td->td_proc; in openatfp()
1134 fdp = p->p_fd; in openatfp()
1135 pdp = p->p_pd; in openatfp()
1166 fp->f_flag = flags & FMASK; in openatfp()
1167 cmode = ((mode & ~pdp->pd_cmask) & ALLPERMS) & ~S_ISTXT; in openatfp()
1170 td->td_dupfd = -1; /* XXX check for fdopen */ in openatfp()
1172 td->td_ucred, fp); in openatfp()
1179 if (error == ENXIO && fp->f_ops != &badfileops) { in openatfp()
1193 td->td_dupfd >= 0) { in openatfp()
1195 error = dupfdopen(td, fdp, td->td_dupfd, flags, error, in openatfp()
1203 td->td_dupfd = 0; in openatfp()
1212 fp->f_vnode = vp; in openatfp()
1218 if (fp->f_ops == &badfileops) { in openatfp()
1219 KASSERT(vp->v_type != VFIFO || (flags & O_PATH) != 0, in openatfp()
1222 finit(fp, (flags & FMASK) | (fp->f_flag & FKQALLOWED), in openatfp()
1231 error = fo_truncate(fp, 0, td->td_ucred, td); in openatfp()
1246 if (indx == -1) { in openatfp()
1263 td->td_retval[0] = indx; in openatfp()
1266 KASSERT(indx == -1, ("indx=%d, should be -1", indx)); in openatfp()
1285 old_dupfd = td->td_dupfd; in kern_openatfp()
1286 td->td_dupfd = -1; in kern_openatfp()
1288 td->td_dupfd = old_dupfd; in kern_openatfp()
1306 return (kern_openat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in ocreat()
1307 O_WRONLY | O_CREAT | O_TRUNC, uap->mode)); in ocreat()
1326 return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode, in sys_mknodat()
1327 uap->dev)); in sys_mknodat()
1336 return (kern_mknodat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in freebsd11_mknod()
1337 uap->mode, uap->dev)); in freebsd11_mknod()
1345 return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode, in freebsd11_mknodat()
1346 uap->dev)); in freebsd11_mknodat()
1401 ~td->td_proc->p_pd->pd_cmask; in kern_mknodat()
1428 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, in kern_mknodat()
1461 return (kern_mkfifoat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_mkfifo()
1462 uap->mode)); in sys_mkfifo()
1476 return (kern_mkfifoat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_mkfifoat()
1477 uap->mode)); in sys_mkfifoat()
1515 vattr.va_mode = (mode & ALLPERMS) & ~td->td_proc->p_pd->pd_cmask; in kern_mkfifoat()
1517 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, in kern_mkfifoat()
1547 return (kern_linkat(td, AT_FDCWD, AT_FDCWD, uap->path, uap->link, in sys_link()
1564 return (kern_linkat(td, uap->fd1, uap->fd2, uap->path1, uap->path2, in sys_linkat()
1565 UIO_USERSPACE, uap->flag)); in sys_linkat()
1592 if (hardlink_check_uid && cred->cr_uid != va.va_uid) { in can_hardlink()
1647 if (vp->v_type == VDIR) { in kern_linkat_vp()
1664 } else if (nd.ni_dvp->v_mount != vp->v_mount) { in kern_linkat_vp()
1666 * Cross-device link. No need to recheck in kern_linkat_vp()
1667 * vp->v_type, since it cannot change, except in kern_linkat_vp()
1675 error = can_hardlink(vp, td->td_ucred); in kern_linkat_vp()
1678 error = mac_vnode_check_link(td->td_ucred, in kern_linkat_vp()
1728 return (kern_symlinkat(td, uap->path, AT_FDCWD, uap->link, in sys_symlink()
1743 return (kern_symlinkat(td, uap->path1, uap->fd, uap->path2, in sys_symlinkat()
1793 vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_pd->pd_cmask; in kern_symlinkat()
1796 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, in kern_symlinkat()
1835 UIO_USERSPACE, uap->path); in sys_undelete()
1878 return (kern_funlinkat(td, AT_FDCWD, uap->path, FD_NONE, UIO_USERSPACE, in sys_unlink()
1907 return (kern_funlinkat_ex(td, uap->fd, uap->path, FD_NONE, uap->flag, in sys_unlinkat()
1923 return (kern_funlinkat_ex(td, uap->dfd, uap->path, uap->fd, uap->flag, in sys_funlinkat()
1957 if (vp->v_type == VDIR && oldinum == 0) { in kern_funlinkat()
1960 ((error = VOP_STAT(vp, &sb, td->td_ucred, NOCRED)) == 0) && in kern_funlinkat()
1963 } else if (fp != NULL && fp->f_vnode != vp) { in kern_funlinkat()
1964 if (VN_IS_DOOMED(fp->f_vnode)) in kern_funlinkat()
1974 if (vp->v_vflag & VV_ROOT) in kern_funlinkat()
1992 error = mac_vnode_check_unlink(td->td_ucred, nd.ni_dvp, vp, in kern_funlinkat()
2033 return (kern_lseek(td, uap->fd, uap->offset, uap->whence)); in sys_lseek()
2046 error = (fp->f_ops->fo_flags & DFLAG_SEEKABLE) != 0 ? in kern_lseek()
2067 return (kern_lseek(td, uap->fd, uap->offset, uap->whence)); in olseek()
2077 return (kern_lseek(td, uap->fd, uap->offset, uap->whence)); in freebsd6_lseek()
2125 return (kern_accessat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_access()
2126 0, uap->amode)); in sys_access()
2141 return (kern_accessat(td, uap->fd, uap->path, UIO_USERSPACE, uap->flag, in sys_faccessat()
2142 uap->amode)); in sys_faccessat()
2164 cred = td->td_ucred; in kern_accessat()
2166 ((cred->cr_uid != cred->cr_ruid || in kern_accessat()
2167 cred->cr_rgid != cred->cr_groups[0]))) { in kern_accessat()
2169 usecred->cr_uid = cred->cr_ruid; in kern_accessat()
2170 usecred->cr_groups[0] = cred->cr_rgid; in kern_accessat()
2171 td->td_ucred = usecred; in kern_accessat()
2187 td->td_ucred = cred; in kern_accessat()
2206 return (kern_accessat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_eaccess()
2207 AT_EACCESS, uap->amode)); in sys_eaccess()
2227 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb); in ostat()
2231 return (copyout(&osb, uap->ub, sizeof (osb))); in ostat()
2250 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path, in olstat()
2255 return (copyout(&osb, uap->ub, sizeof (osb))); in olstat()
2267 ost->st_dev = st->st_dev; in cvtstat()
2268 ost->st_ino = st->st_ino; in cvtstat()
2269 ost->st_mode = st->st_mode; in cvtstat()
2270 ost->st_nlink = st->st_nlink; in cvtstat()
2271 ost->st_uid = st->st_uid; in cvtstat()
2272 ost->st_gid = st->st_gid; in cvtstat()
2273 ost->st_rdev = st->st_rdev; in cvtstat()
2274 ost->st_size = MIN(st->st_size, INT32_MAX); in cvtstat()
2275 ost->st_atim = st->st_atim; in cvtstat()
2276 ost->st_mtim = st->st_mtim; in cvtstat()
2277 ost->st_ctim = st->st_ctim; in cvtstat()
2278 ost->st_blksize = st->st_blksize; in cvtstat()
2279 ost->st_blocks = st->st_blocks; in cvtstat()
2280 ost->st_flags = st->st_flags; in cvtstat()
2281 ost->st_gen = st->st_gen; in cvtstat()
2295 ost->st_dev = st->st_dev; in freebsd11_cvtstat()
2296 if (ost->st_dev != st->st_dev) { in freebsd11_cvtstat()
2308 ost->st_ino = st->st_ino; in freebsd11_cvtstat()
2309 if (ost->st_ino != st->st_ino) { in freebsd11_cvtstat()
2317 ost->st_ino = UINT32_MAX; in freebsd11_cvtstat()
2321 ost->st_mode = st->st_mode; in freebsd11_cvtstat()
2322 ost->st_nlink = st->st_nlink; in freebsd11_cvtstat()
2323 if (ost->st_nlink != st->st_nlink) { in freebsd11_cvtstat()
2331 ost->st_nlink = UINT16_MAX; in freebsd11_cvtstat()
2335 ost->st_uid = st->st_uid; in freebsd11_cvtstat()
2336 ost->st_gid = st->st_gid; in freebsd11_cvtstat()
2337 ost->st_rdev = st->st_rdev; in freebsd11_cvtstat()
2338 if (ost->st_rdev != st->st_rdev) { in freebsd11_cvtstat()
2346 ost->st_atim = st->st_atim; in freebsd11_cvtstat()
2347 ost->st_mtim = st->st_mtim; in freebsd11_cvtstat()
2348 ost->st_ctim = st->st_ctim; in freebsd11_cvtstat()
2349 ost->st_size = st->st_size; in freebsd11_cvtstat()
2350 ost->st_blocks = st->st_blocks; in freebsd11_cvtstat()
2351 ost->st_blksize = st->st_blksize; in freebsd11_cvtstat()
2352 ost->st_flags = st->st_flags; in freebsd11_cvtstat()
2353 ost->st_gen = st->st_gen; in freebsd11_cvtstat()
2354 ost->st_lspare = 0; in freebsd11_cvtstat()
2355 ost->st_birthtim = st->st_birthtim; in freebsd11_cvtstat()
2356 bzero((char *)&ost->st_birthtim + sizeof(ost->st_birthtim), in freebsd11_cvtstat()
2357 sizeof(*ost) - offsetof(struct freebsd11_stat, in freebsd11_cvtstat()
2358 st_birthtim) - sizeof(ost->st_birthtim)); in freebsd11_cvtstat()
2369 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb); in freebsd11_stat()
2374 error = copyout(&osb, uap->ub, sizeof(osb)); in freebsd11_stat()
2385 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path, in freebsd11_lstat()
2391 error = copyout(&osb, uap->ub, sizeof(osb)); in freebsd11_lstat()
2403 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t)); in freebsd11_fhstat()
2411 error = copyout(&osb, uap->sb, sizeof(osb)); in freebsd11_fhstat()
2422 error = kern_statat(td, uap->flag, uap->fd, uap->path, in freebsd11_fstatat()
2428 error = copyout(&osb, uap->buf, sizeof(osb)); in freebsd11_fstatat()
2450 error = kern_statat(td, uap->flag, uap->fd, uap->path, in sys_fstatat()
2453 error = copyout(&sb, uap->buf, sizeof (sb)); in sys_fstatat()
2478 error = VOP_STAT(nd.ni_vp, sbp, td->td_ucred, NOCRED); in kern_statat()
2482 sbp->st_atim_ext = 0; in kern_statat()
2483 sbp->st_mtim_ext = 0; in kern_statat()
2484 sbp->st_ctim_ext = 0; in kern_statat()
2485 sbp->st_btim_ext = 0; in kern_statat()
2541 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb); in freebsd11_nstat()
2546 error = copyout(&nsb, uap->ub, sizeof (nsb)); in freebsd11_nstat()
2566 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path, in freebsd11_nlstat()
2572 error = copyout(&nsb, uap->ub, sizeof (nsb)); in freebsd11_nlstat()
2592 error = kern_pathconf(td, uap->path, UIO_USERSPACE, uap->name, FOLLOW, in sys_pathconf()
2595 td->td_retval[0] = value; in sys_pathconf()
2611 error = kern_pathconf(td, uap->path, UIO_USERSPACE, uap->name, in sys_lpathconf()
2614 td->td_retval[0] = value; in sys_lpathconf()
2650 return (kern_readlinkat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_readlink()
2651 uap->buf, UIO_USERSPACE, uap->count)); in sys_readlink()
2665 return (kern_readlinkat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_readlinkat()
2666 uap->buf, UIO_USERSPACE, uap->bufsize)); in sys_readlinkat()
2707 error = mac_vnode_check_readlink(td->td_ucred, vp); in kern_readlink_vp()
2711 if (vp->v_type != VLNK && (vp->v_vflag & VV_READLINK) == 0) in kern_readlink_vp()
2723 error = VOP_READLINK(vp, &auio, td->td_ucred); in kern_readlink_vp()
2724 td->td_retval[0] = count - auio.uio_resid; in kern_readlink_vp()
2743 * Prevent non-root users from setting flags on devices. When in setfflags()
2748 if (vp->v_type == VCHR || vp->v_type == VBLK) { in setfflags()
2760 error = mac_vnode_check_setflags(td->td_ucred, vp, vattr.va_flags); in setfflags()
2763 error = VOP_SETATTR(vp, &vattr, td->td_ucred); in setfflags()
2782 return (kern_chflagsat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_chflags()
2783 uap->flags, 0)); in sys_chflags()
2798 return (kern_chflagsat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_chflagsat()
2799 uap->flags, uap->atflag)); in sys_chflagsat()
2815 return (kern_chflagsat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_lchflags()
2816 uap->flags, AT_SYMLINK_NOFOLLOW)); in sys_lchflags()
2857 AUDIT_ARG_FD(uap->fd); in sys_fchflags()
2858 AUDIT_ARG_FFLAGS(uap->flags); in sys_fchflags()
2859 error = getvnode(td, uap->fd, &cap_fchflags_rights, in sys_fchflags()
2865 vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); in sys_fchflags()
2866 AUDIT_ARG_VNODE1(fp->f_vnode); in sys_fchflags()
2867 VOP_UNLOCK(fp->f_vnode); in sys_fchflags()
2870 error = setfflags(td, fp->f_vnode, uap->flags); in sys_fchflags()
2913 return (kern_fchmodat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_chmod()
2914 uap->mode, 0)); in sys_chmod()
2929 return (kern_fchmodat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_fchmodat()
2930 uap->mode, uap->flag)); in sys_fchmodat()
2946 return (kern_fchmodat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_lchmod()
2947 uap->mode, AT_SYMLINK_NOFOLLOW)); in sys_lchmod()
2968 error = setfmode(td, td->td_ucred, nd.ni_vp, mode); in kern_fchmodat()
2988 AUDIT_ARG_FD(uap->fd); in sys_fchmod()
2989 AUDIT_ARG_MODE(uap->mode); in sys_fchmod()
2991 error = fget(td, uap->fd, &cap_fchmod_rights, &fp); in sys_fchmod()
2994 error = fo_chmod(fp, uap->mode, td->td_ucred, td); in sys_fchmod()
3041 return (kern_fchownat(td, AT_FDCWD, uap->path, UIO_USERSPACE, uap->uid, in sys_chown()
3042 uap->gid, 0)); in sys_chown()
3058 return (kern_fchownat(td, uap->fd, uap->path, UIO_USERSPACE, uap->uid, in sys_fchownat()
3059 uap->gid, uap->flag)); in sys_fchownat()
3081 error = setfown(td, td->td_ucred, nd.ni_vp, uid, gid); in kern_fchownat()
3100 return (kern_fchownat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_lchown()
3101 uap->uid, uap->gid, AT_SYMLINK_NOFOLLOW)); in sys_lchown()
3120 AUDIT_ARG_FD(uap->fd); in sys_fchown()
3121 AUDIT_ARG_OWNER(uap->uid, uap->gid); in sys_fchown()
3122 error = fget(td, uap->fd, &cap_fchown_rights, &fp); in sys_fchown()
3125 error = fo_chown(fp, uap->uid, uap->gid, td->td_ucred, td); in sys_fchown()
3227 if (numtimes < 3 && VOP_GETATTR(vp, &vattr, td->td_ucred) == 0 && in setutimes()
3240 error = mac_vnode_check_setutimes(td->td_ucred, vp, vattr.va_atime, in setutimes()
3244 error = VOP_SETATTR(vp, &vattr, td->td_ucred); in setutimes()
3263 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_utimes()
3264 uap->tptr, UIO_USERSPACE)); in sys_utimes()
3278 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_futimesat()
3279 uap->times, UIO_USERSPACE)); in sys_futimesat()
3316 return (kern_lutimes(td, uap->path, UIO_USERSPACE, uap->tptr, in sys_lutimes()
3352 return (kern_futimes(td, uap->fd, uap->tptr, UIO_USERSPACE)); in sys_futimes()
3372 vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); in kern_futimes()
3373 AUDIT_ARG_VNODE1(fp->f_vnode); in kern_futimes()
3374 VOP_UNLOCK(fp->f_vnode); in kern_futimes()
3377 error = setutimes(td, fp->f_vnode, ts, 2, tptr == NULL); in kern_futimes()
3386 return (kern_futimens(td, uap->fd, uap->times, UIO_USERSPACE)); in sys_futimens()
3408 vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); in kern_futimens()
3409 AUDIT_ARG_VNODE1(fp->f_vnode); in kern_futimens()
3410 VOP_UNLOCK(fp->f_vnode); in kern_futimens()
3413 error = setutimes(td, fp->f_vnode, ts, 2, flags & UTIMENS_NULL); in kern_futimens()
3422 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE, in sys_utimensat()
3423 uap->times, UIO_USERSPACE, uap->flag)); in sys_utimensat()
3473 return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length)); in sys_truncate()
3502 if (vp->v_type == VDIR) { in kern_truncate()
3507 error = mac_vnode_check_write(td->td_ucred, NOCRED, vp); in kern_truncate()
3511 error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td); in kern_truncate()
3515 error = vn_truncate_locked(vp, length, false, td->td_ucred); in kern_truncate()
3540 return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length)); in otruncate()
3550 return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length)); in freebsd6_truncate()
3557 return (kern_ftruncate(td, uap->fd, uap->length)); in freebsd6_ftruncate()
3573 vp = fp->f_vnode; in kern_fsync()
3607 return (kern_fsync(td, uap->fd, true)); in sys_fsync()
3614 return (kern_fsync(td, uap->fd, false)); in sys_fdatasync()
3631 return (kern_renameat(td, AT_FDCWD, uap->from, AT_FDCWD, in sys_rename()
3632 uap->to, UIO_USERSPACE)); in sys_rename()
3647 return (kern_renameat(td, uap->oldfd, uap->old, uap->newfd, uap->new, in sys_renameat()
3662 error = mac_vnode_check_rename_from(td->td_ucred, fromnd->ni_dvp, in kern_renameat_mac()
3663 fromnd->ni_vp, &fromnd->ni_cnd); in kern_renameat_mac()
3664 VOP_UNLOCK(fromnd->ni_dvp); in kern_renameat_mac()
3665 if (fromnd->ni_dvp != fromnd->ni_vp) in kern_renameat_mac()
3666 VOP_UNLOCK(fromnd->ni_vp); in kern_renameat_mac()
3669 vrele(fromnd->ni_dvp); in kern_renameat_mac()
3670 vrele(fromnd->ni_vp); in kern_renameat_mac()
3705 if (fromnd.ni_vp->v_type == VDIR) in kern_renameat()
3711 if (error == EISDIR && fvp->v_type == VDIR) in kern_renameat()
3738 if (fvp->v_type == VDIR && tvp->v_type != VDIR) { in kern_renameat()
3741 } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) { in kern_renameat()
3770 error = mac_vnode_check_rename_to(td->td_ucred, tdvp, in kern_renameat()
3813 return (kern_mkdirat(td, AT_FDCWD, uap->path, UIO_USERSPACE, in sys_mkdir()
3814 uap->mode)); in sys_mkdir()
3828 return (kern_mkdirat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode)); in sys_mkdirat()
3858 vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_pd->pd_cmask; in kern_mkdirat()
3860 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, in kern_mkdirat()
3889 return (kern_frmdirat(td, AT_FDCWD, uap->path, FD_NONE, UIO_USERSPACE, in sys_rmdir()
3921 if (vp->v_type != VDIR) { in kern_frmdirat()
3935 if (vp->v_vflag & VV_ROOT) { in kern_frmdirat()
3940 if (fp != NULL && fp->f_vnode != vp) { in kern_frmdirat()
3941 if (VN_IS_DOOMED(fp->f_vnode)) in kern_frmdirat()
3949 error = mac_vnode_check_unlink(td->td_ucred, nd.ni_dvp, vp, in kern_frmdirat()
4009 edp = (struct dirent *)&dirbuf[count - resid]; in freebsd11_kern_getdirentries()
4011 if (dp->d_reclen == 0) in freebsd11_kern_getdirentries()
4013 MPASS(dp->d_reclen >= _GENERIC_DIRLEN(0)); in freebsd11_kern_getdirentries()
4014 if (dp->d_namlen >= sizeof(dstdp.d_name)) in freebsd11_kern_getdirentries()
4016 dstdp.d_type = dp->d_type; in freebsd11_kern_getdirentries()
4017 dstdp.d_namlen = dp->d_namlen; in freebsd11_kern_getdirentries()
4018 dstdp.d_fileno = dp->d_fileno; /* truncate */ in freebsd11_kern_getdirentries()
4019 if (dstdp.d_fileno != dp->d_fileno) { in freebsd11_kern_getdirentries()
4032 dstdp.d_reclen = sizeof(dstdp) - sizeof(dstdp.d_name) + in freebsd11_kern_getdirentries()
4033 ((dp->d_namlen + 1 + 3) &~ 3); in freebsd11_kern_getdirentries()
4034 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen); in freebsd11_kern_getdirentries()
4036 dstdp.d_reclen - offsetof(struct freebsd11_dirent, d_name) - in freebsd11_kern_getdirentries()
4038 MPASS(dstdp.d_reclen <= dp->d_reclen); in freebsd11_kern_getdirentries()
4045 dp = (struct dirent *)((char *)dp + dp->d_reclen); in freebsd11_kern_getdirentries()
4052 td->td_retval[0] = ucount; in freebsd11_kern_getdirentries()
4063 * The expected low byte of dp->d_namlen is our dp->d_type. in ogetdirentries_cvt()
4064 * The high MBZ byte of dp->d_namlen is our dp->d_namlen. in ogetdirentries_cvt()
4066 dp->d_type = dp->d_namlen; in ogetdirentries_cvt()
4067 dp->d_namlen = 0; in ogetdirentries_cvt()
4070 * The dp->d_type is the high byte of the expected dp->d_namlen, in ogetdirentries_cvt()
4073 dp->d_type = 0; in ogetdirentries_cvt()
4096 error = copyout(&loff, uap->basep, sizeof(long)); in ogetdirentries()
4108 if (uap->count > 64 * 1024) in kern_ogetdirentries()
4111 error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count, in kern_ogetdirentries()
4114 if (error == 0 && uap->basep != NULL) in kern_ogetdirentries()
4115 error = copyout(&base, uap->basep, sizeof(long)); in kern_ogetdirentries()
4137 error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count, in freebsd11_getdirentries()
4140 if (error == 0 && uap->basep != NULL) in freebsd11_getdirentries()
4141 error = copyout(&base, uap->basep, sizeof(long)); in freebsd11_getdirentries()
4150 ap.fd = uap->fd; in freebsd11_getdents()
4151 ap.buf = uap->buf; in freebsd11_getdents()
4152 ap.count = uap->count; in freebsd11_getdents()
4167 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base, in sys_getdirentries()
4171 if (uap->basep != NULL) in sys_getdirentries()
4172 error = copyout(&base, uap->basep, sizeof(off_t)); in sys_getdirentries()
4195 if ((fp->f_flag & FREAD) == 0) { in kern_getdirentries()
4199 vp = fp->f_vnode; in kern_getdirentries()
4202 if (vp->v_type != VDIR) { in kern_getdirentries()
4206 if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) { in kern_getdirentries()
4221 error = mac_vnode_check_readdir(td->td_ucred, vp); in kern_getdirentries()
4224 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL, in kern_getdirentries()
4232 (vp->v_vflag & VV_ROOT) && in kern_getdirentries()
4233 (vp->v_mount->mnt_flag & MNT_UNION)) { in kern_getdirentries()
4236 vp = vp->v_mount->mnt_vnodecovered; in kern_getdirentries()
4237 VREF(vp); in kern_getdirentries()
4238 fp->f_vnode = vp; in kern_getdirentries()
4247 td->td_retval[0] = count - auio.uio_resid; in kern_getdirentries()
4267 pdp = td->td_proc->p_pd; in sys_umask()
4269 td->td_retval[0] = pdp->pd_cmask; in sys_umask()
4270 pdp->pd_cmask = uap->newmask & ALLPERMS; in sys_umask()
4293 uap->path); in sys_revoke()
4298 if (vp->v_type != VCHR || vp->v_rdev == NULL) { in sys_revoke()
4303 error = mac_vnode_check_revoke(td->td_ucred, vp); in sys_revoke()
4307 error = VOP_GETATTR(vp, &vattr, td->td_ucred); in sys_revoke()
4310 if (td->td_ucred->cr_uid != vattr.va_uid) { in sys_revoke()
4346 * half-baked file into the process descriptor table, allowing in getvnode_path()
4350 if (__predict_false(fp->f_vnode == NULL || fp->f_ops == &badfileops)) { in getvnode_path()
4378 if (__predict_false((*fpp)->f_ops == &path_fileops)) { in getvnode()
4400 return (kern_getfhat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->fname, in sys_lgetfh()
4401 UIO_USERSPACE, uap->fhp, UIO_USERSPACE)); in sys_lgetfh()
4414 return (kern_getfhat(td, 0, AT_FDCWD, uap->fname, UIO_USERSPACE, in sys_getfh()
4415 uap->fhp, UIO_USERSPACE)); in sys_getfh()
4437 return (kern_getfhat(td, uap->flags, uap->fd, uap->path, UIO_USERSPACE, in sys_getfhat()
4438 uap->fhp, UIO_USERSPACE)); in sys_getfhat()
4464 fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; in kern_getfhat()
4486 return (kern_fhlinkat(td, AT_FDCWD, uap->to, UIO_USERSPACE, uap->fhp)); in sys_fhlink()
4500 return (kern_fhlinkat(td, uap->tofd, uap->to, UIO_USERSPACE, uap->fhp)); in sys_fhlinkat()
4550 if (uap->bufsize > IOSIZE_MAX) in sys_fhreadlink()
4552 error = copyin(uap->fhp, &fh, sizeof(fh)); in sys_fhreadlink()
4561 error = kern_readlink_vp(vp, uap->buf, UIO_USERSPACE, uap->bufsize, td); in sys_fhreadlink()
4582 return (kern_fhopen(td, uap->u_fhp, uap->flags)); in sys_fhopen()
4598 indx = -1; in kern_fhopen()
4600 /* why not allow a non-read/write open for our lockd? */ in kern_fhopen()
4627 td->td_dupfd = -1; in kern_fhopen()
4629 error = vn_open_vnode(vp, fmode, td->td_ucred, td, fp); in kern_fhopen()
4631 KASSERT(fp->f_ops == &badfileops, in kern_fhopen()
4633 KASSERT(td->td_dupfd < 0, in kern_fhopen()
4640 td->td_dupfd = 0; in kern_fhopen()
4642 fp->f_vnode = vp; in kern_fhopen()
4646 error = fo_truncate(fp, 0, td->td_ucred, td); in kern_fhopen()
4654 td->td_retval[0] = indx; in kern_fhopen()
4674 error = copyin(uap->u_fhp, &fh, sizeof(fh)); in sys_fhstat()
4679 error = copyout(&sb, uap->sb, sizeof(sb)); in sys_fhstat()
4699 error = VOP_STAT(vp, sb, td->td_ucred, NOCRED); in kern_fhstat()
4720 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t)); in sys_fhstatfs()
4726 error = copyout(sfp, uap->buf, sizeof(*sfp)); in sys_fhstatfs()
4749 error = prison_canseemount(td->td_ucred, mp); in kern_fhstatfs()
4753 error = mac_mount_check_stat(td->td_ucred, mp); in kern_fhstatfs()
4779 if (offset < 0 || len < 0 || offset > OFF_MAX - len) in kern_posix_fadvise()
4801 AUDIT_ARG_FILE(td->td_proc, fp); in kern_posix_fadvise()
4802 if ((fp->f_ops->fo_flags & DFLAG_SEEKABLE) == 0) { in kern_posix_fadvise()
4806 if (fp->f_type != DTYPE_VNODE) { in kern_posix_fadvise()
4810 vp = fp->f_vnode; in kern_posix_fadvise()
4811 if (vp->v_type != VREG) { in kern_posix_fadvise()
4818 end = offset + len - 1; in kern_posix_fadvise()
4824 * Try to merge any existing non-standard region with in kern_posix_fadvise()
4826 * non-standard region for this request. in kern_posix_fadvise()
4829 fa = fp->f_advice; in kern_posix_fadvise()
4830 if (fa != NULL && fa->fa_advice == advice && in kern_posix_fadvise()
4831 ((fa->fa_start <= end && fa->fa_end >= offset) || in kern_posix_fadvise()
4832 (end != OFF_MAX && fa->fa_start == end + 1) || in kern_posix_fadvise()
4833 (fa->fa_end != OFF_MAX && fa->fa_end + 1 == offset))) { in kern_posix_fadvise()
4834 if (offset < fa->fa_start) in kern_posix_fadvise()
4835 fa->fa_start = offset; in kern_posix_fadvise()
4836 if (end > fa->fa_end) in kern_posix_fadvise()
4837 fa->fa_end = end; in kern_posix_fadvise()
4839 new->fa_advice = advice; in kern_posix_fadvise()
4840 new->fa_start = offset; in kern_posix_fadvise()
4841 new->fa_end = end; in kern_posix_fadvise()
4842 fp->f_advice = new; in kern_posix_fadvise()
4850 * non-standard region, trim or remove the in kern_posix_fadvise()
4851 * non-standard region. in kern_posix_fadvise()
4854 fa = fp->f_advice; in kern_posix_fadvise()
4856 if (offset <= fa->fa_start && end >= fa->fa_end) { in kern_posix_fadvise()
4858 fp->f_advice = NULL; in kern_posix_fadvise()
4859 } else if (offset <= fa->fa_start && in kern_posix_fadvise()
4860 end >= fa->fa_start) in kern_posix_fadvise()
4861 fa->fa_start = end + 1; in kern_posix_fadvise()
4862 else if (offset <= fa->fa_end && end >= fa->fa_end) in kern_posix_fadvise()
4863 fa->fa_end = offset - 1; in kern_posix_fadvise()
4864 else if (offset >= fa->fa_start && end <= fa->fa_end) { in kern_posix_fadvise()
4868 * non-standard region, just remove in kern_posix_fadvise()
4874 fp->f_advice = NULL; in kern_posix_fadvise()
4896 error = kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, in sys_posix_fadvise()
4897 uap->advice); in sys_posix_fadvise()
4914 savinoff = -1; in kern_copy_file_range()
4935 if (infp->f_ops == &badfileops) { in kern_copy_file_range()
4939 if (infp->f_vnode == NULL) { in kern_copy_file_range()
4947 if (outfp->f_ops == &badfileops) { in kern_copy_file_range()
4951 if (outfp->f_vnode == NULL) { in kern_copy_file_range()
4958 inoffp = &infp->f_offset; in kern_copy_file_range()
4960 outoffp = &outfp->f_offset; in kern_copy_file_range()
4964 invp = infp->f_vnode; in kern_copy_file_range()
4965 outvp = outfp->f_vnode; in kern_copy_file_range()
4967 if ((outfp->f_flag & (FWRITE | FAPPEND)) != FWRITE || in kern_copy_file_range()
4968 (infp->f_flag & FREAD) == 0) { in kern_copy_file_range()
4987 rangelock_may_recurse(&invp->v_rl); in kern_copy_file_range()
5005 flags, infp->f_cred, outfp->f_cred, td); in kern_copy_file_range()
5011 if (savinoff != -1 && (error == EINTR || error == ERESTART)) { in kern_copy_file_range()
5019 td->td_retval[0] = retlen; in kern_copy_file_range()
5030 if (uap->inoffp != NULL) { in sys_copy_file_range()
5031 error = copyin(uap->inoffp, &inoff, sizeof(off_t)); in sys_copy_file_range()
5036 if (uap->outoffp != NULL) { in sys_copy_file_range()
5037 error = copyin(uap->outoffp, &outoff, sizeof(off_t)); in sys_copy_file_range()
5042 error = kern_copy_file_range(td, uap->infd, inoffp, uap->outfd, in sys_copy_file_range()
5043 outoffp, uap->len, uap->flags); in sys_copy_file_range()
5044 if (error == 0 && uap->inoffp != NULL) in sys_copy_file_range()
5045 error = copyout(inoffp, uap->inoffp, sizeof(off_t)); in sys_copy_file_range()
5046 if (error == 0 && uap->outoffp != NULL) in sys_copy_file_range()
5047 error = copyout(outoffp, uap->outoffp, sizeof(off_t)); in sys_copy_file_range()