2009-06-06 23:22:43 +04:00
|
|
|
/*
|
|
|
|
* blknum.c --- Functions to handle blk64_t and high/low 64-bit block
|
|
|
|
* number.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corporation, 2007
|
|
|
|
* Author Jose R. Santos <jrs@us.ibm.com>
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
2009-06-06 23:22:43 +04:00
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the group # of a block
|
|
|
|
*/
|
|
|
|
dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk)
|
|
|
|
{
|
|
|
|
return (blk - fs->super->s_first_data_block) /
|
|
|
|
fs->super->s_blocks_per_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the first block (inclusive) in a group
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
|
|
|
return fs->super->s_first_data_block +
|
2014-07-26 15:40:36 +04:00
|
|
|
EXT2_GROUPS_TO_BLOCKS(fs->super, group);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the last block (inclusive) in a group
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
|
|
|
return (group == fs->group_desc_count - 1 ?
|
|
|
|
ext2fs_blocks_count(fs->super) - 1 :
|
|
|
|
ext2fs_group_first_block2(fs, group) +
|
|
|
|
(fs->super->s_blocks_per_group - 1));
|
|
|
|
}
|
|
|
|
|
2011-09-16 17:21:53 +04:00
|
|
|
/*
|
|
|
|
* Return the number of blocks in a group
|
|
|
|
*/
|
|
|
|
int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
|
|
|
int num_blocks;
|
|
|
|
|
|
|
|
if (group == fs->group_desc_count - 1) {
|
|
|
|
num_blocks = (ext2fs_blocks_count(fs->super) -
|
|
|
|
fs->super->s_first_data_block) %
|
|
|
|
fs->super->s_blocks_per_group;
|
|
|
|
if (!num_blocks)
|
|
|
|
num_blocks = fs->super->s_blocks_per_group;
|
|
|
|
} else
|
|
|
|
num_blocks = fs->super->s_blocks_per_group;
|
|
|
|
|
|
|
|
return num_blocks;
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:22:43 +04:00
|
|
|
/*
|
|
|
|
* Return the inode data block count
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
|
|
|
|
struct ext2_inode *inode)
|
|
|
|
{
|
|
|
|
return (inode->i_blocks |
|
2010-11-23 01:32:28 +03:00
|
|
|
((fs->super->s_feature_ro_compat &
|
2009-10-24 23:14:54 +04:00
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ?
|
|
|
|
(__u64) inode->osd2.linux2.l_i_blocks_hi << 32 : 0)) -
|
2009-06-06 23:22:43 +04:00
|
|
|
(inode->i_file_acl ? fs->blocksize >> 9 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the inode i_blocks count
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
|
|
|
|
struct ext2_inode *inode)
|
|
|
|
{
|
|
|
|
return (inode->i_blocks |
|
2010-11-23 01:32:28 +03:00
|
|
|
((fs->super->s_feature_ro_compat &
|
2009-10-24 23:14:54 +04:00
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ?
|
2009-06-06 23:22:43 +04:00
|
|
|
(__u64)inode->osd2.linux2.l_i_blocks_hi << 32 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the fs block count
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_blocks_count(struct ext2_super_block *super)
|
|
|
|
{
|
|
|
|
return super->s_blocks_count |
|
|
|
|
(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64) super->s_blocks_count_hi << 32 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the fs block count
|
|
|
|
*/
|
|
|
|
void ext2fs_blocks_count_set(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
super->s_blocks_count = blk;
|
|
|
|
if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
super->s_blocks_count_hi = (__u64) blk >> 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add to the current fs block count
|
|
|
|
*/
|
|
|
|
void ext2fs_blocks_count_add(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
blk64_t tmp;
|
|
|
|
tmp = ext2fs_blocks_count(super) + blk;
|
|
|
|
ext2fs_blocks_count_set(super, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the fs reserved block count
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super)
|
|
|
|
{
|
|
|
|
return super->s_r_blocks_count |
|
|
|
|
(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64) super->s_r_blocks_count_hi << 32 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the fs reserved block count
|
|
|
|
*/
|
|
|
|
void ext2fs_r_blocks_count_set(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
super->s_r_blocks_count = blk;
|
|
|
|
if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
super->s_r_blocks_count_hi = (__u64) blk >> 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add to the current reserved fs block count
|
|
|
|
*/
|
|
|
|
void ext2fs_r_blocks_count_add(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
blk64_t tmp;
|
|
|
|
tmp = ext2fs_r_blocks_count(super) + blk;
|
|
|
|
ext2fs_r_blocks_count_set(super, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the fs free block count
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super)
|
|
|
|
{
|
|
|
|
return super->s_free_blocks_count |
|
|
|
|
(super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64) super->s_free_blocks_hi << 32 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the fs free block count
|
|
|
|
*/
|
|
|
|
void ext2fs_free_blocks_count_set(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
super->s_free_blocks_count = blk;
|
|
|
|
if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
super->s_free_blocks_hi = (__u64) blk >> 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add to the current free fs block count
|
|
|
|
*/
|
|
|
|
void ext2fs_free_blocks_count_add(struct ext2_super_block *super, blk64_t blk)
|
|
|
|
{
|
|
|
|
blk64_t tmp;
|
|
|
|
tmp = ext2fs_free_blocks_count(super) + blk;
|
|
|
|
ext2fs_free_blocks_count_set(super, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a pointer to a block group descriptor. We need the explicit
|
|
|
|
* pointer to the group desc for code that swaps block group
|
|
|
|
* descriptors before writing them out, as it wants to make a copy and
|
|
|
|
* do the swap there.
|
|
|
|
*/
|
|
|
|
struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
|
2010-06-14 05:00:00 +04:00
|
|
|
struct opaque_ext2_group_desc *gdp,
|
2009-06-06 23:22:43 +04:00
|
|
|
dgrp_t group)
|
|
|
|
{
|
debugfs, e2fsck: fix s_desc_size handling
The s_desc_size in the superblock specifies the group descriptor
size in bytes, but in various places the EXT4_FEATURE_INCOMPAT_64BIT
flag implies that the descriptor size is EXT2_MIN_DESC_SIZE_64BIT
(64 bytes) instead of checking the actual size. In other places,
the s_desc_size field is used without checking for INCOMPAT_64BIT.
In the case of ext2fs_group_desc() the s_desc_size was being ignored,
and assumed to be sizeof(struct ext4_group_desc), which would result
in garbage for any but the first group descriptor. Similarly, in
ext2fs_group_desc_csum() and print_csum() they assumed that the
maximum group descriptor size was sizeof(struct ext4_group_desc).
Fix these functions to use the actual superblock s_desc_size if
INCOMPAT_64BIT.
Conversely, in ext2fs_swap_group_desc2() s_desc_size was used
without checking for INCOMPAT_64BIT being set.
The e2fsprogs behaviour is different than that of the kernel,
which always checks INCOMPAT_64BIT, and only uses s_desc_size to
determine the offset of group descriptors and what range of bytes
to checksum.
Allow specifying the s_desc_size field at mke2fs time with the
"-E desc_size=NNN" option. Allow a power-of-two s_desc_size
value up to s_blocksize if INCOMPAT_64BIT is specified. This
is not expected to be used by regular users at this time, so it
is not currently documented in the mke2fs usage or man page.
Add m_desc_size_128, f_desc_size_128, and f_desc_bad test cases to
verify mke2fs and e2fsck handling of larger group descriptor sizes.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-24 01:04:46 +04:00
|
|
|
return (struct ext2_group_desc *)((char *)gdp +
|
|
|
|
group * EXT2_DESC_SIZE(fs->super));
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
/* Do the same but as an ext4 group desc for internal use here */
|
|
|
|
static struct ext4_group_desc *ext4fs_group_desc(ext2_filsys fs,
|
|
|
|
struct opaque_ext2_group_desc *gdp,
|
|
|
|
dgrp_t group)
|
|
|
|
{
|
|
|
|
return (struct ext4_group_desc *)ext2fs_group_desc(fs, gdp, group);
|
|
|
|
}
|
|
|
|
|
2012-07-31 03:04:04 +04:00
|
|
|
/*
|
|
|
|
* Return the block bitmap checksum of a group
|
|
|
|
*/
|
|
|
|
__u32 ext2fs_block_bitmap_checksum(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
__u32 csum;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
csum = gdp->bg_block_bitmap_csum_lo;
|
|
|
|
if (fs->super->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_LOCATION)
|
|
|
|
csum |= ((__u32)gdp->bg_block_bitmap_csum_hi << 16);
|
|
|
|
return csum;
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:22:43 +04:00
|
|
|
/*
|
|
|
|
* Return the block bitmap block of a group
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_block_bitmap |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64)gdp->bg_block_bitmap_hi << 32 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the block bitmap block of a group
|
|
|
|
*/
|
|
|
|
void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_block_bitmap = blk;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_block_bitmap_hi = (__u64) blk >> 32;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 02:56:04 +04:00
|
|
|
/*
|
|
|
|
* Return the inode bitmap checksum of a group
|
|
|
|
*/
|
|
|
|
__u32 ext2fs_inode_bitmap_checksum(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
__u32 csum;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
csum = gdp->bg_inode_bitmap_csum_lo;
|
2012-07-31 03:04:04 +04:00
|
|
|
if (fs->super->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
|
2012-07-31 02:56:04 +04:00
|
|
|
csum |= ((__u32)gdp->bg_inode_bitmap_csum_hi << 16);
|
|
|
|
return csum;
|
|
|
|
}
|
|
|
|
|
2009-06-06 23:22:43 +04:00
|
|
|
/*
|
|
|
|
* Return the inode bitmap block of a group
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_inode_bitmap |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64) gdp->bg_inode_bitmap_hi << 32 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the inode bitmap block of a group
|
|
|
|
*/
|
|
|
|
void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_inode_bitmap = blk;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_inode_bitmap_hi = (__u64) blk >> 32;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the inode table block of a group
|
|
|
|
*/
|
|
|
|
blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_inode_table |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u64) gdp->bg_inode_table_hi << 32 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the inode table block of a group
|
|
|
|
*/
|
|
|
|
void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_inode_table = blk;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_inode_table_hi = (__u64) blk >> 32;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the free blocks count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
__u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_free_blocks_count |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u32) gdp->bg_free_blocks_count_hi << 16 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the free blocks count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group, __u32 n)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_free_blocks_count = n;
|
|
|
|
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_free_blocks_count_hi = (__u32) n >> 16;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the free inodes count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
__u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_free_inodes_count |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u32) gdp->bg_free_inodes_count_hi << 16 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the free inodes count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group, __u32 n)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_free_inodes_count = n;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_free_inodes_count_hi = (__u32) n >> 16;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the used dirs count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
__u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_used_dirs_count |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u32) gdp->bg_used_dirs_count_hi << 16 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the used dirs count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group, __u32 n)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_used_dirs_count = n;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_used_dirs_count_hi = (__u32) n >> 16;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the unused inodes count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
__u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_itable_unused |
|
|
|
|
(fs->super->s_feature_incompat
|
|
|
|
& EXT4_FEATURE_INCOMPAT_64BIT ?
|
|
|
|
(__u32) gdp->bg_itable_unused_hi << 16 : 0);
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the unused inodes count of a group
|
|
|
|
*/
|
2009-09-08 05:13:59 +04:00
|
|
|
void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group, __u32 n)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
|
|
|
|
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_itable_unused = n;
|
|
|
|
if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
gdp->bg_itable_unused_hi = (__u32) n >> 16;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the flags for this block group
|
|
|
|
*/
|
|
|
|
__u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_flags;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
* Zero out the flags for this block group
|
2009-06-06 23:22:43 +04:00
|
|
|
*/
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_flags = 0;
|
|
|
|
return;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the value of a particular flag for this block group
|
|
|
|
*/
|
2009-10-26 04:42:12 +03:00
|
|
|
int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_flags & bg_flag;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
* Set a flag or set of flags for this block group
|
2009-06-06 23:22:43 +04:00
|
|
|
*/
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_flags |= bg_flags;
|
|
|
|
return;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
* Clear a flag or set of flags for this block group
|
2009-06-06 23:22:43 +04:00
|
|
|
*/
|
libext2fs: clean up ext2fs_bg_flags_ interfaces
The ext2fs_bg_flag* functions were confusing.
Currently we have this:
void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group,__u16 bg_flags);
(_set (unused) sets exactly bg_flags; _clear clears all and ignores bg_flags)
and these, which can twiddle individual bits in bg_flags:
void ext2fs_bg_flag_set(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
void ext2fs_bg_flag_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
A better interface, after the patch below, is just:
ext2fs_bg_flags_zap(fs, group) /* zeros bg_flags */
ext2fs_bg_flags_set(fs, group, flags) /* adds flags to bg_flags */
ext2fs_bg_flags_clear(fs, group, flags) /* clears flags in bg_flags */
and remove the original ext2fs_bg_flags_set / ext2fs_bg_flags_clear.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:41:32 +03:00
|
|
|
void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_flags &= ~bg_flags;
|
|
|
|
return;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the checksum for this block group
|
|
|
|
*/
|
|
|
|
__u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
return gdp->bg_checksum;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the checksum for this block group to a previously calculated value
|
|
|
|
*/
|
|
|
|
void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum)
|
|
|
|
{
|
2010-06-14 05:00:00 +04:00
|
|
|
struct ext4_group_desc *gdp;
|
2009-06-06 23:22:43 +04:00
|
|
|
|
2010-06-14 05:00:00 +04:00
|
|
|
gdp = ext4fs_group_desc(fs, fs->group_desc, group);
|
|
|
|
gdp->bg_checksum = checksum;
|
|
|
|
return;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the acl block of a file
|
|
|
|
*/
|
2011-10-17 04:29:00 +04:00
|
|
|
blk64_t ext2fs_file_acl_block(ext2_filsys fs, const struct ext2_inode *inode)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
2011-10-17 04:29:00 +04:00
|
|
|
blk64_t blk = inode->i_file_acl;
|
|
|
|
|
|
|
|
if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
blk |= ((__u64) inode->osd2.linux2.l_i_file_acl_high) << 32;
|
|
|
|
return blk;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the acl block of a file
|
|
|
|
*/
|
2011-10-17 04:29:00 +04:00
|
|
|
void ext2fs_file_acl_block_set(ext2_filsys fs, struct ext2_inode *inode,
|
|
|
|
blk64_t blk)
|
2009-06-06 23:22:43 +04:00
|
|
|
{
|
|
|
|
inode->i_file_acl = blk;
|
2011-10-17 04:29:00 +04:00
|
|
|
if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
|
|
|
|
inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32;
|
2009-06-06 23:22:43 +04:00
|
|
|
}
|
|
|
|
|
2014-07-26 22:34:56 +04:00
|
|
|
/*
|
|
|
|
* Set the size of the inode
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode,
|
|
|
|
ext2_off64_t size)
|
|
|
|
{
|
|
|
|
/* Only regular files get to be larger than 4GB */
|
|
|
|
if (!LINUX_S_ISREG(inode->i_mode) && (size >> 32))
|
|
|
|
return EXT2_ET_FILE_TOO_BIG;
|
|
|
|
|
|
|
|
/* If we're writing a large file, set the large_file flag */
|
|
|
|
if (LINUX_S_ISREG(inode->i_mode) &&
|
|
|
|
ext2fs_needs_large_file_feature(size) &&
|
|
|
|
(!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
|
|
|
|
EXT2_FEATURE_RO_COMPAT_LARGE_FILE) ||
|
|
|
|
fs->super->s_rev_level == EXT2_GOOD_OLD_REV)) {
|
|
|
|
fs->super->s_feature_ro_compat |=
|
|
|
|
EXT2_FEATURE_RO_COMPAT_LARGE_FILE;
|
|
|
|
ext2fs_update_dynamic_rev(fs);
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
}
|
|
|
|
|
|
|
|
inode->i_size = size & 0xffffffff;
|
|
|
|
inode->i_size_high = (size >> 32);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|