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 f1d10e69a84837413882d5462295c04c18925ec6
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Apr 28 12:42:53 2021 +0100
gfs2_edit: Store big-endian data in the global dinode
Add a big-endian lgfs2_dinode_print() function to libgfs2 to enable
that.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/extended.c | 21 +++++++++++----------
gfs2/edit/gfs2hex.c | 30 ++++++++++++++++--------------
gfs2/edit/gfs2hex.h | 2 +-
gfs2/edit/hexedit.c | 41 +++++++++++++++++++++++------------------
gfs2/edit/hexedit.h | 2 +-
gfs2/edit/journal.c | 5 ++---
gfs2/edit/savemeta.c | 2 +-
gfs2/libgfs2/libgfs2.h | 1 +
gfs2/libgfs2/ondisk.c | 28 ++++++++++++++++++++++++++++
9 files changed, 84 insertions(+), 48 deletions(-)
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 7050a36a..4e8a003d 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -103,13 +103,14 @@ static uint64_t metapath_to_lblock(struct metapath *mp, int hgt)
int h;
uint64_t lblock = 0;
uint64_t factor[GFS2_MAX_META_HEIGHT];
+ uint16_t height = be16_to_cpu(di->di_height);
- if (di.di_height < 2)
+ if (height < 2)
return mp->mp_list[0];
/* figure out multiplication factors for each height */
memset(&factor, 0, sizeof(factor));
- factor[di.di_height - 1] = 1ull;
- for (h = di.di_height - 2; h >= 0; h--)
+ factor[height - 1] = 1ull;
+ for (h = height - 2; h >= 0; h--)
factor[h] = factor[h + 1] * sbd.sd_inptrs;
for (h = 0; h <= hgt; h++)
lblock += (mp->mp_list[h] * factor[h]);
@@ -127,7 +128,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int
level,
return -1;
if (!level) {
if (gfs2_struct_type == GFS2_METATYPE_DI) {
- if (S_ISDIR(di.di_mode))
+ if (S_ISDIR(be32_to_cpu(di->di_mode)))
print_gfs2("This directory contains %d indirect blocks",
indblocks);
else
@@ -137,14 +138,14 @@ static int display_indirect(struct iinfo *ind, int indblocks, int
level,
print_gfs2("This indirect block contains %d indirect blocks",
indblocks);
}
- if (dinode_valid() && !S_ISDIR(di.di_mode)) {
+ if (dinode_valid() && !S_ISDIR(be32_to_cpu(di->di_mode))) {
/* See if we are on an inode or have one in history. */
if (level)
cur_height = level;
else {
cur_height = get_height();
print_gfs2(" (at height %d of %d)",
- cur_height, di.di_height);
+ cur_height, be16_to_cpu(di->di_height));
}
}
eol(0);
@@ -189,7 +190,7 @@ static int display_indirect(struct iinfo *ind, int indblocks, int
level,
COLORS_NORMAL;
}
}
- if (dinode_valid() && !S_ISDIR(di.di_mode)) {
+ if (dinode_valid() && !S_ISDIR(be32_to_cpu(di->di_mode))) {
float human_off;
char h;
@@ -211,8 +212,8 @@ static int display_indirect(struct iinfo *ind, int indblocks, int
level,
else
file_offset = 0;
if (dinode_valid() && !termlines &&
- ((level + 1 < di.di_height) ||
- (S_ISDIR(di.di_mode) && level <= di.di_height))) {
+ ((level + 1 < be16_to_cpu(di->di_height)) ||
+ (S_ISDIR(be32_to_cpu(di->di_mode)) && level <=
be16_to_cpu(di->di_height)))) {
print_block_details(ind, level, cur_height, pndx,
file_offset);
}
@@ -394,7 +395,7 @@ static void print_block_details(struct iinfo *ind, int level, int
cur_height,
}
thisblk = 0;
memset(more_indir, 0, sizeof(struct iinfo));
- if (S_ISDIR(di.di_mode) && level == di.di_height) {
+ if (S_ISDIR(be32_to_cpu(di->di_mode)) && level ==
be16_to_cpu(di->di_height)) {
thisblk = do_leaf_extended(tmpbuf, more_indir);
display_leaf(more_indir);
} else {
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index 021c7308..9d5eff71 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -27,7 +27,7 @@
print_it(" "#member, "%"PRIu32, "0x%"PRIx32,
be32_to_cpu(struct->member)); \
} while(0)
-struct gfs2_dinode di;
+struct gfs2_dinode *di;
int line, termlines, modelines[DMODES];
char edit_fmt[80];
char estring[1024];
@@ -231,16 +231,20 @@ static int indirect_dirent(struct indirect_info *indir, char *ptr,
int d)
return de.de_rec_len;
}
-void do_dinode_extended(struct gfs2_dinode *dine, char *buf)
+void do_dinode_extended(char *buf)
{
+ struct gfs2_dinode *dip = (void *)buf;
unsigned int x, y, ptroff = 0;
uint64_t p, last;
- int isdir = !!(S_ISDIR(dine->di_mode)) ||
- (sbd.gfs1 && dine->__pad1 == GFS_FILE_DIR);
+ int isdir = 0;
+
+ if (S_ISDIR(be32_to_cpu(dip->di_mode)) ||
+ (sbd.gfs1 && be16_to_cpu(dip->__pad1) == GFS_FILE_DIR))
+ isdir = 1;
indirect_blocks = 0;
memset(indirect, 0, sizeof(struct iinfo));
- if (dine->di_height > 0) {
+ if (be16_to_cpu(dip->di_height) > 0) {
/* Indirect pointers */
for (x = sizeof(struct gfs2_dinode); x < sbd.bsize;
x += sizeof(uint64_t)) {
@@ -251,13 +255,13 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *buf)
ptroff;
indirect->ii[indirect_blocks].is_dir = FALSE;
indirect->ii[indirect_blocks].ptroff =
- (x - sizeof(*dine)) / sizeof(uint64_t);
+ (x - sizeof(*dip)) / sizeof(uint64_t);
indirect_blocks++;
}
ptroff++;
}
}
- else if (isdir && !(dine->di_flags & GFS2_DIF_EXHASH)) {
+ else if (isdir && !(be32_to_cpu(dip->di_flags) & GFS2_DIF_EXHASH)) {
int skip = 0;
/* Directory Entries: */
@@ -271,19 +275,18 @@ void do_dinode_extended(struct gfs2_dinode *dine, char *buf)
break;
}
}
- else if (isdir &&
- (dine->di_flags & GFS2_DIF_EXHASH) &&
- dine->di_height == 0) {
+ else if (isdir && (be32_to_cpu(dip->di_flags) & GFS2_DIF_EXHASH)
&&
+ dip->di_height == 0) {
/* Leaf Pointers: */
last = be64_to_cpu(*(uint64_t *)(buf + sizeof(struct gfs2_dinode)));
for (x = sizeof(struct gfs2_dinode), y = 0;
- y < (1 << dine->di_depth);
+ y < (1 << be16_to_cpu(dip->di_depth));
x += sizeof(uint64_t), y++) {
p = be64_to_cpu(*(uint64_t *)(buf + x));
- if (p != last || ((y + 1) * sizeof(uint64_t) == dine->di_size)) {
+ if (p != last || ((y + 1) * sizeof(uint64_t) == be64_to_cpu(dip->di_size))) {
struct gfs2_buffer_head *tmp_bh;
int skip = 0, direntcount = 0;
struct gfs2_leaf leaf;
@@ -430,9 +433,8 @@ int display_gfs2(char *buf)
break;
case GFS2_METATYPE_DI:
- gfs2_dinode_print(&di);
+ lgfs2_dinode_print(di);
break;
-
case GFS2_METATYPE_IN:
gfs2_meta_header_print(&mh);
break;
diff --git a/gfs2/edit/gfs2hex.h b/gfs2/edit/gfs2hex.h
index 878ab801..23b1fc60 100644
--- a/gfs2/edit/gfs2hex.h
+++ b/gfs2/edit/gfs2hex.h
@@ -5,7 +5,7 @@
extern int display_gfs2(char *buf);
extern int edit_gfs2(void);
-extern void do_dinode_extended(struct gfs2_dinode *di, char *buf);
+extern void do_dinode_extended(char *buf);
extern void print_gfs2(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
extern uint64_t do_leaf_extended(char *dlebuf, struct iinfo *indir);
extern void eol(int col);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index c497c748..f63dc3ec 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -497,7 +497,7 @@ static int get_pnum(int ptroffset)
/* ------------------------------------------------------------------------ */
/* hexdump - hex dump the filesystem block to the screen */
/* ------------------------------------------------------------------------ */
-static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
+static int hexdump(uint64_t startaddr, uint64_t len, int trunc_zeros,
uint64_t flagref, uint64_t ref_blk)
{
const unsigned char *pointer, *ptr2;
@@ -537,7 +537,7 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
if (l < struct_len)
COLORS_NORMAL; /* normal part of structure */
else if (gfs2_struct_type == GFS2_METATYPE_DI &&
- l < struct_len + di.di_size)
+ l < struct_len + be64_to_cpu(di->di_size))
COLORS_CONTENTS; /* after struct but not eof */
else
COLORS_SPECIAL; /* beyond end of the struct */
@@ -548,8 +548,9 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
/* Figure out if we have a null pointer--for colors */
if (((gfs2_struct_type == GFS2_METATYPE_IN) ||
(gfs2_struct_type == GFS2_METATYPE_DI &&
- l < struct_len + di.di_size &&
- (di.di_height > 0 || !S_ISREG(di.di_mode)))) &&
+ l < struct_len + be64_to_cpu(di->di_size) &&
+ (be16_to_cpu(di->di_height) > 0 ||
+ !S_ISREG(be32_to_cpu(di->di_mode))))) &&
(i==0 || i==8)) {
int j;
@@ -565,9 +566,9 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
if (l + i < struct_len)
COLORS_NORMAL; /* in the structure */
else if (gfs2_struct_type == GFS2_METATYPE_DI
- && l + i < struct_len + di.di_size) {
- if ((!di.di_height &&
- S_ISREG(di.di_mode)) ||
+ && l + i < struct_len + be64_to_cpu(di->di_size)) {
+ if ((!di->di_height &&
+ S_ISREG(be32_to_cpu(di->di_mode))) ||
!ptr_not_null)
COLORS_CONTENTS;/*stuff data */
else
@@ -632,7 +633,7 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
block_type == GFS2_METATYPE_LD ||
((block_type == GFS2_METATYPE_DI) &&
((struct gfs2_dinode*)bh->b_data)->di_height) ||
- S_ISDIR(di.di_mode)) {
+ S_ISDIR(be32_to_cpu(di->di_mode))) {
ptroffset = edit_row[dmode] * 16 +
edit_col[dmode];
@@ -822,7 +823,8 @@ int has_indirect_blocks(void)
if (indirect_blocks || gfs2_struct_type == GFS2_METATYPE_SB ||
gfs2_struct_type == GFS2_METATYPE_LF ||
(gfs2_struct_type == GFS2_METATYPE_DI &&
- (S_ISDIR(di.di_mode) || (sbd.gfs1 && di.__pad1 == GFS_FILE_DIR))))
+ (S_ISDIR(be32_to_cpu(di->di_mode)) ||
+ (sbd.gfs1 && be16_to_cpu(di->__pad1) == GFS_FILE_DIR))))
return TRUE;
return FALSE;
}
@@ -986,8 +988,8 @@ static int read_master_dir(void)
bh = bread(&sbd, sbd.sd_sb.sb_master_dir.no_addr);
if (bh == NULL)
return 1;
- gfs2_dinode_in(&di, bh->b_data);
- do_dinode_extended(&di, bh->b_data); /* get extended data, if any */
+ di = (struct gfs2_dinode *)bh->b_data;
+ do_dinode_extended(bh->b_data); /* get extended data, if any */
memcpy(&masterdir, &indirect[0], sizeof(struct indirect_info));
return 0;
}
@@ -1057,8 +1059,8 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref,
indirect->ii[0].dirent[1].dirent.de_type = DT_DIR;
}
else if (gfs2_struct_type == GFS2_METATYPE_DI) {
- gfs2_dinode_in(&di, bh->b_data);
- do_dinode_extended(&di, bh->b_data); /* get extended data, if any */
+ di = (struct gfs2_dinode *)bh->b_data;
+ do_dinode_extended(bh->b_data); /* get extended data, if any */
}
else if (gfs2_struct_type == GFS2_METATYPE_IN) { /* indirect block list */
if (blockhist) {
@@ -1087,11 +1089,14 @@ int display(int identify_only, int trunc_zeros, uint64_t flagref,
"Pointers "));
move(line, 0);
}
- if (dmode == HEX_MODE) /* if hex display mode */
- hexdump(dev_offset, (gfs2_struct_type == GFS2_METATYPE_DI)?
- struct_len + di.di_size:sbd.bsize, trunc_zeros,
- flagref, ref_blk);
- else if (dmode == GFS2_MODE) { /* if structure display */
+ if (dmode == HEX_MODE) { /* if hex display mode */
+ uint64_t len = sbd.bsize;
+
+ if (gfs2_struct_type == GFS2_METATYPE_DI)
+ len = struct_len + be64_to_cpu(di->di_size);
+
+ hexdump(dev_offset, len, trunc_zeros, flagref, ref_blk);
+ } else if (dmode == GFS2_MODE) { /* if structure display */
if (block != JOURNALS_DUMMY_BLOCK)
display_gfs2(bh->b_data);
} else
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index f44ea3b1..11e6f105 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -49,7 +49,7 @@ extern struct gfs2_sbd sbd;
extern struct gfs_sb *sbd1;
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 struct gfs2_dinode *di;
extern int screen_chunk_size; /* how much of the 4K can fit on screen */
extern int gfs2_struct_type;
extern int identify;
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index e8b71dc5..7f27109a 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -51,11 +51,10 @@ uint64_t find_journal_block(const char *journal, uint64_t *j_size)
jindex_block = masterblock("jindex");
/* read in the block */
jindex_bh = bread(&sbd, jindex_block);
- /* get the dinode data from it. */
- gfs2_dinode_in(&di, jindex_bh->b_data);
+ di = (struct gfs2_dinode *)jindex_bh->b_data;
if (!sbd.gfs1)
- do_dinode_extended(&di, jindex_bh->b_data); /* parse dir. */
+ do_dinode_extended(jindex_bh->b_data); /* parse dir. */
if (sbd.gfs1) {
struct gfs2_inode *jiinode;
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index e9401e4a..664c92d6 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -272,7 +272,7 @@ static int init_per_node_lookup(void)
return 1;
}
- do_dinode_extended(&per_node_di->i_di, per_node_di->i_bh->b_data);
+ do_dinode_extended(per_node_di->i_bh->b_data);
inode_put(&per_node_di);
for (i = 0; i < indirect_blocks; i++) {
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 19d060f5..594db181 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -725,6 +725,7 @@ extern void gfs2_log_header_print(const struct gfs2_log_header *lh);
extern void lgfs2_inum_print(void *nop);
extern void lgfs2_meta_header_print(void *mhp);
extern void lgfs2_sb_print(void *sbp);
+extern void lgfs2_dinode_print(void *dip);
extern void lgfs2_log_descriptor_print(void *ldp);
extern void lgfs2_quota_print(void *qp);
extern void lgfs2_quota_change_print(void *qcp);
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 5e69ee98..a47cf178 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -384,6 +384,34 @@ void gfs2_dinode_print(const struct gfs2_dinode *di)
pv(di, di_eattr, "%"PRIu64, "0x%"PRIx64);
}
+void lgfs2_dinode_print(void *dip)
+{
+ struct gfs2_dinode *di = dip;
+
+ lgfs2_meta_header_print(&di->di_header);
+ lgfs2_inum_print(&di->di_num);
+
+ print_it(" di_mode", "0%"PRIo32, NULL,
be32_to_cpu(di->di_mode));
+ printbe32(di, di_uid);
+ printbe32(di, di_gid);
+ printbe32(di, di_nlink);
+ printbe64(di, di_size);
+ printbe64(di, di_blocks);
+ printbe64(di, di_atime);
+ printbe64(di, di_mtime);
+ printbe64(di, di_ctime);
+ printbe32(di, di_major);
+ printbe32(di, di_minor);
+ printbe64(di, di_goal_meta);
+ printbe64(di, di_goal_data);
+ print_it(" di_flags", "0x%.8"PRIX32, NULL,
be32_to_cpu(di->di_flags));
+ printbe32(di, di_payload_format);
+ printbe16(di, di_height);
+ printbe16(di, di_depth);
+ printbe32(di, di_entries);
+ printbe64(di, di_eattr);
+}
+
void gfs2_dirent_in(struct gfs2_dirent *de, char *buf)
{
struct gfs2_dirent *str = (struct gfs2_dirent *)buf;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.