163
163
* Check to make sure a symlink inode is real. Returns 1 if the symlink
164
164
* checks out, 0 if not.
166
int e2fsck_pass1_check_symlink(ext2_filsys fs, struct ext2_inode *inode,
166
int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
167
struct ext2_inode *inode, char *buf)
169
169
unsigned int len;
172
ext2_extent_handle_t handle;
173
struct ext2_extent_info info;
174
struct ext2fs_extent extent;
173
176
if ((inode->i_size_high || inode->i_size == 0) ||
174
177
(inode->i_flags & EXT2_INDEX_FL))
180
if (inode->i_flags & EXT4_EXTENTS_FL) {
181
if (inode->i_size > fs->blocksize)
183
if (ext2fs_extent_open(fs, ino, &handle))
186
if (ext2fs_extent_get_info(handle, &info) ||
187
(info.num_entries != 1) ||
188
(info.max_depth != 0))
190
if (ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent) ||
191
(extent.e_lblk != 0) ||
192
(extent.e_len != 1) ||
193
(extent.e_pblk < fs->super->s_first_data_block) ||
194
(extent.e_pblk >= fs->super->s_blocks_count))
198
ext2fs_extent_free(handle);
177
202
blocks = ext2fs_inode_data_blocks(fs, inode);
179
204
if ((inode->i_size >= fs->blocksize) ||
685
* Test for incorrect extent flag settings.
687
* On big-endian machines we must be careful:
688
* When the inode is read, the i_block array is not swapped
689
* if the extent flag is set. Therefore if we are testing
690
* for or fixing a wrongly-set flag, we must potentially
691
* (un)swap before testing, or after fixing.
695
* In this case the extents flag was set when read, so
696
* extent_header_verify is ok. If the inode is cleared,
697
* no need to swap... so no extra swapping here.
699
if ((inode->i_flags & EXT4_EXTENTS_FL) && !extent_fs &&
700
(inode->i_links_count || (ino == EXT2_BAD_INO) ||
701
(ino == EXT2_ROOT_INO) || (ino == EXT2_JOURNAL_INO))) {
702
if ((ext2fs_extent_header_verify(inode->i_block,
703
sizeof(inode->i_block)) == 0) &&
704
fix_problem(ctx, PR_1_EXTENT_FEATURE, &pctx)) {
705
sb->s_feature_incompat |= EXT3_FEATURE_INCOMPAT_EXTENTS;
706
ext2fs_mark_super_dirty(fs);
708
} else if (fix_problem(ctx, PR_1_EXTENTS_SET, &pctx)) {
710
e2fsck_clear_inode(ctx, ino, inode, 0, "pass1");
711
if (ino == EXT2_BAD_INO)
712
ext2fs_mark_inode_bitmap(ctx->inode_used_map,
719
* For big-endian machines:
720
* If the inode didn't have the extents flag set when it
721
* was read, then the i_blocks array was swapped. To test
722
* as an extents header, we must swap it back first.
723
* IF we then set the extents flag, the entire i_block
724
* array must be un/re-swapped to make it proper extents data.
726
if (extent_fs && !(inode->i_flags & EXT4_EXTENTS_FL) &&
727
(inode->i_links_count || (ino == EXT2_BAD_INO) ||
728
(ino == EXT2_ROOT_INO) || (ino == EXT2_JOURNAL_INO)) &&
729
(LINUX_S_ISREG(inode->i_mode) ||
730
LINUX_S_ISDIR(inode->i_mode))) {
732
#ifdef WORDS_BIGENDIAN
733
__u32 tmp_block[EXT2_N_BLOCKS];
735
for (i = 0; i < EXT2_N_BLOCKS; i++)
736
tmp_block[i] = ext2fs_swab32(inode->i_block[i]);
739
ehp = inode->i_block;
741
if ((ext2fs_extent_header_verify(ehp,
742
sizeof(inode->i_block)) == 0) &&
743
(fix_problem(ctx, PR_1_UNSET_EXTENT_FL, &pctx))) {
744
inode->i_flags |= EXT4_EXTENTS_FL;
745
#ifdef WORDS_BIGENDIAN
746
memcpy(inode->i_block, tmp_block,
747
sizeof(inode->i_block));
749
e2fsck_write_inode(ctx, ino, inode, "pass1");
656
753
if (ino == EXT2_BAD_INO) {
657
754
struct process_block_struct pb;
868
954
check_inode_extra_space(ctx, &pctx);
869
955
check_is_really_dir(ctx, &pctx, block_buf);
958
* ext2fs_inode_has_valid_blocks does not actually look
959
* at i_block[] values, so not endian-sensitive here.
961
if (extent_fs && (inode->i_flags & EXT4_EXTENTS_FL) &&
962
LINUX_S_ISLNK(inode->i_mode) &&
963
!ext2fs_inode_has_valid_blocks(inode) &&
964
fix_problem(ctx, PR_1_FAST_SYMLINK_EXTENT_FL, &pctx)) {
965
inode->i_flags &= ~EXT4_EXTENTS_FL;
966
e2fsck_write_inode(ctx, ino, inode, "pass1");
871
969
if (LINUX_S_ISDIR(inode->i_mode)) {
872
970
ext2fs_mark_inode_bitmap(ctx->inode_dir_map, ino);
873
971
e2fsck_add_dir_info(ctx, ino, 0);
1431
1545
fix_problem(ctx, PR_1_HTREE_SET, pctx)))
1434
blk = inode->i_block[0];
1436
(blk < fs->super->s_first_data_block) ||
1437
(blk >= fs->super->s_blocks_count)) &&
1438
fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
1548
pctx->errcode = ext2fs_bmap(fs, ino, inode, 0, 0, 0, &blk);
1550
if ((pctx->errcode) ||
1552
(blk < fs->super->s_first_data_block) ||
1553
(blk >= fs->super->s_blocks_count)) {
1554
if (fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
1441
1560
retval = io_channel_read_blk(fs->io, blk, 1, block_buf);
1442
1561
if (retval && fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
1590
void e2fsck_clear_inode(e2fsck_t ctx, ext2_ino_t ino,
1591
struct ext2_inode *inode, int restart_flag,
1595
inode->i_links_count = 0;
1596
ext2fs_icount_store(ctx->inode_link_info, ino, 0);
1597
inode->i_dtime = ctx->now;
1599
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
1600
ext2fs_unmark_inode_bitmap(ctx->inode_used_map, ino);
1601
if (ctx->inode_reg_map)
1602
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
1603
if (ctx->inode_bad_map)
1604
ext2fs_unmark_inode_bitmap(ctx->inode_bad_map, ino);
1607
* If the inode was partially accounted for before processing
1608
* was aborted, we need to restart the pass 1 scan.
1610
ctx->flags |= restart_flag;
1612
e2fsck_write_inode(ctx, ino, inode, source);
1615
static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx,
1616
struct process_block_struct *pb,
1617
blk64_t start_block,
1618
ext2_extent_handle_t ehandle)
1620
struct ext2fs_extent extent;
1622
e2_blkcnt_t blockcnt;
1624
int is_dir, is_leaf;
1626
struct ext2_extent_info info;
1628
pctx->errcode = ext2fs_extent_get_info(ehandle, &info);
1632
pctx->errcode = ext2fs_extent_get(ehandle, EXT2_EXTENT_FIRST_SIB,
1634
while (!pctx->errcode && info.num_entries-- > 0) {
1635
is_leaf = extent.e_flags & EXT2_EXTENT_FLAGS_LEAF;
1636
is_dir = LINUX_S_ISDIR(pctx->inode->i_mode);
1639
if (extent.e_pblk < ctx->fs->super->s_first_data_block ||
1640
extent.e_pblk >= ctx->fs->super->s_blocks_count)
1641
problem = PR_1_EXTENT_BAD_START_BLK;
1642
else if (extent.e_lblk < start_block)
1643
problem = PR_1_OUT_OF_ORDER_EXTENTS;
1645
(extent.e_pblk + extent.e_len) >
1646
ctx->fs->super->s_blocks_count)
1647
problem = PR_1_EXTENT_ENDS_BEYOND;
1650
pctx->blk = extent.e_pblk;
1651
pctx->blk2 = extent.e_lblk;
1652
pctx->num = extent.e_len;
1653
if (fix_problem(ctx, problem, pctx)) {
1655
ext2fs_extent_delete(ehandle, 0);
1656
if (pctx->errcode) {
1658
PR_1_EXTENT_DELETE_FAIL,
1660
/* Should never get here */
1661
ctx->flags |= E2F_FLAG_ABORT;
1664
pctx->errcode = ext2fs_extent_get(ehandle,
1665
EXT2_EXTENT_CURRENT,
1667
if (pctx->errcode == EXT2_ET_NO_CURRENT_NODE) {
1677
mark_block_used(ctx, extent.e_pblk);
1679
pctx->errcode = ext2fs_extent_get(ehandle,
1680
EXT2_EXTENT_DOWN, &extent);
1681
if (pctx->errcode) {
1682
printf("Error1: %s on inode %u\n",
1683
error_message(pctx->errcode), pctx->ino);
1686
scan_extent_node(ctx, pctx, pb, extent.e_lblk, ehandle);
1687
pctx->errcode = ext2fs_extent_get(ehandle,
1688
EXT2_EXTENT_UP, &extent);
1689
if (pctx->errcode) {
1690
printf("Error1: %s on inode %u\n",
1691
error_message(pctx->errcode), pctx->ino);
1697
for (blk = extent.e_pblk, blockcnt = extent.e_lblk, i = 0;
1699
blk++, blockcnt++, i++) {
1700
mark_block_used(ctx, blk);
1703
pctx->errcode = ext2fs_add_dir_block(ctx->fs->dblist, pctx->ino, blk, blockcnt);
1704
if (pctx->errcode) {
1706
pctx->num = blockcnt;
1707
fix_problem(ctx, PR_1_ADD_DBLOCK, pctx);
1708
/* Should never get here */
1709
ctx->flags |= E2F_FLAG_ABORT;
1714
pb->num_blocks += extent.e_len;
1715
start_block = pb->last_block = extent.e_lblk + extent.e_len - 1;
1717
pctx->errcode = ext2fs_extent_get(ehandle,
1718
EXT2_EXTENT_NEXT_SIB,
1721
if (pctx->errcode == EXT2_ET_EXTENT_NO_NEXT)
1725
static void check_blocks_extents(e2fsck_t ctx, struct problem_context *pctx,
1726
struct process_block_struct *pb)
1728
struct ext2_inode *inode = pctx->inode;
1729
ext2_extent_handle_t ehandle;
1730
ext2_filsys fs = ctx->fs;
1731
ext2_ino_t ino = pctx->ino;
1733
pctx->errcode = ext2fs_extent_open(fs, ino, &ehandle);
1734
if (pctx->errcode &&
1735
fix_problem(ctx, PR_1_READ_EXTENT, pctx)) {
1736
e2fsck_clear_inode(ctx, ino, inode, 0, "check_blocks_extents");
1741
scan_extent_node(ctx, pctx, pb, 0, ehandle);
1743
ext2fs_extent_free(ehandle);
1472
1747
* This subroutine is called on each inode to account for all of the
1473
1748
* blocks used by that inode.
1515
if (inode->i_file_acl && check_ext_attr(ctx, pctx, block_buf))
1794
if (inode->i_file_acl && check_ext_attr(ctx, pctx, block_buf)) {
1795
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1516
1797
pb.num_blocks++;
1518
if (ext2fs_inode_has_valid_blocks(inode))
1519
pctx->errcode = ext2fs_block_iterate2(fs, ino,
1520
pb.is_dir ? BLOCK_FLAG_HOLE : 0,
1521
block_buf, process_block, &pb);
1800
if (ext2fs_inode_has_valid_blocks(inode)) {
1801
if (extent_fs && (inode->i_flags & EXT4_EXTENTS_FL))
1802
check_blocks_extents(ctx, pctx, &pb);
1804
pctx->errcode = ext2fs_block_iterate2(fs, ino,
1805
pb.is_dir ? BLOCK_FLAG_HOLE : 0,
1806
block_buf, process_block, &pb);
1522
1808
end_problem_latch(ctx, PR_LATCH_BLOCK);
1523
1809
end_problem_latch(ctx, PR_LATCH_TOOBIG);
1524
1810
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1584
1859
if (!pb.num_blocks && pb.is_dir) {
1585
1860
if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
1586
inode->i_links_count = 0;
1587
ext2fs_icount_store(ctx->inode_link_info, ino, 0);
1588
inode->i_dtime = ctx->now;
1590
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
1591
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
1592
ext2fs_unmark_inode_bitmap(ctx->inode_used_map, ino);
1861
e2fsck_clear_inode(ctx, ino, inode, 0, "check_blocks");
1593
1862
ctx->fs_directory_count--;
1598
pb.num_blocks *= (fs->blocksize / 512);
1867
if (!(fs->super->s_feature_ro_compat &
1868
EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
1869
!(inode->i_flags & EXT4_HUGE_FILE_FL))
1870
pb.num_blocks *= (fs->blocksize / 512);
1600
1872
printf("inode %u, i_size = %lu, last_block = %lld, i_blocks=%lu, num_blocks = %lu\n",
1601
1873
ino, inode->i_size, pb.last_block, inode->i_blocks,
2526
static errcode_t e2fsck_get_alloc_block(ext2_filsys fs, blk64_t goal,
2529
e2fsck_t ctx = (e2fsck_t) fs->priv_data;
2533
if (ctx->block_found_map) {
2534
retval = ext2fs_new_block(fs, (blk_t) goal,
2535
ctx->block_found_map, &new_block);
2539
if (!fs->block_map) {
2540
retval = ext2fs_read_block_bitmap(fs);
2545
retval = ext2fs_new_block(fs, (blk_t) goal, 0, &new_block);
2554
static void e2fsck_block_alloc_stats(ext2_filsys fs, blk64_t blk, int inuse)
2556
e2fsck_t ctx = (e2fsck_t) fs->priv_data;
2558
if (ctx->block_found_map) {
2560
ext2fs_mark_block_bitmap(ctx->block_found_map,
2563
ext2fs_unmark_block_bitmap(ctx->block_found_map,
2243
2568
void e2fsck_use_inode_shortcuts(e2fsck_t ctx, int bool)
2245
2570
ext2_filsys fs = ctx->fs;