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 (ext2fs_has_feature_huge_file(fs->super))
36 b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32;
38 if (!ext2fs_has_feature_huge_file(fs->super) ||
39 !(inode->i_flags & EXT4_HUGE_FILE_FL))
40 num_blocks *= fs->blocksize / 512;
41 num_blocks *= EXT2FS_CLUSTER_RATIO(fs);
45 if (ext2fs_has_feature_huge_file(fs->super))
46 inode->osd2.linux2.l_i_blocks_hi = b >> 32;
47 else if (b > 0xFFFFFFFF)
49 inode->i_blocks = b & 0xFFFFFFFF;
53 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
56 unsigned long long b = inode->i_blocks;
58 if (ext2fs_has_feature_huge_file(fs->super))
59 b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32;
61 if (!ext2fs_has_feature_huge_file(fs->super) ||
62 !(inode->i_flags & EXT4_HUGE_FILE_FL))
63 num_blocks *= fs->blocksize / 512;
64 num_blocks *= EXT2FS_CLUSTER_RATIO(fs);
71 if (ext2fs_has_feature_huge_file(fs->super))
72 inode->osd2.linux2.l_i_blocks_hi = b >> 32;
73 inode->i_blocks = b & 0xFFFFFFFF;
77 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b)
79 if (!ext2fs_has_feature_huge_file(fs->super) ||
80 !(inode->i_flags & EXT4_HUGE_FILE_FL))
81 b *= fs->blocksize / 512;
82 b *= EXT2FS_CLUSTER_RATIO(fs);
84 inode->i_blocks = b & 0xFFFFFFFF;
85 if (ext2fs_has_feature_huge_file(fs->super))
86 inode->osd2.linux2.l_i_blocks_hi = b >> 32;