This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch master
in repository gfs2-utils.
commit 34c6a71642e6e084c5d954edb435fbe833755445
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Sat May 23 14:22:07 2020 +0100
gfs2_edit: restore_block() improvements
No need for maxlen and checklen as the only caller passes in the block
size which is always used as the check length. Return the buffer instead
of an error flag to fix an uninitialised 'bp' warning in restore_data()
and just check mfd->eof again in the caller.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 43 ++++++++++++++++---------------------------
1 file changed, 16 insertions(+), 27 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 43ac425..0c54155 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -1054,15 +1054,15 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
exit(0);
}
-static int restore_block(struct metafd *mfd, struct saved_metablock *svb, char **buf,
uint16_t maxlen)
+static char *restore_block(struct metafd *mfd, struct saved_metablock *svb)
{
struct saved_metablock *svb_be;
const char *errstr;
- uint16_t checklen;
+ char *buf = NULL;
svb_be = (struct saved_metablock *)(restore_buf_next(mfd, sizeof(*svb)));
if (svb_be == NULL)
- goto read_err;
+ goto nobuffer;
svb->blk = be64_to_cpu(svb_be->blk);
svb->siglen = be16_to_cpu(svb_be->siglen);
@@ -1070,34 +1070,25 @@ static int restore_block(struct metafd *mfd, struct
saved_metablock *svb, char *
fprintf(stderr, "Error: File system is too small to restore this
metadata.\n");
fprintf(stderr, "File system is %llu blocks. Restore block = %llu\n",
(unsigned long long)sbd.fssize, (unsigned long long)svb->blk);
- return -1;
+ return NULL;
}
- if (maxlen)
- checklen = maxlen;
- else
- checklen = sbd.bsize;
-
- if (checklen && svb->siglen > checklen) {
+ if (svb->siglen > sbd.bsize) {
fprintf(stderr, "Bad record length: %u for block %"PRIu64"
(0x%"PRIx64").\n",
svb->siglen, svb->blk, svb->blk);
- return -1;
- }
-
- if (buf != NULL && maxlen != 0) {
- *buf = restore_buf_next(mfd, svb->siglen);
- if (*buf == NULL)
- goto read_err;
+ return NULL;
}
- return 0;
-read_err:
+ buf = restore_buf_next(mfd, svb->siglen);
+ if (buf != NULL)
+ return buf;
+nobuffer:
if (mfd->eof)
- return 1;
+ return NULL;
errstr = mfd->strerr(mfd);
fprintf(stderr, "Failed to restore block: %s\n", errstr);
- return -1;
+ return NULL;
}
static int restore_super(struct metafd *mfd, char *buf, int printonly)
@@ -1127,7 +1118,6 @@ static int restore_data(int fd, struct metafd *mfd, int printonly)
struct saved_metablock savedata = {0};
uint64_t writes = 0;
char *buf;
- char *bp;
buf = calloc(1, sbd.bsize);
if (buf == NULL) {
@@ -1137,16 +1127,15 @@ static int restore_data(int fd, struct metafd *mfd, int
printonly)
blks_saved = 0;
while (TRUE) {
- int err;
+ char *bp;
- err = restore_block(mfd, &savedata, &bp, sbd.bsize);
- if (err == 1)
+ bp = restore_block(mfd, &savedata);
+ if (bp == NULL && mfd->eof)
break;
- if (err != 0) {
+ if (bp == NULL) {
free(buf);
return -1;
}
-
if (printonly) {
if (printonly > 1 && printonly == savedata.blk) {
display_block_type(bp, savedata.blk, TRUE);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.