From patchwork Tue Jan 29 17:51:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Blagodarenko X-Patchwork-Id: 1032931 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PCFPfbwk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pvFr2Qh1z9s1l for ; Wed, 30 Jan 2019 04:52:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728022AbfA2RwA (ORCPT ); Tue, 29 Jan 2019 12:52:00 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:38446 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbfA2Rv7 (ORCPT ); Tue, 29 Jan 2019 12:51:59 -0500 Received: by mail-it1-f194.google.com with SMTP id z20so5891141itc.3 for ; Tue, 29 Jan 2019 09:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3+Et5nP7uv92grLMjDx+Rta0GfSYsc+7mr2xH64pblU=; b=PCFPfbwk2KC//PzyPJz5PxBMAFRircsD0XjgwRBlqVUMWIpPpprcyM7Ewxktmrwwv3 xm+VqiNvh3eYqBH/piEGPW1d+3Wtl65Dlis0xSmMOJwpS06MtYBijFX99IXcHBS8g3KR ChbDlnU28S+ZpP2SUaLYlaRclQUW7uGOF+sUEyzMD9R17g37JTaGpPOEke8ZC0V0lMu7 oQxzBsOI03W6n3koHwM0BKgZCx1fRpmL4jd68LkU3ZJJ7F6VFQyuqC8O3tDdMbL5BqtZ WnRlUv2wNY4op3z85xJ/iHGmBhUmIHVyBKj/jruqSHfPYr/kPh1Rl1HxXVMt0VnCuV+E mtvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3+Et5nP7uv92grLMjDx+Rta0GfSYsc+7mr2xH64pblU=; b=auC1clNmsrX1UrD2XEbsYKCpeW2aldHMIOdbKIN9yp8eKidiLJJg8uG58Btr2qyLVF 9TELoXZK0EB9MEUBu/eWidNFXc7tMS3C4NxE5YgaKUNzKMIXjhS4FUjOQf4TS8qdOpeT 2Pb87QziiXY6B8nL+2ReX64hGIF6kzP/OtFlwCk4rOxvimHG3x1wCvitB4HT6hCzPCJa a/GOkpJUWTVxvPJO/2q+5JrkoYd5Sf+TqX2sWjEH1jbv0kSO7E9Xu3hatL0Hl4J3Wa+x 1OlrJVnLT6EnnOXJZkyN/VZFffuMjmQXs6iswBn8lBv1bgj1ckIkVyXbcMr4g1LSot65 iEwA== X-Gm-Message-State: AJcUukcP7WHVXNKW5VS5J6JkgkJNE9DQ/vjagUtYZvn8hEiqe7NN5Irr OXeMilK4/90BdxJP1epu6YRI3bR/ooI= X-Google-Smtp-Source: ALg8bN5sX1IemyK14o27WySLJFWNGb1POb/hXzIBvGdBMNuMP4tgvXNSnwLAlI4CAW39uF8KtFi1zg== X-Received: by 2002:a02:85ae:: with SMTP id d43mr17034558jai.70.1548784318464; Tue, 29 Jan 2019 09:51:58 -0800 (PST) Received: from C02TN4C6HTD6.us.cray.com ([63.239.150.218]) by smtp.gmail.com with ESMTPSA id b5sm15838778ioc.21.2019.01.29.09.51.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:51:58 -0800 (PST) From: Artem Blagodarenko X-Google-Original-From: Artem Blagodarenko To: linux-ext4@vger.kernel.org Cc: adilger.kernel@dilger.ca Subject: [PATCH v7 1/4] ext2fs: opening filesystem code refactoring Date: Tue, 29 Jan 2019 20:51:31 +0300 Message-Id: <20190129175134.26652-2-c17828@cray.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20190129175134.26652-1-c17828@cray.com> References: <20190129175134.26652-1-c17828@cray.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There are similar opening filesystem code in different utilities. The patch moves improved handling from try_open_fs() into ext2fs_open(). This function make one of the action based on parameters: 1) open filesystem with given superblock, superblock size 2) open filesystem with given superblock, but try to find right block size Signed-off-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- e2fsck/unix.c | 28 +++------------------------- lib/ext2fs/openfs.c | 39 +++++++++++++++++++++++++++++++++++---- misc/dumpe2fs.c | 17 ++--------------- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 5b3552ec..ddcf52a4 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1151,31 +1151,9 @@ static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr, ext2_filsys *ret_fs) { errcode_t retval; - - *ret_fs = NULL; - if (ctx->superblock && ctx->blocksize) { - retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, - flags, ctx->superblock, ctx->blocksize, - io_ptr, ret_fs); - } else if (ctx->superblock) { - int blocksize; - for (blocksize = EXT2_MIN_BLOCK_SIZE; - blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) { - if (*ret_fs) { - ext2fs_free(*ret_fs); - *ret_fs = NULL; - } - retval = ext2fs_open2(ctx->filesystem_name, - ctx->io_options, flags, - ctx->superblock, blocksize, - io_ptr, ret_fs); - if (!retval) - break; - } - } else - retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, - flags, 0, 0, io_ptr, ret_fs); - + retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, + flags, ctx->superblock, ctx->blocksize, + io_ptr, ret_fs); if (retval == 0) { (*ret_fs)->priv_data = ctx; e2fsck_set_bitmap_type(*ret_fs, EXT2FS_BMAP64_RBTREE, diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 85d73e2a..16d36200 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -114,10 +114,10 @@ static void block_sha_map_free_entry(void *data) * EXT2_FLAG_64BITS - Allow 64-bit bitfields (needed for large * filesystems) */ -errcode_t ext2fs_open2(const char *name, const char *io_options, - int flags, int superblock, - unsigned int block_size, io_manager manager, - ext2_filsys *ret_fs) +static errcode_t __ext2fs_open2(const char *name, const char *io_options, + int flags, int superblock, + unsigned int block_size, io_manager manager, + ext2_filsys *ret_fs) { ext2_filsys fs; errcode_t retval; @@ -515,6 +515,37 @@ cleanup: return retval; } +errcode_t ext2fs_open2(const char *name, const char *io_options, + int flags, int superblock, + unsigned int block_size, io_manager manager, + ext2_filsys *ret_fs) +{ + errcode_t retval; + + *ret_fs = NULL; + if (superblock && block_size) { + retval = __ext2fs_open2(name, io_options, + flags, superblock, block_size, + manager, ret_fs); + } else { + int size; + + for (size = EXT2_MIN_BLOCK_SIZE; + size <= EXT2_MAX_BLOCK_SIZE; size *= 2) { + if (*ret_fs) { + ext2fs_free(*ret_fs); + *ret_fs = NULL; + } + retval = __ext2fs_open2(name, io_options, flags, + superblock, size, + manager, ret_fs); + if (!retval) + break; + } + } + return retval; +} + /* * Set/get the filesystem data I/O channel. * diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c index 384ce925..183e2f6f 100644 --- a/misc/dumpe2fs.c +++ b/misc/dumpe2fs.c @@ -667,21 +667,8 @@ int main (int argc, char ** argv) if (image_dump) flags |= EXT2_FLAG_IMAGE_FILE; try_open_again: - if (use_superblock && !use_blocksize) { - for (use_blocksize = EXT2_MIN_BLOCK_SIZE; - use_blocksize <= EXT2_MAX_BLOCK_SIZE; - use_blocksize *= 2) { - retval = ext2fs_open (device_name, flags, - use_superblock, - use_blocksize, unix_io_manager, - &fs); - if (!retval) - break; - } - } else { - retval = ext2fs_open(device_name, flags, use_superblock, - use_blocksize, unix_io_manager, &fs); - } + retval = ext2fs_open2(device_name, 0, flags, use_superblock, + use_blocksize, unix_io_manager, &fs); flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; if (retval && !retval_csum) { retval_csum = retval; From patchwork Tue Jan 29 17:51:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Blagodarenko X-Patchwork-Id: 1032932 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="K/iVqFOU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pvFt4lHbz9s1l for ; Wed, 30 Jan 2019 04:52:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728162AbfA2RwC (ORCPT ); Tue, 29 Jan 2019 12:52:02 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:35088 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbfA2RwC (ORCPT ); Tue, 29 Jan 2019 12:52:02 -0500 Received: by mail-it1-f196.google.com with SMTP id p197so5923887itp.0 for ; Tue, 29 Jan 2019 09:52:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pjIqhj17ud7k7lsqJuPirzMlFDbU86F7EHNftih3+qk=; b=K/iVqFOUcwU5DrOYzjsVlwFJ1JwisPS2EF/OKBCkTlWJAi5G3BfaiNJVVSIa1spqdt Ay/Dd9iTb26loBFSOFUUbdAvlSzTgovsERwnkO151J8vRx10f83lCyOQzVhoQZvn2kM5 Pb/udwfG+eARiV2qrTNOo+DOpcv5Bb2KaNHSzuwjB6bPiRrx8g/qwqWa4amUg6fHEHJR ZCINN8wmdmnsbWNmeMnXgpbVXeDMRg9Bfn796eH/qgnccoY3iSh30YU27O76YS0zHn6Q 6iAEKD3QvxIjfIy7zBa9ejuKQoAaosLZ5EdOMzIPPpGaLwR/iHDAfk7S9ia7LsD5rogf 1lEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pjIqhj17ud7k7lsqJuPirzMlFDbU86F7EHNftih3+qk=; b=JbpvrdCYLa0B0/LdTC45Rf2hFC2k3MMTyANPF0KYm7ZMfzODz6mb4BapeE+2dc9In7 0YOtyt4ZoZ6vtSNWG4zAoCyXXNEXBylIDw4yxWramlar2OKWt5fm0uvW20z9AKijglCu gIvPvfhTTq/csvYG9C+w5kDZuHCAeN8IcZXkjIsrKIacniXdjCkptPmChIk8+/IM+4s9 rp5WkfseQtCbEc8XZ4nWQKfzVM4iJ00U+bB963umTYmCy22gLNH4CPjY6Ho0fpY0K4ms +ZaLs77ZE40OpkPuduTynR5dL4GG/i4zt5Yna2HVti3GyJ3WxRCjodnBN18whXyajjB/ tKUg== X-Gm-Message-State: AJcUukcrFyA1vkq1THeSR87NHWr6HYs/tiY89Cap4dexttBdYEWNZLfS CCKoLLYwxiOPzjTzosrnp8ha7cznErU= X-Google-Smtp-Source: ALg8bN4BGtQmoIR8PXSfd6MAJFzcIl5186QBB5KLqfq+KmSWHLgjVBXdBYHdkdeAtxHCjUC/sJ+Dxw== X-Received: by 2002:a02:a15e:: with SMTP id m30mr17041324jah.143.1548784320492; Tue, 29 Jan 2019 09:52:00 -0800 (PST) Received: from C02TN4C6HTD6.us.cray.com ([63.239.150.218]) by smtp.gmail.com with ESMTPSA id b5sm15838778ioc.21.2019.01.29.09.51.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:52:00 -0800 (PST) From: Artem Blagodarenko X-Google-Original-From: Artem Blagodarenko To: linux-ext4@vger.kernel.org Cc: adilger.kernel@dilger.ca Subject: [PATCH v7 2/4] e2image: add -b and -B options to use supperblock backup Date: Tue, 29 Jan 2019 20:51:32 +0300 Message-Id: <20190129175134.26652-3-c17828@cray.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20190129175134.26652-1-c17828@cray.com> References: <20190129175134.26652-1-c17828@cray.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org e2image has no ability to use superblock backup to copy metadata. This feature can be useful if someone wants to make partition image and fix it using e2fsck utility. New -b option allows to pass superblock number, like e2fsck utility does. e2image doesn't change primary superblock and store it as is, so it can be fixed using e2fsck latter. Option -B allows setting superblock size. Signed-off-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- misc/e2image.8.in | 33 +++++++++++++++++++++++++++++++++ misc/e2image.c | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/misc/e2image.8.in b/misc/e2image.8.in index a7bfdf24..bbbb57ae 100644 --- a/misc/e2image.8.in +++ b/misc/e2image.8.in @@ -12,6 +12,15 @@ e2image \- Save critical ext2/ext3/ext4 filesystem metadata to a file ] [ .B \-f +.B \-b +.I superblock +] +[ +.B \-B +.I blocksize +] +[ +.B \-fr ] .I device .I image-file @@ -167,6 +176,22 @@ the option will prevent analysis of problems related to hash-tree indexed directories. .PP +Option +.B \-b +.I superblock +can be used to get image from partition with broken primary superblock. +The partition is copied as-is including broken primary superblock. +.PP +Option +.B \-B +.I blocksize +can be used to set superblock block size. Normally, e2fsck will search +for the superblock at various different block sizes in an attempt to find +the appropriate blocksize. This search can be fooled in some cases. This +option forces e2fsck to only try locating the superblock at a particular +blocksize. If the superblock is not found, e2fsck will terminate with a +fatal error. +.PP Note that this will work even if you substitute "/dev/hda1" for another raw disk image, or QCOW2 image previously created by .BR e2image . @@ -217,6 +242,14 @@ This can be useful to write a qcow2 image containing all data to a sparse image file where it can be loop mounted, or to a disk partition. Note that this may not work with qcow2 images not generated by e2image. .PP +Options +.B \-b +.I superblock +and +.B \-B +.I blocksize +can be used same way as for raw images. +.PP .SH INCLUDING DATA Normally .B e2image diff --git a/misc/e2image.c b/misc/e2image.c index 9e21d0db..3c881fee 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -104,7 +104,8 @@ static int get_bits_from_size(size_t size) static void usage(void) { - fprintf(stderr, _("Usage: %s [ -r|Q ] [ -f ] device image-file\n"), + fprintf(stderr, _("Usage: %s [ -r|Q ] [ -f ] [ -b superblock ] [ -B blocksize]" + "[ -fr ] device image-file\n"), program_name); fprintf(stderr, _(" %s -I device image-file\n"), program_name); fprintf(stderr, _(" %s -ra [ -cfnp ] [ -o src_offset ] " @@ -1267,7 +1268,8 @@ static void output_qcow2_meta_data_blocks(ext2_filsys fs, int fd) free_qcow2_image(img); } -static void write_raw_image_file(ext2_filsys fs, int fd, int type, int flags) +static void write_raw_image_file(ext2_filsys fs, int fd, int type, int flags, + blk64_t superblock) { struct process_block_struct pb; struct ext2_inode inode; @@ -1295,6 +1297,22 @@ static void write_raw_image_file(ext2_filsys fs, int fd, int type, int flags) } } + if (superblock) { + int j; + + ext2fs_mark_block_bitmap2(meta_block_map, superblock); + meta_blocks_count++; + + /* + * Mark the backup superblock descriptors + */ + for (j = 0; j < fs->desc_blocks; j++) { + ext2fs_mark_block_bitmap2(meta_block_map, + ext2fs_descriptor_block_loc2(fs, superblock, j)); + } + meta_blocks_count += fs->desc_blocks; + } + mark_table_blocks(fs); if (show_progress) fprintf(stderr, "%s", _("Scanning inodes...\n")); @@ -1474,6 +1492,8 @@ int main (int argc, char ** argv) int ignore_rw_mount = 0; int check = 0; struct stat st; + blk64_t superblock = 0; + int blocksize = 0; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); @@ -1487,8 +1507,14 @@ int main (int argc, char ** argv) if (argc && *argv) program_name = *argv; add_error_table(&et_ext2_error_table); - while ((c = getopt(argc, argv, "nrsIQafo:O:pc")) != EOF) + while ((c = getopt(argc, argv, "b:B:nrsIQafo:O:pc")) != EOF) switch (c) { + case 'b': + superblock = strtoull(optarg, NULL, 0); + break; + case 'B': + blocksize = strtoul(optarg, NULL, 0); + break; case 'I': flags |= E2IMAGE_INSTALL_FLAG; break; @@ -1540,6 +1566,11 @@ int main (int argc, char ** argv) "with raw or QCOW2 images.")); exit(1); } + if (superblock && !img_type) { + com_err(program_name, 0, "%s", _("-b option can only be used " + "with raw or QCOW2 images.")); + exit(1); + } if ((source_offset || dest_offset) && img_type != E2IMAGE_RAW) { com_err(program_name, 0, "%s", _("Offsets are only allowed with raw images.")); @@ -1590,8 +1621,8 @@ int main (int argc, char ** argv) } } sprintf(offset_opt, "offset=%llu", source_offset); - retval = ext2fs_open2(device_name, offset_opt, open_flag, 0, 0, - unix_io_manager, &fs); + retval = ext2fs_open2(device_name, offset_opt, open_flag, + superblock, blocksize, unix_io_manager, &fs); if (retval) { com_err (program_name, retval, _("while trying to open %s"), device_name); @@ -1681,7 +1712,7 @@ skip_device: exit(1); } if (img_type) - write_raw_image_file(fs, fd, img_type, flags); + write_raw_image_file(fs, fd, img_type, flags, superblock); else write_image_file(fs, fd); From patchwork Tue Jan 29 17:51:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Blagodarenko X-Patchwork-Id: 1032933 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="omUJZfwp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pvFw1stbz9s1l for ; Wed, 30 Jan 2019 04:52:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbfA2RwD (ORCPT ); Tue, 29 Jan 2019 12:52:03 -0500 Received: from mail-it1-f178.google.com ([209.85.166.178]:52538 "EHLO mail-it1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbfA2RwD (ORCPT ); Tue, 29 Jan 2019 12:52:03 -0500 Received: by mail-it1-f178.google.com with SMTP id d11so5958959itf.2 for ; Tue, 29 Jan 2019 09:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FAUEq+0jzAfBo8axIh972Ofnls+ASfZANgtGOcExyfg=; b=omUJZfwpmpNCR9LjkzawY/6QybX7nFi31+0wuz4KyrgINL1NmWDinnfgbXXilHmhkH UZIH5H1HsOzwUJPlbDhbskg2zWhms3gmsQSihQmLS6KO0g1Jc1zonfzMHkMd4KEqm/M0 OeVugmyTx1sv1EnTlzex6cjGZkGddka8UGLFKBiN3QBRGLG/OZ11DAaHrTM5OIkFjFGu Hx8cti/zMbSzx6SR+GJB/Gk+fsel98ZNqjqAJX3W2M+OAoTqSBYBu26d4MK5pE1Johmv ScbDfznGNld7T2Yd7ZhZMp1Orn5dh3Q8P3dgzNkedKRq7Z1UMxnhMuBfTnoKmaPHm0zi eM4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FAUEq+0jzAfBo8axIh972Ofnls+ASfZANgtGOcExyfg=; b=UuuO3+RtJaxPBvEjvgu/qT+JBRnHQHtN0XJQ6LAN6iw/pHq7eOt66jZLLXKFM++84A 165me48Ze9k+jYpKYfeDrUNA4IYz9k8eWj4n6qVmib2HK3H+VHlB9agPFqhYdy0sBL4A jZcT3HbKIDL08WL+9y8UTs67GDtP1jY3pnSmI8uRjrFS1ZefZExS8VChPWWvEZFr3Ys2 gCLZOqUi+IhYBosN2d3GEIvu1WfSiQL4diZGGxjvLTbY3vB18UtVJNHxfY4U0Qt7AgVo GHUXXQBNjUQrSLI02ImOXPKM5X+m5044G/KyD7qL28ZtNwM0iPCcrthdc2UMEfr8TKrp miQg== X-Gm-Message-State: AJcUukc0owgtcbNuZ6XXGDRoVmK8yUvpYNoarU3vecXy5SbdstDsN3wE DxFrY5u1sw//qn9Vr+c5sCKySXxkRDc= X-Google-Smtp-Source: ALg8bN6UURTy9lmikXBvoXxHudrXGYXX23esuVgoW/3OvFyAPP2b9u6mGYGbdKO4UZZm1j2kTOc37Q== X-Received: by 2002:a02:2ac6:: with SMTP id w189mr17262105jaw.33.1548784322289; Tue, 29 Jan 2019 09:52:02 -0800 (PST) Received: from C02TN4C6HTD6.us.cray.com ([63.239.150.218]) by smtp.gmail.com with ESMTPSA id b5sm15838778ioc.21.2019.01.29.09.52.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:52:01 -0800 (PST) From: Artem Blagodarenko X-Google-Original-From: Artem Blagodarenko To: linux-ext4@vger.kernel.org Cc: adilger.kernel@dilger.ca Subject: [PATCH v7 3/4] tests: add test for e2image -b option Date: Tue, 29 Jan 2019 20:51:33 +0300 Message-Id: <20190129175134.26652-4-c17828@cray.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20190129175134.26652-1-c17828@cray.com> References: <20190129175134.26652-1-c17828@cray.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The test makes raw image from partition with broken super block and executes e2fsck. Signed-off-by: Artem Blagodarenko --- tests/i_zero_super/expect.1 | 22 ++++++++++++++++++++++ tests/i_zero_super/image.gz | Bin 0 -> 13262 bytes tests/i_zero_super/script | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/tests/i_zero_super/expect.1 b/tests/i_zero_super/expect.1 new file mode 100644 index 00000000..fda32b96 --- /dev/null +++ b/tests/i_zero_super/expect.1 @@ -0,0 +1,22 @@ +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 +Free blocks count wrong for group #0 (7987, counted=7982). +Fix? no + +Free blocks count wrong (11602, counted=11597). +Fix? no + +Free inodes count wrong for group #0 (1493, counted=1488). +Fix? no + +Free inodes count wrong (2997, counted=2992). +Fix? no + + +test_filesys: ********** WARNING: Filesystem still has errors ********** + +test_filesys: 11/3008 files (0.0% non-contiguous), 398/12000 blocks +Exit status is 4 diff --git a/tests/i_zero_super/image.gz b/tests/i_zero_super/image.gz new file mode 100644 index 0000000000000000000000000000000000000000..eea9140194f4dd9ec9dc8bb7b9e2215b950587d2 GIT binary patch literal 13262 zcmeI&{WsHl902f@Tih#ASFE0G_ld9Vc5R+bpL^V>zwZSynpzd^M0St`F!5z^~3w8H;SqT zqYs|hy;?=Ydxb*`Y=(_Uj;z^->s>9@r^5EDn{U+Cn|rW>b}kfCoqXW-K~s(F;j74# zhqt?LGco2DyY?LC#w8Uk#19^?CI2?lfagqx1)ifG8HH6hag-M>b#n;a0ZPl9H5uQ* zh;IX^QFd*|QbjWJu&O+~X7%S}AV@xtYOvP)CS>1lrK);rafz~F03E!AP48O_FHJ-S zg=;|Z6CYQNv-ZtIAsw=E5_ROA?i#k~veE+)ipFdv$#ixO-jpJlhBw`i@Ze2U$ugXh zEMdbbDH0)^B6nzm#&w;gg^SRCFE9f3*C-V-jA$$~oJK~np*>kNW!_c@&xu+YHyNXN zp%GA9=BovWD%_K}kqu4M8l_Vdo`ZrjD`Rn~ny_y)f?E3F0+*`oZ`-HKopl65$&V?2 z6t#B;?@_*MZBA_RXBf6G+|DYp-XhkO$YO6^T9V`5bn#K^+MJ~w%?yMSFJ^6Sg0UPo zH18)>^zs;IYTrH~YA<7Mr$64hU|~C{vPc@*cM^i?V|<|Jn9+tquql)qba_d&&!IrM zN~Zac^0PwabLqMD!9ml85Ia=TGE1p+3h@zX%O9$xRb*SWAT&w23469Mvy?^fd1|g3 z2OBk4fRetx=bz*1p{n()`A%z>On+9V^5jQ%qmv|KEd9g7%{cya z65*HM6(OZ+6L>k!K_u1|@&p_klxX(aQxoxcuK2-5NAEJvycMqbFk(JtZeOq(eaVqK zE$C<*4!NVbAnmvsr0$0sDX)ZlCMriySRgmmUjO^tlevd#3)Zt$LqUQ_eDSM@rLm)g z!XAD=Sx#gZABPJ)Up{;GKD|C}Y8VkwAwFuhGbzSGG-0EPN6htOi;<%tBC<{2D7MHvi^SK!zjPB6^PPltypW6U@ls8I$Qi8V+~~sMW&Avh1qk{jsdUms4q%_I~j9 zAP1wBH!x%p{*lPf%!OjFcUM;S-X3L~(Ph>1KAIhBU*6R=9GDzLN>@M4QqZpW;86in zU6u2kydgWZ5!3%Mj+USKnvbny#tWU>-s*8m*m3AEb(yr<){ZABVq)XGI#2cz42~T& zGiMA2h%d5h8S#Z$(EIzA$Y}eQPcMd3koG%AZ~YY0O4M39@qm%pxYt5T=-)((!SH_-N)wOT5EJu-k$_?OS4By z`-cNru4=m6(i&s&<}6`1-*Pu6zm4e05s8Xx>Q+>QMg+NP$urt|PT#~`t~3AhF_nSY zvBHEWF`>oD!xz}9ttUu?ntrBkM$M-%!q|)=)_Y)mo((>q^l>hC-8VW!K-)k72mk>f z00e*l5C8%|00;m9AOHk_01yBIKmZ5;0U!VbfB+Bx0zd!=00AKIbp=K!;yw%P>JwUP zN8Z$BYH3yUJBnz@L=EacMGN|;r>&TdDbac%hz*WE#2d70bXsDzshu_)m6AW|wjzkT zcBy>bZol}OTTD6WMU0ljJ&icy#4Kr$Hr@9)dvDXkMN4wZxwi50$>mD+G8Nh><%Z8z z-r_hsyIZ&rI57ThUe6tC!j|bV27G0o?8J#?hL{KkW#FoUb?d|b>Kwkeb>zx!KDuCK v`J3J9`63;-00e*l5C8%|00;m9AOHk_01yBI{~LklvK5${_ikI* X-Patchwork-Id: 1032934 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nDbDU/wF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pvFy6g6Sz9s1l for ; Wed, 30 Jan 2019 04:52:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728454AbfA2RwG (ORCPT ); Tue, 29 Jan 2019 12:52:06 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:33057 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbfA2RwG (ORCPT ); Tue, 29 Jan 2019 12:52:06 -0500 Received: by mail-it1-f196.google.com with SMTP id m8so14427306itk.0 for ; Tue, 29 Jan 2019 09:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UZ69tAKjh5RWpDlInkgxmxiIEXMar0/eXbKNKxDLgRU=; b=nDbDU/wFxOgzxQC8ZqMAl+kUBBiBZ5u+UxQ9LhNjkyCDpA/3rHSI5d3J1wEpUqTVum cZm+GRNc3ob87zQTm14XGvfmBD/VVCi1mfcW6hjdnGMLHoV8I5EsngJg4SVXcCGLGmRM 9n4EBrdSi04FIMeHUHy27XYxUNruar0YD05vfm0KOgIGo/7WvE9XZEciljk57kbbVb/u oxEiXyE5OP3TJJm9J0yR8eSZKQiMp6Z3P4piUUAM0Nguifh34R8KX+5Ojur0GdBnPtCL +DhtcoRpNvgqnZ53diwkNj0GRjtH9GvynIaZMJUXWZuLfFS0tSQplpvOKfzt7j+H59wo 1n7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UZ69tAKjh5RWpDlInkgxmxiIEXMar0/eXbKNKxDLgRU=; b=i0VzNVXvcFTIBC6ts82qSC6+ood/5c0NEzaDXoDXYcqDdY1qER87VrEafCA885+HTf 4+jaqFxPIh0g5yg2Hn2mfx6M5bf5MQq/7BOVWZoObVAdgbEdVp9qbZIyIBF2ztT39Hwt j0MHYZ1JGStjYAqLlwbbH0gpsI1iaFo9dtK0ptGcq7MllpbILLsILnUG2TQPh37yY4GH MTQPg3X15V+37Hp/QAgKWkSkGACHykANQfMs8a9HEpAZ5TueLAZoP3Os5egfZXgXpJpN MHxV+T9ygEauvXGqSvfDAGqWx+ZS5RX/yfvsPMZEHpp8PqaXIIKzlj4PIPOvex/6mzQt AI5Q== X-Gm-Message-State: AJcUukdNsdjv5yK1ldIk5TlLylgIHtnzpOKF9d0oIkex9W+sxUlVSAcD RR0FxUyeMtNvF/ZIgF03mhUgOgySaUc= X-Google-Smtp-Source: ALg8bN48R0ogfQACg5wsPrNfVj7PBByepHXJvp9EHq5X+uLOcFnJbgXWCjn1ePZSVJ7o+HfxIr6Q7A== X-Received: by 2002:a24:4e55:: with SMTP id r82mr15011552ita.128.1548784324493; Tue, 29 Jan 2019 09:52:04 -0800 (PST) Received: from C02TN4C6HTD6.us.cray.com ([63.239.150.218]) by smtp.gmail.com with ESMTPSA id b5sm15838778ioc.21.2019.01.29.09.52.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 09:52:04 -0800 (PST) From: Artem Blagodarenko X-Google-Original-From: Artem Blagodarenko To: linux-ext4@vger.kernel.org Cc: adilger.kernel@dilger.ca Subject: [PATCH v7 4/4] ext2fs: automaticlly open backup superblocks Date: Tue, 29 Jan 2019 20:51:34 +0300 Message-Id: <20190129175134.26652-5-c17828@cray.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20190129175134.26652-1-c17828@cray.com> References: <20190129175134.26652-1-c17828@cray.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org e2image and e2fsck automatically try to open some backup superblocks, if only blocksize is set or passed superblock can't be opened. Try few backup superblocks (e.g. {1, 3, 5, 7, 9} * blocksize * 8). This code is moved to lib/support/. Signed-off-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- e2fsck/e2fsck.h | 2 - e2fsck/message.c | 3 +- e2fsck/unix.c | 14 +++-- e2fsck/util.c | 73 ------------------------- lib/support/Makefile.in | 8 ++- lib/support/sb_backup.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/support/sb_backup.h | 20 +++++++ misc/e2image.c | 7 +++ 8 files changed, 185 insertions(+), 82 deletions(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 1c7a67cb..8576ef24 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -633,8 +633,6 @@ extern void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino, #ifdef MTRACE extern void mtrace_print(char *mesg); #endif -extern blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, - const char *name, io_manager manager); extern int ext2_file_type(unsigned int mode); extern int write_all(int fd, char *buf, size_t count); void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...) diff --git a/e2fsck/message.c b/e2fsck/message.c index 727f71d5..ffb40730 100644 --- a/e2fsck/message.c +++ b/e2fsck/message.c @@ -465,7 +465,8 @@ static _INLINE_ void expand_percent_expression(FILE *f, ext2_filsys fs, fprintf(f, "%*lld", width, (long long) ctx->blkcount); break; case 'S': - fprintf(f, "%llu", get_backup_sb(NULL, fs, NULL, NULL)); + fprintf(f, "%llu", get_first_backup_sb(NULL, NULL, fs, + NULL, NULL)); break; case 's': fprintf(f, "%*s", width, ctx->str ? ctx->str : "NULL"); diff --git a/e2fsck/unix.c b/e2fsck/unix.c index ddcf52a4..4ffc039e 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1489,11 +1489,17 @@ restart: retval ? _("Superblock invalid,") : _("Group descriptors look bad...")); orig_superblock = ctx->superblock; - get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr); - if (fs) - ext2fs_close_free(&fs); orig_retval = retval; - retval = try_open_fs(ctx, flags, io_ptr, &fs); + retval = try_backups(ctx->filesystem_name, + ctx->io_options, + flags, &ctx->superblock, + &ctx->blocksize, io_ptr, &fs); + if (retval == 0) { + fs->priv_data = ctx; + e2fsck_set_bitmap_type(fs, + EXT2FS_BMAP64_RBTREE, + "default", NULL); + } if ((orig_retval == 0) && retval != 0) { if (fs) ext2fs_close_free(&fs); diff --git a/e2fsck/util.c b/e2fsck/util.c index db6a1cc1..e2caf3a2 100644 --- a/e2fsck/util.c +++ b/e2fsck/util.c @@ -549,79 +549,6 @@ void mtrace_print(char *mesg) } #endif -blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name, - io_manager manager) -{ - struct ext2_super_block *sb; - io_channel io = NULL; - void *buf = NULL; - int blocksize; - blk64_t superblock, ret_sb = 8193; - - if (fs && fs->super) { - ret_sb = (fs->super->s_blocks_per_group + - fs->super->s_first_data_block); - if (ctx) { - ctx->superblock = ret_sb; - ctx->blocksize = fs->blocksize; - } - return ret_sb; - } - - if (ctx) { - if (ctx->blocksize) { - ret_sb = ctx->blocksize * 8; - if (ctx->blocksize == 1024) - ret_sb++; - ctx->superblock = ret_sb; - return ret_sb; - } - ctx->superblock = ret_sb; - ctx->blocksize = 1024; - } - - if (!name || !manager) - goto cleanup; - - if (manager->open(name, 0, &io) != 0) - goto cleanup; - - if (ext2fs_get_mem(SUPERBLOCK_SIZE, &buf)) - goto cleanup; - sb = (struct ext2_super_block *) buf; - - for (blocksize = EXT2_MIN_BLOCK_SIZE; - blocksize <= EXT2_MAX_BLOCK_SIZE ; blocksize *= 2) { - superblock = blocksize*8; - if (blocksize == 1024) - superblock++; - io_channel_set_blksize(io, blocksize); - if (io_channel_read_blk64(io, superblock, - -SUPERBLOCK_SIZE, buf)) - continue; -#ifdef WORDS_BIGENDIAN - if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) - ext2fs_swap_super(sb); -#endif - if ((sb->s_magic == EXT2_SUPER_MAGIC) && - (EXT2_BLOCK_SIZE(sb) == blocksize)) { - ret_sb = superblock; - if (ctx) { - ctx->superblock = superblock; - ctx->blocksize = blocksize; - } - break; - } - } - -cleanup: - if (io) - io_channel_close(io); - if (buf) - ext2fs_free_mem(&buf); - return (ret_sb); -} - /* * Given a mode, return the ext2 file type */ diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in index 1d278642..03fdf555 100644 --- a/lib/support/Makefile.in +++ b/lib/support/Makefile.in @@ -22,7 +22,8 @@ OBJS= cstring.o \ quotaio.o \ quotaio_v2.o \ quotaio_tree.o \ - dict.o + dict.o \ + sb_backup.o SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/cstring.c \ @@ -35,7 +36,8 @@ SRCS= $(srcdir)/argv_parse.c \ $(srcdir)/quotaio.c \ $(srcdir)/quotaio_tree.c \ $(srcdir)/quotaio_v2.c \ - $(srcdir)/dict.c + $(srcdir)/dict.c \ + $(srcdir)/sb_backup.c LIBRARY= libsupport LIBDIR= support @@ -168,3 +170,5 @@ quotaio_v2.o: $(srcdir)/quotaio_v2.c $(top_builddir)/lib/config.h \ $(srcdir)/quotaio_tree.h dict.o: $(srcdir)/dict.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(srcdir)/dict.h +sb_backup.o: $(srcdir)/sb_backup.c $(top_builddir)/lib/config.h \ + $(srcdir)/sb_backup.h diff --git a/lib/support/sb_backup.c b/lib/support/sb_backup.c new file mode 100644 index 00000000..cfa671e5 --- /dev/null +++ b/lib/support/sb_backup.c @@ -0,0 +1,140 @@ +/* + * sb_backup.c -- helper functions for getting backup superblocks + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + + +#include "config.h" +#include +#include + +#include "ext2fs/ext2_fs.h" +#include "ext2fs/ext2fs.h" + +blk64_t get_first_backup_sb(blk64_t *superblock, unsigned int *block_size, + ext2_filsys fs, const char *name, + io_manager manager) +{ + struct ext2_super_block *sb; + io_channel io = NULL; + void *buf = NULL; + int try_blocksize; + blk64_t try_superblock, ret_sb = 8193; + + /* superblock and block_size can be NULL if fs->super is passed */ + if (fs && fs->super) { + ret_sb = fs->super->s_blocks_per_group + + fs->super->s_first_data_block; + if (superblock) + *superblock = ret_sb; + if (block_size) + *block_size = fs->blocksize; + return ret_sb; + } + + if (*block_size) { + ret_sb = *block_size * 8; + if (*block_size == 1024) + ret_sb++; + *superblock = ret_sb; + return ret_sb; + } + + *superblock = ret_sb; + *block_size = 1024; + + if (!name || !manager) + goto cleanup; + + if (manager->open(name, 0, &io) != 0) + goto cleanup; + + if (ext2fs_get_mem(SUPERBLOCK_SIZE, &buf)) + goto cleanup; + sb = (struct ext2_super_block *) buf; + + for (try_blocksize = EXT2_MIN_BLOCK_SIZE; + try_blocksize <= EXT2_MAX_BLOCK_SIZE ; try_blocksize *= 2) { + try_superblock = try_blocksize*8; + if (try_blocksize == 1024) + try_superblock++; + io_channel_set_blksize(io, try_blocksize); + if (io_channel_read_blk64(io, try_superblock, + -SUPERBLOCK_SIZE, buf)) + continue; +#ifdef WORDS_BIGENDIAN + if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) + ext2fs_swap_super(sb); +#endif + if ((sb->s_magic == EXT2_SUPER_MAGIC) && + (EXT2_BLOCK_SIZE(sb) == try_blocksize)) { + ret_sb = try_superblock; + *superblock = try_superblock; + *block_size = try_blocksize; + break; + } + } + +cleanup: + if (io) + io_channel_close(io); + if (buf) + ext2fs_free_mem(&buf); + return ret_sb; +} + +errcode_t try_backups(const char *name, const char *io_options, + int flags, blk64_t *superblock, + unsigned int *block_size, io_manager manager, + ext2_filsys *ret_fs) +{ + errcode_t retval, retval2; + blk64_t try_block_number; + unsigned int i; + + /* + * Get first superblock location based on heuristic. + * Blocksize is also returned and used to find next + * superblock copy location. + */ + try_block_number = get_first_backup_sb(superblock, block_size, + *ret_fs, name, manager); + retval = ext2fs_open2(name, io_options, flags, try_block_number, + *block_size, manager, ret_fs); + if (!retval) + return 0; + + /* + * Try 3d, 5th, 7th, 9th superblock copy + */ + for (i = 3; i <= 9; i += 2) { + try_block_number = (i * (*block_size) * 8); + if (*block_size == 1024) + try_block_number++; + if (*ret_fs) { + ext2fs_free(*ret_fs); + *ret_fs = NULL; + } + retval2 = ext2fs_open2(name, io_options, flags, + try_block_number, *block_size, manager, + ret_fs); + /* + * Partition is too small to have this superblock copy. + * Return previous reading return code + */ + if (retval2 == EXT2_ET_SHORT_READ) + break; + + retval = retval2; + if (!retval) { + *superblock = try_block_number; + break; + } + } + + return retval; +} diff --git a/lib/support/sb_backup.h b/lib/support/sb_backup.h new file mode 100644 index 00000000..1e18e37c --- /dev/null +++ b/lib/support/sb_backup.h @@ -0,0 +1,20 @@ +/* + * sb_backup.h -- helper functions for getting backup superblocks + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "ext2fs/ext2_fs.h" +#include "ext2fs/ext2fs.h" + +blk64_t get_first_backup_sb(blk64_t *superblock, unsigned int *block_size, + ext2_filsys fs, const char *name, + io_manager manager); + +errcode_t try_backups(const char *name, const char *io_options, + int flags, blk64_t *superblock, + unsigned int *block_size, io_manager manager, + ext2_filsys *ret_fs); diff --git a/misc/e2image.c b/misc/e2image.c index 3c881fee..786282ec 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -1623,6 +1623,13 @@ int main (int argc, char ** argv) sprintf(offset_opt, "offset=%llu", source_offset); retval = ext2fs_open2(device_name, offset_opt, open_flag, superblock, blocksize, unix_io_manager, &fs); + if (retval & (superblock | blocksize)) { + printf(_("Try backups in other location.\n")); + retval = try_backups(device_name, offset_opt, open_flag, + &superblock, &blocksize, + unix_io_manager, &fs); + printf(_("Use superblock %i.\n"), superblock); + } if (retval) { com_err (program_name, retval, _("while trying to open %s"), device_name);