gfs2_edit: Code cleanups
cover gfs2_edit: Code cleanups
This patch set removes some uses of global variables, mainly in savemeta.c, so that the code is easier to reason about and less fragile to changes. There are a bunch of patches here as the changes had to be done in reverse call chain order, but they're mostly small and simple.
Andrew Price (23):
gfs2_edit: Don't use the global block variable in block_is_a_journal
gfs2_edit: Don't use the global block variable in block_is_in_per_node
gfs2_edit: Don't use the global block variable in block_is_jindex
gfs2_edit: Don't use the global block variable in block_is_inum_file
gfs2_edit: Don't use global block variable in block_is_statfs_file
gfs2_edit: Don't use global block variable in block_is_quota_file
gfs2_edit: Don't use global block variable in block_is_rindex
gfs2_edit: Don't use the global block variable in block_is_per_node
gfs2_edit: Don't use the global block variable in block_is_systemfile
gfs2_edit: Don't use the global block variable in block_is_rgtree
gfs2_edit: Don't use the global block variable in block_is_journals
gfs2_edit: Only declare the block variable where needed
gfs2_edit: Don't use the global block variable in save_block
gfs2_edit: Don't use the global block variable in save_indirect_blocks
gfs2_edit: Don't use the global block variable in save_inode_data
gfs2_edit: Don't use the global block variable in get_gfs_struct_info
gfs2_edit: Don't use the global block variable in save_ea_block
gfs2_edit: Don't use the global block variable in save_allocated
gfs2_edit: Don't use the global block variable in savemeta
gfs2_edit: Don't use the global bh variable in display_block_type
gfs2_edit: Don't use the global block variable in savemeta.c
gfs2_edit: Don't export bh
gfs2_edit: Remove block_in_mem and fix a memory leak
gfs2/edit/extended.c | 16 +++--- gfs2/edit/gfs2hex.c | 34 ++++++------- gfs2/edit/gfs2hex.h | 2 +- gfs2/edit/hexedit.c | 91 +++++++++++++-------------------- gfs2/edit/hexedit.h | 25 ++++----- gfs2/edit/journal.c | 2 + gfs2/edit/savemeta.c | 140 ++++++++++++++++++++++++++------------------------- 7 files changed, 145 insertions(+), 165 deletions(-)
Signature · 1 line
2.4.3
PATCH 1/23 gfs2_edit: Don't use the global block variable in block_is_a_journal
Accept it as an argument instead.
--- gfs2/edit/savemeta.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
gfs2/edit/savemeta.c +3 -3
@@ -64,12 +64,12 @@ static int journals_found = 0;int print_level =MSG_NOTICE ;extern char *device; -static int block_is_a_journal (void ) +static int block_is_a_journal (uint64_t blk) {int j;for (j =0 ; j < journals_found; j++) -if (block == journal_blocks[j]) +if (blk == journal_blocks[j])return TRUE;return FALSE; }
@@ -168,7 +168,7 @@ static int block_is_systemfile(void) {return block_is_jindex () ||block_is_inum_file () ||block_is_statfs_file () ||block_is_quota_file () || -block_is_rindex () ||block_is_a_journal () || +block_is_rindex () ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (); }
Signature · 1 line
2.4.3
PATCH 2/23 gfs2_edit: Don't use the global block variable in block_is_in_per_node
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/savemeta.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
gfs2/edit/savemeta.c +4 -4
@@ -92,14 +92,14 @@ static void destroy_per_node_lookup(void) } } -static int block_is_in_per_node (void ) +static int block_is_in_per_node (uint64_t blk) {struct per_node_node *pnp = (struct per_node_node *)per_node_tree.osi_node;while (pnp) { -if (block < pnp->block) +if (blk < pnp->block) pnp = (struct per_node_node *)pnp->node.osi_left; -else if (block > pnp->block) +else if (blk > pnp->block) pnp = (struct per_node_node *)pnp->node.osi_right;else return 1 ;
@@ -169,7 +169,7 @@ static int block_is_systemfile(void)return block_is_jindex () ||block_is_inum_file () ||block_is_statfs_file () ||block_is_quota_file () ||block_is_rindex () ||block_is_a_journal (block) || -block_is_per_node () ||block_is_in_per_node (); +block_is_per_node () ||block_is_in_per_node (block); }/**
Signature · 1 line
2.4.3
PATCH 3/23 gfs2_edit: Don't use the global block variable in block_is_jindex
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 9 +++------ gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -684,7 +684,7 @@ int display_extended(void)parse_rindex (tmp_inode, FALSE);inode_put (&tmp_inode);brelse (tmp_bh); - }else if (block_is_jindex ()) { + }else if (block_is_jindex (block)) { tmp_bh =bread (&sbd, block); tmp_inode =lgfs2_inode_get (&sbd, tmp_bh);if (tmp_inode ==NULL )
gfs2/edit/hexedit.c +3 -6
@@ -890,12 +890,9 @@ int block_is_rindex(void)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_jindex */ -/* ------------------------------------------------------------------------ */ -int block_is_jindex (void ) +int block_is_jindex (uint64_t blk) { -if ((sbd.gfs1 && block == sbd1->sb_jindex_di.no_addr)) +if ((sbd.gfs1 && blk == sbd1->sb_jindex_di.no_addr))return TRUE;return FALSE; }
@@ -953,7 +950,7 @@ static int block_has_extended_info(void)block_is_rindex () ||block_is_rgtree () ||block_is_journals () || -block_is_jindex () || +block_is_jindex (block) ||block_is_inum_file () ||block_is_statfs_file () || block_is_quota_file())
gfs2/edit/hexedit.h +1 -1
@@ -218,7 +218,7 @@ void die(const char *fmt, ...) } \ }while (0 ) -extern int block_is_jindex(void); +extern int block_is_jindex(uint64_t blk);extern int block_is_rindex (void );extern int block_is_inum_file (void );extern int block_is_statfs_file (void );
gfs2/edit/savemeta.c +1 -1
@@ -166,7 +166,7 @@ static int init_per_node_lookup(void)static int block_is_systemfile (void ) { -return block_is_jindex () ||block_is_inum_file () || +return block_is_jindex (block) ||block_is_inum_file () ||block_is_statfs_file () ||block_is_quota_file () ||block_is_rindex () ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (block);
Signature · 1 line
2.4.3
PATCH 4/23 gfs2_edit: Don't use the global block variable in block_is_inum_file
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 9 +++------ gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -693,7 +693,7 @@ int display_extended(void)inode_put (&tmp_inode);brelse (tmp_bh); } -else if (block_is_inum_file ()) { +else if (block_is_inum_file (block)) { tmp_bh =bread (&sbd, block); tmp_inode =lgfs2_inode_get (&sbd, tmp_bh);if (tmp_inode ==NULL )
gfs2/edit/hexedit.c +3 -6
@@ -897,12 +897,9 @@ int block_is_jindex(uint64_t blk)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_inum_file */ -/* ------------------------------------------------------------------------ */ -int block_is_inum_file (void ) +int block_is_inum_file (uint64_t blk) { -if (!sbd.gfs1 && block ==masterblock ("inum" )) +if (!sbd.gfs1 && blk ==masterblock ("inum" ))return TRUE;return FALSE; }
@@ -951,7 +948,7 @@ static int block_has_extended_info(void)block_is_rgtree () ||block_is_journals () ||block_is_jindex (block) || -block_is_inum_file () || +block_is_inum_file (block) ||block_is_statfs_file () || block_is_quota_file()) return TRUE;
gfs2/edit/hexedit.h +1 -1
@@ -220,7 +220,7 @@ void die(const char *fmt, ...)extern int block_is_jindex (uint64_t blk);extern int block_is_rindex (void ); -extern int block_is_inum_file (void ); +extern int block_is_inum_file (uint64_t blk);extern int block_is_statfs_file (void );extern int block_is_quota_file (void );extern int block_is_per_node (void );
gfs2/edit/savemeta.c +1 -1
@@ -166,7 +166,7 @@ static int init_per_node_lookup(void)static int block_is_systemfile (void ) { -return block_is_jindex (block) ||block_is_inum_file () || +return block_is_jindex (block) ||block_is_inum_file (block) ||block_is_statfs_file () ||block_is_quota_file () ||block_is_rindex () ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (block);
Signature · 1 line
2.4.3
PATCH 5/23 gfs2_edit: Don't use global block variable in block_is_statfs_file
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 11 ++++------- gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -702,7 +702,7 @@ int display_extended(void)inode_put (&tmp_inode);brelse (tmp_bh); } -else if (block_is_statfs_file ()) { +else if (block_is_statfs_file (block)) { tmp_bh =bread (&sbd, block); tmp_inode =lgfs2_inode_get (&sbd, tmp_bh);if (tmp_inode ==NULL )
gfs2/edit/hexedit.c +4 -7
@@ -904,14 +904,11 @@ int block_is_inum_file(uint64_t blk)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_statfs_file */ -/* ------------------------------------------------------------------------ */ -int block_is_statfs_file (void ) +int block_is_statfs_file (uint64_t blk) { -if (sbd.gfs1 && block == gfs1_license_di.no_addr) +if (sbd.gfs1 && blk == gfs1_license_di.no_addr)return TRUE; -if (!sbd.gfs1 && block ==masterblock ("statfs" )) +if (!sbd.gfs1 && blk ==masterblock ("statfs" ))return TRUE;return FALSE; }
@@ -949,7 +946,7 @@ static int block_has_extended_info(void)block_is_journals () ||block_is_jindex (block) ||block_is_inum_file (block) || -block_is_statfs_file () || +block_is_statfs_file (block) || block_is_quota_file()) return TRUE;return FALSE;
gfs2/edit/hexedit.h +1 -1
@@ -221,7 +221,7 @@ void die(const char *fmt, ...)extern int block_is_jindex (uint64_t blk);extern int block_is_rindex (void );extern int block_is_inum_file (uint64_t blk); -extern int block_is_statfs_file (void ); +extern int block_is_statfs_file (uint64_t blk);extern int block_is_quota_file (void );extern int block_is_per_node (void );extern int display_block_type (int from_restore);
gfs2/edit/savemeta.c +1 -1
@@ -167,7 +167,7 @@ static int init_per_node_lookup(void)static int block_is_systemfile (void ) {return block_is_jindex (block) ||block_is_inum_file (block) || -block_is_statfs_file () ||block_is_quota_file () || +block_is_statfs_file (block) ||block_is_quota_file () ||block_is_rindex () ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (block); }
Signature · 1 line
2.4.3
PATCH 6/23 gfs2_edit: Don't use global block variable in block_is_quota_file
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 11 ++++------- gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -711,7 +711,7 @@ int display_extended(void)inode_put (&tmp_inode);brelse (tmp_bh); } -else if (block_is_quota_file ()) { +else if (block_is_quota_file (block)) { tmp_bh =bread (&sbd, block); tmp_inode =lgfs2_inode_get (&sbd, tmp_bh);if (tmp_inode ==NULL )
gfs2/edit/hexedit.c +4 -7
@@ -913,14 +913,11 @@ int block_is_statfs_file(uint64_t blk)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_quota_file */ -/* ------------------------------------------------------------------------ */ -int block_is_quota_file (void ) +int block_is_quota_file (uint64_t blk) { -if (sbd.gfs1 && block == gfs1_quota_di.no_addr) +if (sbd.gfs1 && blk == gfs1_quota_di.no_addr)return TRUE; -if (!sbd.gfs1 && block ==masterblock ("quota" )) +if (!sbd.gfs1 && blk ==masterblock ("quota" ))return TRUE;return FALSE; }
@@ -947,7 +944,7 @@ static int block_has_extended_info(void)block_is_jindex (block) ||block_is_inum_file (block) ||block_is_statfs_file (block) || - block_is_quota_file()) + block_is_quota_file(block)) return TRUE;return FALSE; }
gfs2/edit/hexedit.h +1 -1
@@ -222,7 +222,7 @@ extern int block_is_jindex(uint64_t blk);extern int block_is_rindex (void );extern int block_is_inum_file (uint64_t blk);extern int block_is_statfs_file (uint64_t blk); -extern int block_is_quota_file (void ); +extern int block_is_quota_file (uint64_t blk);extern int block_is_per_node (void );extern int display_block_type (int from_restore);extern void gfs_jindex_in (struct gfs_jindex *jindex,char *buf);
gfs2/edit/savemeta.c +1 -1
@@ -167,7 +167,7 @@ static int init_per_node_lookup(void)static int block_is_systemfile (void ) {return block_is_jindex (block) ||block_is_inum_file (block) || -block_is_statfs_file (block) ||block_is_quota_file () || +block_is_statfs_file (block) ||block_is_quota_file (block) ||block_is_rindex () ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (block); }
Signature · 1 line
2.4.3
PATCH 7/23 gfs2_edit: Don't use global block variable in block_is_rindex
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 13 +++++-------- gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -654,7 +654,7 @@ int display_extended(void) dsplines = termlines - line -1 ;/* Display any indirect pointers that we have. */ -if (block_is_rindex ()) { +if (block_is_rindex (block)) { tmp_bh =bread (&sbd, block); tmp_inode =lgfs2_inode_get (&sbd, tmp_bh);if (tmp_inode ==NULL )
gfs2/edit/hexedit.c +5 -8
@@ -879,13 +879,10 @@ int has_indirect_blocks(void)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_rindex */ -/* ------------------------------------------------------------------------ */ -int block_is_rindex (void ) +int block_is_rindex (uint64_t blk) { -if ((sbd.gfs1 && block == sbd1->sb_rindex_di.no_addr) || - (block ==masterblock ("rindex" ))) +if ((sbd.gfs1 && blk == sbd1->sb_rindex_di.no_addr) || + (blk ==masterblock ("rindex" )))return TRUE;return FALSE; }
@@ -938,7 +935,7 @@ int block_is_per_node(void)static int block_has_extended_info (void ) { if (has_indirect_blocks() || - block_is_rindex() || + block_is_rindex(block) || block_is_rgtree() || block_is_journals() || block_is_jindex(block) ||
@@ -1187,7 +1184,7 @@ static void push_block(uint64_t blk) blockstack[bhst].lines_per_row[i] = lines_per_row[i]; } blockstack[bhst].gfs2_struct_type = gfs2_struct_type; -if (edit_row[dmode] >=0 && !block_is_rindex ()) +if (edit_row[dmode] >=0 && !block_is_rindex (block))memcpy (&blockstack[bhst].mp, &indirect->ii[edit_row[dmode]].mp,sizeof (struct metapath ));
gfs2/edit/hexedit.h +1 -1
@@ -219,7 +219,7 @@ void die(const char *fmt, ...) }while (0 ) extern int block_is_jindex(uint64_t blk); -extern int block_is_rindex (void ); +extern int block_is_rindex (uint64_t blk);extern int block_is_inum_file (uint64_t blk);extern int block_is_statfs_file (uint64_t blk);extern int block_is_quota_file (uint64_t blk);
gfs2/edit/savemeta.c +1 -1
@@ -168,7 +168,7 @@ static int block_is_systemfile(void) {return block_is_jindex (block) ||block_is_inum_file (block) ||block_is_statfs_file (block) ||block_is_quota_file (block) || -block_is_rindex () ||block_is_a_journal (block) || +block_is_rindex (block) ||block_is_a_journal (block) ||block_is_per_node () ||block_is_in_per_node (block); }
Signature · 1 line
2.4.3
PATCH 8/23 gfs2_edit: Don't use the global block variable in block_is_per_node
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/hexedit.c | 7 ++----- gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
gfs2/edit/hexedit.c +2 -5
@@ -919,12 +919,9 @@ int block_is_quota_file(uint64_t blk)return FALSE; } -/* ------------------------------------------------------------------------ */ -/* block_is_per_node */ -/* ------------------------------------------------------------------------ */ -int block_is_per_node (void ) +int block_is_per_node (uint64_t blk) { -if (!sbd.gfs1 && block ==masterblock ("per_node" )) +if (!sbd.gfs1 && blk ==masterblock ("per_node" ))return TRUE;return FALSE; }
gfs2/edit/hexedit.h +1 -1
@@ -223,7 +223,7 @@ extern int block_is_rindex(uint64_t blk);extern int block_is_inum_file (uint64_t blk);extern int block_is_statfs_file (uint64_t blk);extern int block_is_quota_file (uint64_t blk); -extern int block_is_per_node (void ); +extern int block_is_per_node (uint64_t blk);extern int display_block_type (int from_restore);extern void gfs_jindex_in (struct gfs_jindex *jindex,char *buf); extern void gfs_log_header_in(struct gfs_log_header *head,
gfs2/edit/savemeta.c +1 -1
@@ -169,7 +169,7 @@ static int block_is_systemfile(void)return block_is_jindex (block) ||block_is_inum_file (block) ||block_is_statfs_file (block) ||block_is_quota_file (block) ||block_is_rindex (block) ||block_is_a_journal (block) || -block_is_per_node () ||block_is_in_per_node (block); +block_is_per_node (block) ||block_is_in_per_node (block); }/**
Signature · 1 line
2.4.3
PATCH 9/23 gfs2_edit: Don't use the global block variable in block_is_systemfile
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/savemeta.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
gfs2/edit/savemeta.c +8 -8
@@ -164,12 +164,12 @@ static int init_per_node_lookup(void)return 0 ; } -static int block_is_systemfile (void ) +static int block_is_systemfile (uint64_t blk) { -return block_is_jindex (block) ||block_is_inum_file (block) || -block_is_statfs_file (block) ||block_is_quota_file (block) || -block_is_rindex (block) ||block_is_a_journal (block) || -block_is_per_node (block) ||block_is_in_per_node (block); +return block_is_jindex (blk) ||block_is_inum_file (blk) || +block_is_statfs_file (blk) ||block_is_quota_file (blk) || +block_is_rindex (blk) ||block_is_a_journal (blk) || +block_is_per_node (blk) ||block_is_in_per_node (blk); }/**
@@ -238,7 +238,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,if (S_ISDIR (inode->i_di.di_mode) || (sbd.gfs1 && inode->i_di.__pad1 ==GFS_FILE_DIR )) *gstruct_len = sbd.bsize; -else if (!inode->i_di.di_height && !block_is_systemfile () && +else if (!inode->i_di.di_height && !block_is_systemfile (block) && !S_ISDIR (inode->i_di.di_mode)) *gstruct_len =sizeof (struct gfs2_dinode );else
@@ -425,7 +425,7 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk)inode, not the block within the inode "blk". They may or may not be the same thing. */ if (get_gfs_struct_info (savebh, &blktype, &blklen) && - !block_is_systemfile ()) { + !block_is_systemfile (block)) {brelse (savebh);return 0 ;/* Not metadata, and not system file, so skip it */ }
@@ -576,7 +576,7 @@ static void save_inode_data(struct metafd *mfd) (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))) height++; else if (height && !(inode->i_di.di_flags & GFS2_DIF_SYSTEM) && - !block_is_systemfile() && !S_ISDIR(inode->i_di.di_mode)) + !block_is_systemfile(block) && !S_ISDIR(inode->i_di.di_mode)) height--;osi_list_add (&metabh->b_altlist, &metalist[0 ]);for (i =1 ; i <= height; i++){
Signature · 1 line
2.4.3
PATCH 10/23 gfs2_edit: Don't use the global block variable in block_is_rgtree
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 2 +- gfs2/edit/hexedit.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -673,7 +673,7 @@ int display_extended(void)return -1 ; else if (display_indirect(indirect, indirect_blocks, 0, 0) == 0) return -1; - else if (block_is_rgtree()) { + else if (block_is_rgtree(block)) {if (sbd.gfs1) tmp_bh =bread (&sbd, sbd1->sb_rindex_di.no_addr);else
gfs2/edit/hexedit.c +1 -1
@@ -933,7 +933,7 @@ static int block_has_extended_info(void) { if (has_indirect_blocks() || block_is_rindex(block) || - block_is_rgtree() || + block_is_rgtree(block) || block_is_journals() || block_is_jindex(block) || block_is_inum_file(block) ||
gfs2/edit/hexedit.h +2 -2
@@ -114,9 +114,9 @@ extern enum dsp_mode dmode;/* special case meant to parse the rindex and follow the */ /* blocks to the real rgs. */ /* ------------------------------------------------------------------------ */ -static inline int block_is_rgtree (void ) +static inline int block_is_rgtree (uint64_t blk) { -if (block ==RGLIST_DUMMY_BLOCK ) +if (blk ==RGLIST_DUMMY_BLOCK )return TRUE;return FALSE; }
Signature · 1 line
2.4.3
PATCH 11/23 gfs2_edit: Don't use the global block variable in block_is_journals
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/extended.c | 2 +- gfs2/edit/hexedit.c | 2 +- gfs2/edit/hexedit.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
gfs2/edit/extended.c +1 -1
@@ -662,7 +662,7 @@ int display_extended(void)parse_rindex (tmp_inode, TRUE);inode_put (&tmp_inode);brelse (tmp_bh); - }else if (block_is_journals ()) { + }else if (block_is_journals (block)) {if (sbd.gfs1) block = sbd1->sb_jindex_di.no_addr;else
gfs2/edit/hexedit.c +1 -1
@@ -934,7 +934,7 @@ static int block_has_extended_info(void) if (has_indirect_blocks() || block_is_rindex(block) || block_is_rgtree(block) || - block_is_journals() || + block_is_journals(block) || block_is_jindex(block) || block_is_inum_file(block) || block_is_statfs_file(block) ||
gfs2/edit/hexedit.h +2 -2
@@ -121,9 +121,9 @@ static inline int block_is_rgtree(uint64_t blk)return FALSE; } -static inline int block_is_journals (void ) +static inline int block_is_journals (uint64_t blk) { -if (block ==JOURNALS_DUMMY_BLOCK ) +if (blk ==JOURNALS_DUMMY_BLOCK )return TRUE;return FALSE; }
Signature · 1 line
2.4.3
PATCH 12/23 gfs2_edit: Only declare the block variable where needed
In reply to Andrew PriceThis will help in removing it.
--- gfs2/edit/extended.c | 2 ++ gfs2/edit/hexedit.c | 1 + gfs2/edit/hexedit.h | 1 - gfs2/edit/journal.c | 2 ++ gfs2/edit/savemeta.c | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-)
gfs2/edit/extended.c +2 -0
@@ -27,6 +27,8 @@#include "extended.h" #include "gfs2hex.h" +extern uint64_t block; +static void print_block_details (struct iinfo *ind,int level,int cur_height,int pndx,uint64_t file_offset);
gfs2/edit/hexedit.c +1 -0
@@ -45,6 +45,7 @@ int details = 0;long int gziplevel =9 ;static int termcols;char *device =NULL ; +extern uint64_t block;/* ------------------------------------------------------------------------- */ /* erase - clear the screen */
gfs2/edit/hexedit.h +0 -1
@@ -29,7 +29,6 @@ enum dsp_mode { HEX_MODE = 0, GFS2_MODE = 1, EXTENDED_MODE = 2, INIT_MODE = 3 };extern const char *mtypes[];extern struct gfs2_sb sb; -extern uint64_t block;extern int blockhist;extern int edit_mode;extern int line;
gfs2/edit/journal.c +2 -0
@@ -28,6 +28,8 @@#include "gfs2hex.h" #include "journal.h" +extern uint64_t block; +/** * find_journal_block - figure out where a journal starts, given the name * Returns: journal block number, changes j_size to the journal size
gfs2/edit/savemeta.c +2 -0
@@ -27,6 +27,8 @@#include "hexedit.h" #include "libgfs2.h" +extern uint64_t block; +#define DFT_SAVE_FILE "/tmp/gfsmeta.XXXXXX"#define MAX_JOURNALS_SAVED 256
Signature · 1 line
2.4.3
PATCH 13/23 gfs2_edit: Don't use the global block variable in save_block
In reply to Andrew PriceAccept the block's owner's address as an argument instead.
--- gfs2/edit/savemeta.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
gfs2/edit/savemeta.c +17 -17
@@ -405,7 +405,7 @@ static int savemetaclose(struct metafd *mfd)return close (mfd->fd); } -static int save_block (int fd,struct metafd *mfd,uint64_t blk) +static int save_block (int fd,struct metafd *mfd,uint64_t blk,uint64_t owner) {int blktype, blklen;size_t outsz;
@@ -416,18 +416,18 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk)fprintf (stderr,"\nWarning: bad block pointer '0x%llx' " "ignored in block (block %llu (0x%llx))" , (unsigned long long )blk, - (unsigned long long )block, (unsigned long long )block); + (unsigned long long )owner, (unsigned long long )owner);return 0 ; } savebh =bread (&sbd, blk);/* If this isn't metadata and isn't a system file, we don't want it. -Note that we're checking "block" here rather than blk. That's -because we want to know if the source inode's "block" is a system -inode, not the block within the inode "blk". They may or may not +Note that we're checking "owner" here rather than blk. That's +because we want to know if the source inode is a system inode +not the block within the inode "blk". They may or may not be the same thing. */ if (get_gfs_struct_info (savebh, &blktype, &blklen) && - !block_is_systemfile (block)) { + !block_is_systemfile (owner)) {brelse (savebh);return 0 ;/* Not metadata, and not system file, so skip it */ }
@@ -484,7 +484,7 @@ static void save_ea_block(struct metafd *mfd, struct gfs2_buffer_head *metabh) b = (uint64_t *)(metabh->b_data); b += charoff + i; blk =be64_to_cpu (*b); -save_block (sbd.device_fd, mfd, blk); +save_block (sbd.device_fd, mfd, blk, block); }if (!ea.ea_rec_len)break ;
@@ -514,7 +514,7 @@ static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list,if (indir_block == old_block)continue ; old_block = indir_block; - blktype =save_block (sbd.device_fd, mfd, indir_block); + blktype =save_block (sbd.device_fd, mfd, indir_block, block);if (blktype ==GFS2_METATYPE_EA ) { nbh =bread (&sbd, indir_block);save_ea_block (mfd, nbh);
@@ -625,7 +625,7 @@ static void save_inode_data(struct metafd *mfd) mybh =bread (&sbd, leaf_no);warm_fuzzy_stuff (block, FALSE);if (gfs2_check_meta (mybh,GFS2_METATYPE_LF ) ==0 ) -save_block (sbd.device_fd, mfd, leaf_no); +save_block (sbd.device_fd, mfd, leaf_no, block);brelse (mybh); } }
@@ -634,7 +634,7 @@ static void save_inode_data(struct metafd *mfd)struct gfs2_buffer_head *lbh; lbh =bread (&sbd, inode->i_di.di_eattr); -save_block (sbd.device_fd, mfd, inode->i_di.di_eattr); +save_block (sbd.device_fd, mfd, inode->i_di.di_eattr, block);gfs2_meta_header_in (&mh, lbh);if (mh.mh_magic ==GFS2_MAGIC && mh.mh_type ==GFS2_METATYPE_EA )
@@ -645,7 +645,7 @@ static void save_inode_data(struct metafd *mfd)else {if (mh.mh_magic ==GFS2_MAGIC )/* if it's metadata */ save_block (sbd.device_fd, mfd, - inode->i_di.di_eattr); + inode->i_di.di_eattr, block);fprintf (stderr,"\nWarning: corrupt extended " "attribute at block %llu (0x%llx) "
@@ -721,7 +721,7 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd)for (j =0 ; j < m; j++) { block = ibuf[j];warm_fuzzy_stuff (block, FALSE); - blktype =save_block (sbd.device_fd, mfd, block); + blktype =save_block (sbd.device_fd, mfd, block, block);if (blktype ==GFS2_METATYPE_DI )save_inode_data (mfd); }
@@ -733,7 +733,7 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd)* If we don't, we may run into metadata allocation issues. */ m =lgfs2_bm_scan (rgd, i, ibuf,GFS2_BLKST_UNLINKED );for (j =0 ; j < m; j++) { -save_block (sbd.device_fd, mfd, block); +save_block (sbd.device_fd, mfd, block, block); } }free (ibuf);
@@ -825,14 +825,14 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)exit (1 ); }/* Save off the superblock */ -save_block (sbd.device_fd, &mfd,GFS2_SB_ADDR *GFS2_BASIC_BLOCK / sbd.bsize); +save_block (sbd.device_fd, &mfd,GFS2_SB_ADDR *GFS2_BASIC_BLOCK / sbd.bsize, block);/* If this is gfs1, save off the rindex because it's not part of the file system as it is in gfs2. */ if (sbd.gfs1) {int j; block = sbd1->sb_rindex_di.no_addr; -save_block (sbd.device_fd, &mfd, block); +save_block (sbd.device_fd, &mfd, block, block);save_inode_data (&mfd);/* In GFS1, journals aren't part of the RG space */ for (j =0 ; j < journals_found; j++) {
@@ -840,7 +840,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)for (block = journal_blocks[j]; block < journal_blocks[j] + gfs1_journal_size; block++) -save_block (sbd.device_fd, &mfd, block); +save_block (sbd.device_fd, &mfd, block, block); } }/* Walk through the resource groups saving everything within */
@@ -858,7 +858,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)for (block = rgd->ri.ri_addr; block < rgd->ri.ri_data0; block++) {warm_fuzzy_stuff (block, FALSE); -save_block (sbd.device_fd, &mfd, block); +save_block (sbd.device_fd, &mfd, block, block); }/* Save off the other metadata: inodes, etc. if mode is not 'savergs' */ if (saveoption !=2 ) {
Signature · 1 line
2.4.3
PATCH 14/23 gfs2_edit: Don't use the global block variable in save_indirect_blocks
In reply to Andrew PriceAccept the block's owner's address as an argument instead.
--- gfs2/edit/savemeta.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
gfs2/edit/savemeta.c +4 -4
@@ -495,7 +495,7 @@ static void save_ea_block(struct metafd *mfd, struct gfs2_buffer_head *metabh)* save_indirect_blocks - save all indirect blocks for the given buffer */ static void save_indirect_blocks (struct metafd *mfd,osi_list_t *cur_list, -struct gfs2_buffer_head *mybh,int height,int hgt) +struct gfs2_buffer_head *mybh,uint64_t owner,int height,int hgt) {uint64_t old_block =0 , indir_block;uint64_t *ptr;
@@ -514,7 +514,7 @@ static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list,if (indir_block == old_block)continue ; old_block = indir_block; - blktype =save_block (sbd.device_fd, mfd, indir_block, block); + blktype =save_block (sbd.device_fd, mfd, indir_block, owner);if (blktype ==GFS2_METATYPE_EA ) { nbh =bread (&sbd, indir_block);save_ea_block (mfd, nbh);
@@ -589,7 +589,7 @@ static void save_inode_data(struct metafd *mfd) mybh = osi_list_entry(tmp, struct gfs2_buffer_head, b_altlist);warm_fuzzy_stuff (block, FALSE); -save_indirect_blocks (mfd, cur_list, mybh, +save_indirect_blocks (mfd, cur_list, mybh, block, height, i); }/* for blocks at that height */ }/* for height */
@@ -641,7 +641,7 @@ static void save_inode_data(struct metafd *mfd)save_ea_block (mfd, lbh); else if (mh.mh_magic == GFS2_MAGIC && mh.mh_type == GFS2_METATYPE_IN) - save_indirect_blocks(mfd, cur_list, lbh, 2, 2); + save_indirect_blocks(mfd, cur_list, lbh, block, 2, 2); else {if (mh.mh_magic ==GFS2_MAGIC )/* if it's metadata */ save_block(sbd.device_fd, mfd,
Signature · 1 line
2.4.3
PATCH 15/23 gfs2_edit: Don't use the global block variable in save_inode_data
In reply to Andrew PriceAccept the block's owner's address as an argument instead.
--- gfs2/edit/savemeta.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
gfs2/edit/savemeta.c +15 -15
@@ -535,7 +535,7 @@ static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list,* save_inode_data - save off important data associated with an inode * * mfd - destination file descriptor -* block - block number of the inode to save the data for +* iblk - block number of the inode to save the data for * * For user files, we don't want anything except all the indirect block * pointers that reside on blocks on all but the highest height.
@@ -546,7 +546,7 @@ static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list,* For file system journals, the "data" is a mixture of metadata and * journaled data. We want all the metadata and none of the user data. */ -static void save_inode_data (struct metafd *mfd) +static void save_inode_data (struct metafd *mfd,uint64_t iblk) {uint32_t height;struct gfs2_inode *inode;
@@ -557,7 +557,7 @@ static void save_inode_data(struct metafd *mfd)for (i =0 ; i <GFS2_MAX_META_HEIGHT ; i++)osi_list_init (&metalist[i]); - metabh =bread (&sbd, block); + metabh =bread (&sbd, iblk);if (sbd.gfs1) { inode =lgfs2_gfs_inode_get (&sbd, metabh); }else {
@@ -578,7 +578,7 @@ static void save_inode_data(struct metafd *mfd) (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))) height++; else if (height && !(inode->i_di.di_flags & GFS2_DIF_SYSTEM) && - !block_is_systemfile(block) && !S_ISDIR(inode->i_di.di_mode)) + !block_is_systemfile(iblk) && !S_ISDIR(inode->i_di.di_mode)) height--;osi_list_add (&metabh->b_altlist, &metalist[0 ]);for (i =1 ; i <= height; i++){
@@ -588,8 +588,8 @@ static void save_inode_data(struct metafd *mfd)for (tmp = prev_list->next; tmp != prev_list; tmp = tmp->next){ mybh = osi_list_entry(tmp, struct gfs2_buffer_head, b_altlist); -warm_fuzzy_stuff (block, FALSE); -save_indirect_blocks (mfd, cur_list, mybh, block, +warm_fuzzy_stuff (iblk, FALSE); +save_indirect_blocks (mfd, cur_list, mybh, iblk, height, i); }/* for blocks at that height */ }/* for height */
@@ -623,9 +623,9 @@ static void save_inode_data(struct metafd *mfd)continue ; old_leaf = leaf_no; mybh =bread (&sbd, leaf_no); -warm_fuzzy_stuff (block, FALSE); +warm_fuzzy_stuff (iblk, FALSE);if (gfs2_check_meta (mybh,GFS2_METATYPE_LF ) ==0 ) -save_block (sbd.device_fd, mfd, leaf_no, block); +save_block (sbd.device_fd, mfd, leaf_no, iblk);brelse (mybh); } }
@@ -634,26 +634,26 @@ static void save_inode_data(struct metafd *mfd)struct gfs2_buffer_head *lbh; lbh =bread (&sbd, inode->i_di.di_eattr); -save_block (sbd.device_fd, mfd, inode->i_di.di_eattr, block); +save_block (sbd.device_fd, mfd, inode->i_di.di_eattr, iblk);gfs2_meta_header_in (&mh, lbh);if (mh.mh_magic ==GFS2_MAGIC && mh.mh_type ==GFS2_METATYPE_EA )save_ea_block (mfd, lbh);else if (mh.mh_magic ==GFS2_MAGIC && mh.mh_type ==GFS2_METATYPE_IN ) -save_indirect_blocks (mfd, cur_list, lbh, block,2 ,2 ); +save_indirect_blocks (mfd, cur_list, lbh, iblk,2 ,2 );else {if (mh.mh_magic ==GFS2_MAGIC )/* if it's metadata */ save_block (sbd.device_fd, mfd, - inode->i_di.di_eattr, block); + inode->i_di.di_eattr, iblk);fprintf (stderr,"\nWarning: corrupt extended " "attribute at block %llu (0x%llx) " "detected in inode %lld (0x%llx).\n" , (unsigned long long )inode->i_di.di_eattr, (unsigned long long )inode->i_di.di_eattr, - (unsigned long long )block, - (unsigned long long )block); + (unsigned long long )iblk, + (unsigned long long )iblk); }brelse (lbh); }
@@ -723,7 +723,7 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd)warm_fuzzy_stuff (block, FALSE); blktype =save_block (sbd.device_fd, mfd, block, block);if (blktype ==GFS2_METATYPE_DI ) -save_inode_data (mfd); +save_inode_data (mfd, block); }if (!sbd.gfs1)
@@ -833,7 +833,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) block = sbd1->sb_rindex_di.no_addr;save_block (sbd.device_fd, &mfd, block, block); -save_inode_data (&mfd); +save_inode_data (&mfd, block);/* In GFS1, journals aren't part of the RG space */ for (j =0 ; j < journals_found; j++) {log_debug ("Saving journal #%d\n" , j +1 );
Signature · 1 line
2.4.3
PATCH 16/23 gfs2_edit: Don't use the global block variable in get_gfs_struct_info
In reply to Andrew PriceAccept the block's owner's address as an argument instead.
--- gfs2/edit/savemeta.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
gfs2/edit/savemeta.c +7 -5
@@ -196,14 +196,16 @@ static const char *anthropomorphize(unsigned long long inhuman_value)/* * get_gfs_struct_info - get block type and structure length * +* @lbh - The block buffer to examine +* @owner - The block address of the parent structure * @block_type - pointer to integer to hold the block type -* @struct_length - pointer to integet to hold the structure length +* @gstruct_len - pointer to integer to hold the structure length * * returns: 0 if successful * -1 if this isn't gfs metadata. */ -static int get_gfs_struct_info (struct gfs2_buffer_head *lbh,int *block_type, -int *gstruct_len) +static int get_gfs_struct_info (struct gfs2_buffer_head *lbh,uint64_t owner, +int *block_type,int *gstruct_len) {struct gfs2_meta_header mh;struct gfs2_inode *inode;
@@ -240,7 +242,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,if (S_ISDIR (inode->i_di.di_mode) || (sbd.gfs1 && inode->i_di.__pad1 ==GFS_FILE_DIR )) *gstruct_len = sbd.bsize; -else if (!inode->i_di.di_height && !block_is_systemfile (block) && +else if (!inode->i_di.di_height && !block_is_systemfile (owner) && !S_ISDIR (inode->i_di.di_mode)) *gstruct_len =sizeof (struct gfs2_dinode );else
@@ -426,7 +428,7 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk, uint64_t owner)because we want to know if the source inode is a system inode not the block within the inode "blk". They may or may not be the same thing. */ -if (get_gfs_struct_info (savebh, &blktype, &blklen) && +if (get_gfs_struct_info (savebh, owner, &blktype, &blklen) && !block_is_systemfile (owner)) {brelse (savebh);return 0 ;/* Not metadata, and not system file, so skip it */
Signature · 1 line
2.4.3
PATCH 17/23 gfs2_edit: Don't use the global block variable in save_ea_block
In reply to Andrew PriceAccept the block's owner's address as an argument instead.
--- gfs2/edit/savemeta.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
gfs2/edit/savemeta.c +4 -4
@@ -468,7 +468,7 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk, uint64_t owner)/* * save_ea_block - save off an extended attribute block */ -static void save_ea_block (struct metafd *mfd,struct gfs2_buffer_head *metabh) +static void save_ea_block (struct metafd *mfd,struct gfs2_buffer_head *metabh,uint64_t owner) {int e;struct gfs2_ea_header ea;
@@ -486,7 +486,7 @@ static void save_ea_block(struct metafd *mfd, struct gfs2_buffer_head *metabh) b = (uint64_t *)(metabh->b_data); b += charoff + i; blk =be64_to_cpu (*b); -save_block (sbd.device_fd, mfd, blk, block); +save_block (sbd.device_fd, mfd, blk, owner); }if (!ea.ea_rec_len)break ;
@@ -519,7 +519,7 @@ static void save_indirect_blocks(struct metafd *mfd, osi_list_t *cur_list, blktype =save_block (sbd.device_fd, mfd, indir_block, owner);if (blktype ==GFS2_METATYPE_EA ) { nbh =bread (&sbd, indir_block); -save_ea_block (mfd, nbh); +save_ea_block (mfd, nbh, owner);brelse (nbh); } if (height != hgt && /* If not at max height and */
@@ -640,7 +640,7 @@ static void save_inode_data(struct metafd *mfd, uint64_t iblk)gfs2_meta_header_in (&mh, lbh);if (mh.mh_magic ==GFS2_MAGIC && mh.mh_type ==GFS2_METATYPE_EA ) -save_ea_block (mfd, lbh); +save_ea_block (mfd, lbh, iblk);else if (mh.mh_magic ==GFS2_MAGIC && mh.mh_type ==GFS2_METATYPE_IN )save_indirect_blocks (mfd, cur_list, lbh, iblk,2 ,2 );
Signature · 1 line
2.4.3
PATCH 18/23 gfs2_edit: Don't use the global block variable in save_allocated
In reply to Andrew PriceReplace it with a local variable as save_allocated doesn't use its existing value.
--- gfs2/edit/savemeta.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
gfs2/edit/savemeta.c +6 -5
@@ -714,6 +714,7 @@ static void get_journal_inode_blocks(void)static void save_allocated (struct rgrp_tree *rgd,struct metafd *mfd) {int blktype; +uint64_t blk;unsigned i, j, m;uint64_t *ibuf =malloc (sbd.bsize *GFS2_NBBY *sizeof (uint64_t ));
@@ -721,11 +722,11 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd) m =lgfs2_bm_scan (rgd, i, ibuf,GFS2_BLKST_DINODE );for (j =0 ; j < m; j++) { - block = ibuf[j]; -warm_fuzzy_stuff (block, FALSE); - blktype =save_block (sbd.device_fd, mfd, block, block); + blk = ibuf[j]; +warm_fuzzy_stuff (blk, FALSE); + blktype =save_block (sbd.device_fd, mfd, blk, blk);if (blktype ==GFS2_METATYPE_DI ) -save_inode_data (mfd, block); +save_inode_data (mfd, blk); }if (!sbd.gfs1)
@@ -735,7 +736,7 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd)* If we don't, we may run into metadata allocation issues. */ m =lgfs2_bm_scan (rgd, i, ibuf,GFS2_BLKST_UNLINKED );for (j =0 ; j < m; j++) { -save_block (sbd.device_fd, mfd, block, block); +save_block (sbd.device_fd, mfd, blk, blk); } }free (ibuf);
Signature · 1 line
2.4.3
PATCH 19/23 gfs2_edit: Don't use the global block variable in savemeta
In reply to Andrew PriceReplace it with local variables as savemeta doesn't use its existing value.
--- gfs2/edit/savemeta.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
gfs2/edit/savemeta.c +15 -14
@@ -828,26 +828,28 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)exit (1 ); }/* Save off the superblock */ -save_block (sbd.device_fd, &mfd,GFS2_SB_ADDR *GFS2_BASIC_BLOCK / sbd.bsize, block); +save_block (sbd.device_fd, &mfd,GFS2_SB_ADDR *GFS2_BASIC_BLOCK / sbd.bsize,0 );/* If this is gfs1, save off the rindex because it's not part of the file system as it is in gfs2. */ if (sbd.gfs1) { +uint64_t blk;int j; - block = sbd1->sb_rindex_di.no_addr; -save_block (sbd.device_fd, &mfd, block, block); -save_inode_data (&mfd, block); + blk = sbd1->sb_rindex_di.no_addr; +save_block (sbd.device_fd, &mfd, blk, blk); +save_inode_data (&mfd, blk);/* In GFS1, journals aren't part of the RG space */ for (j =0 ; j < journals_found; j++) {log_debug ("Saving journal #%d\n" , j +1 ); -for (block = journal_blocks[j]; - block < journal_blocks[j] + gfs1_journal_size; - block++) -save_block (sbd.device_fd, &mfd, block, block); +for (blk = journal_blocks[j]; + blk < journal_blocks[j] + gfs1_journal_size; + blk++) +save_block (sbd.device_fd, &mfd, blk, blk); } }/* Walk through the resource groups saving everything within */ for (n =osi_first (&sbd.rgtree); n; n =osi_next (n)) { +uint64_t blk;struct rgrp_tree *rgd; rgd = (struct rgrp_tree *)n;
@@ -858,10 +860,10 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) (unsigned long long )rgd->ri.ri_addr, rgd->ri.ri_length);/* Save off the rg and bitmaps */ -for (block = rgd->ri.ri_addr; - block < rgd->ri.ri_data0; block++) { -warm_fuzzy_stuff (block, FALSE); -save_block (sbd.device_fd, &mfd, block, block); +for (blk = rgd->ri.ri_addr; + blk < rgd->ri.ri_data0; blk++) { +warm_fuzzy_stuff (blk, FALSE); +save_block (sbd.device_fd, &mfd, blk, blk); }/* Save off the other metadata: inodes, etc. if mode is not 'savergs' */ if (saveoption !=2 ) {
@@ -872,8 +874,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)/* Clean up */ /* There may be a gap between end of file system and end of device */ /* so we tell the user that we've processed everything. */ - block = sbd.fssize; -warm_fuzzy_stuff (block, TRUE); +warm_fuzzy_stuff (sbd.fssize, TRUE);printf ("\nMetadata saved to file %s " , mfd.filename);if (mfd.gziplevel) {printf ("(gzipped, level %d).\n" , mfd.gziplevel);
Signature · 1 line
2.4.3
PATCH 20/23 gfs2_edit: Don't use the global bh variable in display_block_type
In reply to Andrew PriceAccept it as an argument instead.
--- gfs2/edit/hexedit.c | 13 ++++--------- gfs2/edit/hexedit.h | 2 +- gfs2/edit/savemeta.c | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-)
gfs2/edit/hexedit.c +4 -9
@@ -313,7 +313,7 @@ uint32_t get_block_type(const struct gfs2_buffer_head *lbh, int *structlen)/* returns: metatype if block is a GFS2 structure block type */ /* 0 if block is not a GFS2 structure */ /* ------------------------------------------------------------------------ */ -int display_block_type (int from_restore) +int display_block_type (struct gfs2_buffer_head *dbh,int from_restore) {const struct gfs2_meta_header *mh;int ret_type =0 ;/* return type */
@@ -349,7 +349,7 @@ int display_block_type(int from_restore) ret_type =GFS2_METATYPE_DI ; struct_len =0 ; }else { - ret_type =get_block_type (bh, &struct_len); + ret_type =get_block_type (dbh, &struct_len);switch (ret_type) {case GFS2_METATYPE_SB :/* 1 */ print_gfs2 ("(superblock)" );
@@ -398,9 +398,7 @@ int display_block_type(int from_restore)break ; } } - - - mh = bh->iov.iov_base; + mh = dbh->iov.iov_base;eol (0 );if (from_restore)return ret_type;
@@ -1052,9 +1050,6 @@ static void read_master_dir(void)memcpy (&masterdir, &indirect[0 ],sizeof (struct indirect_info )); } -/* ------------------------------------------------------------------------ */ -/* display */ -/* ------------------------------------------------------------------------ */ int display (int identify_only,int trunc_zeros,uint64_t flagref,uint64_t ref_blk) {
@@ -1090,7 +1085,7 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref, block_in_mem = blk;/* remember which block is in memory */ } line =1 ; - gfs2_struct_type =display_block_type (FALSE); + gfs2_struct_type =display_block_type (bh, FALSE);if (identify_only)return 0 ; indirect_blocks =0 ;
gfs2/edit/hexedit.h +1 -1
@@ -223,7 +223,7 @@ extern int block_is_inum_file(uint64_t blk);extern int block_is_statfs_file (uint64_t blk);extern int block_is_quota_file (uint64_t blk);extern int block_is_per_node (uint64_t blk); -extern int display_block_type (int from_restore); +extern int display_block_type (struct gfs2_buffer_head *bh,int from_restore);extern void gfs_jindex_in (struct gfs_jindex *jindex,char *buf);extern void gfs_log_header_in (struct gfs_log_header *head,struct gfs2_buffer_head *bh);
gfs2/edit/savemeta.c +1 -1
@@ -1087,7 +1087,7 @@ static int restore_data(int fd, gzFile gzin_fd, off_t pos, int printonly)break ; }else if (printonly ==1 ) {print_gfs2 ("%" PRId64" (l=0x%x): " , blks_saved, savedata->siglen); -display_block_type (TRUE); +display_block_type (&dummy_bh, TRUE); } bh =NULL ; }else {
Signature · 1 line
2.4.3
PATCH 21/23 gfs2_edit: Don't use the global block variable in savemeta.c
In reply to Andrew PriceTweak the display functions used by printsavedmeta to accept a bh and use the block number from it. Remove the last uses of 'block' from restore_data.
--- gfs2/edit/gfs2hex.c | 32 ++++++++++++++++---------------- gfs2/edit/gfs2hex.h | 2 +- gfs2/edit/hexedit.c | 4 ++-- gfs2/edit/savemeta.c | 18 +++++++----------- 4 files changed, 26 insertions(+), 30 deletions(-)
gfs2/edit/gfs2hex.c +16 -16
@@ -455,7 +455,7 @@ static void gfs1_rgrp_print(struct gfs_rgrp *rg)pv (rg, rg_freemeta,"%u" ,"0x%x" ); } -int display_gfs2 (void ) +int display_gfs2 (struct gfs2_buffer_head *dbh) {struct gfs2_meta_header mh;struct gfs2_rgrp rg;
@@ -467,22 +467,22 @@ int display_gfs2(void)uint32_t magic; - magic =be32_to_cpu (*(uint32_t *)bh->b_data); + magic =be32_to_cpu (*(uint32_t *)dbh->b_data);switch (magic) {case GFS2_MAGIC : -gfs2_meta_header_in (&mh, bh); +gfs2_meta_header_in (&mh, dbh);if (mh.mh_type >GFS2_METATYPE_QC )print_gfs2 ("Unknown metadata type" );else print_gfs2 ("%s:" , block_type_str[mh.mh_type]);eol (0 ); - +switch (mh.mh_type) {case GFS2_METATYPE_SB : -gfs2_sb_in (&sbd.sd_sb, bh); +gfs2_sb_in (&sbd.sd_sb, dbh);gfs2_sb_print2 (&sbd.sd_sb);break ;
@@ -490,10 +490,10 @@ int display_gfs2(void)if (sbd.gfs1) {struct gfs_rgrp rg1; -gfs1_rgrp_in (&rg1, bh); +gfs1_rgrp_in (&rg1, dbh);gfs1_rgrp_print (&rg1); }else { -gfs2_rgrp_in (&rg, bh); +gfs2_rgrp_in (&rg, dbh);gfs2_rgrp_print (&rg); }break ;
@@ -511,7 +511,7 @@ int display_gfs2(void)break ;case GFS2_METATYPE_LF : -gfs2_leaf_in (&lf, bh); +gfs2_leaf_in (&lf, dbh);gfs2_leaf_print (&lf);break ;
@@ -521,33 +521,33 @@ int display_gfs2(void)case GFS2_METATYPE_LH :if (sbd.gfs1) { -gfs_log_header_in (&lh1, bh); +gfs_log_header_in (&lh1, dbh);gfs_log_header_print (&lh1); }else { -gfs2_log_header_in (&lh, bh); +gfs2_log_header_in (&lh, dbh);gfs2_log_header_print (&lh); }break ;case GFS2_METATYPE_LD : -gfs2_log_descriptor_in (&ld, bh); +gfs2_log_descriptor_in (&ld, dbh);gfs2_log_descriptor_print (&ld);break ;case GFS2_METATYPE_EA : -do_eattr_extended (bh); +do_eattr_extended (dbh);break ; - +case GFS2_METATYPE_ED :gfs2_meta_header_print (&mh);break ; - +case GFS2_METATYPE_LB :gfs2_meta_header_print (&mh);break ;case GFS2_METATYPE_QC : -gfs2_quota_change_in (&qc, bh); +gfs2_quota_change_in (&qc, dbh);gfs2_quota_change_print (&qc);break ;
@@ -555,7 +555,7 @@ int display_gfs2(void)break ; }break ; - +default :print_gfs2 ("Unknown block type" );eol (0 );
gfs2/edit/gfs2hex.h +1 -1
@@ -3,7 +3,7 @@#include "hexedit.h" -extern int display_gfs2 (void ); +extern int display_gfs2 (struct gfs2_buffer_head *dbh);extern int edit_gfs2 (void );extern void do_dinode_extended (struct gfs2_dinode *di,struct gfs2_buffer_head *lbh);
gfs2/edit/hexedit.c +2 -2
@@ -333,7 +333,7 @@ int display_block_type(struct gfs2_buffer_head *dbh, int from_restore)else if (block ==JOURNALS_DUMMY_BLOCK )print_gfs2 ("Journal Status: " );else -print_gfs2 ("%" PRId64" (0x%" PRIx64")" , block, block); +print_gfs2 ("%" PRIu64" (0x%" PRIx64")" , dbh->b_blocknr, dbh->b_blocknr);if (termlines) {if (edit_row[dmode] ==-1 )COLORS_NORMAL ;
@@ -1150,7 +1150,7 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref, flagref, ref_blk); else if (dmode == GFS2_MODE) { /* if structure display */if (block !=JOURNALS_DUMMY_BLOCK ) -display_gfs2 ();/* display the gfs2 structure */ +display_gfs2 (bh);/* display the gfs2 structure */ } elsedisplay_extended ();/* display extended blocks */ /* No else here because display_extended can switch back to hex mode */
gfs2/edit/savemeta.c +7 -11
@@ -27,8 +27,6 @@#include "hexedit.h" #include "libgfs2.h" -extern uint64_t block; -#define DFT_SAVE_FILE "/tmp/gfsmeta.XXXXXX"#define MAX_JOURNALS_SAVED 256
@@ -1076,20 +1074,18 @@ static int restore_data(int fd, gzFile gzin_fd, off_t pos, int printonly) }if (printonly) { -struct gfs2_buffer_head dummy_bh; - dummy_bh.b_data = savedata->buf; - bh = &dummy_bh; - block = savedata->blk; -if (printonly >1 && printonly == block) { - block_in_mem = block; -display (0 ,0 ,0 ,0 ); - bh =NULL ; +struct gfs2_buffer_head dummy_bh = { + .b_data = savedata->buf, + .b_blocknr = savedata->blk, + }; +if (printonly >1 && printonly == savedata->blk) { +display_block_type (&dummy_bh, TRUE); +display_gfs2 (&dummy_bh);break ; }else if (printonly ==1 ) {print_gfs2 ("%" PRId64" (l=0x%x): " , blks_saved, savedata->siglen);display_block_type (&dummy_bh, TRUE); } - bh =NULL ; }else {warm_fuzzy_stuff (savedata->blk, FALSE);memset (savedata->buf + savedata->siglen,0 , sbd.bsize - savedata->siglen);
Signature · 1 line
2.4.3
PATCH 22/23 gfs2_edit: Don't export bh
In reply to Andrew Pricebh is now only used in hexedit.c so restrict its visibility to that file.
--- gfs2/edit/gfs2hex.c | 1 - gfs2/edit/hexedit.c | 1 + gfs2/edit/hexedit.h | 1 - 3 files changed, 1 insertion(+), 2 deletions(-)
gfs2/edit/gfs2hex.c +0 -1
@@ -29,7 +29,6 @@ }while (FALSE);struct gfs2_sb sb; -struct gfs2_buffer_head *bh;struct gfs2_dinode di;int line, termlines, modelines[DMODES ];char edit_fmt[80 ];
gfs2/edit/hexedit.c +1 -0
@@ -34,6 +34,7 @@ const char *allocdesc[2][5] = { {"Free ", "Data ", "Unlnk", "Meta ", "Resrv"}, {"Free ", "Data ", "FreeM", "Meta ", "Resrv"},}; +struct gfs2_buffer_head *bh;struct gfs2_rgrp *lrgrp;struct gfs2_meta_header *lmh;struct gfs2_dinode *ldi;
gfs2/edit/hexedit.h +0 -1
@@ -37,7 +37,6 @@ extern char estring[1024]; /* edit string */extern char efield[64 ];extern uint64_t dev_offset;extern uint64_t max_block; -extern struct gfs2_buffer_head *bh;extern int termlines;extern int insert;extern const char *termtype;
Signature · 1 line
2.4.3
PATCH 23/23 gfs2_edit: Remove block_in_mem and fix a memory leak
In reply to Andrew Priceblock_in_mem is meant to be the block number that relates to the global bh. bh->b_blocknr can be used for the same purpose so remove block_in_mem. Also fix a memory leak that occurs when the displayed block changes.
--- gfs2/edit/gfs2hex.c | 1 - gfs2/edit/hexedit.c | 8 ++++---- gfs2/edit/hexedit.h | 1 - 3 files changed, 4 insertions(+), 6 deletions(-)
gfs2/edit/gfs2hex.c +0 -1
@@ -42,7 +42,6 @@ uint64_t block = 0;int blockhist =0 ;struct iinfo *indirect;int indirect_blocks; -uint64_t block_in_mem =-1 ;struct gfs2_sbd sbd;uint64_t starting_blk;struct blkstack_info blockstack[BLOCK_STACK_SIZE ];
gfs2/edit/hexedit.c +4 -4
@@ -1072,7 +1072,9 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref,display_title_lines ();move (2 ,0 ); } -if (block_in_mem != blk) {/* If we changed blocks from the last read */ +if (bh ==NULL || bh->b_blocknr != blk) {/* If we changed blocks from the last read */ +if (bh !=NULL ) +brelse (bh); dev_offset = blk * sbd.bsize;ioctl (sbd.device_fd,BLKFLSBUF ,0 );if (!(bh =bread (&sbd, blk))) {
@@ -1083,7 +1085,6 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref, (unsigned long long)dev_offset);exit (-1 ); } - block_in_mem = blk;/* remember which block is in memory */ } line =1 ; gfs2_struct_type =display_block_type (bh, FALSE);
@@ -1869,7 +1870,6 @@ static void interactive_mode(void)bobgets (estring, edit_row[dmode]+4 ,24 ,10 , &ch);process_field (efield, estring); - block_in_mem =-1 ; }else bobgets (estring, edit_row[dmode]+6 ,14 , edit_size[dmode], &ch);
@@ -2534,7 +2534,7 @@ int main(int argc, char *argv[]) edit_row[GFS2_MODE ]++; elseread_master_dir (); - block_in_mem =-1 ; +process_parameters (argc, argv,1 );/* get what to print from cmdline */ block = blockstack[0 ].block = starting_blk * (4096 / sbd.bsize);
gfs2/edit/hexedit.h +0 -1
@@ -54,7 +54,6 @@ 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; -extern uint64_t block_in_mem;extern int identify;extern int color_scheme;extern WINDOW *wind;
Signature · 1 line
2.4.3