This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch andyp-sparse
in repository gfs2-utils.
commit e2d50e6044d9d75b1bad31000ff4a43bfffea585
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Jun 11 18:25:38 2021 +0100
gfs2_edit: Fix remaining endianness sparse warnings
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/extended.c | 7 +--
gfs2/edit/gfs2hex.c | 11 +++--
gfs2/edit/hexedit.c | 26 ++++++-----
gfs2/edit/hexedit.h | 2 -
gfs2/edit/journal.c | 39 ++++++++--------
gfs2/edit/savemeta.c | 125 +++++++++++++++++++++++++++------------------------
6 files changed, 110 insertions(+), 100 deletions(-)
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index d6e4624a..c2865829 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -61,7 +61,7 @@ static int _do_indirect_extended(char *diebuf, struct iinfo *iinf, int
hgt)
}
headoff = sbd.gfs1 ? sizeof(struct gfs_indirect) : sizeof(struct gfs2_meta_header);
for (x = headoff, y = 0; x < sbd.sd_bsize; x += sizeof(uint64_t), y++) {
- p = be64_to_cpu(*(uint64_t *)(diebuf + x));
+ p = be64_to_cpu(*(__be64 *)(diebuf + x));
if (p) {
iinf->ii[i_blocks].block = p;
iinf->ii[i_blocks].mp.mp_list[hgt] = i_blocks;
@@ -228,7 +228,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int
level,
return 0;
}
-static void print_inode_type(__be16 de_type)
+static void print_inode_type(uint16_t de_type)
{
if (sbd.gfs1) {
switch(de_type) {
@@ -558,7 +558,8 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
static int print_inum(struct gfs2_inode *dii)
{
- uint64_t inum, inodenum;
+ uint64_t inodenum;
+ __be64 inum;
int rc;
rc = gfs2_readi(dii, (void *)&inum, 0, sizeof(inum));
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 95572fef..219a20ea 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -49,9 +49,7 @@ int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
int gfs2_struct_type;
unsigned int offset;
struct indirect_info masterdir;
-struct gfs2_inum gfs1_quota_di;
int print_entry_ndx;
-struct gfs2_inum gfs1_license_di;
int screen_chunk_size = 512;
uint64_t temp_blk;
int color_scheme = 0;
@@ -244,12 +242,13 @@ static int indirect_dirent(struct indirect_info *indir, void *ptr,
int d)
void do_dinode_extended(char *buf)
{
struct gfs2_dinode *dip = (void *)buf;
+ struct gfs_dinode *dip1 = (void *)buf;
unsigned int x, y, ptroff = 0;
uint64_t p, last;
int isdir = 0;
if (S_ISDIR(be32_to_cpu(dip->di_mode)) ||
- (sbd.gfs1 && be16_to_cpu(dip->__pad1) == GFS_FILE_DIR))
+ (sbd.gfs1 && be16_to_cpu(dip1->di_type) == GFS_FILE_DIR))
isdir = 1;
indirect_blocks = 0;
@@ -258,7 +257,7 @@ void do_dinode_extended(char *buf)
/* Indirect pointers */
for (x = sizeof(struct gfs2_dinode); x < sbd.sd_bsize;
x += sizeof(uint64_t)) {
- p = be64_to_cpu(*(uint64_t *)(buf + x));
+ p = be64_to_cpu(*(__be64 *)(buf + x));
if (p) {
indirect->ii[indirect_blocks].block = p;
indirect->ii[indirect_blocks].mp.mp_list[0] =
@@ -289,12 +288,12 @@ void do_dinode_extended(char *buf)
dip->di_height == 0) {
/* Leaf Pointers: */
- last = be64_to_cpu(*(uint64_t *)(buf + sizeof(struct gfs2_dinode)));
+ last = be64_to_cpu(*(__be64 *)(buf + sizeof(struct gfs2_dinode)));
for (x = sizeof(struct gfs2_dinode), y = 0;
y < (1 << be16_to_cpu(dip->di_depth));
x += sizeof(uint64_t), y++) {
- p = be64_to_cpu(*(uint64_t *)(buf + x));
+ p = be64_to_cpu(*(__be64 *)(buf + x));
if (p != last || ((y + 1) * sizeof(uint64_t) == be64_to_cpu(dip->di_size))) {
struct gfs2_buffer_head *tmp_bh;
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index fd7388ce..302f0843 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -40,6 +40,8 @@ static struct gfs2_buffer_head *bh;
static int pgnum;
static long int gziplevel = 9;
static int termcols;
+static struct lgfs2_inum gfs1_quota_di;
+static struct lgfs2_inum gfs1_license_di;
int details = 0;
char *device = NULL;
@@ -445,11 +447,11 @@ int display_block_type(char *buf, uint64_t addr, int from_restore)
if (sbd.gfs1) {
if (block == sbd.sd_rindex_di.in_addr)
print_gfs2("---------------- rindex file -------------------");
- else if (block == gfs1_quota_di.no_addr)
+ else if (block == gfs1_quota_di.in_addr)
print_gfs2("---------------- Quota file --------------------");
else if (block == sbd.sd_jindex_di.in_addr)
print_gfs2("--------------- Journal Index ------------------");
- else if (block == gfs1_license_di.no_addr)
+ else if (block == gfs1_license_di.in_addr)
print_gfs2("--------------- License file -------------------");
}
else {
@@ -501,13 +503,13 @@ static int hexdump(uint64_t startaddr, uint64_t len, int
trunc_zeros,
const char *zeros_strt = lpBuffer + sbd.sd_bsize;
int print_field, cursor_line;
const struct lgfs2_metadata *m = get_block_type(bh->b_data);
- uint64_t *ref;
+ __be64 *ref;
int ptroffset = 0;
strcpy(edit_fmt,"%02x");
pointer = (unsigned char *)lpBuffer + offset;
ptr2 = (unsigned char *)lpBuffer + offset;
- ref = (uint64_t *)lpBuffer + offset;
+ ref = (__be64 *)lpBuffer + offset;
if (trunc_zeros) {
while (zeros_strt > lpBuffer && (*(zeros_strt - 1) == 0))
zeros_strt--;
@@ -810,11 +812,13 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int
modify, int full)
/* ------------------------------------------------------------------------ */
int has_indirect_blocks(void)
{
+ struct gfs_dinode *d1 = (struct gfs_dinode *)di;
+
if (indirect_blocks || gfs2_struct_type == GFS2_METATYPE_SB ||
gfs2_struct_type == GFS2_METATYPE_LF ||
(gfs2_struct_type == GFS2_METATYPE_DI &&
(S_ISDIR(be32_to_cpu(di->di_mode)) ||
- (sbd.gfs1 && be16_to_cpu(di->__pad1) == GFS_FILE_DIR))))
+ (sbd.gfs1 && be16_to_cpu(d1->di_type) == GFS_FILE_DIR))))
return TRUE;
return FALSE;
}
@@ -843,7 +847,7 @@ int block_is_inum_file(uint64_t blk)
int block_is_statfs_file(uint64_t blk)
{
- if (sbd.gfs1 && blk == gfs1_license_di.no_addr)
+ if (sbd.gfs1 && blk == gfs1_license_di.in_addr)
return TRUE;
if (!sbd.gfs1 && blk == masterblock("statfs"))
return TRUE;
@@ -852,7 +856,7 @@ int block_is_statfs_file(uint64_t blk)
int block_is_quota_file(uint64_t blk)
{
- if (sbd.gfs1 && blk == gfs1_quota_di.no_addr)
+ if (sbd.gfs1 && blk == gfs1_quota_di.in_addr)
return TRUE;
if (!sbd.gfs1 && blk == masterblock("quota"))
return TRUE;
@@ -1330,7 +1334,7 @@ uint64_t check_keywords(const char *kword)
blk = masterblock("inum");
else if (!strcmp(kword, "statfs")) {
if (sbd.gfs1)
- blk = gfs1_license_di.no_addr;
+ blk = gfs1_license_di.in_addr;
else
blk = masterblock("statfs");
}
@@ -1343,7 +1347,7 @@ uint64_t check_keywords(const char *kword)
blk = RGLIST_DUMMY_BLOCK;
} else if (!strcmp(kword, "quota")) {
if (sbd.gfs1)
- blk = gfs1_quota_di.no_addr;
+ blk = gfs1_quota_di.in_addr;
else
blk = masterblock("quota");
} else if (!strncmp(kword, "rg ", 3)) {
@@ -1548,7 +1552,7 @@ static void jump(void)
{
if (dmode == HEX_MODE) {
unsigned int col2;
- uint64_t *b;
+ __be64 *b;
const struct lgfs2_metadata *mtype = get_block_type(bh->b_data);
uint32_t block_type = 0;
@@ -1563,7 +1567,7 @@ static void jump(void)
temp_blk = bh->b_blocknr + pnum + 1;
} else if (edit_row[dmode] >= 0) {
col2 = edit_col[dmode] & 0x08;/* thus 0-7->0, 8-15->8 */
- b = (uint64_t *)&bh->b_data[edit_row[dmode]*16 +
+ b = (__be64 *)&bh->b_data[edit_row[dmode]*16 +
offset + col2];
temp_blk = be64_to_cpu(*b);
}
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index e48c5885..29f465a0 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -46,8 +46,6 @@ extern int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
extern int edit_size[DMODES], last_entry_onscreen[DMODES];
extern char edit_fmt[80];
extern struct gfs2_sbd sbd;
-extern struct gfs2_inum gfs1_quota_di; /* kludge because gfs2 sb too small */
-extern struct gfs2_inum gfs1_license_di; /* kludge because gfs2 sb too small */
extern struct gfs2_dinode *di;
extern int screen_chunk_size; /* how much of the 4K can fit on screen */
extern int gfs2_struct_type;
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index d7710c2b..ea32f9a2 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -36,7 +36,6 @@ uint64_t find_journal_block(const char *journal, uint64_t *j_size)
uint64_t jindex_block, jblock = 0;
int amtread;
struct gfs2_buffer_head *jindex_bh, *j_bh;
- char jbuf[sbd.sd_bsize];
journal_num = atoi(journal + 7);
if (journal_num < 0)
@@ -56,17 +55,17 @@ uint64_t find_journal_block(const char *journal, uint64_t *j_size)
if (sbd.gfs1) {
struct gfs2_inode *jiinode;
+ struct gfs_jindex jidx;
jiinode = lgfs2_inode_get(&sbd, jindex_bh);
if (jiinode == NULL)
return 0;
- amtread = gfs2_readi(jiinode, (void *)&jbuf,
+ amtread = gfs2_readi(jiinode, &jidx,
journal_num * sizeof(struct gfs_jindex),
sizeof(struct gfs_jindex));
if (amtread) {
- struct gfs_jindex *ji = (struct gfs_jindex *)jbuf;
- jblock = be64_to_cpu(ji->ji_addr);
- *j_size = (uint64_t)be32_to_cpu(ji->ji_nsegment) * 0x10;
+ jblock = be64_to_cpu(jidx.ji_addr);
+ *j_size = (uint64_t)be32_to_cpu(jidx.ji_nsegment) * 0x10;
}
inode_put(&jiinode);
} else {
@@ -174,10 +173,10 @@ static int fsck_readi(struct gfs2_inode *ip, void *rbuf, uint64_t
roffset,
* This function checks a log descriptor buffer to see if it contains
* references to a given traced block, or its rgrp bitmap block.
*/
-static int ld_is_pertinent(const uint64_t *b, const char *end, uint64_t tblk,
+static int ld_is_pertinent(const __be64 *b, const char *end, uint64_t tblk,
struct rgrp_tree *rgd, uint64_t bitblk)
{
- const uint64_t *blk = b;
+ const __be64 *blk = b;
if (!tblk)
return 1;
@@ -196,7 +195,7 @@ static int ld_is_pertinent(const uint64_t *b, const char *end,
uint64_t tblk,
* print_ld_blks - print all blocks given in a log descriptor
* returns: the number of block numbers it printed
*/
-static int print_ld_blks(const uint64_t *b, const char *end, int start_line,
+static int print_ld_blks(const __be64 *b, const char *end, int start_line,
uint64_t tblk, uint64_t *tblk_off, uint64_t bitblk,
struct rgrp_tree *rgd, uint64_t abs_block, int prnt,
uint64_t *bblk_off, int is_meta_ld)
@@ -223,13 +222,12 @@ static int print_ld_blks(const uint64_t *b, const char *end, int
start_line,
if (is_meta_ld) {
j_bmap_bh = bread(&sbd, abs_block +
bcount);
- sprintf(str, "0x%llx %2s",
- (unsigned long long)be64_to_cpu(*b),
+ sprintf(str, "0x%"PRIx64" %2s",
+ be64_to_cpu(*b),
mtypes[lgfs2_get_block_type(j_bmap_bh->b_data)]);
brelse(j_bmap_bh);
} else {
- sprintf(str, "0x%llx",
- (unsigned long long)be64_to_cpu(*b));
+ sprintf(str, "0x%"PRIx64, be64_to_cpu(*b));
}
print_gfs2("%-18.18s ", str);
}
@@ -360,7 +358,7 @@ static int process_ld(uint64_t abs_block, uint64_t wrappt, uint64_t
j_size,
uint64_t *tblk_off, uint64_t bitblk,
struct rgrp_tree *rgd, int *prnt, uint64_t *bblk_off)
{
- uint64_t *b;
+ __be64 *b;
struct gfs2_log_descriptor *ld = (void *)buf;
int ltndx, is_meta_ld = 0;
int ld_blocks = 0;
@@ -379,9 +377,9 @@ static int process_ld(uint64_t abs_block, uint64_t wrappt, uint64_t
j_size,
"Quota", "Final Entry", "Unknown"}};
if (sbd.gfs1)
- b = (uint64_t *)(buf + sizeof(struct gfs_log_descriptor));
+ b = (__be64 *)(buf + sizeof(struct gfs_log_descriptor));
else
- b = (uint64_t *)(buf + sizeof(struct gfs2_log_descriptor));
+ b = (__be64 *)(buf + sizeof(struct gfs2_log_descriptor));
*prnt = ld_is_pertinent(b, (buf + sbd.sd_bsize), tblk, rgd, bitblk);
if (*prnt) {
@@ -418,7 +416,7 @@ static int meta_has_ref(uint64_t abs_block, int tblk)
const struct lgfs2_metadata *mtype;
struct gfs2_buffer_head *mbh;
int structlen = 0, has_ref = 0;
- uint64_t *b;
+ __be64 *b;
struct gfs2_dinode *dinode;
mbh = bread(&sbd, abs_block);
@@ -431,7 +429,7 @@ static int meta_has_ref(uint64_t abs_block, int tblk)
has_ref = 1;
}
}
- b = (uint64_t *)(mbh->b_data + structlen);
+ b = (__be64 *)(mbh->b_data + structlen);
while (!has_ref && mtype && (char *)b < mbh->b_data +
sbd.sd_bsize) {
if (be64_to_cpu(*b) == tblk)
has_ref = 1;
@@ -452,10 +450,11 @@ static int meta_has_ref(uint64_t abs_block, int tblk)
static uint64_t get_ldref(uint64_t abs_ld, int offset_from_ld)
{
struct gfs2_buffer_head *jbh;
- uint64_t *b, refblk;
+ uint64_t refblk;
+ __be64 *b;
jbh = bread(&sbd, abs_ld);
- b = (uint64_t *)(jbh->b_data + sizeof(struct gfs2_log_descriptor));
+ b = (__be64 *)(jbh->b_data + sizeof(struct gfs2_log_descriptor));
b += offset_from_ld - 1;
refblk = be64_to_cpu(*b);
brelse(jbh);
@@ -618,7 +617,7 @@ void dump_journal(const char *journal, int tblk)
eol(0);
} else if ((ld_blocks > 0) &&
(sbd.gfs1 || block_type == GFS2_METATYPE_LB)) {
- uint64_t *b = (uint64_t *)(buf + (sbd.gfs1 ? 0 : sizeof(struct gfs2_meta_header)));
+ __be64 *b = (__be64 *)(buf + (sbd.gfs1 ? 0 : sizeof(struct gfs2_meta_header)));
print_gfs2("0x%"PRIx64" (j+%4"PRIx64"): Log descriptor"
" continuation block", abs_block,
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 473a2d03..5ccc46a8 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -32,17 +32,23 @@
/* Header for the savemeta output file */
struct savemeta_header {
#define SAVEMETA_MAGIC (0x01171970)
- uint32_t sh_magic;
+ __be32 sh_magic;
#define SAVEMETA_FORMAT (1)
- uint32_t sh_format; /* In case we want to change the layout */
- uint64_t sh_time; /* When savemeta was run */
- uint64_t sh_fs_bytes; /* Size of the fs */
+ __be32 sh_format; /* In case we want to change the layout */
+ __be64 sh_time; /* When savemeta was run */
+ __be64 sh_fs_bytes; /* Size of the fs */
uint8_t __reserved[104];
};
+struct savemeta {
+ time_t sm_time;
+ unsigned sm_format;
+ size_t sm_fs_bytes;
+};
+
struct saved_metablock {
- uint64_t blk;
- uint16_t siglen; /* significant data length */
+ __be64 blk;
+ __be16 siglen; /* significant data length */
/* This needs to be packed because old versions of gfs2_edit read and write the
individual fields separately, so the hole after siglen must be eradicated
before the struct reflects what's on disk. */
@@ -296,15 +302,17 @@ static int block_is_systemfile(uint64_t blk)
static size_t di_save_len(const char *buf, uint64_t owner)
{
const struct gfs2_dinode *dn;
+ const struct gfs_dinode *d1;
uint16_t di_height;
uint32_t di_mode;
int gfs1dir;
dn = (void *)buf;
+ d1 = (void *)buf;
di_mode = be32_to_cpu(dn->di_mode);
di_height = be16_to_cpu(dn->di_height);
/* __pad1 is di_type in gfs1 */
- gfs1dir = sbd.gfs1 && (be16_to_cpu(dn->__pad1) == GFS_FILE_DIR);
+ gfs1dir = sbd.gfs1 && (be16_to_cpu(d1->di_type) == GFS_FILE_DIR);
/* Do not save (user) data from the inode block unless they are
indirect pointers, dirents, symlinks or fs internal data */
@@ -697,8 +705,9 @@ static void save_ea_block(struct metafd *mfd, char *buf, uint64_t
owner)
int e;
for (e = sizeof(struct gfs2_meta_header); e < sbd.sd_bsize; e += rec_len) {
- uint64_t blk, *b;
+ uint64_t blk;
int charoff, i;
+ __be64 *b;
ea = (void *)(buf + e);
/* ea_num_ptrs and ea_name_len are u8 so no endianness worries */
@@ -709,7 +718,7 @@ static void save_ea_block(struct metafd *mfd, char *buf, uint64_t
owner)
sizeof(struct gfs2_ea_header) +
sizeof(uint64_t) - 1;
charoff /= sizeof(uint64_t);
- b = (uint64_t *)buf;
+ b = (__be64 *)buf;
b += charoff + i;
blk = be64_to_cpu(*b);
_buf = check_read_block(sbd.device_fd, blk, owner, NULL, NULL);
@@ -751,9 +760,9 @@ static void save_indirect_blocks(struct metafd *mfd, char *buf,
uint64_t owner,
{
uint64_t old_block = 0, indir_block;
struct block_range *br = NULL;
- uint64_t *ptr;
+ __be64 *ptr;
- for (ptr = (uint64_t *)(buf + headsize);
+ for (ptr = (__be64 *)(buf + headsize);
(char *)ptr < (buf + sbd.sd_bsize); ptr++) {
if (!*ptr)
continue;
@@ -854,6 +863,7 @@ static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t
iblk)
{
struct block_range_queue indq[GFS2_MAX_META_HEIGHT] = {{NULL}};
struct gfs2_dinode *dip = (struct gfs2_dinode *)ibuf;
+ struct gfs_dinode *dip1 = (struct gfs_dinode *)ibuf;
uint16_t height;
int is_exhash;
@@ -869,7 +879,7 @@ static void save_inode_data(struct metafd *mfd, char *ibuf, uint64_t
iblk)
the hash table exists, and we have to save the directory data. */
is_exhash = (S_ISDIR(be32_to_cpu(dip->di_mode)) ||
- (sbd.gfs1 && be16_to_cpu(dip->__pad1) == GFS_FILE_DIR))
&&
+ (sbd.gfs1 && be16_to_cpu(dip1->di_type) == GFS_FILE_DIR))
&&
be32_to_cpu(dip->di_flags) & GFS2_DIF_EXHASH;
if (is_exhash)
height++;
@@ -1090,24 +1100,23 @@ static int save_header(struct metafd *mfd, uint64_t fsbytes)
return 0;
}
-static int parse_header(char *buf, struct savemeta_header *smh)
+static int parse_header(char *buf, struct savemeta *sm)
{
- struct savemeta_header *smh_be = (void *)buf;
+ struct savemeta_header *smh = (void *)buf;
- if (be32_to_cpu(smh_be->sh_magic) != SAVEMETA_MAGIC) {
+ if (be32_to_cpu(smh->sh_magic) != SAVEMETA_MAGIC) {
printf("No valid file header found. Falling back to old format...\n");
return 1;
}
- if (be32_to_cpu(smh_be->sh_format) > SAVEMETA_FORMAT) {
+ if (be32_to_cpu(smh->sh_format) > SAVEMETA_FORMAT) {
printf("This version of gfs2_edit is too old to restore this metadata
format.\n");
return -1;
}
- smh->sh_magic = be32_to_cpu(smh_be->sh_magic);
- smh->sh_format = be32_to_cpu(smh_be->sh_format);
- smh->sh_time = be64_to_cpu(smh_be->sh_time);
- smh->sh_fs_bytes = be64_to_cpu(smh_be->sh_fs_bytes);
- printf("Metadata saved at %s", ctime((time_t *)&smh->sh_time)); /*
ctime() adds \n */
- printf("File system size %.2fGB\n", smh->sh_fs_bytes / ((float)(1 <<
30)));
+ sm->sm_format = be32_to_cpu(smh->sh_format);
+ sm->sm_time = be64_to_cpu(smh->sh_time);
+ sm->sm_fs_bytes = be64_to_cpu(smh->sh_fs_bytes);
+ printf("Metadata saved at %s", ctime(&sm->sm_time)); /* ctime() adds \n
*/
+ printf("File system size %.2fGB\n", sm->sm_fs_bytes / ((float)(1 <<
30)));
return 0;
}
@@ -1206,34 +1215,35 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
exit(0);
}
-static char *restore_block(struct metafd *mfd, struct saved_metablock *svb)
+static char *restore_block(struct metafd *mfd, uint64_t *blk, uint16_t *siglen)
{
- struct saved_metablock *svb_be;
+ struct saved_metablock *svb;
const char *errstr;
char *buf = NULL;
- svb_be = (struct saved_metablock *)(restore_buf_next(mfd, sizeof(*svb)));
- if (svb_be == NULL)
+ svb = (struct saved_metablock *)(restore_buf_next(mfd, sizeof(*svb)));
+ if (svb == NULL)
goto nobuffer;
- svb->blk = be64_to_cpu(svb_be->blk);
- svb->siglen = be16_to_cpu(svb_be->siglen);
+ *blk = be64_to_cpu(svb->blk);
+ *siglen = be16_to_cpu(svb->siglen);
- if (sbd.fssize && svb->blk >= sbd.fssize) {
+ if (sbd.fssize && *blk >= sbd.fssize) {
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);
+ fprintf(stderr, "File system is %"PRIu64" blocks. Restore block =
%"PRIu64"\n",
+ sbd.fssize, *blk);
return NULL;
}
- if (svb->siglen > sbd.sd_bsize) {
+ if (*siglen > sbd.sd_bsize) {
fprintf(stderr, "Bad record length: %u for block %"PRIu64"
(0x%"PRIx64").\n",
- svb->siglen, svb->blk, svb->blk);
+ *siglen, *blk, *blk);
return NULL;
}
- buf = restore_buf_next(mfd, svb->siglen);
- if (buf != NULL)
+ buf = restore_buf_next(mfd, *siglen);
+ if (buf != NULL) {
return buf;
+ }
nobuffer:
if (mfd->eof)
return NULL;
@@ -1266,7 +1276,6 @@ static int restore_super(struct metafd *mfd, void *buf, int
printonly)
static int restore_data(int fd, struct metafd *mfd, int printonly)
{
- struct saved_metablock savedata = {0};
uint64_t writes = 0;
char *buf;
@@ -1277,9 +1286,11 @@ static int restore_data(int fd, struct metafd *mfd, int printonly)
}
while (TRUE) {
+ uint16_t siglen = 0;
+ uint64_t blk = 0;
char *bp;
- bp = restore_block(mfd, &savedata);
+ bp = restore_block(mfd, &blk, &siglen);
if (bp == NULL && mfd->eof)
break;
if (bp == NULL) {
@@ -1287,23 +1298,21 @@ static int restore_data(int fd, struct metafd *mfd, int
printonly)
return -1;
}
if (printonly) {
- if (printonly > 1 && printonly == savedata.blk) {
- display_block_type(bp, savedata.blk, TRUE);
+ if (printonly > 1 && printonly == blk) {
+ display_block_type(bp, blk, TRUE);
display_gfs2(bp);
break;
} else if (printonly == 1) {
- print_gfs2("%"PRId64" (l=0x%x): ", blks_saved, savedata.siglen);
- display_block_type(bp, savedata.blk, TRUE);
+ print_gfs2("%"PRId64" (l=0x%x): ", blks_saved, siglen);
+ display_block_type(bp, blk, TRUE);
}
} else {
- report_progress(savedata.blk, 0);
- memcpy(buf, bp, savedata.siglen);
- memset(buf + savedata.siglen, 0, sbd.sd_bsize - savedata.siglen);
- if (pwrite(fd, buf, sbd.sd_bsize, savedata.blk * sbd.sd_bsize) != sbd.sd_bsize) {
- fprintf(stderr, "write error: %s from %s:%d: block %lld (0x%llx)\n",
- strerror(errno), __FUNCTION__, __LINE__,
- (unsigned long long)savedata.blk,
- (unsigned long long)savedata.blk);
+ report_progress(blk, 0);
+ memcpy(buf, bp, siglen);
+ memset(buf + siglen, 0, sbd.sd_bsize - siglen);
+ if (pwrite(fd, buf, sbd.sd_bsize, blk * sbd.sd_bsize) != sbd.sd_bsize) {
+ fprintf(stderr, "write error: %s from %s:%d: block %"PRIu64"
(0x%"PRIx64")\n",
+ strerror(errno), __FUNCTION__, __LINE__, blk, blk);
free(buf);
return -1;
}
@@ -1326,8 +1335,9 @@ static void complain(const char *complaint)
"<dest file system>\n");
}
-static int restore_init(const char *path, struct metafd *mfd, struct savemeta_header
*smh, int printonly)
+static int restore_init(const char *path, struct metafd *mfd, int printonly)
{
+ struct savemeta sm = {0};
struct gfs2_sb rsb;
uint16_t sb_siglen;
char *end;
@@ -1355,10 +1365,10 @@ static int restore_init(const char *path, struct metafd *mfd,
struct savemeta_he
return -1;
}
bp = restore_buf;
- ret = parse_header(bp, smh);
+ ret = parse_header(bp, &sm);
if (ret == 0) {
- bp = restore_buf + sizeof(*smh);
- restore_off = sizeof(*smh);
+ bp = restore_buf + sizeof(struct savemeta_header);
+ restore_off = sizeof(struct savemeta_header);
} else if (ret == -1) {
return -1;
}
@@ -1381,10 +1391,10 @@ static int restore_init(const char *path, struct metafd *mfd,
struct savemeta_he
if (ret != 0)
return ret;
- if (smh->sh_fs_bytes > 0) {
- sbd.fssize = smh->sh_fs_bytes / sbd.sd_bsize;
+ if (sm.sm_fs_bytes > 0) {
+ sbd.fssize = sm.sm_fs_bytes / sbd.sd_bsize;
printf("Saved file system size is %"PRIu64" blocks, %.2fGB\n",
- sbd.fssize, smh->sh_fs_bytes / ((float)(1 << 30)));
+ sbd.fssize, sm.sm_fs_bytes / ((float)(1 << 30)));
}
printf("Block size is %uB\n", sbd.sd_bsize);
printf("This is gfs%c metadata.\n", sbd.gfs1 ? '1': '2');
@@ -1403,7 +1413,6 @@ static int restore_init(const char *path, struct metafd *mfd, struct
savemeta_he
void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly)
{
- struct savemeta_header smh = {0};
struct metafd mfd = {0};
int error;
@@ -1422,7 +1431,7 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t
printonly)
optional block no */
printonly = check_keywords(out_device);
- error = restore_init(in_fn, &mfd, &smh, printonly);
+ error = restore_init(in_fn, &mfd, printonly);
if (error != 0)
exit(error);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.