diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index a3a8e1cc..bc6ffa18 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -150,6 +150,7 @@ void e2fsck_pass2(e2fsck_t ctx) mtrace_print("Pass 2"); #endif + fs->flags |= EXT2_FLAG_IGNORE_SWAP_DIRENT; if (!(ctx->options & E2F_OPT_PREEN)) fix_problem(ctx, PR_2_PASS_HEADER, &cd.pctx); @@ -317,6 +318,7 @@ void e2fsck_pass2(e2fsck_t ctx) print_resource_track(ctx, _("Pass 2"), &rtrack, fs->io); cleanup: ext2fs_free_mem(&buf); + fs->flags &= ~EXT2_FLAG_IGNORE_SWAP_DIRENT; } #define MAX_DEPTH 32000 diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 5d924fda..e5b672a2 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -75,15 +75,11 @@ int journal_enable_debug = -1; static void usage(e2fsck_t ctx) { - char *program_name = "e2fsck"; - - if (ctx && ctx->program_name) - program_name = ctx>program_name; fprintf(stderr, _("Usage: %s [-panyrcdfktvDFV] [-b superblock] [-B blocksize]\n" "\t\t[-l|-L bad_blocks_file] [-C fd] [-j external_journal]\n" "\t\t[-E extended-options] [-z undo_file] device\n"), - program_name); + ctx->program_name ? ctx->program_name : "e2fsck"); fprintf(stderr, "%s", _("\nEmergency help:\n" " -p Automatic repair (no questions)\n" diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 68f9c1fe..9cc994b1 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -219,6 +219,7 @@ typedef struct ext2_file *ext2_file_t; #define EXT2_FLAG_BBITMAP_TAIL_PROBLEM 0x1000000 #define EXT2_FLAG_IBITMAP_TAIL_PROBLEM 0x2000000 #define EXT2_FLAG_THREADS 0x4000000 +#define EXT2_FLAG_IGNORE_SWAP_DIRENT 0x8000000 /* * Special flag in the ext2 inode i_flag field that means that this is diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c index 6f8582a8..23290a6a 100644 --- a/lib/ext2fs/imager.c +++ b/lib/ext2fs/imager.c @@ -372,6 +372,8 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) size = sizeof(buf); if (size > (cnt >> 3)) size = (cnt >> 3); + if (size == 0) + break; retval = ext2fs_get_generic_bmap_range(bmap, itr, size << 3, buf); @@ -447,6 +449,8 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) size = sizeof(buf); if (size > (cnt >> 3)) size = (cnt >> 3); + if (size == 0) + break; actual = read(fd, buf, size); if (actual == -1) diff --git a/lib/ext2fs/swapfs.c b/lib/ext2fs/swapfs.c index aa2d8268..fe764b9e 100644 --- a/lib/ext2fs/swapfs.c +++ b/lib/ext2fs/swapfs.c @@ -435,11 +435,14 @@ errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf, return retval; if ((rec_len < 8) || (rec_len % 4)) { rec_len = 8; - retval = EXT2_ET_DIR_CORRUPTED; + if (!(fs->flags & EXT2_FLAG_IGNORE_SWAP_DIRENT)) + return EXT2_ET_DIR_CORRUPTED; } else if (((name_len & 0xFF) + 8) > rec_len) - retval = EXT2_ET_DIR_CORRUPTED; + if (!(fs->flags & EXT2_FLAG_IGNORE_SWAP_DIRENT)) + return EXT2_ET_DIR_CORRUPTED; if (rec_len > left) - return EXT2_ET_DIR_CORRUPTED; + if (!(fs->flags & EXT2_FLAG_IGNORE_SWAP_DIRENT)) + return EXT2_ET_DIR_CORRUPTED; left -= rec_len; p += rec_len; } diff --git a/misc/e2image.c b/misc/e2image.c index 079c6812..1ae03001 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -1263,7 +1263,7 @@ static void output_qcow2_meta_data_blocks(ext2_filsys fs, int fd) offset += img->cluster_size; } } - update_refcount(fd, img, offset, offset); + (void) update_refcount(fd, img, offset, offset); flush_l2_cache(img); sync_refcount(fd, img);