Module Name:    src
Committed By:   christos
Date:           Sun Feb  3 06:16:53 UTC 2013

Modified Files:
        src/usr.sbin/makefs: makefs.8 makefs.c makefs.h walk.c

Log Message:
add a replace flag so we can overlay exiting files when we merge directories.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.sbin/makefs/makefs.8
cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/makefs/makefs.c
cvs rdiff -u -r1.33 -r1.34 src/usr.sbin/makefs/makefs.h
cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/makefs/walk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/makefs.8
diff -u src/usr.sbin/makefs/makefs.8:1.44 src/usr.sbin/makefs/makefs.8:1.45
--- src/usr.sbin/makefs/makefs.8:1.44	Sat Feb  2 15:42:02 2013
+++ src/usr.sbin/makefs/makefs.8	Sun Feb  3 01:16:53 2013
@@ -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 @@ Set the file system sector size to
 .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 .

Index: src/usr.sbin/makefs/makefs.c
diff -u src/usr.sbin/makefs/makefs.c:1.48 src/usr.sbin/makefs/makefs.c:1.49
--- src/usr.sbin/makefs/makefs.c:1.48	Sat Feb  2 15:42:02 2013
+++ src/usr.sbin/makefs/makefs.c	Sun Feb  3 01:16:53 2013
@@ -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 @@ main(int argc, char *argv[])
 	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 @@ main(int argc, char *argv[])
 			break;
 		}
 
+		case 'r':
+			fsoptions.replace = 1;
+			break;
+
 		case 's':
 			fsoptions.minsize = fsoptions.maxsize =
 			    strsuftoll("size", optarg, 1LL, LLONG_MAX);
@@ -268,7 +272,7 @@ main(int argc, char *argv[])
 
 				/* 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 @@ main(int argc, char *argv[])
 		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 @@ usage(fstype_t *fstype, fsinfo_t *fsopti
 
 	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",

Index: src/usr.sbin/makefs/makefs.h
diff -u src/usr.sbin/makefs/makefs.h:1.33 src/usr.sbin/makefs/makefs.h:1.34
--- src/usr.sbin/makefs/makefs.h:1.33	Sat Feb  2 15:42:02 2013
+++ src/usr.sbin/makefs/makefs.h	Sun Feb  3 01:16:53 2013
@@ -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 @@ typedef struct makefs_fsinfo {
 	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 @@ const char *	inode_type(mode_t);
 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 *);
 

Index: src/usr.sbin/makefs/walk.c
diff -u src/usr.sbin/makefs/walk.c:1.27 src/usr.sbin/makefs/walk.c:1.28
--- src/usr.sbin/makefs/walk.c:1.27	Mon Jan 28 16:03:27 2013
+++ src/usr.sbin/makefs/walk.c	Sun Feb  3 01:16:53 2013
@@ -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 @@ static	fsinode	*link_check(fsinode *);
  *	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 @@ walk_dir(const char *root, const char *d
 						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 @@ walk_dir(const char *root, const char *d
 				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;
 			}
 		}

Reply via email to