2 * i_block.c --- Manage the i_block field for i_blocks
4 * Copyright (C) 2008 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
23 #include <sys/types.h>
30 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
33 unsigned long long b = inode->i_blocks;
35 if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
36 b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32;
38 if (!(fs->super->s_feature_ro_compat &
39 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
40 !(inode->i_flags & EXT4_HUGE_FILE_FL))
41 num_blocks *= fs->blocksize / 512;
42 num_blocks *= EXT2FS_CLUSTER_RATIO(fs);
46 if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
47 inode->osd2.linux2.l_i_blocks_hi = b >> 32;
48 else if (b > 0xFFFFFFFF)
50 inode->i_blocks = b & 0xFFFFFFFF;
54 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
57 unsigned long long b = inode->i_blocks;
59 if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
60 b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32;
62 if (!(fs->super->s_feature_ro_compat &
63 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
64 !(inode->i_flags & EXT4_HUGE_FILE_FL))
65 num_blocks *= fs->blocksize / 512;
66 num_blocks *= EXT2FS_CLUSTER_RATIO(fs);
73 if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
74 inode->osd2.linux2.l_i_blocks_hi = b >> 32;
75 inode->i_blocks = b & 0xFFFFFFFF;
79 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b)
81 if (!(fs->super->s_feature_ro_compat &
82 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
83 !(inode->i_flags & EXT4_HUGE_FILE_FL))
84 b *= fs->blocksize / 512;
85 b *= EXT2FS_CLUSTER_RATIO(fs);
87 inode->i_blocks = b & 0xFFFFFFFF;
88 if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
89 inode->osd2.linux2.l_i_blocks_hi = b >> 32;