Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makefs add a replace flag so we can overlay exiting...
details: https://anonhg.NetBSD.org/src/rev/42023854f559
branches: trunk
changeset: 784600:42023854f559
user: christos <christos%NetBSD.org@localhost>
date: Sun Feb 03 06:16:53 2013 +0000
description:
add a replace flag so we can overlay exiting files when we merge directories.
diffstat:
usr.sbin/makefs/makefs.8 | 6 ++++--
usr.sbin/makefs/makefs.c | 16 ++++++++++------
usr.sbin/makefs/makefs.h | 5 +++--
usr.sbin/makefs/walk.c | 36 ++++++++++++++++++++++++++++--------
4 files changed, 45 insertions(+), 18 deletions(-)
diffs (191 lines):
diff -r 8f3244cfb3e7 -r 42023854f559 usr.sbin/makefs/makefs.8
--- a/usr.sbin/makefs/makefs.8 Sun Feb 03 05:37:43 2013 +0000
+++ b/usr.sbin/makefs/makefs.8 Sun Feb 03 06:16:53 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: makefs.8,v 1.44 2013/02/02 20:42:02 christos Exp $
+.\" $NetBSD: makefs.8,v 1.45 2013/02/03 06:16:53 christos Exp $
.\"
.\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
.\" All rights reserved.
@@ -41,7 +41,7 @@
.Nd create a file system image from a directory tree
.Sh SYNOPSIS
.Nm
-.Op Fl xZ
+.Op Fl rxZ
.Op Fl B Ar endian
.Op Fl b Ar free-blocks
.Op Fl d Ar debug-mask
@@ -194,6 +194,8 @@
.Ar sector-size .
.\" XXX: next line also true for cd9660?
Defaults to 512.
+.It Fl r
+When merging multiple directories replace duplicate files with the last found.
.It Fl s Ar image-size
Set the size of the file system image to
.Ar image-size .
diff -r 8f3244cfb3e7 -r 42023854f559 usr.sbin/makefs/makefs.c
--- a/usr.sbin/makefs/makefs.c Sun Feb 03 05:37:43 2013 +0000
+++ b/usr.sbin/makefs/makefs.c Sun Feb 03 06:16:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.c,v 1.48 2013/02/02 20:42:02 christos Exp $ */
+/* $NetBSD: makefs.c,v 1.49 2013/02/03 06:16:53 christos Exp $ */
/*
* Copyright (c) 2001-2003 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: makefs.c,v 1.48 2013/02/02 20:42:02 christos Exp $");
+__RCSID("$NetBSD: makefs.c,v 1.49 2013/02/03 06:16:53 christos Exp $");
#endif /* !__lint */
#include <assert.h>
@@ -121,7 +121,7 @@
start_time.tv_sec = start.tv_sec;
start_time.tv_nsec = start.tv_usec * 1000;
- while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:O:o:s:S:t:xZ")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:O:o:rs:S:t:xZ")) != -1) {
switch (ch) {
case 'B':
@@ -214,6 +214,10 @@
break;
}
+ case 'r':
+ fsoptions.replace = 1;
+ break;
+
case 's':
fsoptions.minsize = fsoptions.maxsize =
strsuftoll("size", optarg, 1LL, LLONG_MAX);
@@ -268,7 +272,7 @@
/* walk the tree */
TIMER_START(start);
- root = walk_dir(argv[1], ".", NULL, NULL);
+ root = walk_dir(argv[1], ".", NULL, NULL, fsoptions.replace);
TIMER_RESULTS(start, "walk_dir");
/* append extra directory */
@@ -279,7 +283,7 @@
if (!S_ISDIR(sb.st_mode))
errx(1, "%s: not a directory", argv[i]);
TIMER_START(start);
- root = walk_dir(argv[i], ".", NULL, root);
+ root = walk_dir(argv[i], ".", NULL, root, fsoptions.replace);
TIMER_RESULTS(start, "walk_dir2");
}
@@ -411,7 +415,7 @@
prog = getprogname();
fprintf(stderr,
-"Usage: %s [-xZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
+"Usage: %s [-rxZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
"\t[-F mtree-specfile] [-f free-files] [-M minimum-size] [-m maximum-size]\n"
"\t[-N userdb-dir] [-O offset] [-o fs-options] [-S sector-size]\n"
"\t[-s image-size] [-t fs-type] image-file directory [extra-directory ...]\n",
diff -r 8f3244cfb3e7 -r 42023854f559 usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h Sun Feb 03 05:37:43 2013 +0000
+++ b/usr.sbin/makefs/makefs.h Sun Feb 03 06:16:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.h,v 1.33 2013/02/02 20:42:02 christos Exp $ */
+/* $NetBSD: makefs.h,v 1.34 2013/02/03 06:16:53 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -164,6 +164,7 @@
int needswap; /* non-zero if byte swapping needed */
int sectorsize; /* sector size */
int sparse; /* sparse image, don't fill it with zeros */
+ int replace; /* replace files when merging */
void *fs_specific; /* File system specific additions. */
option_t *fs_options; /* File system specific options */
@@ -178,7 +179,7 @@
int set_option(const option_t *, const char *, char *, size_t);
int set_option_var(const option_t *, const char *, const char *,
char *, size_t);
-fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
+fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *, int);
void free_fsnodes(fsnode *);
option_t * copy_opts(const option_t *);
diff -r 8f3244cfb3e7 -r 42023854f559 usr.sbin/makefs/walk.c
--- a/usr.sbin/makefs/walk.c Sun Feb 03 05:37:43 2013 +0000
+++ b/usr.sbin/makefs/walk.c Sun Feb 03 06:16:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: walk.c,v 1.27 2013/01/28 21:03:27 christos Exp $ */
+/* $NetBSD: walk.c,v 1.28 2013/02/03 06:16:53 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: walk.c,v 1.27 2013/01/28 21:03:27 christos Exp $");
+__RCSID("$NetBSD: walk.c,v 1.28 2013/02/03 06:16:53 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -76,7 +76,8 @@
* at the start of the list, and without ".." entries.
*/
fsnode *
-walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join)
+walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join,
+ int replace)
{
fsnode *first, *cur, *prev, *last;
DIR *dirp;
@@ -154,12 +155,30 @@
printf("merging %s with %p\n",
path, cur->child);
cur->child = walk_dir(root, rp, cur,
- cur->child);
+ cur->child, replace);
continue;
}
- errx(1, "Can't merge %s `%s' with existing %s",
- inode_type(stbuf.st_mode), path,
- inode_type(cur->type));
+ if (!replace)
+ errx(1, "Can't merge %s `%s' with "
+ "existing %s",
+ inode_type(stbuf.st_mode), path,
+ inode_type(cur->type));
+ else {
+ if (debug & DEBUG_WALK_DIR_NODE)
+ printf("replacing %s %s\n",
+ inode_type(stbuf.st_mode),
+ path);
+ if (cur == join->next)
+ join->next = cur->next;
+ else {
+ fsnode *p;
+ for (p = join->next;
+ p->next != cur; p = p->next)
+ continue;
+ p->next = cur->next;
+ }
+ free(cur);
+ }
}
}
@@ -180,7 +199,8 @@
first = cur;
cur->first = first;
if (S_ISDIR(cur->type)) {
- cur->child = walk_dir(root, rp, cur, NULL);
+ cur->child = walk_dir(root, rp, cur, NULL,
+ replace);
continue;
}
}
Home |
Main Index |
Thread Index |
Old Index