On Tue, May 23, 2023 at 02:30:46PM +0530, Chandan Babu R wrote: I'll have more to say about this in patch 22. --D > Signed-off-by: Chandan Babu R <chandan.babu@xxxxxxxxxx> > --- > mdrestore/xfs_mdrestore.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c > index 5ec1a47b0..52081a6ca 100644 > --- a/mdrestore/xfs_mdrestore.c > +++ b/mdrestore/xfs_mdrestore.c > @@ -8,7 +8,7 @@ > #include "xfs_metadump.h" > > struct mdrestore_ops { > - void (*read_header)(void *header, FILE *mdfp); > + int (*read_header)(void *header, FILE *mdfp); > void (*show_info)(void *header, const char *mdfile); > void (*restore)(void *header, FILE *mdfp, int data_fd, > bool is_target_file); > @@ -86,7 +86,7 @@ open_device( > return fd; > } > > -static void > +static int > read_header_v1( > void *header, > FILE *mdfp) > @@ -96,7 +96,9 @@ read_header_v1( > if (fread(mb, sizeof(*mb), 1, mdfp) != 1) > fatal("error reading from metadump file\n"); > if (mb->mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) > - fatal("specified file is not a metadata dump\n"); > + return -1; > + > + return 0; > } > > static void > @@ -316,9 +318,10 @@ main( > fatal("cannot open source dump file\n"); > } > > - mdrestore.mdrops = &mdrestore_ops_v1; > - > - mdrestore.mdrops->read_header(&mb, src_f); > + if (mdrestore_ops_v1.read_header(&mb, src_f) == 0) > + mdrestore.mdrops = &mdrestore_ops_v1; > + else > + fatal("Invalid metadump format\n"); > > if (mdrestore.show_info) { > mdrestore.mdrops->show_info(&mb, argv[optind]); > -- > 2.39.1 >