Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs when zeroing the image, use fstatfs() to find the...



details:   https://anonhg.NetBSD.org/src/rev/b76927607b76
branches:  trunk
changeset: 513693:b76927607b76
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Aug 08 07:34:53 2001 +0000

description:
when zeroing the image, use fstatfs() to find the optimal block size
(falling back to 8KB) instead of 512. should speed things up.

diffstat:

 sbin/newfs/newfs.c |  35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diffs (59 lines):

diff -r 56b86f08f1ec -r b76927607b76 sbin/newfs/newfs.c
--- a/sbin/newfs/newfs.c        Wed Aug 08 00:17:00 2001 +0000
+++ b/sbin/newfs/newfs.c        Wed Aug 08 07:34:53 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newfs.c,v 1.44 2001/07/30 07:45:08 lukem Exp $ */
+/*     $NetBSD: newfs.c,v 1.45 2001/08/08 07:34:53 lukem Exp $ */
 
 /*
  * Copyright (c) 1983, 1989, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)newfs.c    8.13 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: newfs.c,v 1.44 2001/07/30 07:45:08 lukem Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.45 2001/08/08 07:34:53 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -416,20 +416,29 @@
 
                        if (Zflag) {    /* pre-zero the file */
                                char    *buf;
-                               int     i;
+                               int     bufsize, i;
+                               off_t   bufrem;
+                               struct statfs sfs;
 
-                               if ((buf = calloc(1, sectorsize)) == NULL)
+                               if (fstatfs(fso, &sfs) == -1) {
+                                       warn("can't fstatfs `%s'", special);
+                                       bufsize = 8192;
+                               } else
+                                       bufsize = sfs.f_iosize;
+
+                               if ((buf = calloc(1, bufsize)) == NULL)
                                        err(1, "can't malloc buffer of %d",
-                                       sectorsize);
+                                       bufsize);
+                               bufrem = fssize * sectorsize;
                                printf(
-                   "Creating file system image in `%s', size %lld bytes.\n",
-                                   special, (long long)(fssize * sectorsize));
-                               for (i = 0; i < fssize; i++) {
-                                       if (write(fso, buf, sectorsize) !=
-                                           sectorsize)
-                                               err(1,
-                                                   "writing image sector %d",
-                                                   i);
+    "Creating file system image in `%s', size %lld bytes, in %d byte chunks.\n",
+                                   special, (long long)bufrem, bufsize);
+                               while (bufrem > 0) {
+                                       i = write(fso, buf,
+                                           MIN(bufsize, bufrem));
+                                       if (i == -1)
+                                               err(1, "writing image");
+                                       bufrem -= i;
                                }
                        }
 



Home | Main Index | Thread Index | Old Index