From owner-freebsd-current@FreeBSD.ORG Tue May 1 00:24:45 2012 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AE2E01065673 for ; Tue, 1 May 2012 00:24:45 +0000 (UTC) (envelope-from shesha@juniper.net) Received: from exprod7og122.obsmtp.com (exprod7og122.obsmtp.com [64.18.2.22]) by mx1.freebsd.org (Postfix) with ESMTP id 5C1CD8FC12 for ; Tue, 1 May 2012 00:24:45 +0000 (UTC) Received: from P-EMHUB01-HQ.jnpr.net ([66.129.224.36]) (using TLSv1) by exprod7ob122.postini.com ([64.18.6.12]) with SMTP ID DSNKT58tRwnuRl8rRTlH+8aKkzeEvL9MdS25@postini.com; Mon, 30 Apr 2012 17:24:45 PDT Received: from EMBX01-HQ.jnpr.net ([fe80::c821:7c81:f21f:8bc7]) by P-EMHUB01-HQ.jnpr.net ([fe80::fc92:eb1:759:2c72%11]) with mapi; Mon, 30 Apr 2012 17:21:58 -0700 From: Shesha Sreenivasamurthy To: "current@FreeBSD.org" Date: Mon, 30 Apr 2012 17:21:59 -0700 Thread-Topic: Sparse option for makefs Thread-Index: Ac0nMGvFbDNWkQjwThio0CM8h8/5Vg== Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.2.1.120420 acceptlanguage: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 01 May 2012 01:54:30 +0000 Cc: Marcel Moolenaar Subject: Sparse option for makefs X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 May 2012 00:24:45 -0000 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; }