linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Zippel <zippel@linux-m68k.org>
To: Andrew Morton <akpm@osdl.org>, linux-fsdevel@vger.kernel.org
Subject: [PATCH 3/6] manage correct block count
Date: Thu, 21 Oct 2004 01:13:30 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0410210113200.1073@scrub.home> (raw)


Manage the fs block count with a separate variable and keep a correct
i_blocks for e.g. correct du output.

Signed-off-by: Roman Zippel <zippel@linux-m68k.org>

Index: linux-2.6-hfs/fs/hfs/inode.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/inode.c	2004-10-19 19:34:42.000000000 +0200
+++ linux-2.6-hfs/fs/hfs/inode.c	2004-10-21 00:43:06.378104370 +0200
@@ -170,8 +170,10 @@ struct inode *hfs_new_inode(struct inode
 	inode->i_gid = current->fsgid;
 	inode->i_nlink = 1;
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
+	inode->i_blksize = HFS_SB(sb)->alloc_blksz;
 	HFS_I(inode)->flags = 0;
 	HFS_I(inode)->rsrc_inode = NULL;
+	HFS_I(inode)->fs_blocks = 0;
 	if (S_ISDIR(inode->i_mode)) {
 		inode->i_size = 2;
 		HFS_SB(sb)->folder_count++;
@@ -243,7 +245,8 @@ void hfs_inode_read_fork(struct inode *i
 	HFS_I(inode)->first_blocks = count;
 
 	inode->i_size = HFS_I(inode)->phys_size = log_size;
-	inode->i_blocks = (log_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	HFS_I(inode)->fs_blocks = (log_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits);
 	HFS_I(inode)->alloc_blocks = be32_to_cpu(phys_size) /
 				     HFS_SB(sb)->alloc_blksz;
 	HFS_I(inode)->clump_blocks = clump_size / HFS_SB(sb)->alloc_blksz;
@@ -291,6 +294,7 @@ int hfs_read_inode(struct inode *inode, 
 	inode->i_uid = hsb->s_uid;
 	inode->i_gid = hsb->s_gid;
 	inode->i_nlink = 1;
+	inode->i_blksize = HFS_SB(inode->i_sb)->alloc_blksz;
 
 	if (idata->key)
 		HFS_I(inode)->cat_key = *idata->key;
@@ -320,12 +324,11 @@ int hfs_read_inode(struct inode *inode, 
 		inode->i_op = &hfs_file_inode_operations;
 		inode->i_fop = &hfs_file_operations;
 		inode->i_mapping->a_ops = &hfs_aops;
-		HFS_I(inode)->phys_size = inode->i_size;
 		break;
 	case HFS_CDR_DIR:
 		inode->i_ino = be32_to_cpu(rec->dir.DirID);
-		inode->i_blocks = 0;
 		inode->i_size = be16_to_cpu(rec->dir.Val) + 2;
+		HFS_I(inode)->fs_blocks = 0;
 		inode->i_mode = S_IFDIR | (S_IRWXUGO & hsb->s_dir_umask);
 		inode->i_ctime = inode->i_atime = inode->i_mtime =
 				hfs_m_to_utime(rec->file.MdDat);
Index: linux-2.6-hfs/fs/hfs/extent.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/extent.c	2004-10-19 19:34:42.000000000 +0200
+++ linux-2.6-hfs/fs/hfs/extent.c	2004-10-21 00:43:06.379104199 +0200
@@ -328,8 +328,8 @@ int hfs_get_block(struct inode *inode, s
 	/* Convert inode block to disk allocation block */
 	ablock = (u32)block / HFS_SB(sb)->fs_div;
 
-	if (block >= inode->i_blocks) {
-		if (block > inode->i_blocks || !create)
+	if (block >= HFS_I(inode)->fs_blocks) {
+		if (block > HFS_I(inode)->fs_blocks || !create)
 			return -EIO;
 		if (ablock >= HFS_I(inode)->alloc_blocks) {
 			res = hfs_extend_file(inode);
@@ -363,7 +363,8 @@ done:
 	if (create) {
 		set_buffer_new(bh_result);
 		HFS_I(inode)->phys_size += sb->s_blocksize;
-		inode->i_blocks++;
+		HFS_I(inode)->fs_blocks++;
+		inode_add_bytes(inode, sb->s_blocksize);
 		mark_inode_dirty(inode);
 	}
 	return 0;
@@ -521,6 +522,7 @@ void hfs_file_truncate(struct inode *ino
 	HFS_I(inode)->alloc_blocks = blk_cnt;
 out:
 	HFS_I(inode)->phys_size = inode->i_size;
+	HFS_I(inode)->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits);
 	mark_inode_dirty(inode);
-	inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 }
Index: linux-2.6-hfs/fs/hfs/hfs_fs.h
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/hfs_fs.h	2004-10-19 19:34:42.000000000 +0200
+++ linux-2.6-hfs/fs/hfs/hfs_fs.h	2004-10-21 00:43:06.379104199 +0200
@@ -60,6 +60,7 @@ struct hfs_inode_info {
 	struct semaphore extents_lock;
 
 	u16 alloc_blocks, clump_blocks;
+	sector_t fs_blocks;
 	/* Allocation extents from catlog record or volume header */
 	hfs_extent_rec first_extents;
 	u16 first_blocks;
Index: linux-2.6-hfs/fs/hfs/btree.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfs/btree.c	2004-10-19 19:34:42.000000000 +0200
+++ linux-2.6-hfs/fs/hfs/btree.c	2004-10-21 00:43:06.387102825 +0200
@@ -201,10 +201,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct 
 		res = hfs_extend_file(inode);
 		if (res)
 			return ERR_PTR(res);
-		inode->i_blocks = HFS_I(inode)->alloc_blocks *
-				  HFS_SB(tree->sb)->fs_div;
 		HFS_I(inode)->phys_size = inode->i_size =
-			(loff_t)inode->i_blocks << tree->sb->s_blocksize_bits;
+				(loff_t)HFS_I(inode)->alloc_blocks *
+				HFS_SB(tree->sb)->alloc_blksz;
+		HFS_I(inode)->fs_blocks = inode->i_size >>
+					  tree->sb->s_blocksize_bits;
+		inode_set_bytes(inode, inode->i_size);
 		count = inode->i_size >> tree->node_size_shift;
 		tree->free_nodes = count - tree->node_count;
 		tree->node_count = count;
Index: linux-2.6-hfs/fs/hfsplus/hfsplus_fs.h
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/hfsplus_fs.h	2004-10-19 19:34:43.000000000 +0200
+++ linux-2.6-hfs/fs/hfsplus/hfsplus_fs.h	2004-10-21 00:43:06.394101623 +0200
@@ -155,6 +155,7 @@ struct hfsplus_sb_info {
 struct hfsplus_inode_info {
 	struct semaphore extents_lock;
 	u32 clump_blocks, alloc_blocks;
+	sector_t fs_blocks;
 	/* Allocation extents from catalog record or volume header */
 	hfsplus_extent_rec first_extents;
 	u32 first_blocks;
Index: linux-2.6-hfs/fs/hfsplus/btree.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/btree.c	2004-10-19 19:34:43.000000000 +0200
+++ linux-2.6-hfs/fs/hfsplus/btree.c	2004-10-21 00:43:06.404099906 +0200
@@ -187,10 +187,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct 
 		res = hfsplus_file_extend(inode);
 		if (res)
 			return ERR_PTR(res);
-		inode->i_blocks = HFSPLUS_I(inode).alloc_blocks <<
-				  HFSPLUS_SB(tree->sb).fs_shift;
 		HFSPLUS_I(inode).phys_size = inode->i_size =
-			(loff_t)inode->i_blocks << tree->sb->s_blocksize_bits;
+				(loff_t)HFSPLUS_I(inode).alloc_blocks <<
+				HFSPLUS_SB(tree->sb).alloc_blksz_shift;
+		HFSPLUS_I(inode).fs_blocks = HFSPLUS_I(inode).alloc_blocks <<
+					     HFSPLUS_SB(tree->sb).fs_shift;
+		inode_set_bytes(inode, inode->i_size);
 		count = inode->i_size >> tree->node_size_shift;
 		tree->free_nodes = count - tree->node_count;
 		tree->node_count = count;
Index: linux-2.6-hfs/fs/hfsplus/inode.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/inode.c	2004-10-19 19:34:43.000000000 +0200
+++ linux-2.6-hfs/fs/hfsplus/inode.c	2004-10-21 00:43:06.411098703 +0200
@@ -332,6 +332,7 @@ struct inode *hfsplus_new_inode(struct s
 	inode->i_gid = current->fsgid;
 	inode->i_nlink = 1;
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
+	inode->i_blksize = HFSPLUS_SB(sb).alloc_blksz;
 	INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
 	init_MUTEX(&HFSPLUS_I(inode).extents_lock);
 	atomic_set(&HFSPLUS_I(inode).opencnt, 0);
@@ -343,6 +344,7 @@ struct inode *hfsplus_new_inode(struct s
 	HFSPLUS_I(inode).cached_start = 0;
 	HFSPLUS_I(inode).cached_blocks = 0;
 	HFSPLUS_I(inode).phys_size = 0;
+	HFSPLUS_I(inode).fs_blocks = 0;
 	HFSPLUS_I(inode).rsrc_inode = NULL;
 	if (S_ISDIR(inode->i_mode)) {
 		inode->i_size = 2;
@@ -408,7 +410,8 @@ void hfsplus_inode_read_fork(struct inod
 
 	HFSPLUS_I(inode).alloc_blocks = be32_to_cpu(fork->total_blocks);
 	inode->i_size = HFSPLUS_I(inode).phys_size = be64_to_cpu(fork->total_size);
-	inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	HFSPLUS_I(inode).fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	inode_set_bytes(inode, HFSPLUS_I(inode).fs_blocks << sb->s_blocksize_bits);
 	HFSPLUS_I(inode).clump_blocks = be32_to_cpu(fork->clump_size) >> HFSPLUS_SB(sb).alloc_blksz_shift;
 	if (!HFSPLUS_I(inode).clump_blocks)
 		HFSPLUS_I(inode).clump_blocks = HFSPLUS_IS_RSRC(inode) ? HFSPLUS_SB(sb).rsrc_clump_blocks :
@@ -432,7 +435,7 @@ int hfsplus_cat_read_inode(struct inode 
 	type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
 
 	HFSPLUS_I(inode).dev = 0;
-	inode->i_blksize = PAGE_SIZE; /* Doesn't seem to be useful... */
+	inode->i_blksize = HFSPLUS_SB(inode->i_sb).alloc_blksz;
 	if (type == HFSPLUS_FOLDER) {
 		struct hfsplus_cat_folder *folder = &entry.folder;
 
@@ -446,7 +449,7 @@ int hfsplus_cat_read_inode(struct inode 
 		inode->i_atime = hfsp_mt2ut(folder->access_date);
 		inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
 		inode->i_ctime = inode->i_mtime;
-		inode->i_blocks = 0;
+		HFSPLUS_I(inode).fs_blocks = 0;
 		inode->i_op = &hfsplus_dir_inode_operations;
 		inode->i_fop = &hfsplus_dir_operations;
 	} else if (type == HFSPLUS_FILE) {
Index: linux-2.6-hfs/fs/hfsplus/extents.c
===================================================================
--- linux-2.6-hfs.orig/fs/hfsplus/extents.c	2004-10-19 19:34:43.000000000 +0200
+++ linux-2.6-hfs/fs/hfsplus/extents.c	2004-10-21 00:43:06.412098532 +0200
@@ -183,8 +183,8 @@ int hfsplus_get_block(struct inode *inod
 	shift = HFSPLUS_SB(sb).alloc_blksz_shift - sb->s_blocksize_bits;
 	ablock = iblock >> HFSPLUS_SB(sb).fs_shift;
 
-	if (iblock >= inode->i_blocks) {
-		if (iblock > inode->i_blocks || !create)
+	if (iblock >= HFSPLUS_I(inode).fs_blocks) {
+		if (iblock > HFSPLUS_I(inode).fs_blocks || !create)
 			return -EIO;
 		if (ablock >= HFSPLUS_I(inode).alloc_blocks) {
 			res = hfsplus_file_extend(inode);
@@ -217,7 +217,8 @@ done:
 	if (create) {
 		set_buffer_new(bh_result);
 		HFSPLUS_I(inode).phys_size += sb->s_blocksize;
-		inode->i_blocks++;
+		HFSPLUS_I(inode).fs_blocks++;
+		inode_add_bytes(inode, sb->s_blocksize);
 		mark_inode_dirty(inode);
 	}
 	return 0;
@@ -497,6 +498,7 @@ void hfsplus_file_truncate(struct inode 
 	HFSPLUS_I(inode).alloc_blocks = blk_cnt;
 out:
 	HFSPLUS_I(inode).phys_size = inode->i_size;
+	HFSPLUS_I(inode).fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
+	inode_set_bytes(inode, HFSPLUS_I(inode).fs_blocks << sb->s_blocksize_bits);
 	mark_inode_dirty(inode);
-	inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 }

                 reply	other threads:[~2004-10-20 23:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61.0410210113200.1073@scrub.home \
    --to=zippel@linux-m68k.org \
    --cc=akpm@osdl.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).