From d007cb4cbb4b8b190ffd9a597f0e88ea365926c5 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 4 Aug 2001 20:39:39 -0400 Subject: [PATCH] Cleanup changes to Andreas' symlink patch. Remove use of EXT2_LINK_DIR Also cleaned up the symlink handling code to make it a bit more compact and to test for a bad symlink block earlier. --- e2fsck/ChangeLog | 15 +++++++++++++++ e2fsck/pass1.c | 26 ++++++++++---------------- e2fsck/pass2.c | 1 - e2fsck/problem.c | 10 +++++----- lib/ext2fs/ext2_fs.h | 2 -- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 9b7f0af2..d2c422d3 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,18 @@ +2001-08-04 Theodore Tso + + * problem.c (PR_2_SYMLINK_SIZE): Change description to make it + more clear (and remove %s expansion). Also add missing + periods to the end of a number of problem descriptions. + + * pass2.c (e2fsck_process_bad_inode): Remove unneeded problem + context string set now that the problem description for + PR_2_SYMLINK_SIZE has been changed. + + * pass1.c (e2fsck_pass1_check_symlink): Consolidate some checks, + and check the validity of the symlink block here (so that + we detect this case here instead of later). Also use + sizeof(inode->i_block) instead EXT2_LINK_DIR. + 2001-07-30 Theodore Tso * unix.c (check_mount): Remove the code which tested for the root diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index a8188ff7..ebed95d2 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -152,35 +152,31 @@ int e2fsck_pass1_check_device_inode(struct ext2_inode *inode) */ int e2fsck_pass1_check_symlink(ext2_filsys fs, struct ext2_inode *inode) { - if (inode->i_size_high || inode->i_size == 0) - return 0; + int i; - if (inode->i_flags & (EXT2_IMMUTABLE_FL |EXT2_APPEND_FL |EXT2_INDEX_FL)) + if ((inode->i_size_high || inode->i_size == 0) || + (inode->i_flags & (EXT2_IMMUTABLE_FL | EXT2_APPEND_FL | + EXT2_INDEX_FL))) return 0; if (inode->i_blocks) { - int i; - - if (inode->i_blocks > fs->blocksize >> 9) + if ((inode->i_size > fs->blocksize) || + (inode->i_blocks != fs->blocksize >> 9) || + (inode->i_block[0] < fs->super->s_first_data_block) || + (inode->i_block[0] >= fs->super->s_blocks_count)) return 0; for (i = 1; i < EXT2_N_BLOCKS; i++) if (inode->i_block[i]) return 0; - - if (inode->i_size > fs->blocksize) - return 0; - - /* Defer check of i_size until block number validated */ } else { - if (inode->i_size > EXT2_LINK_DIR - 1) + if (inode->i_size > sizeof(inode->i_block) - 1) return 0; if (inode->i_size != - strnlen((char *)inode->i_block, EXT2_LINK_DIR)) + strnlen((char *)inode->i_block, sizeof(inode->i_block))) return 0; } - return 1; } @@ -1261,8 +1257,6 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, pctx->num = pb.num_blocks; if (fix_problem(ctx, PR_1_BAD_I_BLOCKS, pctx)) { inode->i_blocks = pb.num_blocks; - if (LINUX_S_ISLNK(inode->i_mode)) - mark_inode_bad(ctx, ino); e2fsck_write_inode(ctx, ino, inode, "check_blocks"); } pctx->num = 0; diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index 0d27d96c..7575b81c 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -700,7 +700,6 @@ extern int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir, problem = PR_2_BAD_SOCKET; else if (LINUX_S_ISLNK(inode.i_mode) && !e2fsck_pass1_check_symlink(fs, &inode)) { - pctx.str = inode.i_blocks ? "" : "fast "; problem = PR_2_SYMLINK_SIZE; } diff --git a/e2fsck/problem.c b/e2fsck/problem.c index ebfaab47..34f4e9d4 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -913,22 +913,22 @@ static const struct e2fsck_problem problem_table[] = { /* Directory filetype incorrect */ { PR_2_BAD_FILETYPE, - N_("@E has an incorrect filetype (was %dt, should be %N)\n"), + N_("@E has an incorrect filetype (was %dt, should be %N).\n"), PROMPT_FIX, 0 }, /* Directory filetype set on filesystem */ { PR_2_CLEAR_FILETYPE, - N_("@E has filetype set\n"), + N_("@E has filetype set.\n"), PROMPT_CLEAR, PR_PREEN_OK }, /* Directory filename is null */ { PR_2_NULL_NAME, - N_("@E has a zero-length name\n"), + N_("@E has a zero-length name.\n"), PROMPT_CLEAR, 0 }, /* Invalid fast symlink size */ { PR_2_SYMLINK_SIZE, - N_("@i %i (%Q) is a %ssymlink with a bad size (%Is)\n"), + N_("Symlink %Q (@i #%i) has an invalid size (%Is).\n"), PROMPT_CLEAR, 0 }, /* i_file_acl (extended attribute block) is bad */ @@ -970,7 +970,7 @@ static const struct e2fsck_problem problem_table[] = { /* Bad or non-existent /lost+found. Cannot reconnect */ { PR_3_NO_LPF, - N_("Bad or non-existent /@l. Cannot reconnect\n"), + N_("Bad or non-existent /@l. Cannot reconnect.\n"), PROMPT_NONE, 0 }, /* Could not expand /lost+found */ diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index 0a773d16..0eb7be71 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -169,8 +169,6 @@ struct ext2_group_desc #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1) #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1) -#define EXT2_LINK_DIR (EXT2_N_BLOCKS * 4) - /* * Inode flags */