Blame gfs2/fsck/util.h

Packit 6ef888
#ifndef __UTIL_H__
Packit 6ef888
#define __UTIL_H__
Packit 6ef888
Packit 6ef888
#include <sys/stat.h>
Packit 6ef888
Packit 6ef888
#include "fsck.h"
Packit 6ef888
#include "libgfs2.h"
Packit 6ef888
Packit 6ef888
#define fsck_lseek(fd, off) \
Packit 6ef888
  ((lseek((fd), (off), SEEK_SET) == (off)) ? 0 : -1)
Packit 6ef888
Packit 6ef888
#define INODE_VALID 1
Packit 6ef888
#define INODE_INVALID 0
Packit 6ef888
Packit 6ef888
struct di_info *search_list(osi_list_t *list, uint64_t addr);
Packit 6ef888
void big_file_comfort(struct gfs2_inode *ip, uint64_t blks_checked);
Packit 6ef888
void warm_fuzzy_stuff(uint64_t block);
Packit 6ef888
int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
Packit 6ef888
		      enum dup_ref_type reftype, int first, int inode_valid);
Packit 6ef888
extern struct inode_with_dups *find_dup_ref_inode(struct duptree *dt,
Packit 6ef888
						  struct gfs2_inode *ip);
Packit 6ef888
extern void dup_listent_delete(struct duptree *dt, struct inode_with_dups *id);
Packit 6ef888
extern int count_dup_meta_refs(struct duptree *dt);
Packit 6ef888
extern const char *reftypes[ref_types + 1];
Packit 6ef888
Packit 6ef888
#define BLOCKMAP_SIZE1(size) ((size) >> 3)
Packit 6ef888
#define BLOCKMAP_SIZE2(size) ((size) >> 2)
Packit 6ef888
#define BLOCKMAP_BYTE_OFFSET2(x) ((x & 0x0000000000000003) << 1)
Packit 6ef888
#define BLOCKMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007)
Packit 6ef888
#define BLOCKMAP_MASK2 (0x3)
Packit 6ef888
#define BLOCKMAP_MASK1 (1)
Packit 6ef888
Packit 6ef888
struct fsck_pass {
Packit 6ef888
	const char *name;
Packit 6ef888
	int (*f)(struct gfs2_sbd *sdp);
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
static inline int block_type(struct gfs2_bmap *bl, uint64_t bblock)
Packit 6ef888
{
Packit 6ef888
	static unsigned char *byte;
Packit 6ef888
	static uint64_t b;
Packit 6ef888
	static int btype;
Packit 6ef888
Packit 6ef888
	byte = bl->map + BLOCKMAP_SIZE2(bblock);
Packit 6ef888
	b = BLOCKMAP_BYTE_OFFSET2(bblock);
Packit 6ef888
	btype = (*byte & (BLOCKMAP_MASK2 << b )) >> b;
Packit 6ef888
	return btype;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static inline int link1_type(struct gfs2_bmap *bl, uint64_t bblock)
Packit 6ef888
{
Packit 6ef888
	static unsigned char *byte;
Packit 6ef888
	static uint64_t b;
Packit 6ef888
	static int btype;
Packit 6ef888
Packit 6ef888
	byte = bl->map + BLOCKMAP_SIZE1(bblock);
Packit 6ef888
	b = BLOCKMAP_BYTE_OFFSET1(bblock);
Packit 6ef888
	btype = (*byte & (BLOCKMAP_MASK1 << b )) >> b;
Packit 6ef888
	return btype;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static inline void link1_destroy(struct gfs2_bmap *bmap)
Packit 6ef888
{
Packit 6ef888
	if (bmap->map)
Packit 6ef888
		free(bmap->map);
Packit 6ef888
	bmap->size = 0;
Packit 6ef888
	bmap->mapsize = 0;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static inline int bitmap_type(struct gfs2_sbd *sdp, uint64_t bblock)
Packit 6ef888
{
Packit 6ef888
	struct rgrp_tree *rgd;
Packit 6ef888
Packit 6ef888
	rgd = gfs2_blk2rgrpd(sdp, bblock);
Packit 6ef888
	return lgfs2_get_bitmap(sdp, bblock, rgd);
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static const inline char *block_type_string(int q)
Packit 6ef888
{
Packit 6ef888
	const char *blktyp[] = {"free", "data", "other", "inode", "invalid"};
Packit 6ef888
	if (q >= GFS2_BLKST_FREE && q <= GFS2_BLKST_DINODE)
Packit 6ef888
		return (blktyp[q]);
Packit 6ef888
	return blktyp[4];
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static inline int is_dir(struct gfs2_dinode *dinode, int gfs1)
Packit 6ef888
{
Packit 6ef888
	if (gfs1 && is_gfs_dir(dinode))
Packit 6ef888
		return 1;
Packit 6ef888
	if (S_ISDIR(dinode->di_mode))
Packit 6ef888
		return 1;
Packit 6ef888
Packit 6ef888
	return 0;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static inline uint32_t gfs_to_gfs2_mode(struct gfs2_inode *ip)
Packit 6ef888
{
Packit 6ef888
	uint16_t gfs1mode = ip->i_di.__pad1;
Packit 6ef888
Packit 6ef888
	switch (gfs1mode) {
Packit 6ef888
	case GFS_FILE_DIR:
Packit 6ef888
		return S_IFDIR;
Packit 6ef888
	case GFS_FILE_REG:
Packit 6ef888
		return S_IFREG;
Packit 6ef888
	case GFS_FILE_LNK:
Packit 6ef888
		return S_IFLNK;
Packit 6ef888
	case GFS_FILE_BLK:
Packit 6ef888
		return S_IFBLK;
Packit 6ef888
	case GFS_FILE_CHR:
Packit 6ef888
		return S_IFCHR;
Packit 6ef888
	case GFS_FILE_FIFO:
Packit 6ef888
		return S_IFIFO;
Packit 6ef888
	case GFS_FILE_SOCK:
Packit 6ef888
		return S_IFSOCK;
Packit 6ef888
	default:
Packit 6ef888
		/* This could be an aborted gfs2_convert so look for both. */
Packit 6ef888
		if (ip->i_di.di_entries ||
Packit 6ef888
		    (ip->i_di.di_mode & S_IFMT) == S_IFDIR)
Packit 6ef888
			return S_IFDIR;
Packit 6ef888
		else
Packit 6ef888
			return S_IFREG;
Packit 6ef888
	}
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
extern enum dup_ref_type get_ref_type(struct inode_with_dups *id);
Packit 6ef888
extern char generic_interrupt(const char *caller, const char *where,
Packit 6ef888
                       const char *progress, const char *question,
Packit 6ef888
                       const char *answers);
Packit 6ef888
extern char gfs2_getch(void);
Packit 6ef888
extern uint64_t find_free_blk(struct gfs2_sbd *sdp);
Packit 6ef888
extern uint64_t *get_dir_hash(struct gfs2_inode *ip);
Packit 6ef888
extern void delete_all_dups(struct gfs2_inode *ip);
Packit 6ef888
extern void print_pass_duration(const char *name, struct timeval *start);
Packit 6ef888
Packit 6ef888
#define stack log_debug("<backtrace> - %s()\n", __func__)
Packit 6ef888
Packit 6ef888
#endif /* __UTIL_H__ */