Source-Changes-HG archive

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

[src/trunk]: src/sbin/resize_ffs if the -p flag is specified, display a progr...



details:   https://anonhg.NetBSD.org/src/rev/be878eaa9df8
branches:  trunk
changeset: 337220:be878eaa9df8
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Apr 06 22:44:04 2015 +0000

description:
if the -p flag is specified, display a progress bar while growing the file-system

diffstat:

 sbin/resize_ffs/Makefile     |   7 +++++--
 sbin/resize_ffs/resize_ffs.8 |   8 +++++---
 sbin/resize_ffs/resize_ffs.c |  39 +++++++++++++++++++++++++++++++++++----
 3 files changed, 45 insertions(+), 9 deletions(-)

diffs (193 lines):

diff -r b77778e8d265 -r be878eaa9df8 sbin/resize_ffs/Makefile
--- a/sbin/resize_ffs/Makefile  Mon Apr 06 22:40:09 2015 +0000
+++ b/sbin/resize_ffs/Makefile  Mon Apr 06 22:44:04 2015 +0000
@@ -1,11 +1,14 @@
-#      $NetBSD: Makefile,v 1.4 2011/08/15 02:19:50 dholland Exp $
+#      $NetBSD: Makefile,v 1.5 2015/04/06 22:44:04 jmcneill Exp $
 
 .include <bsd.own.mk>
 
 PROG=resize_ffs
 MAN=resize_ffs.8
-SRCS=resize_ffs.c ffs_bswap.c
+SRCS=resize_ffs.c ffs_bswap.c progress.c
+
+CPPFLAGS+=-I${NETBSDSRCDIR}/sbin/fsck
 
 .PATH: ${NETBSDSRCDIR}/sys/ufs/ffs
+.PATH: ${NETBSDSRCDIR}/sbin/fsck
 
 .include <bsd.prog.mk>
diff -r b77778e8d265 -r be878eaa9df8 sbin/resize_ffs/resize_ffs.8
--- a/sbin/resize_ffs/resize_ffs.8      Mon Apr 06 22:40:09 2015 +0000
+++ b/sbin/resize_ffs/resize_ffs.8      Mon Apr 06 22:44:04 2015 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: resize_ffs.8,v 1.15 2015/03/29 19:42:15 wiz Exp $
+.\"     $NetBSD: resize_ffs.8,v 1.16 2015/04/06 22:44:04 jmcneill Exp $
 .\"
 .\" As its sole author, I explicitly place this man page in the public
 .\" domain.  Anyone may use it in any way for any purpose (though I would
@@ -9,7 +9,7 @@
 .\"  X  Against HTML               mouse%rodents.montreal.qc.ca@localhost
 .\" / \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
 .\"
-.Dd January 4, 2011
+.Dd April 6, 2015
 .Dt RESIZE_FFS 8
 .Os
 .Sh NAME
@@ -17,7 +17,7 @@
 .Nd resize a file system on disk or in a file
 .Sh SYNOPSIS
 .Nm
-.Op Fl cvy
+.Op Fl cpvy
 .Op Fl s Ar size
 .Ar special
 .Sh DESCRIPTION
@@ -58,6 +58,8 @@
 .It Fl c
 Check to see if the new size would change the file system.
 No changes will be made to the file system.
+.It Fl p
+Display a progress meter during the resize process.
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
diff -r b77778e8d265 -r be878eaa9df8 sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Mon Apr 06 22:40:09 2015 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Mon Apr 06 22:44:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $  */
+/*     $NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $ */
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: resize_ffs.c,v 1.43 2015/04/06 13:33:42 mlelstv Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.44 2015/04/06 22:44:04 jmcneill Exp $");
 
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -59,12 +59,17 @@
 #include <strings.h>
 #include <unistd.h>
 
+#include "progress.h"
+
 /* new size of file system, in sectors */
 static int64_t newsize;
 
 /* fd open onto disk device or file */
 static int fd;
 
+/* disk device or file path */
+char *special;
+
 /* must we break up big I/O operations - see checksmallio() */
 static int smallio;
 
@@ -153,6 +158,7 @@
 int is_ufs2 = 0;
 int needswap = 0;
 int verbose = 0;
+int progress = 0;
 
 static void usage(void) __dead;
 
@@ -1015,6 +1021,8 @@
                                 "cgs");
                for (i = oldsb->fs_ncg; i < newsb->fs_ncg; i++) {
                        cgs[i] = (struct cg *) cgp;
+                       progress_bar(special, "grow cg",
+                           i - oldsb->fs_ncg, newsb->fs_ncg - oldsb->fs_ncg);
                        initcg(i);
                        cgp += cgblksz;
                }
@@ -1043,6 +1051,8 @@
        csum_fixup();
        /* Make fs_dsize match the new reality. */
        recompute_fs_dsize();
+
+       progress_done();
 }
 /*
  * Call (*fn)() for each inode, passing the inode and its inumber.  The
@@ -1990,6 +2000,8 @@
        int i;
 
        for (i = 0; i < newsb->fs_ncg; i++) {
+               progress_bar(special, "flush cg",
+                   i, newsb->fs_ncg - 1);
                if (cgflags[i] & CGF_BLKMAPS) {
                        rescan_blkmaps(i);
                }
@@ -2009,6 +2021,8 @@
        if (needswap)
                ffs_csum_swap(csums,csums,newsb->fs_cssize);
        writeat(FFS_FSBTODB(newsb, newsb->fs_csaddr), csums, newsb->fs_cssize);
+
+       progress_done();
 }
 /*
  * Write the superblock, both to the main superblock and to each cg's
@@ -2038,8 +2052,12 @@
                ffs_sb_swap(newsb,newsb);
        writeat(where /  DEV_BSIZE, newsb, SBLOCKSIZE);
        for (i = 0; i < oldsb->fs_ncg; i++) {
+               progress_bar(special, "write sb",
+                   i, oldsb->fs_ncg - 1);
                writeat(FFS_FSBTODB(oldsb, cgsblock(oldsb, i)), newsb, SBLOCKSIZE);
        }
+
+       progress_done();
 }
 
 /*
@@ -2103,7 +2121,6 @@
        int SFlag;
        size_t i;
 
-       char *special;
        char reply[5];
 
        newsize = 0;
@@ -2111,11 +2128,14 @@
        SFlag = 0;
         CheckOnlyFlag = 0;
 
-       while ((ch = getopt(argc, argv, "cs:vy")) != -1) {
+       while ((ch = getopt(argc, argv, "cps:vy")) != -1) {
                switch (ch) {
                 case 'c':
                        CheckOnlyFlag = 1;
                        break;
+               case 'p':
+                       progress = 1;
+                       break;
                case 's':
                        SFlag = 1;
                        newsize = strtoll(optarg, NULL, 10);
@@ -2218,8 +2238,19 @@
         * thing.  SBLOCKSIZE may be an over-estimate, but we do this
         * just once, so being generous is cheap. */
        memcpy(newsb, oldsb, SBLOCKSIZE);
+
+       if (progress) {
+               progress_ttywidth(0);
+               signal(SIGWINCH, progress_ttywidth);
+       }
+
        loadcgs();
 
+       if (progress && !CheckOnlyFlag) {
+               progress_switch(progress);
+               progress_init();
+       }
+
        if (newsize > FFS_FSBTODB(oldsb, oldsb->fs_size)) {
                if (CheckOnlyFlag)
                        exit(checkonly());



Home | Main Index | Thread Index | Old Index