#ifndef _MAKEFS_H
#define _MAKEFS_H
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#endif
#include <sys/stat.h>
#include <err.h>
enum fi_flags {
FI_SIZED = 1<<0,
FI_ALLOCATED = 1<<1,
FI_WRITTEN = 1<<2,
FI_ROOT = 1<<3,
};
typedef struct {
uint32_t ino;
uint32_t nlink;
enum fi_flags flags;
void *param;
struct stat st;
#if !HAVE_STRUCT_STAT_ST_FLAGS
uint32_t st_flags;
#endif
} fsinode;
#if HAVE_STRUCT_STAT_ST_FLAGS
#define FSINODE_ST_FLAGS(inode) (inode).st.st_flags
#else
#define FSINODE_ST_FLAGS(inode) (inode).st_flags
#endif
typedef struct _fsnode {
struct _fsnode *parent;
struct _fsnode *child;
struct _fsnode *next;
struct _fsnode *first;
uint32_t type;
fsinode *inode;
char *symlink;
char *contents;
const char *root;
char *path;
char *name;
int flags;
} fsnode;
#define FSNODE_F_HASSPEC 0x01
#define FSNODE_F_OPTIONAL 0x02
typedef enum {
OPT_STRARRAY,
OPT_STRPTR,
OPT_STRBUF,
OPT_BOOL,
OPT_INT8,
OPT_INT16,
OPT_INT32,
OPT_INT64
} opttype_t;
typedef struct {
char letter;
const char *name;
void *value;
opttype_t type;
long long minimum;
long long maximum;
const char *desc;
} option_t;
typedef struct makefs_fsinfo {
off_t size;
off_t inodes;
uint32_t curinode;
int fd;
void *superblock;
int onlyspec;
off_t minsize;
off_t maxsize;
off_t freefiles;
off_t freeblocks;
off_t offset;
off_t roundup;
int freefilepc;
int freeblockpc;
int needswap;
int sectorsize;
int sparse;
void *fs_specific;
option_t *fs_options;
} fsinfo_t;
void apply_specfile(const char *, const char *, fsnode *, int);
void dump_fsnodes(fsnode *);
const char * inode_type(mode_t);
fsnode * read_mtree(const char *, fsnode *);
int set_option(const option_t *, const char *, char *, size_t);
int set_option_var(const option_t *, const char *, const char *,
char *, size_t);
void set_tstamp(fsnode *);
fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
void free_fsnodes(fsnode *);
option_t * copy_opts(const option_t *);
#define DECLARE_FUN(fs) \
void fs ## _prep_opts(fsinfo_t *); \
int fs ## _parse_opts(const char *, fsinfo_t *); \
void fs ## _cleanup_opts(fsinfo_t *); \
void fs ## _makefs(const char *, const char *, fsnode *, fsinfo_t *)
DECLARE_FUN(cd9660);
DECLARE_FUN(ffs);
DECLARE_FUN(msdos);
#ifdef HAVE_ZFS
DECLARE_FUN(zfs);
#endif
extern u_int debug;
extern int dupsok;
extern struct timespec start_time;
extern struct stat stampst;
#define FSNODE_EXCLUDE_P(opts, fsnode) \
((opts)->onlyspec != 0 && ((fsnode)->flags & FSNODE_F_HASSPEC) == 0)
#define DEBUG_TIME 0x00000001
#define DEBUG_WALK_DIR 0x00000010
#define DEBUG_WALK_DIR_NODE 0x00000020
#define DEBUG_WALK_DIR_LINKCHECK 0x00000040
#define DEBUG_DUMP_FSNODES 0x00000080
#define DEBUG_DUMP_FSNODES_VERBOSE 0x00000100
#define DEBUG_FS_PARSE_OPTS 0x00000200
#define DEBUG_FS_MAKEFS 0x00000400
#define DEBUG_FS_VALIDATE 0x00000800
#define DEBUG_FS_CREATE_IMAGE 0x00001000
#define DEBUG_FS_SIZE_DIR 0x00002000
#define DEBUG_FS_SIZE_DIR_NODE 0x00004000
#define DEBUG_FS_SIZE_DIR_ADD_DIRENT 0x00008000
#define DEBUG_FS_POPULATE 0x00010000
#define DEBUG_FS_POPULATE_DIRBUF 0x00020000
#define DEBUG_FS_POPULATE_NODE 0x00040000
#define DEBUG_FS_WRITE_FILE 0x00080000
#define DEBUG_FS_WRITE_FILE_BLOCK 0x00100000
#define DEBUG_FS_MAKE_DIRBUF 0x00200000
#define DEBUG_FS_WRITE_INODE 0x00400000
#define DEBUG_BUF_BREAD 0x00800000
#define DEBUG_BUF_BWRITE 0x01000000
#define DEBUG_BUF_GETBLK 0x02000000
#define DEBUG_APPLY_SPECFILE 0x04000000
#define DEBUG_APPLY_SPECENTRY 0x08000000
#define DEBUG_APPLY_SPECONLY 0x10000000
#define DEBUG_MSDOSFS 0x20000000
#define TIMER_START(x) \
if (debug & DEBUG_TIME) \
gettimeofday(&(x), NULL)
#define TIMER_RESULTS(x,d) \
if (debug & DEBUG_TIME) { \
struct timeval end, td; \
gettimeofday(&end, NULL); \
timersub(&end, &(x), &td); \
printf("%s took %lld.%06ld seconds\n", \
(d), (long long)td.tv_sec, \
(long)td.tv_usec); \
}
#ifndef DEFAULT_FSTYPE
#define DEFAULT_FSTYPE "ffs"
#endif
#define FFS_EI
#define FS_SWAPPED 0x80000000
#define FS_INTERNAL 0x80000000
#define FS_ISCLEAN 1
#define DINODE1_SIZE (sizeof(struct ufs1_dinode))
#define DINODE2_SIZE (sizeof(struct ufs2_dinode))
#define UFS1_MAXSYMLINKLEN ((UFS_NDADDR + UFS_NIADDR) * sizeof(ufs1_daddr_t))
#define UFS2_MAXSYMLINKLEN ((UFS_NDADDR + UFS_NIADDR) * sizeof(ufs2_daddr_t))
#if (BYTE_ORDER == LITTLE_ENDIAN)
#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
(((oldfmt) && !(needswap)) ? \
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
#else
#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
(((oldfmt) && (needswap)) ? \
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
#endif
#define cg_chkmagic_swap(cgp, ns) \
(ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)
#define cg_inosused_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_iusedoff, (ns))))
#define cg_blksfree_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_freeoff, (ns))))
#define cg_clustersfree_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_clusteroff, (ns))))
#define cg_clustersum_swap(cgp, ns) \
((int32_t *)((uintptr_t)(cgp) + ufs_rw32((cgp)->cg_clustersumoff, ns)))
struct fs;
void ffs_fragacct_swap(struct fs *, int, uint32_t [], int, int);
fsinode *link_check(fsinode *);
#endif