Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/vfs_syscalls.c
Show First 20 Lines • Show All 1,094 Lines • ▼ Show 20 Lines | return (kern_openat(td, uap->fd, uap->path, UIO_USERSPACE, uap->flag, | ||||
uap->mode)); | uap->mode)); | ||||
} | } | ||||
int | int | ||||
kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg, | kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg, | ||||
int flags, int mode) | int flags, int mode) | ||||
{ | { | ||||
struct proc *p = td->td_proc; | struct proc *p = td->td_proc; | ||||
struct filedesc *fdp = p->p_fd; | struct filedesc *fdp; | ||||
struct pathsdesc *pdp; | |||||
struct file *fp; | struct file *fp; | ||||
struct vnode *vp; | struct vnode *vp; | ||||
struct nameidata nd; | struct nameidata nd; | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
int cmode, error, indx; | int cmode, error, indx; | ||||
indx = -1; | indx = -1; | ||||
fdp = p->p_fd; | |||||
pdp = p->p_pd; | |||||
AUDIT_ARG_FFLAGS(flags); | AUDIT_ARG_FFLAGS(flags); | ||||
AUDIT_ARG_MODE(mode); | AUDIT_ARG_MODE(mode); | ||||
cap_rights_init_one(&rights, CAP_LOOKUP); | cap_rights_init_one(&rights, CAP_LOOKUP); | ||||
flags_to_rights(flags, &rights); | flags_to_rights(flags, &rights); | ||||
/* | /* | ||||
* Only one of the O_EXEC, O_RDONLY, O_WRONLY and O_RDWR flags | * Only one of the O_EXEC, O_RDONLY, O_WRONLY and O_RDWR flags | ||||
* may be specified. | * may be specified. | ||||
Show All 15 Lines | kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg, | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
/* | /* | ||||
* An extra reference on `fp' has been held for us by | * An extra reference on `fp' has been held for us by | ||||
* falloc_noinstall(). | * falloc_noinstall(). | ||||
*/ | */ | ||||
/* Set the flags early so the finit in devfs can pick them up. */ | /* Set the flags early so the finit in devfs can pick them up. */ | ||||
fp->f_flag = flags & FMASK; | fp->f_flag = flags & FMASK; | ||||
cmode = ((mode & ~fdp->fd_cmask) & ALLPERMS) & ~S_ISTXT; | cmode = ((mode & ~pdp->pd_cmask) & ALLPERMS) & ~S_ISTXT; | ||||
kib: So I just remembered that this and other similar places are not broken for mt process because… | |||||
NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, fd, | NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, fd, | ||||
&rights, td); | &rights, td); | ||||
td->td_dupfd = -1; /* XXX check for fdopen */ | td->td_dupfd = -1; /* XXX check for fdopen */ | ||||
error = vn_open(&nd, &flags, cmode, fp); | error = vn_open(&nd, &flags, cmode, fp); | ||||
if (error != 0) { | if (error != 0) { | ||||
/* | /* | ||||
* If the vn_open replaced the method vector, something | * If the vn_open replaced the method vector, something | ||||
* wonderous happened deep below and we just pass it up | * wonderous happened deep below and we just pass it up | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | if (vp == nd.ni_dvp) | ||||
vrele(nd.ni_dvp); | vrele(nd.ni_dvp); | ||||
else | else | ||||
vput(nd.ni_dvp); | vput(nd.ni_dvp); | ||||
vrele(vp); | vrele(vp); | ||||
return (EEXIST); | return (EEXIST); | ||||
} else { | } else { | ||||
VATTR_NULL(&vattr); | VATTR_NULL(&vattr); | ||||
vattr.va_mode = (mode & ALLPERMS) & | vattr.va_mode = (mode & ALLPERMS) & | ||||
~td->td_proc->p_fd->fd_cmask; | ~td->td_proc->p_pd->pd_cmask; | ||||
vattr.va_rdev = dev; | vattr.va_rdev = dev; | ||||
whiteout = 0; | whiteout = 0; | ||||
switch (mode & S_IFMT) { | switch (mode & S_IFMT) { | ||||
case S_IFCHR: | case S_IFCHR: | ||||
vattr.va_type = VCHR; | vattr.va_type = VCHR; | ||||
break; | break; | ||||
case S_IFBLK: | case S_IFBLK: | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { | ||||
NDFREE(&nd, NDF_ONLY_PNBUF); | NDFREE(&nd, NDF_ONLY_PNBUF); | ||||
vput(nd.ni_dvp); | vput(nd.ni_dvp); | ||||
if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | ||||
return (error); | return (error); | ||||
goto restart; | goto restart; | ||||
} | } | ||||
VATTR_NULL(&vattr); | VATTR_NULL(&vattr); | ||||
vattr.va_type = VFIFO; | vattr.va_type = VFIFO; | ||||
vattr.va_mode = (mode & ALLPERMS) & ~td->td_proc->p_fd->fd_cmask; | vattr.va_mode = (mode & ALLPERMS) & ~td->td_proc->p_pd->pd_cmask; | ||||
#ifdef MAC | #ifdef MAC | ||||
error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | ||||
&vattr); | &vattr); | ||||
if (error != 0) | if (error != 0) | ||||
goto out; | goto out; | ||||
#endif | #endif | ||||
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); | error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); | ||||
if (error == 0) | if (error == 0) | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | restart: | ||||
if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { | if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { | ||||
NDFREE(&nd, NDF_ONLY_PNBUF); | NDFREE(&nd, NDF_ONLY_PNBUF); | ||||
vput(nd.ni_dvp); | vput(nd.ni_dvp); | ||||
if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | ||||
goto out; | goto out; | ||||
goto restart; | goto restart; | ||||
} | } | ||||
VATTR_NULL(&vattr); | VATTR_NULL(&vattr); | ||||
vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_fd->fd_cmask; | vattr.va_mode = ACCESSPERMS &~ td->td_proc->p_pd->pd_cmask; | ||||
#ifdef MAC | #ifdef MAC | ||||
vattr.va_type = VLNK; | vattr.va_type = VLNK; | ||||
error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | ||||
&vattr); | &vattr); | ||||
if (error != 0) | if (error != 0) | ||||
goto out2; | goto out2; | ||||
#endif | #endif | ||||
error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, syspath); | error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr, syspath); | ||||
▲ Show 20 Lines • Show All 2,046 Lines • ▼ Show 20 Lines | if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { | ||||
NDFREE(&nd, NDF_ONLY_PNBUF); | NDFREE(&nd, NDF_ONLY_PNBUF); | ||||
vput(nd.ni_dvp); | vput(nd.ni_dvp); | ||||
if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) | ||||
return (error); | return (error); | ||||
goto restart; | goto restart; | ||||
} | } | ||||
VATTR_NULL(&vattr); | VATTR_NULL(&vattr); | ||||
vattr.va_type = VDIR; | vattr.va_type = VDIR; | ||||
vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_fd->fd_cmask; | vattr.va_mode = (mode & ACCESSPERMS) &~ td->td_proc->p_pd->pd_cmask; | ||||
#ifdef MAC | #ifdef MAC | ||||
error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, | ||||
&vattr); | &vattr); | ||||
if (error != 0) | if (error != 0) | ||||
goto out; | goto out; | ||||
#endif | #endif | ||||
error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); | error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); | ||||
#ifdef MAC | #ifdef MAC | ||||
▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | |||||
#ifndef _SYS_SYSPROTO_H_ | #ifndef _SYS_SYSPROTO_H_ | ||||
struct umask_args { | struct umask_args { | ||||
int newmask; | int newmask; | ||||
}; | }; | ||||
#endif | #endif | ||||
int | int | ||||
sys_umask(struct thread *td, struct umask_args *uap) | sys_umask(struct thread *td, struct umask_args *uap) | ||||
{ | { | ||||
struct filedesc *fdp; | struct pathsdesc *pdp; | ||||
fdp = td->td_proc->p_fd; | pdp = td->td_proc->p_pd; | ||||
FILEDESC_XLOCK(fdp); | PATHSDESC_XLOCK(pdp); | ||||
td->td_retval[0] = fdp->fd_cmask; | td->td_retval[0] = pdp->pd_cmask; | ||||
fdp->fd_cmask = uap->newmask & ALLPERMS; | pdp->pd_cmask = uap->newmask & ALLPERMS; | ||||
FILEDESC_XUNLOCK(fdp); | PATHSDESC_XUNLOCK(pdp); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Void all references to file by ripping underlying filesystem away from | * Void all references to file by ripping underlying filesystem away from | ||||
* vnode. | * vnode. | ||||
*/ | */ | ||||
#ifndef _SYS_SYSPROTO_H_ | #ifndef _SYS_SYSPROTO_H_ | ||||
▲ Show 20 Lines • Show All 726 Lines • Show Last 20 Lines |
So I just remembered that this and other similar places are not broken for mt process because rfork(RFCFDG | RFFDG) single-threads.