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 -Z to enable sparse files - for ffs at l...



details:   https://anonhg.NetBSD.org/src/rev/bd1c6d9d133a
branches:  trunk
changeset: 779836:bd1c6d9d133a
user:      sjg <sjg%NetBSD.org@localhost>
date:      Fri Jun 22 06:15:18 2012 +0000

description:
Add -Z to enable sparse files - for ffs at least.
Based on a patch from shesha at juniper.

diffstat:

 usr.sbin/makefs/ffs.c    |  22 +++++++++++++++++-----
 usr.sbin/makefs/makefs.8 |  10 +++++++---
 usr.sbin/makefs/makefs.c |  12 ++++++++----
 usr.sbin/makefs/makefs.h |   3 ++-
 4 files changed, 34 insertions(+), 13 deletions(-)

diffs (155 lines):

diff -r e1ab26346094 -r bd1c6d9d133a usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c     Fri Jun 22 00:12:23 2012 +0000
+++ b/usr.sbin/makefs/ffs.c     Fri Jun 22 06:15:18 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs.c,v 1.47 2012/04/19 17:28:25 christos Exp $        */
+/*     $NetBSD: ffs.c,v 1.48 2012/06/22 06:15:18 sjg 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.47 2012/04/19 17:28:25 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.48 2012/06/22 06:15:18 sjg Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -498,11 +498,22 @@
                bufsize = sfs.f_iosize;
 #endif
        bufrem = fsopts->size;
-       if (debug & DEBUG_FS_CREATE_IMAGE)
+
+       if (fsopts->sparse) {
+               if (ftruncate(fsopts->fd, bufrem) == -1) {
+                       printf ("ERROR in truncate. Sparse option disabled\n");
+                       fsopts->sparse = 0;
+               } else {
+                       bufrem = 0; /* File truncated at bufrem. Remaining is 0 */
+                       buf = NULL;
+               }
+       }
+
+       if ((debug & DEBUG_FS_CREATE_IMAGE) && fsopts->sparse == 0)
                printf(
                    "zero-ing image `%s', %lld sectors, using %d byte chunks\n",
                    image, (long long)bufrem, bufsize);
-       if ((buf = calloc(1, bufsize)) == NULL) {
+       if ((bufrem > 0) && ((buf = calloc(1, bufsize)) == NULL)) {
                warn("Can't create buffer for sector");
                return (-1);
        }
@@ -516,7 +527,8 @@
                }
                bufrem -= i;
        }
-       free(buf);
+       if (buf)
+               free(buf);
 
                /* make the file system */
        if (debug & DEBUG_FS_CREATE_IMAGE)
diff -r e1ab26346094 -r bd1c6d9d133a usr.sbin/makefs/makefs.8
--- a/usr.sbin/makefs/makefs.8  Fri Jun 22 00:12:23 2012 +0000
+++ b/usr.sbin/makefs/makefs.8  Fri Jun 22 06:15:18 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: makefs.8,v 1.40 2012/04/19 16:00:25 wiz Exp $
+.\"    $NetBSD: makefs.8,v 1.41 2012/06/22 06:15:18 sjg 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 April 5, 2012
+.Dd June 12, 2012
 .Dt MAKEFS 8
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Nd create a file system image from a directory tree
 .Sh SYNOPSIS
 .Nm
-.Op Fl x
+.Op Fl xZ
 .Op Fl B Ar endian
 .Op Fl b Ar free-blocks
 .Op Fl d Ar debug-mask
@@ -206,6 +206,10 @@
 .El
 .It Fl x
 Exclude file system nodes not explicitly listed in the specfile.
+.It Fl Z
+Create a sparse file for
+.Sy ffs .
+This is useful for virtual machine images.
 .El
 .Pp
 Where sizes are specified, a decimal number of bytes is expected.
diff -r e1ab26346094 -r bd1c6d9d133a usr.sbin/makefs/makefs.c
--- a/usr.sbin/makefs/makefs.c  Fri Jun 22 00:12:23 2012 +0000
+++ b/usr.sbin/makefs/makefs.c  Fri Jun 22 06:15:18 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makefs.c,v 1.34 2012/04/29 13:32:21 joerg Exp $        */
+/*     $NetBSD: makefs.c,v 1.35 2012/06/22 06:15:18 sjg 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.34 2012/04/29 13:32:21 joerg Exp $");
+__RCSID("$NetBSD: makefs.c,v 1.35 2012/06/22 06:15:18 sjg Exp $");
 #endif /* !__lint */
 
 #include <assert.h>
@@ -117,7 +117,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:s:S:t:x")) != -1) {
+       while ((ch = getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:xZ")) != -1) {
                switch (ch) {
 
                case 'B':
@@ -230,6 +230,10 @@
                        fsoptions.onlyspec = 1;
                        break;
 
+               case 'Z':
+                       fsoptions.sparse = 1;
+                       break;
+
                case '?':
                default:
                        usage();
@@ -329,7 +333,7 @@
 
        prog = getprogname();
        fprintf(stderr,
-"usage: %s [-x] [-B endian] [-b free-blocks] [-d debug-mask]\n"
+"usage: %s [-xZ] [-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 [extra-directory ...]\n",
diff -r e1ab26346094 -r bd1c6d9d133a usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h  Fri Jun 22 00:12:23 2012 +0000
+++ b/usr.sbin/makefs/makefs.h  Fri Jun 22 06:15:18 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makefs.h,v 1.26 2012/04/19 17:09:53 christos Exp $     */
+/*     $NetBSD: makefs.h,v 1.27 2012/06/22 06:15:18 sjg Exp $  */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -136,6 +136,7 @@
        int     freeblockpc;    /* free block % */
        int     needswap;       /* non-zero if byte swapping needed */
        int     sectorsize;     /* sector size */
+       int     sparse;         /* sparse image, don't fill it with zeros */
 
        void    *fs_specific;   /* File system specific additions. */
 } fsinfo_t;



Home | Main Index | Thread Index | Old Index