Commit de57d832 authored by Roman Zippel's avatar Roman Zippel Committed by Linus Torvalds

[PATCH] hfs: manage correct block count

Manage the fs block count with a separate variable and keep a correct i_blocks
for e.g.  correct du output.
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c85441c2
...@@ -201,10 +201,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) ...@@ -201,10 +201,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
res = hfs_extend_file(inode); res = hfs_extend_file(inode);
if (res) if (res)
return ERR_PTR(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 = 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; count = inode->i_size >> tree->node_size_shift;
tree->free_nodes = count - tree->node_count; tree->free_nodes = count - tree->node_count;
tree->node_count = count; tree->node_count = count;
......
...@@ -328,8 +328,8 @@ int hfs_get_block(struct inode *inode, sector_t block, ...@@ -328,8 +328,8 @@ int hfs_get_block(struct inode *inode, sector_t block,
/* Convert inode block to disk allocation block */ /* Convert inode block to disk allocation block */
ablock = (u32)block / HFS_SB(sb)->fs_div; ablock = (u32)block / HFS_SB(sb)->fs_div;
if (block >= inode->i_blocks) { if (block >= HFS_I(inode)->fs_blocks) {
if (block > inode->i_blocks || !create) if (block > HFS_I(inode)->fs_blocks || !create)
return -EIO; return -EIO;
if (ablock >= HFS_I(inode)->alloc_blocks) { if (ablock >= HFS_I(inode)->alloc_blocks) {
res = hfs_extend_file(inode); res = hfs_extend_file(inode);
...@@ -363,7 +363,8 @@ int hfs_get_block(struct inode *inode, sector_t block, ...@@ -363,7 +363,8 @@ int hfs_get_block(struct inode *inode, sector_t block,
if (create) { if (create) {
set_buffer_new(bh_result); set_buffer_new(bh_result);
HFS_I(inode)->phys_size += sb->s_blocksize; 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); mark_inode_dirty(inode);
} }
return 0; return 0;
...@@ -521,6 +522,7 @@ void hfs_file_truncate(struct inode *inode) ...@@ -521,6 +522,7 @@ void hfs_file_truncate(struct inode *inode)
HFS_I(inode)->alloc_blocks = blk_cnt; HFS_I(inode)->alloc_blocks = blk_cnt;
out: out:
HFS_I(inode)->phys_size = inode->i_size; 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); mark_inode_dirty(inode);
inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
} }
...@@ -60,6 +60,7 @@ struct hfs_inode_info { ...@@ -60,6 +60,7 @@ struct hfs_inode_info {
struct semaphore extents_lock; struct semaphore extents_lock;
u16 alloc_blocks, clump_blocks; u16 alloc_blocks, clump_blocks;
sector_t fs_blocks;
/* Allocation extents from catlog record or volume header */ /* Allocation extents from catlog record or volume header */
hfs_extent_rec first_extents; hfs_extent_rec first_extents;
u16 first_blocks; u16 first_blocks;
......
...@@ -170,8 +170,10 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, int mode) ...@@ -170,8 +170,10 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, int mode)
inode->i_gid = current->fsgid; inode->i_gid = current->fsgid;
inode->i_nlink = 1; inode->i_nlink = 1;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 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)->flags = 0;
HFS_I(inode)->rsrc_inode = NULL; HFS_I(inode)->rsrc_inode = NULL;
HFS_I(inode)->fs_blocks = 0;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
inode->i_size = 2; inode->i_size = 2;
HFS_SB(sb)->folder_count++; HFS_SB(sb)->folder_count++;
...@@ -243,7 +245,8 @@ void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext, ...@@ -243,7 +245,8 @@ void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
HFS_I(inode)->first_blocks = count; HFS_I(inode)->first_blocks = count;
inode->i_size = HFS_I(inode)->phys_size = log_size; 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_I(inode)->alloc_blocks = be32_to_cpu(phys_size) /
HFS_SB(sb)->alloc_blksz; HFS_SB(sb)->alloc_blksz;
HFS_I(inode)->clump_blocks = clump_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, void *data) ...@@ -291,6 +294,7 @@ int hfs_read_inode(struct inode *inode, void *data)
inode->i_uid = hsb->s_uid; inode->i_uid = hsb->s_uid;
inode->i_gid = hsb->s_gid; inode->i_gid = hsb->s_gid;
inode->i_nlink = 1; inode->i_nlink = 1;
inode->i_blksize = HFS_SB(inode->i_sb)->alloc_blksz;
if (idata->key) if (idata->key)
HFS_I(inode)->cat_key = *idata->key; HFS_I(inode)->cat_key = *idata->key;
...@@ -320,12 +324,11 @@ int hfs_read_inode(struct inode *inode, void *data) ...@@ -320,12 +324,11 @@ int hfs_read_inode(struct inode *inode, void *data)
inode->i_op = &hfs_file_inode_operations; inode->i_op = &hfs_file_inode_operations;
inode->i_fop = &hfs_file_operations; inode->i_fop = &hfs_file_operations;
inode->i_mapping->a_ops = &hfs_aops; inode->i_mapping->a_ops = &hfs_aops;
HFS_I(inode)->phys_size = inode->i_size;
break; break;
case HFS_CDR_DIR: case HFS_CDR_DIR:
inode->i_ino = be32_to_cpu(rec->dir.DirID); inode->i_ino = be32_to_cpu(rec->dir.DirID);
inode->i_blocks = 0;
inode->i_size = be16_to_cpu(rec->dir.Val) + 2; 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_mode = S_IFDIR | (S_IRWXUGO & hsb->s_dir_umask);
inode->i_ctime = inode->i_atime = inode->i_mtime = inode->i_ctime = inode->i_atime = inode->i_mtime =
hfs_m_to_utime(rec->file.MdDat); hfs_m_to_utime(rec->file.MdDat);
......
...@@ -187,10 +187,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) ...@@ -187,10 +187,12 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
res = hfsplus_file_extend(inode); res = hfsplus_file_extend(inode);
if (res) if (res)
return ERR_PTR(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 = 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; count = inode->i_size >> tree->node_size_shift;
tree->free_nodes = count - tree->node_count; tree->free_nodes = count - tree->node_count;
tree->node_count = count; tree->node_count = count;
......
...@@ -183,8 +183,8 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock, ...@@ -183,8 +183,8 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
shift = HFSPLUS_SB(sb).alloc_blksz_shift - sb->s_blocksize_bits; shift = HFSPLUS_SB(sb).alloc_blksz_shift - sb->s_blocksize_bits;
ablock = iblock >> HFSPLUS_SB(sb).fs_shift; ablock = iblock >> HFSPLUS_SB(sb).fs_shift;
if (iblock >= inode->i_blocks) { if (iblock >= HFSPLUS_I(inode).fs_blocks) {
if (iblock > inode->i_blocks || !create) if (iblock > HFSPLUS_I(inode).fs_blocks || !create)
return -EIO; return -EIO;
if (ablock >= HFSPLUS_I(inode).alloc_blocks) { if (ablock >= HFSPLUS_I(inode).alloc_blocks) {
res = hfsplus_file_extend(inode); res = hfsplus_file_extend(inode);
...@@ -217,7 +217,8 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock, ...@@ -217,7 +217,8 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
if (create) { if (create) {
set_buffer_new(bh_result); set_buffer_new(bh_result);
HFSPLUS_I(inode).phys_size += sb->s_blocksize; 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); mark_inode_dirty(inode);
} }
return 0; return 0;
...@@ -497,6 +498,7 @@ void hfsplus_file_truncate(struct inode *inode) ...@@ -497,6 +498,7 @@ void hfsplus_file_truncate(struct inode *inode)
HFSPLUS_I(inode).alloc_blocks = blk_cnt; HFSPLUS_I(inode).alloc_blocks = blk_cnt;
out: out:
HFSPLUS_I(inode).phys_size = inode->i_size; 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); mark_inode_dirty(inode);
inode->i_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
} }
...@@ -155,6 +155,7 @@ struct hfsplus_sb_info { ...@@ -155,6 +155,7 @@ struct hfsplus_sb_info {
struct hfsplus_inode_info { struct hfsplus_inode_info {
struct semaphore extents_lock; struct semaphore extents_lock;
u32 clump_blocks, alloc_blocks; u32 clump_blocks, alloc_blocks;
sector_t fs_blocks;
/* Allocation extents from catalog record or volume header */ /* Allocation extents from catalog record or volume header */
hfsplus_extent_rec first_extents; hfsplus_extent_rec first_extents;
u32 first_blocks; u32 first_blocks;
......
...@@ -332,6 +332,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode) ...@@ -332,6 +332,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode)
inode->i_gid = current->fsgid; inode->i_gid = current->fsgid;
inode->i_nlink = 1; inode->i_nlink = 1;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 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_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
init_MUTEX(&HFSPLUS_I(inode).extents_lock); init_MUTEX(&HFSPLUS_I(inode).extents_lock);
atomic_set(&HFSPLUS_I(inode).opencnt, 0); atomic_set(&HFSPLUS_I(inode).opencnt, 0);
...@@ -343,6 +344,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode) ...@@ -343,6 +344,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode)
HFSPLUS_I(inode).cached_start = 0; HFSPLUS_I(inode).cached_start = 0;
HFSPLUS_I(inode).cached_blocks = 0; HFSPLUS_I(inode).cached_blocks = 0;
HFSPLUS_I(inode).phys_size = 0; HFSPLUS_I(inode).phys_size = 0;
HFSPLUS_I(inode).fs_blocks = 0;
HFSPLUS_I(inode).rsrc_inode = NULL; HFSPLUS_I(inode).rsrc_inode = NULL;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
inode->i_size = 2; inode->i_size = 2;
...@@ -408,7 +410,8 @@ void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork) ...@@ -408,7 +410,8 @@ void hfsplus_inode_read_fork(struct inode *inode, struct hfsplus_fork_raw *fork)
HFSPLUS_I(inode).alloc_blocks = be32_to_cpu(fork->total_blocks); 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_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; HFSPLUS_I(inode).clump_blocks = be32_to_cpu(fork->clump_size) >> HFSPLUS_SB(sb).alloc_blksz_shift;
if (!HFSPLUS_I(inode).clump_blocks) if (!HFSPLUS_I(inode).clump_blocks)
HFSPLUS_I(inode).clump_blocks = HFSPLUS_IS_RSRC(inode) ? HFSPLUS_SB(sb).rsrc_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 *inode, struct hfs_find_data *fd) ...@@ -432,7 +435,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset); type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
HFSPLUS_I(inode).dev = 0; 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) { if (type == HFSPLUS_FOLDER) {
struct hfsplus_cat_folder *folder = &entry.folder; struct hfsplus_cat_folder *folder = &entry.folder;
...@@ -446,7 +449,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd) ...@@ -446,7 +449,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
inode->i_atime = hfsp_mt2ut(folder->access_date); inode->i_atime = hfsp_mt2ut(folder->access_date);
inode->i_mtime = hfsp_mt2ut(folder->content_mod_date); inode->i_mtime = hfsp_mt2ut(folder->content_mod_date);
inode->i_ctime = inode->i_mtime; 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_op = &hfsplus_dir_inode_operations;
inode->i_fop = &hfsplus_dir_operations; inode->i_fop = &hfsplus_dir_operations;
} else if (type == HFSPLUS_FILE) { } else if (type == HFSPLUS_FILE) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment