#ifndef _MAKEFS_H
#define _MAKEFS_H
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#define HAVE_STRUCT_STAT_ST_GEN 1
#define HAVE_STRUCT_STAT_ST_MTIMENSEC 1
#define HAVE_STRUCT_STATVFS_F_IOSIZE 1
#define HAVE_STRUCT_STAT_BIRTHTIME 1
#define HAVE_FSTATVFS 1
#endif
#include <stdio.h>
#include <sys/stat.h>
#include <err.h>
enum fi_flags {
FI_SIZED = 1<<0,
FI_ALLOCATED = 1<<1,
FI_WRITTEN = 1<<2,
};
typedef struct {
uint64_t ino;
uint32_t nlink;
enum fi_flags flags;
struct stat st;
void *fsuse;
#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;
const char *root;
char *path;
char *name;
int flags;
} fsnode;
#define FSNODE_F_HASSPEC 0x01
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;
int freefilepc;
int freeblockpc;
int needswap;
int sectorsize;
int sparse;
int replace;
int follow;
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);
int set_option(const option_t *, const char *, char *, size_t);
void print_options(FILE *, const option_t *);
int set_option_var(const option_t *, const char *, const char *,
char *, size_t);
fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *, int,
int);
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(ffs);
DECLARE_FUN(cd9660);
DECLARE_FUN(chfs);
DECLARE_FUN(v7fs);
DECLARE_FUN(msdos);
DECLARE_FUN(udf);
extern u_int debug;
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_STRINGS \
{ "time", DEBUG_TIME }, \
{ "walk_dir", DEBUG_WALK_DIR }, \
{ "walk_dir_node", DEBUG_WALK_DIR_NODE }, \
{ "walk_dir_linkcheck", DEBUG_WALK_DIR_LINKCHECK }, \
{ "dump_fsnodes", DEBUG_DUMP_FSNODES }, \
{ "dump_fsnodes_verbose", DEBUG_DUMP_FSNODES_VERBOSE }, \
{ "fs_parse_opts", DEBUG_FS_PARSE_OPTS }, \
{ "fs_makefs", DEBUG_FS_MAKEFS }, \
{ "fs_validate", DEBUG_FS_VALIDATE }, \
{ "fs_create_image", DEBUG_FS_CREATE_IMAGE }, \
{ "fs_size_dir", DEBUG_FS_SIZE_DIR }, \
{ "fs_size_dir_node", DEBUG_FS_SIZE_DIR_NODE }, \
{ "fs_size_dir_add_dirent", DEBUG_FS_SIZE_DIR_ADD_DIRENT }, \
{ "fs_populate", DEBUG_FS_POPULATE }, \
{ "fs_populate_dirbuf", DEBUG_FS_POPULATE_DIRBUF }, \
{ "fs_populate_node", DEBUG_FS_POPULATE_NODE }, \
{ "fs_write_file", DEBUG_FS_WRITE_FILE }, \
{ "fs_write_file_block", DEBUG_FS_WRITE_FILE_BLOCK }, \
{ "fs_make_dirbuf", DEBUG_FS_MAKE_DIRBUF }, \
{ "fs_write_inode", DEBUG_FS_WRITE_INODE }, \
{ "buf_bread", DEBUG_BUF_BREAD }, \
{ "buf_bwrite", DEBUG_BUF_BWRITE }, \
{ "buf_getblk", DEBUG_BUF_GETBLK }, \
{ "apply_specfile", DEBUG_APPLY_SPECFILE }, \
{ "apply_specentry", DEBUG_APPLY_SPECENTRY }, \
{ "apply_speconly", DEBUG_APPLY_SPECONLY },
#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
#endif