Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/vfs_vnops.c
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
vn_open(struct nameidata *ndp, int *flagp, int cmode, struct file *fp) | vn_open(struct nameidata *ndp, int *flagp, int cmode, struct file *fp) | ||||
{ | { | ||||
struct thread *td = ndp->ni_cnd.cn_thread; | struct thread *td = ndp->ni_cnd.cn_thread; | ||||
return (vn_open_cred(ndp, flagp, cmode, 0, td->td_ucred, fp)); | return (vn_open_cred(ndp, flagp, cmode, 0, td->td_ucred, fp)); | ||||
} | } | ||||
static uint64_t | |||||
open2nameif(int fmode, u_int vn_open_flags) | |||||
{ | |||||
uint64_t res; | |||||
res = ISOPEN | LOCKLEAF; | |||||
if ((fmode & O_BENEATH) != 0) | |||||
res |= BENEATH; | |||||
if ((fmode & O_RESOLVE_BENEATH) != 0) | |||||
res |= RBENEATH; | |||||
if ((vn_open_flags & VN_OPEN_NOAUDIT) == 0) | |||||
res |= AUDITVNODE1; | |||||
if ((vn_open_flags & VN_OPEN_NOCAPCHECK) != 0) | |||||
res |= NOCAPCHECK; | |||||
return (res); | |||||
} | |||||
/* | /* | ||||
* Common code for vnode open operations via a name lookup. | * Common code for vnode open operations via a name lookup. | ||||
* Lookup the vnode and invoke VOP_CREATE if needed. | * Lookup the vnode and invoke VOP_CREATE if needed. | ||||
* Check permissions, and call the VOP_OPEN or VOP_CREATE routine. | * Check permissions, and call the VOP_OPEN or VOP_CREATE routine. | ||||
* | * | ||||
* Note that this does NOT free nameidata for the successful case, | * Note that this does NOT free nameidata for the successful case, | ||||
* due to the NDINIT being done elsewhere. | * due to the NDINIT being done elsewhere. | ||||
*/ | */ | ||||
Show All 10 Lines | |||||
restart: | restart: | ||||
fmode = *flagp; | fmode = *flagp; | ||||
if ((fmode & (O_CREAT | O_EXCL | O_DIRECTORY)) == (O_CREAT | | if ((fmode & (O_CREAT | O_EXCL | O_DIRECTORY)) == (O_CREAT | | ||||
O_EXCL | O_DIRECTORY)) | O_EXCL | O_DIRECTORY)) | ||||
return (EINVAL); | return (EINVAL); | ||||
else if ((fmode & (O_CREAT | O_DIRECTORY)) == O_CREAT) { | else if ((fmode & (O_CREAT | O_DIRECTORY)) == O_CREAT) { | ||||
ndp->ni_cnd.cn_nameiop = CREATE; | ndp->ni_cnd.cn_nameiop = CREATE; | ||||
ndp->ni_cnd.cn_flags = open2nameif(fmode, vn_open_flags); | |||||
/* | /* | ||||
* Set NOCACHE to avoid flushing the cache when | * Set NOCACHE to avoid flushing the cache when | ||||
* rolling in many files at once. | * rolling in many files at once. | ||||
*/ | */ | ||||
ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF | NOCACHE; | ndp->ni_cnd.cn_flags |= LOCKPARENT | NOCACHE; | ||||
if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0) | if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0) | ||||
ndp->ni_cnd.cn_flags |= FOLLOW; | ndp->ni_cnd.cn_flags |= FOLLOW; | ||||
if ((fmode & O_BENEATH) != 0) | |||||
ndp->ni_cnd.cn_flags |= BENEATH; | |||||
if (!(vn_open_flags & VN_OPEN_NOAUDIT)) | |||||
ndp->ni_cnd.cn_flags |= AUDITVNODE1; | |||||
if (vn_open_flags & VN_OPEN_NOCAPCHECK) | |||||
ndp->ni_cnd.cn_flags |= NOCAPCHECK; | |||||
if ((vn_open_flags & VN_OPEN_INVFS) == 0) | if ((vn_open_flags & VN_OPEN_INVFS) == 0) | ||||
bwillwrite(); | bwillwrite(); | ||||
if ((error = namei(ndp)) != 0) | if ((error = namei(ndp)) != 0) | ||||
return (error); | return (error); | ||||
if (ndp->ni_vp == NULL) { | if (ndp->ni_vp == NULL) { | ||||
VATTR_NULL(vap); | VATTR_NULL(vap); | ||||
vap->va_type = VREG; | vap->va_type = VREG; | ||||
vap->va_mode = cmode; | vap->va_mode = cmode; | ||||
Show All 38 Lines | #endif | ||||
if (vp->v_type == VDIR) { | if (vp->v_type == VDIR) { | ||||
error = EISDIR; | error = EISDIR; | ||||
goto bad; | goto bad; | ||||
} | } | ||||
fmode &= ~O_CREAT; | fmode &= ~O_CREAT; | ||||
} | } | ||||
} else { | } else { | ||||
ndp->ni_cnd.cn_nameiop = LOOKUP; | ndp->ni_cnd.cn_nameiop = LOOKUP; | ||||
ndp->ni_cnd.cn_flags = ISOPEN | | ndp->ni_cnd.cn_flags = open2nameif(fmode, vn_open_flags); | ||||
((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF; | ndp->ni_cnd.cn_flags |= (fmode & O_NOFOLLOW) != 0 ? NOFOLLOW : | ||||
if (!(fmode & FWRITE)) | FOLLOW; | ||||
markj: It looks like there is extra ws following `|=`. | |||||
Done Inline ActionsIt was a tab. kib: It was a tab. | |||||
if ((fmode & FWRITE) == 0) | |||||
ndp->ni_cnd.cn_flags |= LOCKSHARED; | ndp->ni_cnd.cn_flags |= LOCKSHARED; | ||||
if ((fmode & O_BENEATH) != 0) | |||||
ndp->ni_cnd.cn_flags |= BENEATH; | |||||
if (!(vn_open_flags & VN_OPEN_NOAUDIT)) | |||||
ndp->ni_cnd.cn_flags |= AUDITVNODE1; | |||||
if (vn_open_flags & VN_OPEN_NOCAPCHECK) | |||||
ndp->ni_cnd.cn_flags |= NOCAPCHECK; | |||||
if ((error = namei(ndp)) != 0) | if ((error = namei(ndp)) != 0) | ||||
Done Inline ActionsPerhaps factor the common bits for LOOKUP and CREATE into a subroutine. markj: Perhaps factor the common bits for LOOKUP and CREATE into a subroutine. | |||||
return (error); | return (error); | ||||
vp = ndp->ni_vp; | vp = ndp->ni_vp; | ||||
} | } | ||||
error = vn_open_vnode(vp, fmode, cred, td, fp); | error = vn_open_vnode(vp, fmode, cred, td, fp); | ||||
if (error) | if (error) | ||||
goto bad; | goto bad; | ||||
*flagp = fmode; | *flagp = fmode; | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 2,979 Lines • Show Last 20 Lines |
It looks like there is extra ws following |=.