standards/167779: makefs does not create sparse file
Shesha Sreenivasamurthy
sheshas at gmail.com
Thu May 10 18:40:14 UTC 2012
>Number: 167779
>Category: standards
>Synopsis: makefs does not create sparse file
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu May 10 18:40:13 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Shesha Sreenivasamurthy
>Release: freebsd 9.0
>Organization:
Juniper Networks
>Environment:
>Description:
When a file system is laid out using makefs, then it zeros out the size of the file specified. This is not essentially needed. We can just create a container, so that the file thus created is sparse. This is particularly helpful we we are creating a disk image for a VM (Virtual Machine). This,
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=Always' etc.
>How-To-Repeat:
Just create a filesystem using makefs by specifying a file size:
makefs -t ffs -s 4G -o version=1 <filename> <dirname>
'du -sh' as well as 'ls -lh' on the file thus created shows 4GB.
>Fix:
Add another option '-p' for sparse and seek to the size instead of filling with zeros.
Patch attached with submission follows:
*** usr/src/usr.sbin/makefs/makefs.c 2012-04-22 22:38:49.000000000 -0700
--- ../9/usr/src/usr.sbin/makefs/makefs.c 2012-01-02 19:25:41.000000000 -0800
***************
*** 112,118 ****
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:xp")) != -1) {
switch (ch) {
case 'B':
--- 112,118 ----
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) {
switch (ch) {
case 'B':
***************
*** 224,232 ****
case 'x':
fsoptions.onlyspec = 1;
break;
! case 'p':
! fsoptions.sparse = 1;
! break;
case '?':
default:
usage();
--- 224,230 ----
case 'x':
fsoptions.onlyspec = 1;
break;
!
case '?':
default:
usage();
***************
*** 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);
--- 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);
*** usr/src/usr.sbin/makefs/makefs.h 2012-04-22 22:49:25.000000000 -0700
--- ../9/usr/src/usr.sbin/makefs/makefs.h 2012-01-02 19:25:41.000000000 -0800
***************
*** 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 */
void *fs_specific; /* File system specific additions. */
} fsinfo_t;
--- 127,132 ----
*** usr/src/usr.sbin/makefs/ffs.c 2012-04-30 16:06:01.715365000 -0700
--- ../9/usr/src/usr.sbin/makefs/ffs.c 2012-01-02 19:25:41.000000000 -0800
***************
*** 493,508 ****
bufsize = sfs.f_iosize;
#endif
bufrem = fsopts->size;
-
- if (fsopts->sparse) {
- if (lseek(fsopts->fd, bufrem - bufsize, SEEK_SET) == -1) {
- printf ("ERROR in lseek. Sparse option disabled\n");
- fsopts->sparse = 0;
- } else {
- bufrem = bufsize; /* Seek to end and write one block */
- }
- }
-
if (debug & DEBUG_FS_CREATE_IMAGE)
printf(
"zero-ing image `%s', %lld sectors, using %d byte chunks\n",
--- 493,498 ----
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list