From: Marco A Benatto <marco.antonio.780@gmail.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH] xfs_mdrestore: Don't restore over a dump file
Date: Thu, 1 Feb 2018 18:37:43 -0200 [thread overview]
Message-ID: <1517517463-99951-1-git-send-email-marco.antonio.780@gmail.com> (raw)
Currently, if the user switch source and target parameters
position, xfs_mdrestore truncates the dumpfile before abort
the execution.
This patch checks the target parameter and if XFS_MD_MAGIC is
found, it aborts execution and leave dump file intact.
Signed-off-by: Marco A Benatto <marco.antonio.780@gmail.com>
---
mdrestore/xfs_mdrestore.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
index c49c13a..b4bf7b4 100644
--- a/mdrestore/xfs_mdrestore.c
+++ b/mdrestore/xfs_mdrestore.c
@@ -205,7 +205,7 @@ main(
int argc,
char **argv)
{
- FILE *src_f;
+ FILE *src_f, *dst_f;
int dst_fd;
int c;
int open_flags;
@@ -277,6 +277,7 @@ main(
optind++;
+
/* check and open target */
open_flags = O_RDWR;
is_target_file = 0;
@@ -285,6 +286,19 @@ main(
open_flags |= O_CREAT;
is_target_file = 1;
} else if (S_ISREG(statbuf.st_mode)) {
+ xfs_metablock_t mb;
+
+ dst_f = fopen(argv[optind], "rb");
+ if (dst_f == NULL)
+ fatal("cannot open target\n");
+
+ if (fread(&mb, sizeof(mb), 1, dst_f) == 1) {
+ if (be32_to_cpu(mb.mb_magic) == XFS_MD_MAGIC)
+ fatal("target file is a xfs_metadump. switched arguments?\n");
+ }
+
+ fclose(dst_f);
+
open_flags |= O_TRUNC;
is_target_file = 1;
} else {
--
1.8.3.1
next reply other threads:[~2018-02-01 20:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-01 20:37 Marco A Benatto [this message]
2018-02-01 20:50 ` [PATCH] xfs_mdrestore: Don't restore over a dump file Eric Sandeen
2018-02-01 22:28 ` Darrick J. Wong
2018-02-01 22:39 ` Eric Sandeen
2018-02-02 17:52 ` Marco Benatto
2018-02-01 21:54 ` Bill O'Donnell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1517517463-99951-1-git-send-email-marco.antonio.780@gmail.com \
--to=marco.antonio.780@gmail.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).