2010-11-07 16:05:04 +00:00
|
|
|
/* $NetBSD: makefs.c,v 1.26 2006/10/22 21:11:56 christos Exp $ */
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2017-11-27 15:37:16 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
2008-11-23 19:59:42 +00:00
|
|
|
* Copyright (c) 2001-2003 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2008-12-19 18:45:43 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2011-06-19 18:34:49 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2008-11-23 19:59:42 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-01-24 06:17:05 +00:00
|
|
|
#include <time.h>
|
2008-11-23 19:59:42 +00:00
|
|
|
#include <unistd.h>
|
2017-03-15 13:34:51 +00:00
|
|
|
#include <stdbool.h>
|
2017-04-06 16:18:42 +00:00
|
|
|
#include <util.h>
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
#include "makefs.h"
|
|
|
|
#include "mtree.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list of supported file systems and dispatch functions
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
const char *type;
|
2010-11-07 16:05:04 +00:00
|
|
|
void (*prepare_options)(fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
int (*parse_options)(const char *, fsinfo_t *);
|
2010-11-07 16:05:04 +00:00
|
|
|
void (*cleanup_options)(fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
void (*make_fs)(const char *, const char *, fsnode *,
|
|
|
|
fsinfo_t *);
|
|
|
|
} fstype_t;
|
|
|
|
|
|
|
|
static fstype_t fstypes[] = {
|
2015-12-21 16:12:41 +00:00
|
|
|
#define ENTRY(name) { \
|
|
|
|
# name, name ## _prep_opts, name ## _parse_opts, \
|
|
|
|
name ## _cleanup_opts, name ## _makefs \
|
|
|
|
}
|
|
|
|
ENTRY(ffs),
|
|
|
|
ENTRY(cd9660),
|
2010-11-07 16:05:04 +00:00
|
|
|
{ .type = NULL },
|
2008-11-23 19:59:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
u_int debug;
|
2013-02-20 15:18:42 +00:00
|
|
|
int dupsok;
|
2008-11-23 19:59:42 +00:00
|
|
|
struct timespec start_time;
|
2016-06-14 14:03:28 +00:00
|
|
|
struct stat stampst;
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
static fstype_t *get_fstype(const char *);
|
2016-06-14 14:03:28 +00:00
|
|
|
static int get_tstamp(const char *, struct stat *);
|
2017-03-15 13:34:51 +00:00
|
|
|
static void usage(fstype_t *, fsinfo_t *);
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2011-06-19 18:34:49 +00:00
|
|
|
struct stat sb;
|
2008-11-23 19:59:42 +00:00
|
|
|
struct timeval start;
|
|
|
|
fstype_t *fstype;
|
|
|
|
fsinfo_t fsoptions;
|
|
|
|
fsnode *root;
|
2012-01-31 00:32:37 +00:00
|
|
|
int ch, i, len;
|
2017-05-03 14:57:04 +00:00
|
|
|
const char *subtree;
|
|
|
|
const char *specfile;
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
setprogname(argv[0]);
|
|
|
|
|
|
|
|
debug = 0;
|
|
|
|
if ((fstype = get_fstype(DEFAULT_FSTYPE)) == NULL)
|
|
|
|
errx(1, "Unknown default fs type `%s'.", DEFAULT_FSTYPE);
|
|
|
|
|
|
|
|
/* set default fsoptions */
|
|
|
|
(void)memset(&fsoptions, 0, sizeof(fsoptions));
|
|
|
|
fsoptions.fd = -1;
|
|
|
|
fsoptions.sectorsize = -1;
|
2010-11-07 16:05:04 +00:00
|
|
|
|
|
|
|
if (fstype->prepare_options)
|
|
|
|
fstype->prepare_options(&fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
specfile = NULL;
|
2017-03-14 18:08:32 +00:00
|
|
|
#ifdef CLOCK_REALTIME
|
|
|
|
ch = clock_gettime(CLOCK_REALTIME, &start_time);
|
|
|
|
#else
|
2016-06-14 14:03:28 +00:00
|
|
|
ch = gettimeofday(&start, NULL);
|
2008-11-23 19:59:42 +00:00
|
|
|
start_time.tv_sec = start.tv_sec;
|
|
|
|
start_time.tv_nsec = start.tv_usec * 1000;
|
2017-03-14 18:08:32 +00:00
|
|
|
#endif
|
2016-06-14 14:03:28 +00:00
|
|
|
if (ch == -1)
|
|
|
|
err(1, "Unable to get system time");
|
|
|
|
|
|
|
|
|
2017-05-26 15:49:20 +00:00
|
|
|
while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:O:o:pR:s:S:t:T:xZ")) != -1) {
|
2008-11-23 19:59:42 +00:00
|
|
|
switch (ch) {
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
if (strcmp(optarg, "be") == 0 ||
|
|
|
|
strcmp(optarg, "4321") == 0 ||
|
|
|
|
strcmp(optarg, "big") == 0) {
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
fsoptions.needswap = 1;
|
|
|
|
#endif
|
|
|
|
} else if (strcmp(optarg, "le") == 0 ||
|
|
|
|
strcmp(optarg, "1234") == 0 ||
|
|
|
|
strcmp(optarg, "little") == 0) {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
fsoptions.needswap = 1;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
warnx("Invalid endian `%s'.", optarg);
|
2017-03-15 13:34:51 +00:00
|
|
|
usage(fstype, &fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
len = strlen(optarg) - 1;
|
|
|
|
if (optarg[len] == '%') {
|
|
|
|
optarg[len] = '\0';
|
|
|
|
fsoptions.freeblockpc =
|
|
|
|
strsuftoll("free block percentage",
|
|
|
|
optarg, 0, 99);
|
|
|
|
} else {
|
|
|
|
fsoptions.freeblocks =
|
|
|
|
strsuftoll("free blocks",
|
|
|
|
optarg, 0, LLONG_MAX);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-20 15:18:42 +00:00
|
|
|
case 'D':
|
|
|
|
dupsok = 1;
|
|
|
|
break;
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
case 'd':
|
2010-11-07 16:05:04 +00:00
|
|
|
debug = strtoll(optarg, NULL, 0);
|
2008-11-23 19:59:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
len = strlen(optarg) - 1;
|
|
|
|
if (optarg[len] == '%') {
|
|
|
|
optarg[len] = '\0';
|
|
|
|
fsoptions.freefilepc =
|
|
|
|
strsuftoll("free file percentage",
|
|
|
|
optarg, 0, 99);
|
|
|
|
} else {
|
|
|
|
fsoptions.freefiles =
|
|
|
|
strsuftoll("free files",
|
|
|
|
optarg, 0, LLONG_MAX);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
specfile = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
fsoptions.minsize =
|
|
|
|
strsuftoll("minimum size", optarg, 1LL, LLONG_MAX);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'N':
|
|
|
|
if (! setup_getid(optarg))
|
|
|
|
errx(1,
|
|
|
|
"Unable to use user and group databases in `%s'",
|
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
fsoptions.maxsize =
|
|
|
|
strsuftoll("maximum size", optarg, 1LL, LLONG_MAX);
|
|
|
|
break;
|
2017-05-26 15:49:20 +00:00
|
|
|
|
|
|
|
case 'O':
|
|
|
|
fsoptions.offset =
|
|
|
|
strsuftoll("offset", optarg, 0LL, LLONG_MAX);
|
|
|
|
break;
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
case 'o':
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while ((p = strsep(&optarg, ",")) != NULL) {
|
|
|
|
if (*p == '\0')
|
|
|
|
errx(1, "Empty option");
|
|
|
|
if (! fstype->parse_options(p, &fsoptions))
|
2017-03-15 13:34:51 +00:00
|
|
|
usage(fstype, &fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-08-22 06:37:30 +00:00
|
|
|
case 'p':
|
2013-08-16 05:30:13 +00:00
|
|
|
/* Deprecated in favor of 'Z' */
|
2012-08-22 06:37:30 +00:00
|
|
|
fsoptions.sparse = 1;
|
|
|
|
break;
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2015-10-30 05:55:56 +00:00
|
|
|
case 'R':
|
2015-10-13 02:32:15 +00:00
|
|
|
/* Round image size up to specified block size */
|
|
|
|
fsoptions.roundup =
|
2015-10-30 05:55:56 +00:00
|
|
|
strsuftoll("roundup-size", optarg, 0, LLONG_MAX);
|
2015-10-13 02:32:15 +00:00
|
|
|
break;
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
case 's':
|
|
|
|
fsoptions.minsize = fsoptions.maxsize =
|
|
|
|
strsuftoll("size", optarg, 1LL, LLONG_MAX);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
fsoptions.sectorsize =
|
|
|
|
(int)strsuftoll("sector size", optarg,
|
|
|
|
1LL, INT_MAX);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
2010-11-07 16:05:04 +00:00
|
|
|
/* Check current one and cleanup if necessary. */
|
|
|
|
if (fstype->cleanup_options)
|
|
|
|
fstype->cleanup_options(&fsoptions);
|
|
|
|
fsoptions.fs_specific = NULL;
|
2008-11-23 19:59:42 +00:00
|
|
|
if ((fstype = get_fstype(optarg)) == NULL)
|
|
|
|
errx(1, "Unknown fs type `%s'.", optarg);
|
2010-11-07 16:05:04 +00:00
|
|
|
fstype->prepare_options(&fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
break;
|
|
|
|
|
2016-06-14 14:03:28 +00:00
|
|
|
case 'T':
|
|
|
|
if (get_tstamp(optarg, &stampst) == -1)
|
|
|
|
errx(1, "Cannot get timestamp from `%s'",
|
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
case 'x':
|
|
|
|
fsoptions.onlyspec = 1;
|
|
|
|
break;
|
|
|
|
|
2013-08-16 05:30:13 +00:00
|
|
|
case 'Z':
|
|
|
|
/* Superscedes 'p' for compatibility with NetBSD makefs(8) */
|
|
|
|
fsoptions.sparse = 1;
|
|
|
|
break;
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
2017-03-15 13:34:51 +00:00
|
|
|
usage(fstype, &fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug) {
|
|
|
|
printf("debug mask: 0x%08x\n", debug);
|
|
|
|
printf("start time: %ld.%ld, %s",
|
|
|
|
(long)start_time.tv_sec, (long)start_time.tv_nsec,
|
|
|
|
ctime(&start_time.tv_sec));
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2012-01-31 00:32:37 +00:00
|
|
|
if (argc < 2)
|
2017-03-15 13:34:51 +00:00
|
|
|
usage(fstype, &fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
/* -x must be accompanied by -F */
|
|
|
|
if (fsoptions.onlyspec != 0 && specfile == NULL)
|
|
|
|
errx(1, "-x requires -F mtree-specfile.");
|
|
|
|
|
2011-06-19 18:34:49 +00:00
|
|
|
/* Accept '-' as meaning "read from standard input". */
|
|
|
|
if (strcmp(argv[1], "-") == 0)
|
|
|
|
sb.st_mode = S_IFREG;
|
|
|
|
else {
|
|
|
|
if (stat(argv[1], &sb) == -1)
|
|
|
|
err(1, "Can't stat `%s'", argv[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sb.st_mode & S_IFMT) {
|
|
|
|
case S_IFDIR: /* walk the tree */
|
|
|
|
subtree = argv[1];
|
|
|
|
TIMER_START(start);
|
2012-01-31 00:32:37 +00:00
|
|
|
root = walk_dir(subtree, ".", NULL, NULL);
|
2011-06-19 18:34:49 +00:00
|
|
|
TIMER_RESULTS(start, "walk_dir");
|
|
|
|
break;
|
|
|
|
case S_IFREG: /* read the manifest file */
|
|
|
|
subtree = ".";
|
|
|
|
TIMER_START(start);
|
|
|
|
root = read_mtree(argv[1], NULL);
|
|
|
|
TIMER_RESULTS(start, "manifest");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "%s: not a file or directory", argv[1]);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2008-11-23 19:59:42 +00:00
|
|
|
|
2012-01-31 00:32:37 +00:00
|
|
|
/* append extra directory */
|
|
|
|
for (i = 2; i < argc; i++) {
|
|
|
|
if (stat(argv[i], &sb) == -1)
|
|
|
|
err(1, "Can't stat `%s'", argv[i]);
|
|
|
|
if (!S_ISDIR(sb.st_mode))
|
|
|
|
errx(1, "%s: not a directory", argv[i]);
|
|
|
|
TIMER_START(start);
|
|
|
|
root = walk_dir(argv[i], ".", NULL, root);
|
|
|
|
TIMER_RESULTS(start, "walk_dir2");
|
|
|
|
}
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
if (specfile) { /* apply a specfile */
|
|
|
|
TIMER_START(start);
|
2011-06-19 18:34:49 +00:00
|
|
|
apply_specfile(specfile, subtree, root, fsoptions.onlyspec);
|
2008-11-23 19:59:42 +00:00
|
|
|
TIMER_RESULTS(start, "apply_specfile");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug & DEBUG_DUMP_FSNODES) {
|
2011-06-19 18:34:49 +00:00
|
|
|
printf("\nparent: %s\n", subtree);
|
2012-01-31 00:32:37 +00:00
|
|
|
dump_fsnodes(root);
|
2008-11-23 19:59:42 +00:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build the file system */
|
|
|
|
TIMER_START(start);
|
2011-06-19 18:34:49 +00:00
|
|
|
fstype->make_fs(argv[0], subtree, root, &fsoptions);
|
2008-11-23 19:59:42 +00:00
|
|
|
TIMER_RESULTS(start, "make_fs");
|
|
|
|
|
2010-11-07 16:05:04 +00:00
|
|
|
free_fsnodes(root);
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
exit(0);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2017-03-15 13:34:51 +00:00
|
|
|
int
|
|
|
|
set_option(const option_t *options, const char *option, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
char *var, *val;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
assert(option != NULL);
|
|
|
|
|
2017-04-06 16:18:42 +00:00
|
|
|
var = estrdup(option);
|
2017-03-15 13:34:51 +00:00
|
|
|
for (val = var; *val; val++)
|
|
|
|
if (*val == '=') {
|
|
|
|
*val++ = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
retval = set_option_var(options, var, val, buf, len);
|
|
|
|
free(var);
|
|
|
|
return retval;
|
|
|
|
}
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
int
|
2017-03-15 13:34:51 +00:00
|
|
|
set_option_var(const option_t *options, const char *var, const char *val,
|
|
|
|
char *buf, size_t len)
|
2008-11-23 19:59:42 +00:00
|
|
|
{
|
2017-03-15 13:34:51 +00:00
|
|
|
char *s;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
#define NUM(type) \
|
|
|
|
if (!*val) { \
|
|
|
|
*(type *)options[i].value = 1; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
*(type *)options[i].value = (type)strsuftoll(options[i].desc, val, \
|
|
|
|
options[i].minimum, options[i].maximum); break
|
2008-11-23 19:59:42 +00:00
|
|
|
|
|
|
|
for (i = 0; options[i].name != NULL; i++) {
|
2017-03-15 13:34:51 +00:00
|
|
|
if (var[1] == '\0') {
|
|
|
|
if (options[i].letter != var[0])
|
|
|
|
continue;
|
|
|
|
} else if (strcmp(options[i].name, var) != 0)
|
2008-11-23 19:59:42 +00:00
|
|
|
continue;
|
2017-03-15 13:34:51 +00:00
|
|
|
switch (options[i].type) {
|
|
|
|
case OPT_BOOL:
|
|
|
|
*(bool *)options[i].value = 1;
|
|
|
|
break;
|
|
|
|
case OPT_STRARRAY:
|
|
|
|
strlcpy((void *)options[i].value, val, (size_t)
|
|
|
|
options[i].maximum);
|
|
|
|
break;
|
|
|
|
case OPT_STRPTR:
|
2017-04-06 16:18:42 +00:00
|
|
|
s = estrdup(val);
|
2017-03-15 13:34:51 +00:00
|
|
|
*(char **)options[i].value = s;
|
|
|
|
break;
|
|
|
|
case OPT_STRBUF:
|
|
|
|
if (buf == NULL)
|
|
|
|
abort();
|
|
|
|
strlcpy(buf, val, len);
|
|
|
|
break;
|
|
|
|
case OPT_INT64:
|
|
|
|
NUM(uint64_t);
|
|
|
|
case OPT_INT32:
|
|
|
|
NUM(uint32_t);
|
|
|
|
case OPT_INT16:
|
|
|
|
NUM(uint16_t);
|
|
|
|
case OPT_INT8:
|
|
|
|
NUM(uint8_t);
|
|
|
|
default:
|
|
|
|
warnx("Unknown type %d in option %s", options[i].type,
|
|
|
|
val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return i;
|
2008-11-23 19:59:42 +00:00
|
|
|
}
|
|
|
|
warnx("Unknown option `%s'", var);
|
2017-03-15 13:34:51 +00:00
|
|
|
return -1;
|
2008-11-23 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static fstype_t *
|
|
|
|
get_fstype(const char *type)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; fstypes[i].type != NULL; i++)
|
|
|
|
if (strcmp(fstypes[i].type, type) == 0)
|
|
|
|
return (&fstypes[i]);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2017-03-15 13:34:51 +00:00
|
|
|
option_t *
|
|
|
|
copy_opts(const option_t *o)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; o[i].name; i++)
|
|
|
|
continue;
|
|
|
|
i++;
|
2017-04-06 16:18:42 +00:00
|
|
|
return memcpy(ecalloc(i, sizeof(*o)), o, i * sizeof(*o));
|
2017-03-15 13:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 14:03:28 +00:00
|
|
|
static int
|
|
|
|
get_tstamp(const char *b, struct stat *st)
|
|
|
|
{
|
|
|
|
time_t when;
|
|
|
|
char *eb;
|
|
|
|
long long l;
|
|
|
|
|
|
|
|
if (stat(b, st) != -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
l = strtoll(b, &eb, 0);
|
|
|
|
if (b == eb || *eb || errno)
|
|
|
|
return -1;
|
|
|
|
when = (time_t)l;
|
|
|
|
}
|
|
|
|
|
|
|
|
st->st_ino = 1;
|
|
|
|
#ifdef HAVE_STRUCT_STAT_BIRTHTIME
|
|
|
|
st->st_birthtime =
|
|
|
|
#endif
|
|
|
|
st->st_mtime = st->st_ctime = st->st_atime = when;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-23 19:59:42 +00:00
|
|
|
static void
|
2017-03-15 13:34:51 +00:00
|
|
|
usage(fstype_t *fstype, fsinfo_t *fsoptions)
|
2008-11-23 19:59:42 +00:00
|
|
|
{
|
|
|
|
const char *prog;
|
|
|
|
|
|
|
|
prog = getprogname();
|
|
|
|
fprintf(stderr,
|
2017-03-15 13:34:51 +00:00
|
|
|
"Usage: %s [-xZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
|
2016-07-19 18:15:22 +00:00
|
|
|
"\t[-F mtree-specfile] [-f free-files] [-M minimum-size] [-m maximum-size]\n"
|
2017-05-26 15:49:20 +00:00
|
|
|
"\t[-N userdb-dir] [-O offset] [-o fs-options] [-R roundup-size]\n"
|
|
|
|
"\t[-S sector-size] [-s image-size] [-T <timestamp/file>] [-t fs-type]\n"
|
2016-06-14 14:03:28 +00:00
|
|
|
"\timage-file directory | manifest [extra-directory ...]\n",
|
2008-11-23 19:59:42 +00:00
|
|
|
prog);
|
2017-03-15 13:34:51 +00:00
|
|
|
|
|
|
|
if (fstype) {
|
|
|
|
size_t i;
|
|
|
|
option_t *o = fsoptions->fs_options;
|
|
|
|
|
|
|
|
fprintf(stderr, "\n%s specific options:\n", fstype->type);
|
|
|
|
for (i = 0; o[i].name != NULL; i++)
|
|
|
|
fprintf(stderr, "\t%c%c%20.20s\t%s\n",
|
|
|
|
o[i].letter ? o[i].letter : ' ',
|
|
|
|
o[i].letter ? ',' : ' ',
|
|
|
|
o[i].name, o[i].desc);
|
|
|
|
}
|
2008-11-23 19:59:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|