Source-Changes-HG archive

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

[src/trunk]: src/sbin/resize_ffs - Add -c to check to see if grow/shrink is r...



details:   https://anonhg.NetBSD.org/src/rev/4dd93e04c2e0
branches:  trunk
changeset: 807135:4dd93e04c2e0
user:      chopps <chopps%NetBSD.org@localhost>
date:      Sun Mar 29 19:33:55 2015 +0000

description:
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage

diffstat:

 sbin/resize_ffs/resize_ffs.8 |   9 +++++++--
 sbin/resize_ffs/resize_ffs.c |  40 ++++++++++++++++++++++++++++++++++------
 2 files changed, 41 insertions(+), 8 deletions(-)

diffs (149 lines):

diff -r 61885c0a002b -r 4dd93e04c2e0 sbin/resize_ffs/resize_ffs.8
--- a/sbin/resize_ffs/resize_ffs.8      Sun Mar 29 17:38:31 2015 +0000
+++ b/sbin/resize_ffs/resize_ffs.8      Sun Mar 29 19:33:55 2015 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: resize_ffs.8,v 1.13 2011/08/28 21:25:11 wiz Exp $
+.\"     $NetBSD: resize_ffs.8,v 1.14 2015/03/29 19:33:55 chopps 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
@@ -17,7 +17,7 @@
 .Nd resize a file system on disk or in a file
 .Sh SYNOPSIS
 .Nm
-.Op Fl y
+.Op Fl cvy
 .Op Fl s Ar size
 .Ar special
 .Sh DESCRIPTION
@@ -55,6 +55,9 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.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 s
 Specify the file system size to which the file system should be
 resized.
@@ -66,6 +69,8 @@
 .It Fl y
 Disable sanity questions made by
 .Nm .
+.It Fl v
+Be more verbose.
 .El
 .Sh WARNING
 .Em Interrupting
diff -r 61885c0a002b -r 4dd93e04c2e0 sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Sun Mar 29 17:38:31 2015 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Sun Mar 29 19:33:55 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.40 2015/03/28 17:25:33 riastradh Exp $        */
+/*     $NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps 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.40 2015/03/28 17:25:33 riastradh Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.41 2015/03/29 19:33:55 chopps Exp $");
 
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -152,6 +152,7 @@
 /* global flags */
 int is_ufs2 = 0;
 int needswap = 0;
+int verbose = 0;
 
 static void usage(void) __dead;
 
@@ -2040,7 +2041,7 @@
                return pp->p_size;
        }
        if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode))
-               return st.st_size;
+               return st.st_size / DEV_BSIZE;
 
        return 0;
 }
@@ -2052,6 +2053,7 @@
 main(int argc, char **argv)
 {
        int ch;
+       int CheckOnlyFlag;
        int ExpertFlag;
        int SFlag;
        size_t i;
@@ -2062,9 +2064,13 @@
        newsize = 0;
        ExpertFlag = 0;
        SFlag = 0;
+        CheckOnlyFlag = 0;
 
-       while ((ch = getopt(argc, argv, "s:y")) != -1) {
+       while ((ch = getopt(argc, argv, "cs:vy")) != -1) {
                switch (ch) {
+                case 'c':
+                       CheckOnlyFlag = 1;
+                       break;
                case 's':
                        SFlag = 1;
                        newsize = strtoll(optarg, NULL, 10);
@@ -2072,6 +2078,9 @@
                                usage();
                        }
                        break;
+               case 'v':
+                       verbose = 1;
+                       break;
                case 'y':
                        ExpertFlag = 1;
                        break;
@@ -2090,7 +2099,7 @@
 
        special = *argv;
 
-       if (ExpertFlag == 0) {
+       if (ExpertFlag == 0 && CheckOnlyFlag == 0) {
                printf("It's required to manually run fsck on file system "
                    "before you can resize it\n\n"
                    " Did you run fsck on your disk (Yes/No) ? ");
@@ -2165,6 +2174,25 @@
         * just once, so being generous is cheap. */
        memcpy(newsb, oldsb, SBLOCKSIZE);
        loadcgs();
+
+        if (CheckOnlyFlag) {
+               /* Check to see if the newsize would change the file system. */
+               if (FFS_DBTOFSB(oldsb, newsize) == oldsb->fs_size) {
+                       if (verbose) {
+                               printf("Wouldn't change: already %" PRId64
+                                   " blocks\n", newsize);
+                       }
+                       exit(1);
+               }
+               if (verbose) {
+                       printf("Would change: newsize: %" PRId64 " oldsize: %"
+                           PRId64 " fsdb: %" PRId64 "\n", FFS_DBTOFSB(oldsb, newsize),
+                           (int64_t)oldsb->fs_size,
+                           (int64_t)oldsb->fs_fsbtodb);
+               }
+               exit(0);
+        }
+
        if (newsize > FFS_FSBTODB(oldsb, oldsb->fs_size)) {
                grow();
        } else if (newsize < FFS_FSBTODB(oldsb, oldsb->fs_size)) {
@@ -2183,7 +2211,7 @@
 usage(void)
 {
 
-       (void)fprintf(stderr, "usage: %s [-y] [-s size] special\n",
+       (void)fprintf(stderr, "usage: %s [-cvy] [-s size] special\n",
            getprogname());
        exit(EXIT_FAILURE);
 }



Home | Main Index | Thread Index | Old Index