Source-Changes-HG archive

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

[src/trunk]: src/sbin/resize_ffs PR/45301: Julian Fagir: make clear that the ...



details:   https://anonhg.NetBSD.org/src/rev/766e537dca55
branches:  trunk
changeset: 768792:766e537dca55
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 27 16:34:57 2011 +0000

description:
PR/45301: Julian Fagir: make clear that the unit is sectors and fix a typo.
While there, use errx, and sizeof(*var) instead of sizeof(type)

diffstat:

 sbin/resize_ffs/resize_ffs.8 |   7 ++--
 sbin/resize_ffs/resize_ffs.c |  60 +++++++++++++++++--------------------------
 2 files changed, 28 insertions(+), 39 deletions(-)

diffs (195 lines):

diff -r f4a441184ec9 -r 766e537dca55 sbin/resize_ffs/resize_ffs.8
--- a/sbin/resize_ffs/resize_ffs.8      Sat Aug 27 16:34:38 2011 +0000
+++ b/sbin/resize_ffs/resize_ffs.8      Sat Aug 27 16:34:57 2011 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: resize_ffs.8,v 1.10 2011/01/05 02:18:15 riz Exp $
+.\"     $NetBSD: resize_ffs.8,v 1.11 2011/08/27 16:34:57 christos 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
@@ -24,8 +24,7 @@
 .Nm
 resizes a file system.
 .Ar special
-is the name of the raw disk device or file where the file system resides;
-(Sectors are almost always 512 bytes, and
+is the name of the raw disk device or file where the file system resides.
 .Nm
 can both grow and shrink file systems.
 When growing, the disk device
@@ -60,6 +59,8 @@
 .It Fl s
 Specify the file system size to which the file system should be
 resized.
+The size is given as the count of disk sectors, usually 512 bytes. To see the 
+exact value, have a look at the disk specification or the disklabel.
 Mostly used to shrink file systems.
 .It Fl y
 Disable sanity questions made by
diff -r f4a441184ec9 -r 766e537dca55 sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Sat Aug 27 16:34:38 2011 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Sat Aug 27 16:34:57 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.31 2011/08/15 02:22:46 dholland Exp $ */
+/*     $NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos 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.31 2011/08/15 02:22:46 dholland Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.32 2011/08/27 16:34:57 christos Exp $");
 
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -322,7 +322,7 @@
        char *cgp;
 
        cgblksz = roundup(oldsb->fs_cgsize, oldsb->fs_fsize);
-       cgs = nfmalloc(oldsb->fs_ncg * sizeof(struct cg *), "cg pointers");
+       cgs = nfmalloc(oldsb->fs_ncg * sizeof(*cgs), "cg pointers");
        cgp = alloconce(oldsb->fs_ncg * cgblksz, "cgs");
        cgflags = nfmalloc(oldsb->fs_ncg, "cg flags");
        csums = nfmalloc(oldsb->fs_cssize, "cg summary");
@@ -611,7 +611,7 @@
        if (is_ufs2 == 0)
                /* Write out the cleared inodes. */
                writeat(fsbtodb(newsb, cgimin(newsb, cgn)), zinodes,
-                   newsb->fs_ipg * sizeof(struct ufs1_dinode));
+                   newsb->fs_ipg * sizeof(*zinodes));
        /* Dirty the cg. */
        cgflags[cgn] |= CGF_DIRTY;
 }
@@ -862,10 +862,8 @@
         * on disk at this point; the csum info will be written to the
         * then-current fs_csaddr as part of the final flush. */
        newloc = find_freespace(ntot);
-       if (newloc < 0) {
-               printf("Sorry, no space available for new csums\n");
-               exit(EXIT_FAILURE);
-       }
+       if (newloc < 0)
+               errx(EXIT_FAILURE, "Sorry, no space available for new csums");
        for (i = 0, f = newsb->fs_csaddr, t = newloc; i < ntot; i++, f++, t++) {
                if (i < nold) {
                        free_frag(f);
@@ -926,16 +924,15 @@
        /* Update the timestamp. */
        newsb->fs_time = timestamp();
        /* Allocate and clear the new-inode area, in case we add any cgs. */
-       zinodes = alloconce(newsb->fs_ipg * sizeof(struct ufs1_dinode),
-                            "zeroed inodes");
-       memset(zinodes, 0, newsb->fs_ipg * sizeof(struct ufs1_dinode));
+       zinodes = alloconce(newsb->fs_ipg * sizeof(*zinodes), "zeroed inodes");
+       memset(zinodes, 0, newsb->fs_ipg * sizeof(*zinodes));
        /* Update the size. */
        newsb->fs_size = dbtofsb(newsb, newsize);
        /* Did we actually not grow?  (This can happen if newsize is less than
         * a frag larger than the old size - unlikely, but no excuse to
         * misbehave if it happens.) */
        if (newsb->fs_size == oldsb->fs_size) {
-               printf("New fs size %"PRIu64" = odl fs size %"PRIu64
+               printf("New fs size %"PRIu64" = old fs size %"PRIu64
                    ", not growing.\n", newsb->fs_size, oldsb->fs_size);
                return;
        }
@@ -977,7 +974,7 @@
           cgs. */
        if (newsb->fs_ncg > oldsb->fs_ncg) {
                char *cgp;
-               cgs = nfrealloc(cgs, newsb->fs_ncg * sizeof(struct cg *),
+               cgs = nfrealloc(cgs, newsb->fs_ncg * sizeof(*cgs),
                                 "cg pointers");
                cgflags = nfrealloc(cgflags, newsb->fs_ncg, "cg flags");
                memset(cgflags + oldsb->fs_ncg, 0,
@@ -1228,7 +1225,7 @@
                                                    bswap32(dp2[i].di_db[j]);
                                }
                                memcpy(&inodes[ino].dp2, &dp2[i],
-                                   sizeof(struct ufs2_dinode));
+                                   sizeof(inodes[ino].dp2));
                        } else {
                                if (needswap) {
                                        ffs_dinode1_swap(&(dp1[i]), &(dp1[i]));
@@ -1237,7 +1234,7 @@
                                                    bswap32(dp1[i].di_db[j]);
                                }
                                memcpy(&inodes[ino].dp1, &dp1[i],
-                                   sizeof(struct ufs1_dinode));
+                                   sizeof(inodes[ino].dp1));
                        }
                            if (++ino > imax)
                                    errx(EXIT_FAILURE,
@@ -1249,11 +1246,10 @@
 /*
  * Report a file-system-too-full problem.
  */
-static void
+__dead static void
 toofull(void)
 {
-       printf("Sorry, would run out of data blocks\n");
-       exit(EXIT_FAILURE);
+       errx(EXIT_FAILURE, "Sorry, would run out of data blocks");
 }
 /*
  * Record a desire to move "n" frags from "from" to "to".
@@ -1584,11 +1580,9 @@
        for (i = 0; i < newsb->fs_ipg; i++, inum++) {
                if (DIP(inodes + inum,di_mode) != 0) {
                        fi = find_freeinode();
-                       if (fi < 0) {
-                               printf("Sorry, inodes evaporated - "
-                                   "file system probably needs fsck\n");
-                               exit(EXIT_FAILURE);
-                       }
+                       if (fi < 0)
+                               errx(EXIT_FAILURE, "Sorry, inodes evaporated - "
+                                   "file system probably needs fsck");
                        inomove[inum] = fi;
                        clr_bits(cg_inosused(cg, 0), i, 1);
                        set_bits(cg_inosused(cgs[ino_to_cg(newsb, fi)], 0),
@@ -1720,11 +1714,9 @@
                    (unsigned long int) fsbtodb(newsb, newsb->fs_size));
        }
        /* Let's make sure we're not being shrunk into oblivion. */
-       if (newsb->fs_ncg < 1) {
-               printf("Size too small - file system would "
-                   "have no cylinders\n");
-               exit(EXIT_FAILURE);
-       }
+       if (newsb->fs_ncg < 1)
+               errx(EXIT_FAILURE, "Size too small - file system would "
+                   "have no cylinders");
        /* Initialize for block motion. */
        blkmove_init();
        /* Update csum size, then fix up for the new size */
@@ -1778,10 +1770,8 @@
                        slop += cgs[i]->cg_cs.cs_nifree;
                for (; i < oldsb->fs_ncg; i++)
                        slop -= oldsb->fs_ipg - cgs[i]->cg_cs.cs_nifree;
-               if (slop < 0) {
-                       printf("Sorry, would run out of inodes\n");
-                       exit(EXIT_FAILURE);
-               }
+               if (slop < 0)
+                       errx(EXIT_FAILURE, "Sorry, would run out of inodes");
        }
        /* Copy data, then update pointers to data.  See the comment
         * header on perform_data_move for ordering considerations. */
@@ -2165,11 +2155,9 @@
 
        oldsb->fs_qbmask = ~(int64_t) oldsb->fs_bmask;
        oldsb->fs_qfmask = ~(int64_t) oldsb->fs_fmask;
-       if (oldsb->fs_ipg % INOPB(oldsb)) {
-               (void)fprintf(stderr, "ipg[%d] %% INOPB[%d] != 0\n",
+       if (oldsb->fs_ipg % INOPB(oldsb))
+               errx(EXIT_FAILURE, "ipg[%d] %% INOPB[%d] != 0",
                    (int) oldsb->fs_ipg, (int) INOPB(oldsb));
-               exit(EXIT_FAILURE);
-       }
        /* The superblock is bigger than struct fs (there are trailing
         * tables, of non-fixed size); make sure we copy the whole
         * thing.  SBLOCKSIZE may be an over-estimate, but we do this



Home | Main Index | Thread Index | Old Index