Skip to contentSkip to conversation

: ufs: track i_size

RFC PATCH In review Evgeniy Dushistov 2 participants 2 messages Jun 26, 2006 VFS

lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/3 : ufs: track i_size

To make possible proper work of ufs_truncate'(see the next patch), I need to know old size of file in ufs_truncate',
but for some unknown for me reason VFS layer doesn't tell old size to file system, or at least I don't find way to get this information.
So I have to add per each inode `loff_t' field and update it in
- alloc inode
- read inode
- commit write
- truncate(see the next patch)
is this right way to know "old size" in truncate method?

---

fs/ufs/ialloc.c +1 -0
Index: linux-2.6.17-mm2/fs/ufs/ialloc.c
===================================================================
@@ -265,6 +265,7 @@ cg_found:
 	ufsi->i_osync = 0;
 	ufsi->i_oeftflag = 0;
 	ufsi->i_dir_start_lookup = 0;
+	ufsi->i_size = 0;
 	memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1));
 
 	insert_inode_hash(inode);
fs/ufs/inode.c +15 -1
Index: linux-2.6.17-mm2/fs/ufs/inode.c
===================================================================
@@ -574,12 +574,25 @@ static sector_t ufs_bmap(struct address_
 {
 	return generic_block_bmap(mapping,block,ufs_getfrag_block);
 }
+
+/*
+ * we have to update our internal i_size holder,
+ * because of we want know old size in truncate
+ */
+static int ufs_commit_write(struct file *file, struct page *page,
+			    unsigned from, unsigned to)
+{
+	UFS_I(page->mapping->host)->i_size =
+		((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
+	return generic_commit_write(file, page, from, to);
+}
+
 const struct address_space_operations ufs_aops = {
 	.readpage = ufs_readpage,
 	.writepage = ufs_writepage,
 	.sync_page = block_sync_page,
 	.prepare_write = ufs_prepare_write,
-	.commit_write = generic_commit_write,
+	.commit_write = ufs_commit_write,
 	.bmap = ufs_bmap
 };
 
@@ -738,6 +751,7 @@ void ufs_read_inode(struct inode * inode
 		(inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift;
 	ufsi->i_dir_start_lookup = 0;
 	ufsi->i_osync = 0;
+	ufsi->i_size = inode->i_size;
 
 	ufs_set_inode_ops(inode);
 
include/linux/ufs_fs_i.h +1 -0
Index: linux-2.6.17-mm2/include/linux/ufs_fs_i.h
===================================================================
@@ -28,6 +28,7 @@ struct ufs_inode_info {
 	__u16	i_osync;
 	__u32	i_lastfrag;
 	__u32   i_dir_start_lookup;
+	loff_t	i_size;
 	struct inode vfs_inode;
 };
 
Signature · 1 line
/Evgeniy
#1 lore raw
Quoted 4 lines · On Mon, 26 Jun 2006 17:48:36 +0400 Evgeniy Dushistov <[email protected]> wrote:

To make possible proper work of ufs_truncate'(see the next patch), I need to know old size of file in ufs_truncate',
but for some unknown for me reason VFS layer doesn't tell old size to file system, or at least I don't find way to get

Quoted 8 lines

this information.
So I have to add per each inode `loff_t' field and update it in
- alloc inode
- read inode
- commit write
- truncate(see the next patch)
is this right way to know "old size" in truncate method?

You can get this info by implementing inode_operations.setattr(). See the callsite in fs/attr.c:notify_change(). You'd do something like:

ufs_setattr()

{
	loff_t old_i_size = inode->i_size;

	/* Stuff copied from notify_change(): */
	inode_change_ok()
	security_inode_setattr()
	inode_setattr()

	new_i_size = inode->i_size;
	....
}