Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Apr 2012 17:21:59 -0700
From:      Shesha Sreenivasamurthy <shesha@juniper.net>
To:        "current@FreeBSD.org" <current@FreeBSD.org>
Cc:        Marcel Moolenaar <marcelm@juniper.net>
Subject:   Sparse option for makefs
Message-ID:  <CBC47AB7.2D0DD%shesha@juniper.net>

next in thread | raw e-mail | index | archive | help
Hi,
   I have added a sparse option to makefs, where the tool does not fill
the file with zeros, before laying out the data on it. This is handy when
we are creating a VM image because,
	1. It reduces the creation time significantly.
	2. Copying around is less time consuming (Tools like rsync and cp can
deal efficiently with sparse files)
	3. Easily fits the image into a CD without additional processing like 'cp
--sparse=3DAlways' etc.

Please see if this can be made a part of main tree.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
*** ../9/usr/src/usr.sbin/makefs/makefs.c       2012-01-02
19:25:41.000000000 -0800
--- usr/src/usr.sbin/makefs/makefs.c    2012-04-22 22:38:49.000000000 -0700
***************
*** 112,118 ****
        start_time.tv_sec =3D start.tv_sec;
        start_time.tv_nsec =3D start.tv_usec * 1000;
 =20
!       while ((ch =3D getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:x")) !=
=3D
-1) {
                switch (ch) {
 =20
                case 'B':
--- 112,118 ----
        start_time.tv_sec =3D start.tv_sec;
        start_time.tv_nsec =3D start.tv_usec * 1000;
 =20
!       while ((ch =3D getopt(argc, argv, "B:b:d:f:F:M:m:N:o:s:S:t:xp")) !=
=3D
-1) {
                switch (ch) {
 =20
                case 'B':
***************
*** 224,230 ****
                case 'x':
                        fsoptions.onlyspec =3D 1;
                        break;
!=20
                case '?':
                default:
                        usage();
--- 224,232 ----
                case 'x':
                        fsoptions.onlyspec =3D 1;
                        break;
!               case 'p':
!                       fsoptions.sparse =3D 1;
!                       break;
                case '?':
                default:
                        usage();
***************
*** 335,341 ****
        fprintf(stderr,
  "usage: %s [-t fs-type] [-o fs-options] [-d debug-mask] [-B endian]\n"
  "\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-s
image-size]\n"
! "\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-x]\n"
  "\t[-N userdb-dir] image-file directory | manifest\n",
            prog);
        exit(1);
--- 337,343 ----
        fprintf(stderr,
  "usage: %s [-t fs-type] [-o fs-options] [-d debug-mask] [-B endian]\n"
  "\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-s
image-size]\n"
! "\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-x] [-p
sparse]\n"
  "\t[-N userdb-dir] image-file directory | manifest\n",
            prog);
        exit(1);
*** ../9/usr/src/usr.sbin/makefs/makefs.h       2012-01-02
19:25:41.000000000 -0800
--- usr/src/usr.sbin/makefs/makefs.h    2012-04-22 22:49:25.000000000 -0700
***************
*** 127,132 ****
--- 127,133 ----
        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
*/
 =20
        void    *fs_specific;   /* File system specific additions. */
  } fsinfo_t;
*** ../9/usr/src/usr.sbin/makefs/ffs.c  2012-01-02 19:25:41.000000000 -0800
--- usr/src/usr.sbin/makefs/ffs.c       2012-04-30 16:06:01.715365000 -0700
***************
*** 493,498 ****
--- 493,508 ----
                bufsize =3D sfs.f_iosize;
  #endif
        bufrem =3D fsopts->size;
+=20
+       if (fsopts->sparse) {
+               if (lseek(fsopts->fd, bufrem - bufsize, SEEK_SET) =3D=3D -1=
) {
+                       printf ("ERROR in lseek. Sparse option
disabled\n");
+                       fsopts->sparse =3D 0;
+               } else {
+                       bufrem =3D bufsize; /* Seek to end and write one
block */
+               }
+       }
+=20
        if (debug & DEBUG_FS_CREATE_IMAGE)
                printf(
                    "zero-ing image `%s', %lld sectors, using %d byte
chunks\n",



=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


--
Thanks,
Sh=E9sha (uint64_t cache, uint16_t  FOOD)
	{ return 0XCODE; }






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CBC47AB7.2D0DD%shesha>