Skip to contentSkip to conversation

e2fsprogs: Check journal inode sanity and recreate journal

PATCH In review Kalpak Shah 2 participants 3 messages Mar 14, 2007 – May 24, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsprogs: Check journal inode sanity and recreate journal

Hi,

Currently e2fsck does not check the sanity of all the journal blocks. E2fsck does check EXT2_N_BLOCKS to check is they are sane but if any indirect blocks belonging to the journal become sparse due to corruption, e2fsck would not be able to correct this. If such a filesystem is mounted, it suddenly goes read-only if the sparse blocks are accessed. So this patch adds sanity checking for all the journal blocks.

Also, it adds support to recreate the journal if the journal had been deleted. This means that an ext3 filesystem does not end up as an ext2 filesystem. The journal size is taken from the backup journal inode in the superblock, if it exists or the default journal size will be used to recreate the journal.

Also another small change is that, if the backup journal inode from the superblock has been used, it should be written to disk.

This patch caused some existing regression tests to fail since the journal was being recreated. I have attached a patch to correct the expected output for f_badjourblks and f_miss_journal tests. Also I have attached a regression test for this patch, f_badjour_indblks, which has a corrupt indirect block in the journal inode.

e2fsck/journal.c +23 -1
Index: e2fsprogs-1.39/e2fsck/journal.c
===================================================================
@@ -206,6 +206,7 @@ static errcode_t e2fsck_get_journal(e2fs
 	int			ext_journal = 0;
 	int			tried_backup_jnl = 0;
 	int			i;
+	unsigned int            lblock;
 		
 	clear_problem_context(&pctx);
 	
@@ -283,6 +284,13 @@ static errcode_t e2fsck_get_journal(e2fs
 				goto try_backup_journal;
 			}
 		}
+		if (tried_backup_jnl && !(ctx->options & E2F_OPT_READONLY)) {
+			retval = ext2fs_write_inode(ctx->fs, sb->s_journal_inum,
+						    &j_inode->i_ext2);
+			if (retval)
+				goto errout;
+		}
+
 		journal->j_maxlen = j_inode->i_ext2.i_size / journal->j_blocksize;
 
 #ifdef USE_INODE_IO
@@ -299,6 +307,20 @@ static errcode_t e2fsck_get_journal(e2fs
 		if ((retval = journal_bmap(journal, 0, &start)) != 0)
 			goto errout;
 #endif
+		for (lblock = 0; lblock < j_inode->i_ext2.i_size /
+	    				journal->j_blocksize; lblock++) {
+			unsigned long pblock;
+
+			if ((retval = journal_bmap(journal, lblock,
+			     &pblock)) != 0) {
+				goto errout;
+			}
+			if (pblock == 0 || pblock < sb->s_first_data_block ||
+			    pblock >= sb->s_blocks_count) {
+				retval = EXT2_ET_BAD_BLOCK_NUM;
+				goto errout;
+			}
+		}
 	} else {
 		ext_journal = 1;
 		if (!ctx->journal_name) {
@@ -418,7 +440,7 @@ static errcode_t e2fsck_journal_fix_bad_
 				       "filesystem is now ext2 only ***\n\n");
 			sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
 			sb->s_journal_inum = 0;
-			ctx->flags |= E2F_FLAG_JOURNAL_INODE; /* FIXME: todo */
+			ctx->flags |= E2F_FLAG_JOURNAL_INODE;
 			e2fsck_clear_recover(ctx, 1);
 			return 0;
 		}
e2fsck/unix.c +36 -0
Index: e2fsprogs-1.39/e2fsck/unix.c
===================================================================
@@ -847,6 +847,7 @@ int main (int argc, char *argv[])
 	e2fsck_t	ctx;
 	struct problem_context pctx;
 	int flags, run_result;
+	int journal_blocks, journal_size;
 	
 	clear_problem_context(&pctx);
 #ifdef MTRACE
@@ -1141,8 +1142,43 @@ restart:
 			 " but we'll try to go on...\n"));
 	}
 
+	/*
+	 * Save the journal size in megabytes.
+	 * Try and use the journal size from the backup else let e2fsck
+	 * find the default journal size.
+	 */
+	if (sb->s_jnl_backup_type == EXT3_JNL_BACKUP_BLOCKS)
+		journal_size = sb->s_jnl_blocks[16] >> 20;
+	else
+		journal_size = -1;
+
 	run_result = e2fsck_run(ctx);
 	e2fsck_clear_progbar(ctx);
+
+	if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
+                if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
+			journal_blocks = ext2fs_figure_journal_size(journal_size, fs);
+
+			if (journal_blocks <= 0) {
+				fs->super->s_feature_compat &=
+					~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
+				goto no_journal;
+			}
+			printf(_("Creating journal (%d blocks): "), journal_blocks);
+			fflush(stdout);
+			retval = ext2fs_add_journal_inode(fs, journal_blocks, 0);
+			if (retval) {
+				com_err("Error ", retval,
+					 _("\n\twhile trying to create journal"));
+				goto no_journal;
+			}
+			printf(_(" Done.\n"));
+			printf(_("\n*** journal has been re-created - "
+				       "filesystem is now ext3 again ***\n"));
+		}
+	}
+no_journal:
+
 	if (run_result == E2F_FLAG_RESTART) {
 		printf(_("Restarting e2fsck from the beginning...\n"));
 		retval = e2fsck_reset_context(ctx);
lib/ext2fs/ext2fs.h +2 -0
Index: e2fsprogs-1.39/lib/ext2fs/ext2fs.h
===================================================================
@@ -869,6 +869,8 @@ extern errcode_t ext2fs_add_journal_devi
 					   ext2_filsys journal_dev);
 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
 					  int flags);
+extern int ext2fs_figure_journal_size(int size, ext2_filsys fs);
+
 
 /* openfs.c */
 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
lib/ext2fs/mkjournal.c +51 -0

57 lines not on this page · raw message

misc/mke2fs.c +3 -1
Index: e2fsprogs-1.39/misc/mke2fs.c
===================================================================
@@ -1649,8 +1649,10 @@ int main (int argc, char *argv[])
 	} else if ((journal_size) ||
 		   (fs_param.s_feature_compat & 
 		    EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
-		journal_blocks = figure_journal_size(journal_size, fs);
+		journal_blocks = ext2fs_figure_journal_size(journal_size, fs);
 
+		if (journal_blocks < 0)
+			exit(1);
 		if (!journal_blocks) {
 			fs->super->s_feature_compat &=
 				~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
misc/tune2fs.c +3 -1
Index: e2fsprogs-1.39/misc/tune2fs.c
===================================================================
@@ -417,8 +417,10 @@ static void add_journal(ext2_filsys fs)
 	} else if (journal_size) {
 		fputs(_("Creating journal inode: "), stdout);
 		fflush(stdout);
-		journal_blocks = figure_journal_size(journal_size, fs);
+		journal_blocks = ext2fs_figure_journal_size(journal_size, fs);
 
+		if (journal_blocks < 0)
+			exit(1);
 		retval = ext2fs_add_journal_inode(fs, journal_blocks,
 						  journal_flags);
 		if (retval) {
misc/util.c +0 -51

57 lines not on this page · raw message

misc/util.h +0 -1
Index: e2fsprogs-1.39/misc/util.h
===================================================================
@@ -22,5 +22,4 @@ extern void proceed_question(void);
 extern void check_plausibility(const char *device);
 extern void parse_journal_opts(const char *opts);
 extern void check_mount(const char *device, int force, const char *type);
-extern int figure_journal_size(int size, ext2_filsys fs);
 extern void print_check_message(ext2_filsys fs);
e2fsck/problem.c +5 -0
Index: e2fsprogs-1.39/e2fsck/problem.c
===================================================================
@@ -1479,6 +1479,11 @@ static struct e2fsck_problem problem_tab
 	  " +(%i--%j)",
 	  PROMPT_NONE, PR_LATCH_IBITMAP | PR_PREEN_OK | PR_PREEN_NOMSG },
 
+        /* Recreate journal if E2F_FLAG_JOURNAL_INODE flag is set */
+        { PR_6_RECREATE_JOURNAL,
+          N_("Recreate journal to make the filesystem ext3 again?\n"),
+          PROMPT_FIX, PR_PREEN_OK | PR_NO_OK },
+
 	{ 0 }
 };
 
e2fsck/problem.h +7 -0
Index: e2fsprogs-1.39/e2fsck/problem.h
===================================================================
@@ -892,6 +892,13 @@ struct problem_context {
 #define PR_5_INODE_RANGE_USED		0x050017
 
 /*
+ * Post-Pass 5 errors
+ */
+
+/* Recreate the journal if E2F_FLAG_JOURNAL_INODE flag is set */
+#define PR_6_RECREATE_JOURNAL		0x060000
+
+/*
  * Function declarations
  */
 int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx);

Thanks,
Kalpak.

tests/f_badjour_indblks/expect.1 new file +31 -0
Index: e2fsprogs-1.39/tests/f_badjour_indblks/expect.1
===================================================================
@@ -0,0 +1,31 @@
+Superblock has an invalid ext3 journal (inode 8).
+Clear? yes
+
+*** ext3 journal has been deleted - filesystem is now ext2 only ***
+
+Pass 1: Checking inodes, blocks, and sizes
+Journal inode is not in use, but contains data.  Clear? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(82--1111)
+Fix? yes
+
+Free blocks count wrong for group #0 (7080, counted=8110).
+Fix? yes
+
+Free blocks count wrong (7080, counted=8110).
+Fix? yes
+
+Recreate journal to make the filesystem ext3 again?
+Fix? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been re-created - filesystem is now ext3 again ***
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/256 files (9.1% non-contiguous), 1112/8192 blocks
+Exit status is 1
tests/f_badjour_indblks/expect.2 new file +7 -0
Index: e2fsprogs-1.39/tests/f_badjour_indblks/expect.2
===================================================================
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/256 files (9.1% non-contiguous), 1112/8192 blocks
+Exit status is 0
tests/f_badjour_indblks/name new file +1 -0
Index: e2fsprogs-1.39/tests/f_badjour_indblks/name
===================================================================
@@ -0,0 +1 @@
+corruption in journal inode's indirect blocks
tests/f_badjourblks/expect.1 +7 -1
Index: e2fsprogs-1.39/tests/f_badjourblks/expect.1
===================================================================
@@ -19,7 +19,13 @@ Fix? yes
 Free blocks count wrong (7112, counted=8142).
 Fix? yes
 
+Recreate journal to make the filesystem ext3 again?
+Fix? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been re-created - filesystem is now ext3 again ***
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/256 files (0.0% non-contiguous), 50/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/8192 blocks
 Exit status is 1
tests/f_badjourblks/expect.2 +1 -1
Index: e2fsprogs-1.39/tests/f_badjourblks/expect.2
===================================================================
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/256 files (0.0% non-contiguous), 50/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/8192 blocks
 Exit status is 0
tests/f_miss_journal/expect.1 +7 -1
Index: e2fsprogs-1.39/tests/f_miss_journal/expect.1
===================================================================
@@ -17,7 +17,13 @@ Fix? yes
 Free blocks count wrong (968, counted=1998).
 Fix? yes
 
+Recreate journal to make the filesystem ext3 again?
+Fix? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been re-created - filesystem is now ext3 again ***
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/256 files (0.0% non-contiguous), 50/2048 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/2048 blocks
 Exit status is 1
tests/f_miss_journal/expect.2 +1 -1
Index: e2fsprogs-1.39/tests/f_miss_journal/expect.2
===================================================================
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/256 files (0.0% non-contiguous), 50/2048 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/2048 blocks
 Exit status is 0

*** /dev/null 2007-03-15 00:26:50.565995286 +0530
--- e2fsprogs-1.39/tests/f_badjour_indblks/image.gz 2007-03-15 01:23:11.000000000 +0530
***************
*** 0 ****
--- 1 ----
+ �.�Eimage��u��u����>��q��PIQI��n�V@��N�EB@JAA�F ��N�KJ�}]P\ܳ{Ϊ�,��y�3���ߙ9��|g��� XCj����>c򁁗���Ӽ��;O���%F�X�!����+>���a�ڷ�����}��7��Ԓ˞yּW�����9Of����]�g���[ßYt��Ͼb���=���w=��cծW��k�Z�֪�k�Z�֫�k�ڰ6���5���+���5È����?�+|м��>^ �����Q�/����Μ�6�K�ӿrzj�.����:0����V���ܯ�9� {��o������^������ ���c����V��j�Z�֬�j�Z�֭�j�ڠ6���x}�+��X��{����$�:n��%k�Z���ek�Z�V�k�Z�ix��1� ������ٺ1Fۏ}p��v�i�-��y�͜+��f��0�/���> �9������0����?���_ }{ �F�Qj��Fx�7c��5�Ʃqk��&� k���&�Ik�����)k�����i�z�_u���~�����9���c�S������\�̳��E�����l���ƵImZ#����EmY����V�umS��mk��|m_;Ԏ�S�\�Ԯ�[�^{�j�ګ��}j�گ����:��C��:��#��:��X_�������j}���c��5�������V�P߮�:�N��ԩuZ�^߭3��:�ήs�{��:�Ϋ���ú�.��Euq��~R�ԥ���Y]V��ue]UW�5um]W�� uc�T7���uK�Z������U���;뮺�~S�Խ���]�W���`=T�#�h=V���d���PO���L=[����B�X/���J��^����z�ެ?�[#�|C���Z�j��F�Qk��ƨ1k����85n�W��5aMT�$5iMV��5eMUS�45mMW�� 5c}�>\3�Gj暥>Z��l5{�Qs�\����>^��O�<5o�W���`}���k�Z���k�Z����k�Z����k�Z�V��k�Z�V��k�Z�֪�k�Z�֫�k���/w����C6�d�s47��Ԧ�Ym^[Ԗ���lmU[�6��ڶ������C�X;�εK�Z���G}����j�ڧ���j�:�����:�����:�������:��\_�����:��^ߨ����f}�N�o׉uR�\��w��:�N���uf�Ug�9���~�[������a]P֏ꢺ�~\?�K���i��.��늺����뚺����놺�n��������n�����e��~]wԝuW�]��{���m�����z����z����z�~_����z������z�^����z��X��k�z�Qo֟��sgH ��V#��5J�Z���5F�Yc��5�Ʃqk��&� k���&�Ik�����)k�����ik���f��C�ᚩ>R3�,�њ�f��k���檏�����D}��yk�����S�P-\�Ԣ�X-^KԒ�T-]�Բ�\-_+Ԋ�R�\�Ԫ�Z�^kԚ�V�]�Ժ�^�_Ԇ�Q}z����&���f�ymQ[�g공Um]���j�ڮ>_���c�T;�.�k�V����ڳ���k�ڷ����:����:����:���/֗���r}��Z_�c���z}�������:��]'�Iur�RߩS�:��[gԙuV�]�����un�W���uA]X?�����q��.�K�����.�+�ʺ���k�ں����ƺ�n���/ꖺ�n������u�Qw�]uw���{��������z��G��z��'���}������z�����z�^����c�Z����F�Y��j`������5�F��k��F��k��ƪ�kx�S��x5~MP�D5qMR��d5yMQS�T5uMS��t5}�P3և��5S}�f�Y�5k�V��5g�U�������d�S��|5-P ֧j�Z��Ek�Z���%k�Z���ek�Z�V�k�Z�V�Uk�Z�֨5k�Z�֩uk�Z�6� k��tm<���צC6��k�ڲ>S���j�ڦ>W��v��ھv�k�ڹv�]k�ڽ��/Ԟ�W�]�Ծ�_�_ԁuP\�ԡuX^GԑuT}��TGח�+���ZS����u\_߬o� ��:�N����N�Z�����:�ά���:��W߯s�:�~P?� ���Q]T׏�'uI]Z?���euy]QW�Uuu]S��uu}�P7�Mus��~Q�ԭu[�^��_կ뎺��7uO�[����}u=P�C�p=R��c�x=QO����T=]�Գ�\=_/ԋ�R�\����z�^�7���S�U���` �a5R�\�Ԩ5Z�^cԘ5V�]�k��ƫ�k���&��k���&��k������k������k���>T���#5s�R�Yk����9k��X�]�O�'k�����k�Z�>U �µH-Z���D-YK�ҵL-[���B�X+�ʵJ�Z���F�Yk ���o��!������� �9���
\ No newline at end of file

#1 lore raw

lib/ext2fs/mkjournal.c errcode_t ext2fs_add_journal_device(ext2 · line 326

Quoted 8 lines · Kalpak Shah

Index: e2fsprogs-1.39/lib/ext2fs/mkjournal.c
===================================================================

lib/ext2fs/mkjournal.c +4 -0
+	if (fs->super->s_blocks_count < 2048) {
+		fputs(("\nFilesystem too small for a journal\n"), stderr);
+		return 0;
+	}

Code in lib/ext2fs isn't allowed to do any output to stdio (except for debugging purposes). It causes internationalization problems, and it's just in general a bad idea for ext2fs library code to try to do any UI.

- Ted

#2 lore raw
Quoted 15 lines · Theodore Tso

lib/ext2fs/mkjournal.c

Quoted 8 lines · Kalpak Shah

Index: e2fsprogs-1.39/lib/ext2fs/mkjournal.c
===================================================================

lib/ext2fs/mkjournal.c +4 -0
+	if (fs->super->s_blocks_count < 2048) {
+		fputs(("\nFilesystem too small for a journal\n"), stderr);
+		return 0;
+	}

Code in lib/ext2fs isn't allowed to do any output to stdio (except for debugging purposes). It causes internationalization problems, and it's just in general a bad idea for ext2fs library code to try to do any UI.

Quoted 1 line

- Ted

Hi Ted,

I have reworked the patch to make sure that lib/ext2fs does not do any output. Added that to my mistakes-not-to-be-made-again list.

Thanks,
Kalpak.

e2fsck/journal.c +23 -1
Index: e2fsprogs-1.40/e2fsck/journal.c
===================================================================
@@ -206,6 +206,7 @@ static errcode_t e2fsck_get_journal(e2fs
 	int			ext_journal = 0;
 	int			tried_backup_jnl = 0;
 	int			i;
+	blk_t			lblock;
 		
 	clear_problem_context(&pctx);
 	
@@ -283,6 +284,13 @@ static errcode_t e2fsck_get_journal(e2fs
 				goto try_backup_journal;
 			}
 		}
+		if (tried_backup_jnl && !(ctx->options & E2F_OPT_READONLY)) {
+			retval = ext2fs_write_inode(ctx->fs, sb->s_journal_inum,
+						    &j_inode->i_ext2);
+			if (retval)
+				goto errout;
+		}
+
 		journal->j_maxlen = j_inode->i_ext2.i_size / journal->j_blocksize;
 
 #ifdef USE_INODE_IO
@@ -299,6 +307,20 @@ static errcode_t e2fsck_get_journal(e2fs
 		if ((retval = journal_bmap(journal, 0, &start)) != 0)
 			goto errout;
 #endif
+		for (lblock = 0; lblock < j_inode->i_ext2.i_size /
+	    				journal->j_blocksize; lblock++) {
+			blk_t pblock;
+
+			if ((retval = journal_bmap(journal, lblock,
+			     &pblock)) != 0) {
+				goto errout;
+			}
+			if (pblock == 0 || pblock < sb->s_first_data_block ||
+			    pblock >= sb->s_blocks_count) {
+				retval = EXT2_ET_BAD_BLOCK_NUM;
+				goto errout;
+			}
+		}
 	} else {
 		ext_journal = 1;
 		if (!ctx->journal_name) {
@@ -418,7 +440,7 @@ static errcode_t e2fsck_journal_fix_bad_
 				       "filesystem is now ext2 only ***\n\n");
 			sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
 			sb->s_journal_inum = 0;
-			ctx->flags |= E2F_FLAG_JOURNAL_INODE; /* FIXME: todo */
+			ctx->flags |= E2F_FLAG_JOURNAL_INODE;
 			e2fsck_clear_recover(ctx, 1);
 			return 0;
 		}
e2fsck/unix.c +40 -0
Index: e2fsprogs-1.40/e2fsck/unix.c
===================================================================
@@ -849,6 +849,7 @@ int main (int argc, char *argv[])
 	e2fsck_t	ctx;
 	struct problem_context pctx;
 	int flags, run_result;
+	int journal_size;
 	
 	clear_problem_context(&pctx);
 #ifdef MTRACE
@@ -1143,8 +1144,47 @@ restart:
 			 " but we'll try to go on...\n"));
 	}
 
+	/*
+	 * Save the journal size in megabytes.
+	 * Try and use the journal size from the backup else let e2fsck
+	 * find the default journal size.
+	 */
+	if (sb->s_jnl_backup_type == EXT3_JNL_BACKUP_BLOCKS)
+		journal_size = sb->s_jnl_blocks[16] >> 20;
+	else
+		journal_size = -1;
+
 	run_result = e2fsck_run(ctx);
 	e2fsck_clear_progbar(ctx);
+
+	if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
+		if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
+			retval = ext2fs_figure_journal_size(&journal_size, fs);
+
+			if (journal_size && retval) {
+				fs->super->s_feature_compat &=
+					~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
+				com_err("Error ", retval, _("\n\twhile "
+					"trying to create journal file"));
+				goto no_journal;
+			}
+			printf(_("Creating journal (%d blocks): "),
+			       journal_size);
+			fflush(stdout);
+			retval = ext2fs_add_journal_inode(fs,
+							  journal_size, 0);
+			if (retval) {
+				com_err("Error ", retval,
+					_("\n\twhile trying to create journal"));
+				goto no_journal;
+			}
+			printf(_(" Done.\n"));
+			printf(_("\n*** journal has been re-created - "
+				       "filesystem is now ext3 again ***\n"));
+		}
+	}
+no_journal:
+
 	if (run_result == E2F_FLAG_RESTART) {
 		printf(_("Restarting e2fsck from the beginning...\n"));
 		retval = e2fsck_reset_context(ctx);
lib/ext2fs/ext2fs.h +2 -0
Index: e2fsprogs-1.40/lib/ext2fs/ext2fs.h
===================================================================
@@ -879,6 +879,8 @@ extern errcode_t ext2fs_add_journal_devi
 					   ext2_filsys journal_dev);
 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
 					  int flags);
+extern int ext2fs_figure_journal_size(int *size, ext2_filsys fs);
+
 
 /* openfs.c */
 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
lib/ext2fs/mkjournal.c +45 -0

51 lines not on this page · raw message

misc/mke2fs.c +9 -4
Index: e2fsprogs-1.40/misc/mke2fs.c
===================================================================
@@ -1691,19 +1691,24 @@ int main (int argc, char *argv[])
 	} else if ((journal_size) ||
 		   (fs_param.s_feature_compat & 
 		    EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
-		journal_blocks = figure_journal_size(journal_size, fs);
+		retval = ext2fs_figure_journal_size(&journal_size, fs);
 
-		if (!journal_blocks) {
+		if (journal_size && retval) {
+			com_err(program_name, retval,
+				_("\n\twhile trying to create journal file"));
+			exit(1);
+		}
+		if (!journal_size) {
 			fs->super->s_feature_compat &=
 				~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
 			goto no_journal;
 		}
 		if (!quiet) {
 			printf(_("Creating journal (%d blocks): "),
-			       journal_blocks);
+			       journal_size);
 			fflush(stdout);
 		}
-		retval = ext2fs_add_journal_inode(fs, journal_blocks,
+		retval = ext2fs_add_journal_inode(fs, journal_size,
 						  journal_flags);
 		if (retval) {
 			com_err (program_name, retval,
misc/tune2fs.c +7 -3
Index: e2fsprogs-1.40/misc/tune2fs.c
===================================================================
@@ -373,7 +373,6 @@ static void update_feature_set(ext2_fils
  */
 static void add_journal(ext2_filsys fs)
 {
-	unsigned long journal_blocks;
 	errcode_t	retval;
 	ext2_filsys	jfs;
 	io_manager	io_ptr;
@@ -417,9 +416,14 @@ static void add_journal(ext2_filsys fs)
 	} else if (journal_size) {
 		fputs(_("Creating journal inode: "), stdout);
 		fflush(stdout);
-		journal_blocks = figure_journal_size(journal_size, fs);
+		retval = ext2fs_figure_journal_size(&journal_size, fs);
 
-		retval = ext2fs_add_journal_inode(fs, journal_blocks,
+		if (journal_size && retval) {
+			com_err(program_name, retval,
+				_("\n\twhile trying to create journal file"));
+			exit(1);
+		}
+		retval = ext2fs_add_journal_inode(fs, journal_size,
 						  journal_flags);
 		if (retval) {
 			fprintf(stderr, "\n");
misc/util.c +0 -51

57 lines not on this page · raw message

misc/util.h +0 -1
Index: e2fsprogs-1.40/misc/util.h
===================================================================
@@ -22,5 +22,4 @@ extern void proceed_question(void);
 extern void check_plausibility(const char *device);
 extern void parse_journal_opts(const char *opts);
 extern void check_mount(const char *device, int force, const char *type);
-extern int figure_journal_size(int size, ext2_filsys fs);
 extern void print_check_message(ext2_filsys fs);
e2fsck/problem.c +5 -0
Index: e2fsprogs-1.40/e2fsck/problem.c
===================================================================
@@ -1489,6 +1489,11 @@ static struct e2fsck_problem problem_tab
 	  " +(%i--%j)",
 	  PROMPT_NONE, PR_LATCH_IBITMAP | PR_PREEN_OK | PR_PREEN_NOMSG },
 
+	/* Recreate journal if E2F_FLAG_JOURNAL_INODE flag is set */
+	{ PR_6_RECREATE_JOURNAL,
+	  N_("Recreate journal to make the filesystem ext3 again?\n"),
+	  PROMPT_FIX, PR_PREEN_OK | PR_NO_OK },
+
 	{ 0 }
 };
 
e2fsck/problem.h +7 -0
Index: e2fsprogs-1.40/e2fsck/problem.h
===================================================================
@@ -898,6 +898,13 @@ struct problem_context {
 #define PR_5_INODE_RANGE_USED		0x050017
 
 /*
+ * Post-Pass 5 errors
+ */
+
+/* Recreate the journal if E2F_FLAG_JOURNAL_INODE flag is set */
+#define PR_6_RECREATE_JOURNAL		0x060000
+
+/*
  * Function declarations
  */
 int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx);
lib/ext2fs/ext2_err.et.in +9 -0
Index: e2fsprogs-1.40/lib/ext2fs/ext2_err.et.in
===================================================================
@@ -275,6 +275,15 @@ ec	EXT2_ET_LOAD_EXT_JOURNAL,
 ec	EXT2_ET_NO_JOURNAL,
 	"Journal not found"
 
+ec	EXT2_ET_JOURNAL_FS_TOO_SMALL,
+	"Filesystem too small for a journal"
+
+ec	EXT2_ET_JOURNAL_TOO_BIG,
+	"Journal size too big for filesystem"
+
+ec	EXT2_ET_JOURNAL_INVALID_SIZE,
+	"The journal size must be between 1024 and 102400 blocks."
+
 ec	EXT2_ET_DIRHASH_UNSUPP,
 	"Directory hash unsupported"