Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110451105
D20808.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D20808.diff
View Options
Index: head/sys/kern/vfs_vnops.c
===================================================================
--- head/sys/kern/vfs_vnops.c
+++ head/sys/kern/vfs_vnops.c
@@ -1289,7 +1289,6 @@
vn_truncate(struct file *fp, off_t length, struct ucred *active_cred,
struct thread *td)
{
- struct vattr vattr;
struct mount *mp;
struct vnode *vp;
void *rl_cookie;
@@ -1316,20 +1315,35 @@
if (error)
goto out;
#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);
if (error == 0) {
VATTR_NULL(&vattr);
vattr.va_size = length;
- if ((fp->f_flag & O_FSYNC) != 0)
+ if (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);
}
-out:
- VOP_UNLOCK(vp, 0);
- vn_finished_write(mp);
-out1:
- vn_rangelock_unlock(vp, rl_cookie);
return (error);
}
Index: head/sys/sys/vnode.h
===================================================================
--- head/sys/sys/vnode.h
+++ head/sys/sys/vnode.h
@@ -695,6 +695,8 @@
int vn_start_write(struct vnode *vp, struct mount **mpp, int flags);
int vn_start_secondary_write(struct vnode *vp, struct mount **mpp,
int flags);
+int vn_truncate_locked(struct vnode *vp, off_t length, bool sync,
+ struct ucred *cred);
int vn_writechk(struct vnode *vp);
int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace,
const char *attrname, int *buflen, char *buf, struct thread *td);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Feb 19, 3:30 PM (20 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16723166
Default Alt Text
D20808.diff (1 KB)
Attached To
Mode
D20808: factor out the code that actually does the truncation from vn_truncate() into vn_truncate_locked()
Attached
Detach File
Event Timeline
Log In to Comment