All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] [gfs2-utils PATCH] gfs2_edit: Make 'j' jump to journaled block on log descriptors
       [not found] <1838160711.10782099.1464199256454.JavaMail.zimbra@redhat.com>
@ 2016-05-25 18:03 ` Bob Peterson
  2016-05-26 13:47   ` Andrew Price
  0 siblings, 1 reply; 2+ messages in thread
From: Bob Peterson @ 2016-05-25 18:03 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

This is a bit of a quick hack, but it works:

The jump command ordinarily jumps to the absolute block in the file
system. That makes sense for almost all cases. For log descriptors,
you're usually more interested in the journaled blocks than the
actual blocks. So this patch makes 'j' jump to the journaled version
of the block rather than the absolute block, when you're looking
at a log descriptor block.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 2ce111d..40a719e 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -545,6 +545,17 @@ static const struct lgfs2_metadata *find_mtype(uint32_t mtype, const unsigned ve
 	return NULL;
 }
 
+static int get_pnum(int ptroffset)
+{
+	int pnum;
+
+	pnum = pgnum * screen_chunk_size;
+	pnum += (ptroffset - struct_len);
+	pnum /= sizeof(uint64_t);
+
+	return pnum;
+}
+
 /* ------------------------------------------------------------------------ */
 /* hexdump - hex dump the filesystem block to the screen                    */
 /* ------------------------------------------------------------------------ */
@@ -559,6 +570,7 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
 	int print_field, cursor_line;
 	const uint32_t block_type = get_block_type(bh, NULL);
 	uint64_t *ref;
+	int ptroffset = 0;
 
 	strcpy(edit_fmt,"%02x");
 	pointer = (unsigned char *)lpBuffer + offset;
@@ -679,19 +691,17 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
 		}
 		if (cursor_line) {
 			if (block_type == GFS2_METATYPE_IN ||
+			    block_type == GFS2_METATYPE_LD ||
 			    ((block_type == GFS2_METATYPE_DI) &&
 			     ((struct gfs2_dinode*)bh->b_data)->di_height) ||
 			     S_ISDIR(di.di_mode)) {
-				int ptroffset = edit_row[dmode] * 16 +
+				ptroffset = edit_row[dmode] * 16 +
 					edit_col[dmode];
 
 				if (ptroffset >= struct_len || pgnum) {
-					int pnum;
-
-					pnum = pgnum * screen_chunk_size;
-					pnum += (ptroffset - struct_len);
-					pnum /= sizeof(uint64_t);
-
+					int pnum = get_pnum(ptroffset);
+					if (block_type == GFS2_METATYPE_LD)
+						print_gfs2("*");
 					print_gfs2("pointer 0x%x", pnum);
 				}
 			}
@@ -713,6 +723,13 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
 		if ((const char *)pointer >= zeros_strt)
 			break;
 	} /* while */
+	if (block_type == GFS2_METATYPE_LD && ptroffset >= struct_len) {
+		COLORS_NORMAL;
+		eol(0);
+		print_gfs2("         * 'j' will jump to the journaled block, "
+			   "not the absolute block.");
+		eol(0);
+	}
 	if (sbd.gfs1) {
 		COLORS_NORMAL;
 		print_gfs2("         *** This seems to be a GFS-1 file system ***");
@@ -1610,18 +1627,28 @@ static void pagedn(void)
 
 /* ------------------------------------------------------------------------ */
 /* jump - jump to the address the cursor is on                              */
+/*                                                                          */
+/* If the cursor is in a log descriptor, jump to the log-descriptor version */
+/* of the block instead of the "real" block.                                */
 /* ------------------------------------------------------------------------ */
 static void jump(void)
 {
 	if (dmode == HEX_MODE) {
 		unsigned int col2;
 		uint64_t *b;
+		const uint32_t block_type = get_block_type(bh, NULL);
 		
-		if (edit_row[dmode] >= 0) {
+		/* special exception for log descriptors: jump the journaled
+		   version of the block, not the "real" block */
+		if (block_type == GFS2_METATYPE_LD) {
+			int ptroffset = edit_row[dmode] * 16 + edit_col[dmode];
+			int pnum = get_pnum(ptroffset);
+			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 +
 						    offset + col2];
-			temp_blk=be64_to_cpu(*b);
+			temp_blk = be64_to_cpu(*b);
 		}
 	}
 	else



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Cluster-devel] [gfs2-utils PATCH] gfs2_edit: Make 'j' jump to journaled block on log descriptors
  2016-05-25 18:03 ` [Cluster-devel] [gfs2-utils PATCH] gfs2_edit: Make 'j' jump to journaled block on log descriptors Bob Peterson
@ 2016-05-26 13:47   ` Andrew Price
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Price @ 2016-05-26 13:47 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On 25/05/16 19:03, Bob Peterson wrote:
> Hi,
>
> This is a bit of a quick hack, but it works:
>
> The jump command ordinarily jumps to the absolute block in the file
> system. That makes sense for almost all cases. For log descriptors,
> you're usually more interested in the journaled blocks than the
> actual blocks. So this patch makes 'j' jump to the journaled version
> of the block rather than the absolute block, when you're looking
> at a log descriptor block.
>
> Signed-off-by: Bob Peterson <rpeterso@redhat.com>

ACK

Andy

> ---
> diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
> index 2ce111d..40a719e 100644
> --- a/gfs2/edit/hexedit.c
> +++ b/gfs2/edit/hexedit.c
> @@ -545,6 +545,17 @@ static const struct lgfs2_metadata *find_mtype(uint32_t mtype, const unsigned ve
>  	return NULL;
>  }
>
> +static int get_pnum(int ptroffset)
> +{
> +	int pnum;
> +
> +	pnum = pgnum * screen_chunk_size;
> +	pnum += (ptroffset - struct_len);
> +	pnum /= sizeof(uint64_t);
> +
> +	return pnum;
> +}
> +
>  /* ------------------------------------------------------------------------ */
>  /* hexdump - hex dump the filesystem block to the screen                    */
>  /* ------------------------------------------------------------------------ */
> @@ -559,6 +570,7 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
>  	int print_field, cursor_line;
>  	const uint32_t block_type = get_block_type(bh, NULL);
>  	uint64_t *ref;
> +	int ptroffset = 0;
>
>  	strcpy(edit_fmt,"%02x");
>  	pointer = (unsigned char *)lpBuffer + offset;
> @@ -679,19 +691,17 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
>  		}
>  		if (cursor_line) {
>  			if (block_type == GFS2_METATYPE_IN ||
> +			    block_type == GFS2_METATYPE_LD ||
>  			    ((block_type == GFS2_METATYPE_DI) &&
>  			     ((struct gfs2_dinode*)bh->b_data)->di_height) ||
>  			     S_ISDIR(di.di_mode)) {
> -				int ptroffset = edit_row[dmode] * 16 +
> +				ptroffset = edit_row[dmode] * 16 +
>  					edit_col[dmode];
>
>  				if (ptroffset >= struct_len || pgnum) {
> -					int pnum;
> -
> -					pnum = pgnum * screen_chunk_size;
> -					pnum += (ptroffset - struct_len);
> -					pnum /= sizeof(uint64_t);
> -
> +					int pnum = get_pnum(ptroffset);
> +					if (block_type == GFS2_METATYPE_LD)
> +						print_gfs2("*");
>  					print_gfs2("pointer 0x%x", pnum);
>  				}
>  			}
> @@ -713,6 +723,13 @@ static int hexdump(uint64_t startaddr, int len, int trunc_zeros,
>  		if ((const char *)pointer >= zeros_strt)
>  			break;
>  	} /* while */
> +	if (block_type == GFS2_METATYPE_LD && ptroffset >= struct_len) {
> +		COLORS_NORMAL;
> +		eol(0);
> +		print_gfs2("         * 'j' will jump to the journaled block, "
> +			   "not the absolute block.");
> +		eol(0);
> +	}
>  	if (sbd.gfs1) {
>  		COLORS_NORMAL;
>  		print_gfs2("         *** This seems to be a GFS-1 file system ***");
> @@ -1610,18 +1627,28 @@ static void pagedn(void)
>
>  /* ------------------------------------------------------------------------ */
>  /* jump - jump to the address the cursor is on                              */
> +/*                                                                          */
> +/* If the cursor is in a log descriptor, jump to the log-descriptor version */
> +/* of the block instead of the "real" block.                                */
>  /* ------------------------------------------------------------------------ */
>  static void jump(void)
>  {
>  	if (dmode == HEX_MODE) {
>  		unsigned int col2;
>  		uint64_t *b;
> +		const uint32_t block_type = get_block_type(bh, NULL);
>  		
> -		if (edit_row[dmode] >= 0) {
> +		/* special exception for log descriptors: jump the journaled
> +		   version of the block, not the "real" block */
> +		if (block_type == GFS2_METATYPE_LD) {
> +			int ptroffset = edit_row[dmode] * 16 + edit_col[dmode];
> +			int pnum = get_pnum(ptroffset);
> +			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 +
>  						    offset + col2];
> -			temp_blk=be64_to_cpu(*b);
> +			temp_blk = be64_to_cpu(*b);
>  		}
>  	}
>  	else
>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-26 13:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1838160711.10782099.1464199256454.JavaMail.zimbra@redhat.com>
2016-05-25 18:03 ` [Cluster-devel] [gfs2-utils PATCH] gfs2_edit: Make 'j' jump to journaled block on log descriptors Bob Peterson
2016-05-26 13:47   ` Andrew Price

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.