Wed May 8 15:57:56 2024 UTC (11d)
Add an option to warn and error out for mtree missing entries.


(christos)
diff -r1.71 -r1.72 src/usr.sbin/makefs/makefs.8
diff -r1.57 -r1.58 src/usr.sbin/makefs/makefs.c
diff -r1.39 -r1.40 src/usr.sbin/makefs/walk.c

cvs diff -r1.71 -r1.72 src/usr.sbin/makefs/makefs.8 (expand / switch to unified diff)

--- src/usr.sbin/makefs/makefs.8 2022/11/17 06:40:41 1.71
+++ src/usr.sbin/makefs/makefs.8 2024/05/08 15:57:56 1.72
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: makefs.8,v 1.71 2022/11/17 06:40:41 chs Exp $ 1.\" $NetBSD: makefs.8,v 1.72 2024/05/08 15:57:56 christos Exp $
2.\" 2.\"
3.\" Copyright (c) 2001-2003 Wasabi Systems, Inc. 3.\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" Written by Luke Mewburn for Wasabi Systems, Inc. 6.\" Written by Luke Mewburn for Wasabi Systems, Inc.
7.\" 7.\"
8.\" Redistribution and use in source and binary forms, with or without 8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 9.\" modification, are permitted provided that the following conditions
10.\" are met: 10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright 11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer. 12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23.\" 23.\"
24.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 24.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 27.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
28.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34.\" POSSIBILITY OF SUCH DAMAGE. 34.\" POSSIBILITY OF SUCH DAMAGE.
35.\" 35.\"
36.Dd April 4, 2021 36.Dd May 8, 2024
37.Dt MAKEFS 8 37.Dt MAKEFS 8
38.Os 38.Os
39.Sh NAME 39.Sh NAME
40.Nm makefs 40.Nm makefs
41.Nd create a file system image from a directory tree 41.Nd create a file system image from a directory tree
42.Sh SYNOPSIS 42.Sh SYNOPSIS
43.Nm 43.Nm
44.Op Fl LrxZ 44.Op Fl LrxZ
45.Op Fl B Ar endian 45.Op Fl B Ar endian
46.Op Fl b Ar free-blocks 46.Op Fl b Ar free-blocks
47.Op Fl d Ar debug-mask 47.Op Fl d Ar debug-mask
48.Op Fl F Ar mtree-specfile 48.Op Fl F Ar mtree-specfile
49.Op Fl f Ar free-files 49.Op Fl f Ar free-files
@@ -250,26 +250,30 @@ ISO 9660 file system. @@ -250,26 +250,30 @@ ISO 9660 file system.
250.It Sy chfs 250.It Sy chfs
251Chip flash file system. 251Chip flash file system.
252.It Sy ffs 252.It Sy ffs
253BSD fast file system (default). 253BSD fast file system (default).
254.It Sy msdos 254.It Sy msdos
255FAT12, FAT16, or FAT32 file system. 255FAT12, FAT16, or FAT32 file system.
256.It Sy udf 256.It Sy udf
257ISO/Ecma UDF file system. 257ISO/Ecma UDF file system.
258.It Sy v7fs 258.It Sy v7fs
2597th Edition(V7) file system. 2597th Edition(V7) file system.
260.El 260.El
261.It Fl x 261.It Fl x
262Exclude file system nodes not explicitly listed in the specfile. 262Exclude file system nodes not explicitly listed in the specfile.
 263Repeating this flag causes
 264.Nm
 265to print a warning for each missing system nodes and exit with an error code
 266if there are any missing.
263.It Fl Z 267.It Fl Z
264Create a sparse file for 268Create a sparse file for
265.Sy ffs . 269.Sy ffs .
266This is useful for virtual machine images. 270This is useful for virtual machine images.
267.El 271.El
268.Pp 272.Pp
269Where sizes are specified, a decimal number of bytes is expected. 273Where sizes are specified, a decimal number of bytes is expected.
270Two or more numbers may be separated by an 274Two or more numbers may be separated by an
271.Sq x 275.Sq x
272to indicate a product. 276to indicate a product.
273Each number may have one of the following optional suffixes: 277Each number may have one of the following optional suffixes:
274.Bl -tag -width 3n -offset indent -compact 278.Bl -tag -width 3n -offset indent -compact
275.It b 279.It b

cvs diff -r1.57 -r1.58 src/usr.sbin/makefs/makefs.c (expand / switch to unified diff)

--- src/usr.sbin/makefs/makefs.c 2024/02/18 16:59:16 1.57
+++ src/usr.sbin/makefs/makefs.c 2024/05/08 15:57:56 1.58
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: makefs.c,v 1.57 2024/02/18 16:59:16 christos Exp $ */ 1/* $NetBSD: makefs.c,v 1.58 2024/05/08 15:57:56 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2003 Wasabi Systems, Inc. 4 * Copyright (c) 2001-2003 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Luke Mewburn for Wasabi Systems, Inc. 7 * Written by Luke Mewburn for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -31,27 +31,27 @@ @@ -31,27 +31,27 @@
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#if HAVE_NBTOOL_CONFIG_H 38#if HAVE_NBTOOL_CONFIG_H
39#include "nbtool_config.h" 39#include "nbtool_config.h"
40#endif 40#endif
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43#if defined(__RCSID) && !defined(__lint) 43#if defined(__RCSID) && !defined(__lint)
44__RCSID("$NetBSD: makefs.c,v 1.57 2024/02/18 16:59:16 christos Exp $"); 44__RCSID("$NetBSD: makefs.c,v 1.58 2024/05/08 15:57:56 christos Exp $");
45#endif /* !__lint */ 45#endif /* !__lint */
46 46
47#include <assert.h> 47#include <assert.h>
48#include <ctype.h> 48#include <ctype.h>
49#include <errno.h> 49#include <errno.h>
50#include <limits.h> 50#include <limits.h>
51#include <stdio.h> 51#include <stdio.h>
52#include <stdlib.h> 52#include <stdlib.h>
53#include <string.h> 53#include <string.h>
54#include <unistd.h> 54#include <unistd.h>
55#include <stdbool.h> 55#include <stdbool.h>
56#include <util.h> 56#include <util.h>
57 57
@@ -251,27 +251,27 @@ main(int argc, char *argv[]) @@ -251,27 +251,27 @@ main(int argc, char *argv[])
251 if ((fstype = get_fstype(optarg)) == NULL) 251 if ((fstype = get_fstype(optarg)) == NULL)
252 errx(EXIT_FAILURE, 252 errx(EXIT_FAILURE,
253 "Unknown fs type `%s'.", optarg); 253 "Unknown fs type `%s'.", optarg);
254 fstype->prepare_options(&fsoptions); 254 fstype->prepare_options(&fsoptions);
255 break; 255 break;
256 256
257 case 'T': 257 case 'T':
258 if (get_tstamp(optarg, &stampst) == -1) 258 if (get_tstamp(optarg, &stampst) == -1)
259 errx(EXIT_FAILURE, 259 errx(EXIT_FAILURE,
260 "Cannot get timestamp from `%s'", optarg); 260 "Cannot get timestamp from `%s'", optarg);
261 break; 261 break;
262 262
263 case 'x': 263 case 'x':
264 fsoptions.onlyspec = 1; 264 fsoptions.onlyspec++;
265 break; 265 break;
266 266
267 case 'Z': 267 case 'Z':
268 fsoptions.sparse = 1; 268 fsoptions.sparse = 1;
269 break; 269 break;
270 270
271 case '?': 271 case '?':
272 default: 272 default:
273 usage(fstype, &fsoptions); 273 usage(fstype, &fsoptions);
274 /* NOTREACHED */ 274 /* NOTREACHED */
275 275
276 } 276 }
277 } 277 }

cvs diff -r1.39 -r1.40 src/usr.sbin/makefs/walk.c (expand / switch to unified diff)

--- src/usr.sbin/makefs/walk.c 2024/04/24 21:59:39 1.39
+++ src/usr.sbin/makefs/walk.c 2024/05/08 15:57:56 1.40
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: walk.c,v 1.39 2024/04/24 21:59:39 rillig Exp $ */ 1/* $NetBSD: walk.c,v 1.40 2024/05/08 15:57:56 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Luke Mewburn for Wasabi Systems, Inc. 7 * Written by Luke Mewburn for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -31,50 +31,51 @@ @@ -31,50 +31,51 @@
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#if HAVE_NBTOOL_CONFIG_H 38#if HAVE_NBTOOL_CONFIG_H
39#include "nbtool_config.h" 39#include "nbtool_config.h"
40#endif 40#endif
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43#if defined(__RCSID) && !defined(__lint) 43#if defined(__RCSID) && !defined(__lint)
44__RCSID("$NetBSD: walk.c,v 1.39 2024/04/24 21:59:39 rillig Exp $"); 44__RCSID("$NetBSD: walk.c,v 1.40 2024/05/08 15:57:56 christos Exp $");
45#endif /* !__lint */ 45#endif /* !__lint */
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/stat.h> 48#include <sys/stat.h>
49 49
50#include <assert.h> 50#include <assert.h>
51#include <errno.h> 51#include <errno.h>
52#include <fcntl.h> 52#include <fcntl.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <dirent.h> 54#include <dirent.h>
55#include <stdlib.h> 55#include <stdlib.h>
56#include <string.h> 56#include <string.h>
57#include <unistd.h> 57#include <unistd.h>
58#include <util.h> 58#include <util.h>
59 59
60#include "makefs.h" 60#include "makefs.h"
61#include "mtree.h" 61#include "mtree.h"
62 62
63static void apply_specdir(const char *, NODE *, fsnode *, int); 63static void apply_specdir(const char *, NODE *, fsnode *, int);
64static void apply_specentry(const char *, NODE *, fsnode *); 64static void apply_specentry(const char *, NODE *, fsnode *);
65static fsnode *create_fsnode(const char *, const char *, const char *, 65static fsnode *create_fsnode(const char *, const char *, const char *,
66 struct stat *); 66 struct stat *);
67static fsinode *link_check(fsinode *); 67static fsinode *link_check(fsinode *);
 68static size_t missing = 0;
68 69
69/* 70/*
70 * fsnode_cmp -- 71 * fsnode_cmp --
71 * This function is used by `qsort` so sort one directory's 72 * This function is used by `qsort` so sort one directory's
72 * entries. `.` is always first, sollowed by anything else 73 * entries. `.` is always first, sollowed by anything else
73 * as compared by `strcmp()`. 74 * as compared by `strcmp()`.
74 */ 75 */
75static int 76static int
76fsnode_cmp(const void *vleft, const void *vright) 77fsnode_cmp(const void *vleft, const void *vright)
77{ 78{
78 const fsnode * const *left = vleft; 79 const fsnode * const *left = vleft;
79 const fsnode * const *right = vright; 80 const fsnode * const *right = vright;
80 const char *lname = (*left)->name, *rname = (*right)->name; 81 const char *lname = (*left)->name, *rname = (*right)->name;
@@ -419,26 +420,29 @@ apply_specfile(const char *specfile, con @@ -419,26 +420,29 @@ apply_specfile(const char *specfile, con
419 err(EXIT_FAILURE, "Can't close `%s'", specfile); 420 err(EXIT_FAILURE, "Can't close `%s'", specfile);
420 421
421 /* perform some sanity checks */ 422 /* perform some sanity checks */
422 if (root == NULL) 423 if (root == NULL)
423 errx(EXIT_FAILURE, 424 errx(EXIT_FAILURE,
424 "Specfile `%s' did not contain a tree", specfile); 425 "Specfile `%s' did not contain a tree", specfile);
425 assert(strcmp(root->name, ".") == 0); 426 assert(strcmp(root->name, ".") == 0);
426 assert(root->type == F_DIR); 427 assert(root->type == F_DIR);
427 428
428 /* merge in the changes */ 429 /* merge in the changes */
429 apply_specdir(dir, root, parent, speconly); 430 apply_specdir(dir, root, parent, speconly);
430 431
431 free_nodes(root); 432 free_nodes(root);
 433 if (missing)
 434 errx(EXIT_FAILURE, "Add %zu missing entries in `%s'",
 435 missing, specfile);
432} 436}
433 437
434static void 438static void
435apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly) 439apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly)
436{ 440{
437 char path[MAXPATHLEN + 1]; 441 char path[MAXPATHLEN + 1];
438 NODE *curnode; 442 NODE *curnode;
439 fsnode *curfsnode; 443 fsnode *curfsnode;
440 444
441 assert(specnode != NULL); 445 assert(specnode != NULL);
442 assert(dirnode != NULL); 446 assert(dirnode != NULL);
443 447
444 if (debug & DEBUG_APPLY_SPECFILE) 448 if (debug & DEBUG_APPLY_SPECFILE)
@@ -459,26 +463,31 @@ apply_specdir(const char *dir, NODE *spe @@ -459,26 +463,31 @@ apply_specdir(const char *dir, NODE *spe
459 * to begin with 463 * to begin with
460 */ 464 */
461 if (speconly) { 465 if (speconly) {
462 fsnode *next; 466 fsnode *next;
463 assert(dirnode->name[0] == '.' && dirnode->name[1] == '\0'); 467 assert(dirnode->name[0] == '.' && dirnode->name[1] == '\0');
464 for (curfsnode = dirnode->next; curfsnode != NULL; curfsnode = next) { 468 for (curfsnode = dirnode->next; curfsnode != NULL; curfsnode = next) {
465 next = curfsnode->next; 469 next = curfsnode->next;
466 for (curnode = specnode->child; curnode != NULL; 470 for (curnode = specnode->child; curnode != NULL;
467 curnode = curnode->next) { 471 curnode = curnode->next) {
468 if (strcmp(curnode->name, curfsnode->name) == 0) 472 if (strcmp(curnode->name, curfsnode->name) == 0)
469 break; 473 break;
470 } 474 }
471 if (curnode == NULL) { 475 if (curnode == NULL) {
 476 if (speconly > 1) {
 477 warnx("missing specfile entry for %s/%s",
 478 dir, curfsnode->name);
 479 missing++;
 480 }
472 if (debug & DEBUG_APPLY_SPECONLY) { 481 if (debug & DEBUG_APPLY_SPECONLY) {
473 printf("%s: trimming %s/%s %p\n", 482 printf("%s: trimming %s/%s %p\n",
474 __func__, dir, curfsnode->name, 483 __func__, dir, curfsnode->name,
475 curfsnode); 484 curfsnode);
476 } 485 }
477 free_fsnodes(curfsnode); 486 free_fsnodes(curfsnode);
478 } 487 }
479 } 488 }
480 } 489 }
481 490
482 /* now walk specnode->child matching up with dirnode */ 491 /* now walk specnode->child matching up with dirnode */
483 for (curnode = specnode->child; curnode != NULL; 492 for (curnode = specnode->child; curnode != NULL;
484 curnode = curnode->next) { 493 curnode = curnode->next) {