Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makefs Patch from Jung-uk Kim (jkim at FreeBSD dot ...



details:   https://anonhg.NetBSD.org/src/rev/3147b2e9b4c1
branches:  trunk
changeset: 773107:3147b2e9b4c1
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 28 02:35:46 2012 +0000

description:
Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.

diffstat:

 usr.sbin/makefs/cd9660.c              |   29 ++-----
 usr.sbin/makefs/cd9660.h              |    6 +-
 usr.sbin/makefs/cd9660/cd9660_write.c |    6 +-
 usr.sbin/makefs/ffs.c                 |    8 +-
 usr.sbin/makefs/makefs.8              |   12 ++-
 usr.sbin/makefs/makefs.c              |   26 ++++-
 usr.sbin/makefs/makefs.h              |    8 +-
 usr.sbin/makefs/walk.c                |  131 +++++++++++++++++++++++++--------
 8 files changed, 150 insertions(+), 76 deletions(-)

diffs (truncated from 544 to 300 lines):

diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/cd9660.c
--- a/usr.sbin/makefs/cd9660.c  Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/cd9660.c  Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660.c,v 1.34 2011/08/23 19:57:24 christos Exp $     */
+/*     $NetBSD: cd9660.c,v 1.35 2012/01/28 02:35:46 christos Exp $     */
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -103,7 +103,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660.c,v 1.34 2011/08/23 19:57:24 christos Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.35 2012/01/28 02:35:46 christos Exp $");
 #endif  /* !__lint */
 
 #include <string.h>
@@ -480,8 +480,6 @@
                return;
        }
 
-       diskStructure.rootFilesystemPath = dir;
-
        if (diskStructure.verbose_level > 0)
                printf("cd9660_makefs: image %s directory %s root %p\n",
                    image, dir, root);
@@ -1592,24 +1590,15 @@
 }
 
 void
-cd9660_compute_full_filename(cd9660node *node, char *buf, int level)
+cd9660_compute_full_filename(cd9660node *node, char *buf)
 {
-       cd9660node *parent;
+       int len;
 
-       parent = (node->rr_real_parent == NULL ?
-                 node->parent : node->rr_real_parent);
-       if (parent != NULL) {
-               cd9660_compute_full_filename(parent, buf, level + 1);
-               strcat(buf, node->node->name);
-       } else {
-               /* We are at the root */
-               strcat(buf, diskStructure.rootFilesystemPath);
-               if (buf[strlen(buf) - 1] == '/')
-                       buf[strlen(buf) - 1] = '\0';
-       }
-
-       if (level != 0)
-               strcat(buf, "/");
+       len = CD9660MAXPATH + 1;
+       len = snprintf(buf, len, "%s/%s/%s", node->node->root,
+           node->node->path, node->node->name);
+       if (len > CD9660MAXPATH)
+               errx(1, "Pathname too long.");
 }
 
 /* NEW filename conversion method */
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/cd9660.h
--- a/usr.sbin/makefs/cd9660.h  Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/cd9660.h  Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660.h,v 1.17 2011/06/23 02:35:56 enami Exp $        */
+/*     $NetBSD: cd9660.h,v 1.18 2012/01/28 02:35:46 christos Exp $     */
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -245,8 +245,6 @@
 
        cd9660node *rootNode;
 
-       const char *rootFilesystemPath;
-
        /* Important sector numbers here */
        /* primaryDescriptor.type_l_path_table*/
        int64_t primaryBigEndianTableSector;
@@ -346,7 +344,7 @@
 int    cd9660_write_image(const char *image);
 int    cd9660_copy_file(FILE *, off_t, const char *);
 
-void   cd9660_compute_full_filename(cd9660node *, char *, int);
+void   cd9660_compute_full_filename(cd9660node *, char *);
 int    cd9660_compute_record_size(cd9660node *);
 
 /* Debugging functions */
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/cd9660/cd9660_write.c
--- a/usr.sbin/makefs/cd9660/cd9660_write.c     Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/cd9660/cd9660_write.c     Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660_write.c,v 1.14 2011/01/04 09:48:21 wiz Exp $    */
+/*     $NetBSD: cd9660_write.c,v 1.15 2012/01/28 02:35:46 christos Exp $       */
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_write.c,v 1.14 2011/01/04 09:48:21 wiz Exp $");
+__RCSID("$NetBSD: cd9660_write.c,v 1.15 2012/01/28 02:35:46 christos Exp $");
 #endif  /* !__lint */
 
 static int cd9660_write_volume_descriptors(FILE *);
@@ -297,7 +297,7 @@
                            __func__, (int)inode->st.st_ino, inode->ino));
                        inode->flags |= FI_WRITTEN;
                        cd9660_compute_full_filename(writenode,
-                           temp_file_name, 0);
+                           temp_file_name);
                        ret = cd9660_copy_file(fd, writenode->fileDataSector,
                            temp_file_name);
                        if (ret == 0)
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c     Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/ffs.c     Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs.c,v 1.45 2011/10/09 21:33:43 christos Exp $        */
+/*     $NetBSD: ffs.c,v 1.46 2012/01/28 02:35:46 christos Exp $        */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs.c,v 1.45 2011/10/09 21:33:43 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.46 2012/01/28 02:35:46 christos Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -784,8 +784,8 @@
                        continue;               /* skip hard-linked entries */
                cur->inode->flags |= FI_WRITTEN;
 
-               if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
-                   >= sizeof(path))
+               if ((size_t)snprintf(path, sizeof(path), "%s/%s/%s", cur->root,
+                   cur->path, cur->name) >= sizeof(path))
                        errx(1, "Pathname too long.");
 
                if (cur->child != NULL)
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/makefs.8
--- a/usr.sbin/makefs/makefs.8  Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/makefs.8  Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: makefs.8,v 1.37 2011/10/09 21:33:43 christos Exp $
+.\"    $NetBSD: makefs.8,v 1.38 2012/01/28 02:35:46 christos Exp $
 .\"
 .\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -33,7 +33,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 9, 2011
+.Dd January 27, 2012
 .Dt MAKEFS 8
 .Os
 .Sh NAME
@@ -56,6 +56,7 @@
 .Op Fl t Ar fs-type
 .Ar image-file
 .Ar directory
+.Op Ar extra-directory ...
 .Sh DESCRIPTION
 The utility
 .Nm
@@ -63,6 +64,13 @@
 .Ar image-file
 from the directory tree
 .Ar directory .
+If any optional directory trees are passed in the
+.Ar extra-directory
+arguments, then the directory tree of each argument will be merged
+into the
+.Ar directory
+first before creating
+.Ar image-file .
 No special devices or privileges are required to perform this task.
 .Pp
 The options are as follows:
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/makefs.c
--- a/usr.sbin/makefs/makefs.c  Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/makefs.c  Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makefs.c,v 1.30 2011/08/15 14:45:01 wiz Exp $  */
+/*     $NetBSD: makefs.c,v 1.31 2012/01/28 02:35:46 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.30 2011/08/15 14:45:01 wiz Exp $");
+__RCSID("$NetBSD: makefs.c,v 1.31 2012/01/28 02:35:46 christos Exp $");
 #endif /* !__lint */
 
 #include <assert.h>
@@ -92,7 +92,7 @@
        fstype_t        *fstype;
        fsinfo_t         fsoptions;
        fsnode          *root;
-       int              ch, len;
+       int              ch, i, len;
        char            *specfile;
 
        setprogname(argv[0]);
@@ -245,7 +245,7 @@
        argc -= optind;
        argv += optind;
 
-       if (argc != 2)
+       if (argc < 2)
                usage();
 
        /* -x must be accompanied by -F */
@@ -254,9 +254,21 @@
 
                                /* walk the tree */
        TIMER_START(start);
-       root = walk_dir(argv[1], NULL);
+       root = walk_dir(argv[1], ".", NULL, NULL);
        TIMER_RESULTS(start, "walk_dir");
 
+       /* append extra directory */
+       for (i = 2; i < argc; i++) {
+               struct stat sb;
+               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");
+       }
+
        if (specfile) {         /* apply a specfile */
                TIMER_START(start);
                apply_specfile(specfile, argv[1], root, fsoptions.onlyspec);
@@ -265,7 +277,7 @@
 
        if (debug & DEBUG_DUMP_FSNODES) {
                printf("\nparent: %s\n", argv[1]);
-               dump_fsnodes(".", root);
+               dump_fsnodes(root);
                putchar('\n');
        }
 
@@ -319,7 +331,7 @@
 "usage: %s [-x] [-B endian] [-b free-blocks] [-d debug-mask]\n"
 "\t[-F mtree-specfile] [-f free-files] [-M minimum-size]\n"
 "\t[-m maximum-size] [-N userdb-dir] [-o fs-options] [-S sector-size]\n"
-"\t[-s image-size] [-t fs-type] image-file directory\n",
+"\t[-s image-size] [-t fs-type] image-file directory [extra-directory ...]\n",
            prog);
        exit(1);
 }
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h  Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/makefs.h  Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makefs.h,v 1.23 2011/07/18 22:52:37 tron Exp $ */
+/*     $NetBSD: makefs.h,v 1.24 2012/01/28 02:35:46 christos Exp $     */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -102,6 +102,8 @@
        uint32_t         type;          /* type of entry */
        fsinode         *inode;         /* actual inode data */
        char            *symlink;       /* symlink target */
+       const char      *root;          /* root path */
+       char            *path;          /* directory name */
        char            *name;          /* file name */
        int             flags;          /* misc flags */
 } fsnode;
@@ -154,10 +156,10 @@
 
 
 void           apply_specfile(const char *, const char *, fsnode *, int);
-void           dump_fsnodes(const char *, fsnode *);
+void           dump_fsnodes(fsnode *);
 const char *   inode_type(mode_t);
 int            set_option(option_t *, const char *, const char *);
-fsnode *       walk_dir(const char *, fsnode *);
+fsnode *       walk_dir(const char *, const char *, fsnode *, fsnode *);
 void           free_fsnodes(fsnode *);
 
 void           ffs_prep_opts(fsinfo_t *);
diff -r ec8dd943e0e6 -r 3147b2e9b4c1 usr.sbin/makefs/walk.c
--- a/usr.sbin/makefs/walk.c    Sat Jan 28 02:21:22 2012 +0000
+++ b/usr.sbin/makefs/walk.c    Sat Jan 28 02:35:46 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: walk.c,v 1.24 2008/12/28 21:51:46 christos Exp $       */
+/*     $NetBSD: walk.c,v 1.25 2012/01/28 02:35:46 christos Exp $       */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@



Home | Main Index | Thread Index | Old Index