Blame gfs2/fsck/util.h

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