libgfs1: Add gfs1 variable to superblock structure
From: Bob Peterson <rpeterso@redhat.com>
This patch adds a "gfs1" variable to the in-core superblock structure
for utils that can operate on both gfs and gfs2 file systems and need
to determine which is which.
if (block == RGLIST_DUMMY_BLOCK) {
- if (gfs1)
+ if (sbd.gfs1)
blk = sbd1->sb_rindex_di.no_addr;
else
blk = masterblock("rindex");
@@ -2014,7 +2015,7 @@ static uint64_t find_journal_block(const char *journal, uint64_t *j_size)
journal_num = atoi(journal + 7);
/* Figure out the block of the jindex file */
- if (gfs1)
+ if (sbd.gfs1)
jindex_block = sbd1->sb_jindex_di.no_addr;
else
jindex_block = masterblock("jindex");
@@ -2023,10 +2024,10 @@ static uint64_t find_journal_block(const char *journal, uint64_t *j_size)
/* get the dinode data from it. */
gfs2_dinode_in(&di, jindex_bh); /* parse disk inode to struct*/
- if (!gfs1)
+ if (!sbd.gfs1)
do_dinode_extended(&di, jindex_bh); /* parse dir. */
- if (gfs1) {
+ if (sbd.gfs1) {
struct gfs2_inode *jiinode;
struct gfs_jindex ji;
@@ -2205,36 +2206,36 @@ uint64_t check_keywords(const char *kword)
else if (!strcmp(kword, "root") || !strcmp(kword, "rootdir"))
blk = sbd.sd_sb.sb_root_dir.no_addr;
else if (!strcmp(kword, "master")) {
- if (!gfs1)
+ if (!sbd.gfs1)
blk = sbd.sd_sb.sb_master_dir.no_addr;
else
fprintf(stderr, "This is GFS1; there's no master directory.
");
}
else if (!strcmp(kword, "jindex")) {
- if (gfs1)
+ if (sbd.gfs1)
blk = sbd1->sb_jindex_di.no_addr;
else
blk = masterblock("jindex"); /* journal index */
}
- else if (!gfs1 && !strcmp(kword, "per_node"))
+ else if (!sbd.gfs1 && !strcmp(kword, "per_node"))
blk = masterblock("per_node");
- else if (!gfs1 && !strcmp(kword, "inum"))
+ else if (!sbd.gfs1 && !strcmp(kword, "inum"))
blk = masterblock("inum");
else if (!strcmp(kword, "statfs")) {
- if (gfs1)
+ if (sbd.gfs1)
blk = gfs1_license_di.no_addr;
else
blk = masterblock("statfs");
}
else if (!strcmp(kword, "rindex") || !strcmp(kword, "rgindex")) {
- if (gfs1)
+ if (sbd.gfs1)
blk = sbd1->sb_rindex_di.no_addr;
else
blk = masterblock("rindex");
} else if (!strcmp(kword, "rgs")) {
blk = RGLIST_DUMMY_BLOCK;
} else if (!strcmp(kword, "quota")) {
- if (gfs1)
+ if (sbd.gfs1)
blk = gfs1_quota_di.no_addr;
else
blk = masterblock("quota");
@@ -2550,7 +2551,7 @@ static void find_change_block_alloc(int *newval)
printf("Error: value %d is not valid.
Valid values are:
",
*newval);
for (i = GFS2_BLKST_FREE; i <= GFS2_BLKST_DINODE; i++)
- printf("%d - %s
", i, allocdesc[gfs1][i]);
+ printf("%d - %s
", i, allocdesc[sbd.gfs1][i]);
gfs2_rgrp_free(&sbd.rglist);
exit(-1);
}
@@ -2573,7 +2574,7 @@ static void find_change_block_alloc(int *newval)
"an rgrp).
");
exit(-1);
}
- printf("%d (%s)
", type, allocdesc[gfs1][type]);
+ printf("%d (%s)
", type, allocdesc[sbd.gfs1][type]);
}
gfs2_rgrp_relse(rgd);
} else {
@@ -3057,7 +3058,7 @@ static int print_ld_blocks(const uint64_t *b, const char *end, int start_line)
bcount++;
}
b++;
- if (gfs1)
+ if (sbd.gfs1)
b++;
}
eol(0);
@@ -3176,14 +3177,14 @@ static void dump_journal(const char *journal)
jblock = find_journal_block(journal, &j_size);
if (!jblock)
return;
- if (!gfs1) {
+ if (!sbd.gfs1) {
j_bh = bread(&sbd, jblock);
j_inode = inode_get(&sbd, j_bh);
jbuf = malloc(sbd.bsize);
}
- for (jb = 0; jb < j_size; jb += (gfs1 ? 1:sbd.bsize)) {
- if (gfs1) {
+ for (jb = 0; jb < j_size; jb += (sbd.gfs1 ? 1:sbd.bsize)) {
+ if (sbd.gfs1) {
if (j_bh)
brelse(j_bh);
j_bh = bread(&sbd, jblock + jb);
@@ -3218,21 +3219,21 @@ static void dump_journal(const char *journal)
"Quota", "Final Entry", "Unknown"}};
- if (gfs1) {
+ if (sbd.gfs1) {
gfs_log_header_in(&lh1, &dummy_bh);
check_journal_wrap(lh1.lh_sequence,
&highest_seq);
@@ -3268,7 +3269,7 @@ static void dump_journal(const char *journal)
lh.lh_tail, lh.lh_blkno);
}
eol(0);
- } else if (gfs1 && ld_blocks > 0) {
+ } else if (sbd.gfs1 && ld_blocks > 0) {
print_gfs2("0x%llx (j+%4llx): GFS log descriptor"
" continuation block", abs_block, jb);
eol(0);
@@ -3658,7 +3659,7 @@ int main(int argc, char *argv[])
read_superblock(fd);
max_block = lseek(fd, 0, SEEK_END) / sbd.bsize;
strcpy(sbd.device_name, device);
- if (gfs1)
+ if (sbd.gfs1)
edit_row[GFS2_MODE]++;
else
read_master_dir();
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index cc87925..8a3c615 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -81,7 +81,6 @@ extern char device[NAME_MAX];
extern int identify;
extern int color_scheme;
extern WINDOW *wind;
-extern int gfs1;
extern int editing;
extern uint64_t temp_blk;
extern uint64_t starting_blk;
@@ -231,7 +230,7 @@ extern enum dsp_mode dmode;
/* ------------------------------------------------------------------------ */
static inline int risize(void)
{
- if (gfs1)
+ if (sbd.gfs1)
return sizeof(struct gfs_rindex);
else
return sizeof(struct gfs2_rindex);
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 160277c..c4719ea 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -120,12 +120,12 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
*gstruct_len = sbd.bsize;
break;
case GFS2_METATYPE_DI: /* 4 (disk inode) */
- if (gfs1)
+ if (sbd.gfs1)
inode = inode_get(&sbd, lbh);
else
inode = gfs_inode_get(&sbd, lbh);
if (S_ISDIR(inode->i_di.di_mode) ||
- (gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
+ (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
*gstruct_len = sbd.bsize;
else if (!inode->i_di.di_height && !block_is_systemfile() &&
!S_ISDIR(inode->i_di.di_mode))
@@ -143,7 +143,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
*gstruct_len = sbd.bsize;
break;
case GFS2_METATYPE_LH: /* 8 (log header) */
- if (gfs1)
+ if (sbd.gfs1)
*gstruct_len = 512; /* gfs copies the log header
twice and compares the copy,
so we need to save all 512
@@ -454,7 +454,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);
- if (gfs1)
+ if (sbd.gfs1)
inode = inode_get(&sbd, metabh);
else
inode = gfs_inode_get(&sbd, metabh);
@@ -466,7 +466,7 @@ static void save_inode_data(struct metafd *mfd)
the hash table exists, and we have to save the directory data. */
if (inode->i_di.di_flags & GFS2_DIF_EXHASH &&
(S_ISDIR(inode->i_di.di_mode) ||
- (gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR)))
+ (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR)))
height++;
else if (height && !block_is_systemfile() &&
!S_ISDIR(inode->i_di.di_mode))
@@ -563,7 +563,7 @@ static void get_journal_inode_blocks(void)
int amt;
struct gfs2_inode *j_inode = NULL;
- if (gfs1) {
+ if (sbd.gfs1) {
struct gfs_jindex ji;
char jbuf[sizeof(struct gfs_jindex)];
@@ -647,7 +647,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
lseek(sbd.device_fd, 0, SEEK_SET);
blks_saved = total_out = last_reported_block = 0;
- if (!gfs1)
+ if (!sbd.gfs1)
sbd.bsize = BUFSIZE;
if (!slow) {
if (device_geometry(&sbd)) {
@@ -660,13 +660,13 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
exit(-1);
}
osi_list_init(&sbd.rglist);
- if (!gfs1)
+ if (!sbd.gfs1)
sbd.sd_sb.sb_bsize = GFS2_DEFAULT_BSIZE;
if (compute_constants(&sbd)) {
fprintf(stderr, "Bad constants (1)
");
exit(-1);
}
- if(gfs1) {
+ if(sbd.gfs1) {
sbd.bsize = sbd.sd_sb.sb_bsize;
sbd.sd_inptrs = (sbd.bsize -
sizeof(struct gfs_indirect)) /
@@ -691,7 +691,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
printf("There are %" PRIu64 " blocks of %u bytes in the destination "
"device.
", last_fs_block, sbd.bsize);
if (!slow) {
- if (gfs1) {
+ if (sbd.gfs1) {
sbd.md.riinode = inode_read(&sbd,
sbd1->sb_rindex_di.no_addr);
jindex_block = sbd1->sb_jindex_di.no_addr;
@@ -706,7 +706,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
}
lbh = bread(&sbd, jindex_block);
gfs2_dinode_in(&di, lbh);
- if (!gfs1)
+ if (!sbd.gfs1)
do_dinode_extended(&di, lbh);
brelse(lbh);
}
@@ -716,7 +716,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
printf("Reading resource groups...");
fflush(stdout);
- if (gfs1)
+ if (sbd.gfs1)
slow = gfs1_ri_update(&sbd, 0, &rgcount, 0);
else
slow = ri_update(&sbd, 0, &rgcount, &sane);
@@ -738,7 +738,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
save_block(sbd.device_fd, &mfd, 0x10 * (4096 / sbd.bsize));
/* If this is gfs1, save off the rindex because it's not
part of the file system as it is in gfs2. */
- if (gfs1) {
+ if (sbd.gfs1) {
int j;