Blame gfs2/edit/hexedit.h

Packit Service 360c39
#ifndef __HEXVIEW_DOT_H__
Packit Service 360c39
#define __HEXVIEW_DOT_H__
Packit Service 360c39
Packit Service 360c39
#include <sys/types.h>
Packit Service 360c39
#include <inttypes.h>
Packit Service 360c39
#include <limits.h>
Packit Service 360c39
#include <linux/gfs2_ondisk.h>
Packit Service 360c39
#include <string.h>
Packit Service 360c39
Packit Service 360c39
#include "libgfs2.h"
Packit Service 360c39
#include "copyright.cf"
Packit Service 360c39
Packit Service 360c39
#ifndef TRUE
Packit Service 360c39
#define TRUE 1
Packit Service 360c39
#endif
Packit Service 360c39
#ifndef FALSE
Packit Service 360c39
#define FALSE 0
Packit Service 360c39
#endif
Packit Service 360c39
Packit Service 360c39
#define DMODES 3
Packit Service 360c39
enum dsp_mode { HEX_MODE = 0, GFS2_MODE = 1, EXTENDED_MODE = 2, INIT_MODE = 3 };
Packit Service 360c39
#define BLOCK_STACK_SIZE 256
Packit Service 360c39
Packit Service 360c39
#define pv(struct, member, fmt, fmt2) do {				\
Packit Service 360c39
		print_it("  "#member, fmt, fmt2, struct->member);	\
Packit Service 360c39
	} while (FALSE);
Packit Service 360c39
#define RGLIST_DUMMY_BLOCK -2
Packit Service 360c39
#define JOURNALS_DUMMY_BLOCK -3
Packit Service 360c39
Packit Service 360c39
extern const char *mtypes[];
Packit Service 360c39
extern struct gfs2_sb sb;
Packit Service 360c39
extern int blockhist;
Packit Service 360c39
extern int edit_mode;
Packit Service 360c39
extern int line;
Packit Service 360c39
extern char edit_fmt[80];
Packit Service 360c39
extern char estring[1024]; /* edit string */
Packit Service 360c39
extern char efield[64];
Packit Service 360c39
extern uint64_t dev_offset;
Packit Service 360c39
extern uint64_t max_block;
Packit Service 360c39
extern int termlines;
Packit Service 360c39
extern int insert;
Packit Service 360c39
extern const char *termtype;
Packit Service 360c39
extern int line;
Packit Service 360c39
extern int struct_len;
Packit Service 360c39
extern unsigned int offset;
Packit Service 360c39
extern int edit_row[DMODES], edit_col[DMODES], print_entry_ndx;
Packit Service 360c39
extern int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
Packit Service 360c39
extern int edit_size[DMODES], last_entry_onscreen[DMODES];
Packit Service 360c39
extern char edit_fmt[80];
Packit Service 360c39
extern struct gfs2_sbd sbd;
Packit Service 360c39
extern struct gfs_sb *sbd1;
Packit Service 360c39
extern struct gfs2_inum gfs1_quota_di;   /* kludge because gfs2 sb too small */
Packit Service 360c39
extern struct gfs2_inum gfs1_license_di; /* kludge because gfs2 sb too small */
Packit Service 360c39
extern struct gfs2_dinode di;
Packit Service 360c39
extern int screen_chunk_size; /* how much of the 4K can fit on screen */
Packit Service 360c39
extern int gfs2_struct_type;
Packit Service 360c39
extern int identify;
Packit Service 360c39
extern int color_scheme;
Packit Service 360c39
extern WINDOW *wind;
Packit Service 360c39
extern int editing;
Packit Service 360c39
extern uint64_t temp_blk;
Packit Service 360c39
extern uint64_t starting_blk;
Packit Service 360c39
extern const char *block_type_str[15];
Packit Service 360c39
extern int dsplines;
Packit Service 360c39
extern int dsp_lines[DMODES];
Packit Service 360c39
extern int combined_display;
Packit Service 360c39
extern int details;
Packit Service 360c39
extern const char *allocdesc[2][5];
Packit Service 360c39
Packit Service 360c39
struct gfs2_dirents {
Packit Service 360c39
	uint64_t block;
Packit Service 360c39
	struct gfs2_dirent dirent;
Packit Service 360c39
	char filename[NAME_MAX];
Packit Service 360c39
};
Packit Service 360c39
Packit Service 360c39
struct indirect_info {
Packit Service 360c39
	int is_dir;
Packit Service 360c39
	int height;
Packit Service 360c39
	uint64_t block;
Packit Service 360c39
	uint32_t dirents;
Packit Service 360c39
	struct gfs2_leaf lf;
Packit Service 360c39
	struct metapath mp;
Packit Service 360c39
	struct gfs2_dirents dirent[64];
Packit Service 360c39
	uint64_t ptroff;
Packit Service 360c39
};
Packit Service 360c39
Packit Service 360c39
struct iinfo {
Packit Service 360c39
	struct indirect_info ii[512];
Packit Service 360c39
};
Packit Service 360c39
Packit Service 360c39
struct blkstack_info {
Packit Service 360c39
	uint64_t block;
Packit Service 360c39
	int start_row[DMODES];
Packit Service 360c39
	int end_row[DMODES];
Packit Service 360c39
	int lines_per_row[DMODES];
Packit Service 360c39
	int edit_row[DMODES];
Packit Service 360c39
	int edit_col[DMODES];
Packit Service 360c39
	enum dsp_mode dmode;
Packit Service 360c39
	int gfs2_struct_type;
Packit Service 360c39
	struct metapath mp;
Packit Service 360c39
};
Packit Service 360c39
Packit Service 360c39
extern struct blkstack_info blockstack[BLOCK_STACK_SIZE];
Packit Service 360c39
extern struct iinfo *indirect; /* more than the most indirect
Packit Service 360c39
			       pointers possible for any given 4K block */
Packit Service 360c39
extern struct indirect_info masterdir; /* Master directory info */
Packit Service 360c39
extern int indirect_blocks;  /* count of indirect blocks */
Packit Service 360c39
extern enum dsp_mode dmode;
Packit Service 360c39
Packit Service 360c39
/* ------------------------------------------------------------------------ */
Packit Service 360c39
/* block_is_rgtree - there's no such block as the rglist.  This is a        */
Packit Service 360c39
/*                   special case meant to parse the rindex and follow the  */
Packit Service 360c39
/*                   blocks to the real rgs.                                */
Packit Service 360c39
/* ------------------------------------------------------------------------ */
Packit Service 360c39
static inline int block_is_rgtree(uint64_t blk)
Packit Service 360c39
{
Packit Service 360c39
	if (blk == RGLIST_DUMMY_BLOCK)
Packit Service 360c39
		return TRUE;
Packit Service 360c39
	return FALSE;
Packit Service 360c39
}
Packit Service 360c39
Packit Service 360c39
static inline int block_is_journals(uint64_t blk)
Packit Service 360c39
{
Packit Service 360c39
	if (blk == JOURNALS_DUMMY_BLOCK)
Packit Service 360c39
		return TRUE;
Packit Service 360c39
	return FALSE;
Packit Service 360c39
}
Packit Service 360c39
Packit Service 360c39
#define SCREEN_HEIGHT   (16)
Packit Service 360c39
#define SCREEN_WIDTH    (16)
Packit Service 360c39
Packit Service 360c39
/* die() used to be in libgfs2.h */
Packit Service 360c39
static __inline__ __attribute__((noreturn, format (printf, 1, 2)))
Packit Service 360c39
void die(const char *fmt, ...)
Packit Service 360c39
{
Packit Service 360c39
	va_list ap;
Packit Service 360c39
	va_start(ap, fmt);
Packit Service 360c39
	vfprintf(stderr, fmt, ap);
Packit Service 360c39
	va_end(ap);
Packit Service 360c39
	exit(-1);
Packit Service 360c39
}
Packit Service 360c39
Packit Service 360c39
/*  Memory macros  */
Packit Service 360c39
Packit Service 360c39
#define type_alloc(ptr, type, count) \
Packit Service 360c39
{ \
Packit Service 360c39
  (ptr) = (type *)malloc(sizeof(type) * (count)); \
Packit Service 360c39
  if (!(ptr)) \
Packit Service 360c39
    die("unable to allocate memory on line %d of file %s\n", \
Packit Service 360c39
	__LINE__, __FILE__); \
Packit Service 360c39
}
Packit Service 360c39
Packit Service 360c39
#define printk printw
Packit Service 360c39
Packit Service 360c39
/*  Divide x by y.  Round up if there is a remainder.  */
Packit Service 360c39
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
Packit Service 360c39
Packit Service 360c39
#define TITLE1 "gfs2_edit - Global File System Editor (use with extreme caution)"
Packit Service 360c39
#define TITLE2 REDHAT_COPYRIGHT " - Press H for help"
Packit Service 360c39
Packit Service 360c39
#define COLOR_TITLE     1
Packit Service 360c39
#define COLOR_NORMAL    2
Packit Service 360c39
#define COLOR_INVERSE   3
Packit Service 360c39
#define COLOR_SPECIAL   4
Packit Service 360c39
#define COLOR_HIGHLIGHT 5
Packit Service 360c39
#define COLOR_OFFSETS   6
Packit Service 360c39
#define COLOR_CONTENTS  7
Packit Service 360c39
Packit Service 360c39
#define COLORS_TITLE     \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_TITLE)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_NORMAL    \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_NORMAL)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_INVERSE   \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_INVERSE)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_SPECIAL   \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_SPECIAL)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_HIGHLIGHT \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_HIGHLIGHT)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_OFFSETS   \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_OFFSETS)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
#define COLORS_CONTENTS  \
Packit Service 360c39
	do { \
Packit Service 360c39
		if (termlines) { \
Packit Service 360c39
			attrset(COLOR_PAIR(COLOR_CONTENTS)); \
Packit Service 360c39
			attron(A_BOLD); \
Packit Service 360c39
		} \
Packit Service 360c39
	} while (0)
Packit Service 360c39
Packit Service 360c39
extern int block_is_jindex(uint64_t blk);
Packit Service 360c39
extern int block_is_rindex(uint64_t blk);
Packit Service 360c39
extern int block_is_inum_file(uint64_t blk);
Packit Service 360c39
extern int block_is_statfs_file(uint64_t blk);
Packit Service 360c39
extern int block_is_quota_file(uint64_t blk);
Packit Service 360c39
extern int block_is_per_node(uint64_t blk);
Packit Service 360c39
extern int display_block_type(struct gfs2_buffer_head *bh, int from_restore);
Packit Service 360c39
extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
Packit Service 360c39
extern void gfs_log_header_in(struct gfs_log_header *head,
Packit Service 360c39
			      struct gfs2_buffer_head *bh);
Packit Service 360c39
extern void gfs_log_header_print(struct gfs_log_header *lh);
Packit Service 360c39
extern void gfs_dinode_in(struct gfs_dinode *di, struct gfs2_buffer_head *bh);
Packit Service 360c39
extern void savemeta(char *out_fn, int saveoption, int gziplevel);
Packit Service 360c39
extern void restoremeta(const char *in_fn, const char *out_device,
Packit Service 360c39
			uint64_t printblocksonly);
Packit Service 360c39
extern int display(int identify_only, int trunc_zeros, uint64_t flagref,
Packit Service 360c39
		   uint64_t ref_blk);
Packit Service 360c39
extern uint64_t check_keywords(const char *kword);
Packit Service 360c39
extern uint64_t masterblock(const char *fn);
Packit Service 360c39
extern void gfs_rgrp_print(struct gfs_rgrp *rg);
Packit Service 360c39
extern int has_indirect_blocks(void);
Packit Service 360c39
extern uint32_t get_block_type(const struct gfs2_buffer_head *lbh,
Packit Service 360c39
			       int *structlen);
Packit Service 360c39
Packit Service 360c39
#endif /* __HEXVIEW_DOT_H__ */