2010-11-07 16:05:04 +00:00
|
|
|
/* $NetBSD: makefs.h,v 1.20 2008/12/28 21:51:46 christos Exp $ */
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Wasabi Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Luke Mewburn for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2008-12-19 18:45:43 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
2008-11-23 19:59:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MAKEFS_H
|
|
|
|
#define _MAKEFS_H
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fsnode -
|
|
|
|
* a component of the tree; contains a filename, a pointer to
|
|
|
|
* fsinode, optional symlink name, and tree pointers
|
|
|
|
*
|
|
|
|
* fsinode -
|
|
|
|
* equivalent to an inode, containing target file system inode number,
|
|
|
|
* refcount (nlink), and stat buffer
|
|
|
|
*
|
|
|
|
* A tree of fsnodes looks like this:
|
|
|
|
*
|
|
|
|
* name "." "bin" "netbsd"
|
|
|
|
* type S_IFDIR S_IFDIR S_IFREG
|
|
|
|
* next > > NULL
|
|
|
|
* parent NULL NULL NULL
|
|
|
|
* child NULL v
|
|
|
|
*
|
|
|
|
* name "." "ls"
|
|
|
|
* type S_IFDIR S_IFREG
|
|
|
|
* next > NULL
|
|
|
|
* parent ^ ^ (to "bin")
|
|
|
|
* child NULL NULL
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* - first always points to first entry, at current level, which
|
|
|
|
* must be "." when the tree has been built; during build it may
|
|
|
|
* not be if "." hasn't yet been found by readdir(2).
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum fi_flags {
|
|
|
|
FI_SIZED = 1<<0, /* inode sized */
|
|
|
|
FI_ALLOCATED = 1<<1, /* fsinode->ino allocated */
|
|
|
|
FI_WRITTEN = 1<<2, /* inode written */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t ino; /* inode number used on target fs */
|
|
|
|
uint32_t nlink; /* number of links to this entry */
|
|
|
|
enum fi_flags flags; /* flags used by fs specific code */
|
|
|
|
struct stat st; /* stat entry */
|
|
|
|
} fsinode;
|
|
|
|
|
|
|
|
typedef struct _fsnode {
|
|
|
|
struct _fsnode *parent; /* parent (NULL if root) */
|
|
|
|
struct _fsnode *child; /* child (if type == S_IFDIR) */
|
|
|
|
struct _fsnode *next; /* next */
|
|
|
|
struct _fsnode *first; /* first node of current level (".") */
|
|
|
|
uint32_t type; /* type of entry */
|
|
|
|
fsinode *inode; /* actual inode data */
|
|
|
|
char *symlink; /* symlink target */
|
2011-06-19 18:34:49 +00:00
|
|
|
char *contents; /* file to provide contents */
|
2012-01-31 00:32:37 +00:00
|
|
|
const char *root; /* root path */
|
|
|
|
char *path; /* directory name */
|
2008-11-23 19:59:42 +00:00
|
|
|
char *name; /* file name */
|
|
|
|
int flags; /* misc flags */
|
|
|
|
} fsnode;
|
|
|
|
|
|
|
|
#define FSNODE_F_HASSPEC 0x01 /* fsnode has a spec entry */
|
2011-06-19 18:34:49 +00:00
|
|
|
#define FSNODE_F_OPTIONAL 0x02 /* fsnode is optional */
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fsinfo_t - contains various settings and parameters pertaining to
|
|
|
|
* the image, including current settings, global options, and fs
|
|
|
|
* specific options
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/* current settings */
|
|
|
|
off_t size; /* total size */
|
|
|
|
off_t inodes; /* number of inodes */
|
|
|
|
uint32_t curinode; /* current inode */
|
|
|
|
|
|
|
|
/* image settings */
|
|
|
|
int fd; /* file descriptor of image */
|
|
|
|
void *superblock; /* superblock */
|
|
|
|
int onlyspec; /* only add entries in specfile */
|
|
|
|
|
|
|
|
|
|
|
|
/* global options */
|
|
|
|
off_t minsize; /* minimum size image should be */
|
|
|
|
off_t maxsize; /* maximum size image can be */
|
|
|
|
off_t freefiles; /* free file entries to leave */
|
|
|
|
int freefilepc; /* free file % */
|
|
|
|
off_t freeblocks; /* free blocks to leave */
|
|
|
|
int freeblockpc; /* free block % */
|
|
|
|
int needswap; /* non-zero if byte swapping needed */
|
|
|
|
int sectorsize; /* sector size */
|
2012-08-22 06:37:30 +00:00
|
|
|
int sparse; /* sparse image, don't fill it with zeros */
|
2015-10-13 02:32:15 +00:00
|
|
|
off_t roundup; /* round image size up to this value */
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
void *fs_specific; /* File system specific additions. */
|
2008-11-23 19:59:42 +00:00
|
|
|
} fsinfo_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* option_t - contains option name, description, pointer to location to store
|
|
|
|
* result, and range checks for the result. Used to simplify fs specific
|
|
|
|
* option setting
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
const char *name; /* option name */
|
|
|
|
int *value; /* where to stuff the value */
|
|
|
|
int minimum; /* minimum for value */
|
|
|
|
int maximum; /* maximum for value */
|
|
|
|
const char *desc; /* option description */
|
|
|
|
} option_t;
|
|
|
|
|
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
void apply_specfile(const char *, const char *, fsnode *, int);
|
2012-01-31 00:32:37 +00:00
|
|
|
void dump_fsnodes(fsnode *);
|
2008-11-23 19:59:42 +00:00
|
|
|
const char * inode_type(mode_t);
|
2011-06-19 18:34:49 +00:00
|
|
|
fsnode * read_mtree(const char *, fsnode *);
|
2008-11-23 19:59:42 +00:00
|
|
|
int set_option(option_t *, const char *, const char *);
|
2012-01-31 00:32:37 +00:00
|
|
|
fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
|
2010-11-07 16:05:04 +00:00
|
|
|
void free_fsnodes(fsnode *);
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
void ffs_prep_opts(fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
int ffs_parse_opts(const char *, fsinfo_t *);
|
2010-11-07 16:05:04 +00:00
|
|
|
void ffs_cleanup_opts(fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
void ffs_makefs(const char *, const char *, fsnode *, fsinfo_t *);
|
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
void cd9660_prep_opts(fsinfo_t *);
|
|
|
|
int cd9660_parse_opts(const char *, fsinfo_t *);
|
|
|
|
void cd9660_cleanup_opts(fsinfo_t *);
|
|
|
|
void cd9660_makefs(const char *, const char *, fsnode *, fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern u_int debug;
|
2013-02-20 15:18:42 +00:00
|
|
|
extern int dupsok;
|
2008-11-23 19:59:42 +00:00
|
|
|
extern struct timespec start_time;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If -x is specified, we want to exclude nodes which do not appear
|
|
|
|
* in the spec file.
|
|
|
|
*/
|
|
|
|
#define FSNODE_EXCLUDE_P(opts, fsnode) \
|
|
|
|
((opts)->onlyspec != 0 && ((fsnode)->flags & FSNODE_F_HASSPEC) == 0)
|
|
|
|
|
|
|
|
#define DEBUG_TIME 0x00000001
|
|
|
|
/* debug bits 1..3 unused at this time */
|
|
|
|
#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
|
2010-11-07 16:05:04 +00:00
|
|
|
#define DEBUG_APPLY_SPECONLY 0x10000000
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
#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); \
|
2010-11-07 16:05:04 +00:00
|
|
|
printf("%s took %lld.%06ld seconds\n", \
|
|
|
|
(d), (long long)td.tv_sec, \
|
|
|
|
(long)td.tv_usec); \
|
2008-11-23 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef DEFAULT_FSTYPE
|
|
|
|
#define DEFAULT_FSTYPE "ffs"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ffs specific settings
|
|
|
|
* ---------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FFS_EI /* for opposite endian support in ffs headers */
|
|
|
|
|
2008-12-18 00:54:15 +00:00
|
|
|
/*
|
|
|
|
* Write-arounds/compat shims for endian-agnostic support.
|
|
|
|
* These belong in the kernel if/when it's possible to mount
|
|
|
|
* filesystems w/ either byte order.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File system internal flags, also in fs_flags.
|
|
|
|
* (Pick highest number to avoid conflicts with others)
|
|
|
|
*/
|
2010-11-07 16:05:04 +00:00
|
|
|
#define FS_SWAPPED 0x80000000 /* file system is endian swapped */
|
|
|
|
#define FS_INTERNAL 0x80000000 /* mask for internal flags */
|
2008-12-18 00:54:15 +00:00
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
#define FS_ISCLEAN 1
|
2008-12-18 00:54:15 +00:00
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
#define DINODE1_SIZE (sizeof(struct ufs1_dinode))
|
|
|
|
#define DINODE2_SIZE (sizeof(struct ufs2_dinode))
|
2008-12-18 00:54:15 +00:00
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
#define MAXSYMLINKLEN_UFS1 ((NDADDR + NIADDR) * sizeof(ufs1_daddr_t))
|
|
|
|
#define MAXSYMLINKLEN_UFS2 ((NDADDR + NIADDR) * sizeof(ufs2_daddr_t))
|
2008-12-18 00:54:15 +00:00
|
|
|
|
|
|
|
#if (BYTE_ORDER == LITTLE_ENDIAN)
|
2010-11-07 16:05:04 +00:00
|
|
|
#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
|
|
|
|
(((oldfmt) && !(needswap)) ? \
|
2008-12-18 00:54:15 +00:00
|
|
|
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
|
|
|
|
#else
|
2010-11-07 16:05:04 +00:00
|
|
|
#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
|
|
|
|
(((oldfmt) && (needswap)) ? \
|
2008-12-18 00:54:15 +00:00
|
|
|
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
|
|
|
|
#endif
|
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
#define cg_chkmagic_swap(cgp, ns) \
|
2008-12-18 04:36:44 +00:00
|
|
|
(ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)
|
2010-11-07 16:05:04 +00:00
|
|
|
#define cg_inosused_swap(cgp, ns) \
|
2008-12-18 05:41:51 +00:00
|
|
|
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_iusedoff, (ns))))
|
2010-11-07 16:05:04 +00:00
|
|
|
#define cg_blksfree_swap(cgp, ns) \
|
2008-12-18 05:41:51 +00:00
|
|
|
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_freeoff, (ns))))
|
2010-11-07 16:05:04 +00:00
|
|
|
#define cg_clustersfree_swap(cgp, ns) \
|
2008-12-18 05:41:51 +00:00
|
|
|
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_clusteroff, (ns))))
|
2010-11-07 16:05:04 +00:00
|
|
|
#define cg_clustersum_swap(cgp, ns) \
|
2008-12-18 00:54:15 +00:00
|
|
|
((int32_t *)((uintptr_t)(cgp) + ufs_rw32((cgp)->cg_clustersumoff, ns)))
|
|
|
|
|
|
|
|
struct fs;
|
2010-11-07 16:05:04 +00:00
|
|
|
void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
|
2008-12-18 00:54:15 +00:00
|
|
|
|
2013-02-20 19:32:31 +00:00
|
|
|
fsinode *link_check(fsinode *);
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
#endif /* _MAKEFS_H */
|