Blame gfs2/edit/hexedit.h

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