summaryrefslogtreecommitdiff
path: root/sys/ufs
diff options
context:
space:
mode:
authorThomas Nordin <nordin@cvs.openbsd.org>2002-01-04 03:53:24 +0000
committerThomas Nordin <nordin@cvs.openbsd.org>2002-01-04 03:53:24 +0000
commit40150489d78bf38fbba62e3e105082948561d924 (patch)
treecb4ab1b383438e31993a1dca1bf02c8ab1aba0d5 /sys/ufs
parent05bc596a4b1ae47fee9fc8a674ee668cb0a016df (diff)
Handle truncation to the middle of a file hole. deraadt@ ok
From FreeBSD
Diffstat (limited to 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_inode.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index fecb1fbed77..cb6e60a956a 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_inode.c,v 1.29 2001/12/19 08:58:07 art Exp $ */
+/* $OpenBSD: ffs_inode.c,v 1.30 2002/01/04 03:53:23 nordin Exp $ */
/* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */
/*
@@ -265,6 +265,18 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred)
cred, aflags, &bp);
if (error)
return (error);
+ /*
+ * When we are doing soft updates and the UFS_BALLOC
+ * above fills in a direct block hole with a full sized
+ * block that will be truncated down to a fragment below,
+ * we must flush out the block dependency with an FSYNC
+ * so that we do not get a soft updates inconsistency
+ * when we create the fragment below.
+ */
+ if (DOINGSOFTDEP(ovp) && lbn < NDADDR &&
+ fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize &&
+ (error = VOP_FSYNC(ovp, cred, MNT_WAIT, curproc)) != 0)
+ return (error);
oip->i_ffs_size = length;
size = blksize(fs, oip, lbn);
(void) uvm_vnp_uncache(ovp);