Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/vfs_vnops.c
Show First 20 Lines • Show All 1,283 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* File table truncate routine. | * File table truncate routine. | ||||
*/ | */ | ||||
static int | static int | ||||
vn_truncate(struct file *fp, off_t length, struct ucred *active_cred, | vn_truncate(struct file *fp, off_t length, struct ucred *active_cred, | ||||
struct thread *td) | struct thread *td) | ||||
{ | { | ||||
struct vattr vattr; | |||||
struct mount *mp; | struct mount *mp; | ||||
struct vnode *vp; | struct vnode *vp; | ||||
void *rl_cookie; | void *rl_cookie; | ||||
int error; | int error; | ||||
vp = fp->f_vnode; | vp = fp->f_vnode; | ||||
/* | /* | ||||
Show All 10 Lines | if (vp->v_type == VDIR) { | ||||
error = EISDIR; | error = EISDIR; | ||||
goto out; | goto out; | ||||
} | } | ||||
#ifdef MAC | #ifdef MAC | ||||
error = mac_vnode_check_write(active_cred, fp->f_cred, vp); | error = mac_vnode_check_write(active_cred, fp->f_cred, vp); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
#endif | #endif | ||||
error = vn_truncate_locked(vp, length, (fp->f_flag & O_FSYNC) != 0, | |||||
fp->f_cred); | |||||
out: | |||||
VOP_UNLOCK(vp, 0); | |||||
vn_finished_write(mp); | |||||
out1: | |||||
vn_rangelock_unlock(vp, rl_cookie); | |||||
return (error); | |||||
} | |||||
/* | |||||
* Truncate a file that is already locked. | |||||
*/ | |||||
int | |||||
vn_truncate_locked(struct vnode *vp, off_t length, bool sync, | |||||
struct ucred *cred) | |||||
{ | |||||
struct vattr vattr; | |||||
int error; | |||||
error = VOP_ADD_WRITECOUNT(vp, 1); | error = VOP_ADD_WRITECOUNT(vp, 1); | ||||
if (error == 0) { | if (error == 0) { | ||||
VATTR_NULL(&vattr); | VATTR_NULL(&vattr); | ||||
vattr.va_size = length; | vattr.va_size = length; | ||||
if ((fp->f_flag & O_FSYNC) != 0) | if (sync) | ||||
vattr.va_vaflags |= VA_SYNC; | vattr.va_vaflags |= VA_SYNC; | ||||
error = VOP_SETATTR(vp, &vattr, fp->f_cred); | error = VOP_SETATTR(vp, &vattr, cred); | ||||
VOP_ADD_WRITECOUNT_CHECKED(vp, -1); | VOP_ADD_WRITECOUNT_CHECKED(vp, -1); | ||||
} | } | ||||
out: | |||||
VOP_UNLOCK(vp, 0); | |||||
vn_finished_write(mp); | |||||
out1: | |||||
vn_rangelock_unlock(vp, rl_cookie); | |||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* File table vnode stat routine. | * File table vnode stat routine. | ||||
*/ | */ | ||||
static int | static int | ||||
vn_statfile(struct file *fp, struct stat *sb, struct ucred *active_cred, | vn_statfile(struct file *fp, struct stat *sb, struct ucred *active_cred, | ||||
▲ Show 20 Lines • Show All 1,262 Lines • Show Last 20 Lines |