makefs.c (186335) | makefs.c (214921) |
---|---|
1/* $NetBSD: makefs.c,v 1.20 2004/06/20 22:20:18 jmc Exp $ */ | 1/* $NetBSD: makefs.c,v 1.26 2006/10/22 21:11:56 christos Exp $ */ |
2 3/* 4 * Copyright (c) 2001-2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Luke Mewburn for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#include <sys/cdefs.h> | 2 3/* 4 * Copyright (c) 2001-2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Luke Mewburn for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without --- 21 unchanged lines hidden (view full) --- 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/usr.sbin/makefs/makefs.c 186334 2008-12-19 18:45:43Z sam $"); | 39__FBSDID("$FreeBSD: head/usr.sbin/makefs/makefs.c 214921 2010-11-07 16:05:04Z cognet $"); |
40 41#include <assert.h> 42#include <ctype.h> 43#include <errno.h> 44#include <limits.h> 45#include <stdio.h> 46#include <stdlib.h> 47#include <string.h> 48#include <unistd.h> 49 50#include "makefs.h" 51#include "mtree.h" 52 53/* 54 * list of supported file systems and dispatch functions 55 */ 56typedef struct { 57 const char *type; | 40 41#include <assert.h> 42#include <ctype.h> 43#include <errno.h> 44#include <limits.h> 45#include <stdio.h> 46#include <stdlib.h> 47#include <string.h> 48#include <unistd.h> 49 50#include "makefs.h" 51#include "mtree.h" 52 53/* 54 * list of supported file systems and dispatch functions 55 */ 56typedef struct { 57 const char *type; |
58 void (*prepare_options)(fsinfo_t *); |
|
58 int (*parse_options)(const char *, fsinfo_t *); | 59 int (*parse_options)(const char *, fsinfo_t *); |
60 void (*cleanup_options)(fsinfo_t *); |
|
59 void (*make_fs)(const char *, const char *, fsnode *, 60 fsinfo_t *); 61} fstype_t; 62 63static fstype_t fstypes[] = { | 61 void (*make_fs)(const char *, const char *, fsnode *, 62 fsinfo_t *); 63} fstype_t; 64 65static fstype_t fstypes[] = { |
64 { "ffs", ffs_parse_opts, ffs_makefs }, 65 { NULL }, | 66 { "ffs", ffs_prep_opts, ffs_parse_opts, ffs_cleanup_opts, ffs_makefs }, 67 { "cd9660", cd9660_prep_opts, cd9660_parse_opts, cd9660_cleanup_opts, 68 cd9660_makefs}, 69 { .type = NULL }, |
66}; 67 68u_int debug; 69struct timespec start_time; 70 71static fstype_t *get_fstype(const char *); 72static void usage(void); 73int main(int, char *[]); --- 13 unchanged lines hidden (view full) --- 87 debug = 0; 88 if ((fstype = get_fstype(DEFAULT_FSTYPE)) == NULL) 89 errx(1, "Unknown default fs type `%s'.", DEFAULT_FSTYPE); 90 91 /* set default fsoptions */ 92 (void)memset(&fsoptions, 0, sizeof(fsoptions)); 93 fsoptions.fd = -1; 94 fsoptions.sectorsize = -1; | 70}; 71 72u_int debug; 73struct timespec start_time; 74 75static fstype_t *get_fstype(const char *); 76static void usage(void); 77int main(int, char *[]); --- 13 unchanged lines hidden (view full) --- 91 debug = 0; 92 if ((fstype = get_fstype(DEFAULT_FSTYPE)) == NULL) 93 errx(1, "Unknown default fs type `%s'.", DEFAULT_FSTYPE); 94 95 /* set default fsoptions */ 96 (void)memset(&fsoptions, 0, sizeof(fsoptions)); 97 fsoptions.fd = -1; 98 fsoptions.sectorsize = -1; |
95 fsoptions.bsize= -1; 96 fsoptions.fsize= -1; 97 fsoptions.cpg= -1; 98 fsoptions.density= -1; 99 fsoptions.minfree= -1; 100 fsoptions.optimization= -1; 101 fsoptions.maxcontig= -1; 102 fsoptions.maxbpg= -1; 103 fsoptions.avgfilesize= -1; 104 fsoptions.avgfpdir= -1; 105 fsoptions.version = 1; | |
106 | 99 |
100 if (fstype->prepare_options) 101 fstype->prepare_options(&fsoptions); 102 |
|
107 specfile = NULL; 108 if (gettimeofday(&start, NULL) == -1) 109 err(1, "Unable to get system time"); 110 111 start_time.tv_sec = start.tv_sec; 112 start_time.tv_nsec = start.tv_usec * 1000; 113 114 while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:x")) != -1) { --- 28 unchanged lines hidden (view full) --- 143 } else { 144 fsoptions.freeblocks = 145 strsuftoll("free blocks", 146 optarg, 0, LLONG_MAX); 147 } 148 break; 149 150 case 'd': | 103 specfile = NULL; 104 if (gettimeofday(&start, NULL) == -1) 105 err(1, "Unable to get system time"); 106 107 start_time.tv_sec = start.tv_sec; 108 start_time.tv_nsec = start.tv_usec * 1000; 109 110 while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:x")) != -1) { --- 28 unchanged lines hidden (view full) --- 139 } else { 140 fsoptions.freeblocks = 141 strsuftoll("free blocks", 142 optarg, 0, LLONG_MAX); 143 } 144 break; 145 146 case 'd': |
151 debug = 152 (int)strsuftoll("debug mask", optarg, 0, UINT_MAX); | 147 debug = strtoll(optarg, NULL, 0); |
153 break; 154 155 case 'f': 156 len = strlen(optarg) - 1; 157 if (optarg[len] == '%') { 158 optarg[len] = '\0'; 159 fsoptions.freefilepc = 160 strsuftoll("free file percentage", --- 46 unchanged lines hidden (view full) --- 207 208 case 'S': 209 fsoptions.sectorsize = 210 (int)strsuftoll("sector size", optarg, 211 1LL, INT_MAX); 212 break; 213 214 case 't': | 148 break; 149 150 case 'f': 151 len = strlen(optarg) - 1; 152 if (optarg[len] == '%') { 153 optarg[len] = '\0'; 154 fsoptions.freefilepc = 155 strsuftoll("free file percentage", --- 46 unchanged lines hidden (view full) --- 202 203 case 'S': 204 fsoptions.sectorsize = 205 (int)strsuftoll("sector size", optarg, 206 1LL, INT_MAX); 207 break; 208 209 case 't': |
210 /* Check current one and cleanup if necessary. */ 211 if (fstype->cleanup_options) 212 fstype->cleanup_options(&fsoptions); 213 fsoptions.fs_specific = NULL; |
|
215 if ((fstype = get_fstype(optarg)) == NULL) 216 errx(1, "Unknown fs type `%s'.", optarg); | 214 if ((fstype = get_fstype(optarg)) == NULL) 215 errx(1, "Unknown fs type `%s'.", optarg); |
216 fstype->prepare_options(&fsoptions); |
|
217 break; 218 219 case 'x': 220 fsoptions.onlyspec = 1; 221 break; 222 223 case '?': 224 default: --- 20 unchanged lines hidden (view full) --- 245 246 /* walk the tree */ 247 TIMER_START(start); 248 root = walk_dir(argv[1], NULL); 249 TIMER_RESULTS(start, "walk_dir"); 250 251 if (specfile) { /* apply a specfile */ 252 TIMER_START(start); | 217 break; 218 219 case 'x': 220 fsoptions.onlyspec = 1; 221 break; 222 223 case '?': 224 default: --- 20 unchanged lines hidden (view full) --- 245 246 /* walk the tree */ 247 TIMER_START(start); 248 root = walk_dir(argv[1], NULL); 249 TIMER_RESULTS(start, "walk_dir"); 250 251 if (specfile) { /* apply a specfile */ 252 TIMER_START(start); |
253 apply_specfile(specfile, argv[1], root); | 253 apply_specfile(specfile, argv[1], root, fsoptions.onlyspec); |
254 TIMER_RESULTS(start, "apply_specfile"); 255 } 256 257 if (debug & DEBUG_DUMP_FSNODES) { 258 printf("\nparent: %s\n", argv[1]); 259 dump_fsnodes(".", root); 260 putchar('\n'); 261 } 262 263 /* build the file system */ 264 TIMER_START(start); 265 fstype->make_fs(argv[0], argv[1], root, &fsoptions); 266 TIMER_RESULTS(start, "make_fs"); 267 | 254 TIMER_RESULTS(start, "apply_specfile"); 255 } 256 257 if (debug & DEBUG_DUMP_FSNODES) { 258 printf("\nparent: %s\n", argv[1]); 259 dump_fsnodes(".", root); 260 putchar('\n'); 261 } 262 263 /* build the file system */ 264 TIMER_START(start); 265 fstype->make_fs(argv[0], argv[1], root, &fsoptions); 266 TIMER_RESULTS(start, "make_fs"); 267 |
268 free_fsnodes(root); 269 |
|
268 exit(0); 269 /* NOTREACHED */ 270} 271 272 273int 274set_option(option_t *options, const char *var, const char *val) 275{ --- 39 unchanged lines hidden --- | 270 exit(0); 271 /* NOTREACHED */ 272} 273 274 275int 276set_option(option_t *options, const char *var, const char *val) 277{ --- 39 unchanged lines hidden --- |