Source-Changes-HG archive

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

[src/trunk]: src/sbin/resize_ffs make this compile again.



details:   https://anonhg.NetBSD.org/src/rev/6f20ec92bc57
branches:  trunk
changeset: 545143:6f20ec92bc57
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Apr 03 14:55:16 2003 +0000

description:
make this compile again.

diffstat:

 sbin/resize_ffs/resize_ffs.c |  269 ++++++++++++++++++++----------------------
 1 files changed, 129 insertions(+), 140 deletions(-)

diffs (truncated from 584 to 300 lines):

diff -r d1b3d53fb04f -r 6f20ec92bc57 sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Thu Apr 03 14:53:38 2003 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Thu Apr 03 14:55:16 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.3 2003/03/10 09:23:50 wiz Exp $       */
+/*     $NetBSD: resize_ffs.c,v 1.4 2003/04/03 14:55:16 christos Exp $  */
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -46,6 +46,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <strings.h>
+#include <err.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <sys/param.h>         /* MAXFRAG */
@@ -54,22 +55,6 @@
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/ufs_bswap.h> /* ufs_rw32 */
 
-extern const char *__progname;
-
-/* Patchup for systems that don't yet have __progname */
-#ifdef NO_PROGNAME
-const char *__progname;
-int main(int, char **);
-int main_(int, char **);
-int
-main(int ac, char **av)
-#define main main_
-{
-       __progname = av[0];
-       return (main(ac, av));
-}
-#endif
-
 /* Suppress warnings about unused arguments */
 #if    defined(__GNUC__) &&                            \
        ( (__GNUC__ > 2) ||                             \
@@ -95,14 +80,19 @@
 /* size of a cg, in bytes, rounded up to a frag boundary */
 static int cgblksz;
 
+/* possible superblock localtions */
+static int search[] = SBLOCKSEARCH;
+/* location of the superblock */
+static off_t where;
+
 /* Superblocks. */
 static struct fs *oldsb;       /* before we started */
 static struct fs *newsb;       /* copy to work with */
 /* Buffer to hold the above.  Make sure it's aligned correctly. */
-static char sbbuf[2 * SBSIZE] __attribute__((__aligned__(__alignof__(struct fs))));
+static char sbbuf[2 * SBLOCKSIZE] __attribute__((__aligned__(__alignof__(struct fs))));
 
 /* a cg's worth of brand new squeaky-clean inodes */
-static struct dinode *zinodes;
+static struct ufs1_dinode *zinodes;
 
 /* pointers to the in-core cgs, read off disk and possibly modified */
 static struct cg **cgs;
@@ -124,7 +114,7 @@
 static unsigned int *inomove;
 
 /* in-core copies of all inodes in the fs, indexed by inumber */
-static struct dinode *inodes;
+static struct ufs1_dinode *inodes;
 
 /* per-inode flags, indexed by inumber */
 static unsigned char *iflags;
@@ -133,6 +123,38 @@
                                 * block of inodes, and applies to the whole
                                 * block. */
 
+/* Old FFS1 macros */
+#define cg_blktot(cgp, ns) \
+    (cg_chkmagic(cgp, ns) ? \
+    ((int32_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_old_btotoff, (ns)))) \
+    : (((struct ocg *)(cgp))->cg_btot))
+#define cg_blks(fs, cgp, cylno, ns) \
+    (cg_chkmagic(cgp, ns) ? \
+    ((int16_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_old_boff, (ns))) + \
+       (cylno) * (fs)->fs_old_nrpos) \
+    : (((struct ocg *)(cgp))->cg_b[cylno]))
+#define cbtocylno(fs, bno) \
+   (fsbtodb(fs, bno) / (fs)->fs_old_spc) 
+#define cbtorpos(fs, bno) \
+    ((fs)->fs_old_nrpos <= 1 ? 0 : \
+     (fsbtodb(fs, bno) % (fs)->fs_old_spc / \
+      (fs)->fs_old_nsect * (fs)->fs_old_trackskew + \
+      fsbtodb(fs, bno) % (fs)->fs_old_spc % \
+      (fs)->fs_old_nsect * (fs)->fs_old_interleave) %\
+    (fs)->fs_old_nsect * (fs)->fs_old_nrpos / (fs)->fs_old_npsect)
+#define dblksize(fs, dip, lbn) \
+    (((lbn) >= NDADDR || (dip)->di_size >= lblktosize(fs, (lbn) + 1)) \
+    ? (fs)->fs_bsize \
+    : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
+
+
+/*
+ * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte
+ * sector size. 
+ */ 
+#define NSPB(fs)       ((fs)->fs_old_nspf << (fs)->fs_fragshift)
+#define NSPF(fs)       ((fs)->fs_old_nspf)
+
 /*
  * See if we need to break up large I/O operations.  This should never
  *  be needed, but under at least one <version,platform> combination,
@@ -157,11 +179,9 @@
 readat(off_t blkno, void *buf, int size)
 {
        /* Seek to the correct place. */
-       if (lseek(fd, blkno * DEV_BSIZE, L_SET) < 0) {
-               fprintf(stderr, "%s: lseek: %s\n", __progname,
-                   strerror(errno));
-               exit(1);
-       }
+       if (lseek(fd, blkno * DEV_BSIZE, L_SET) < 0)
+               err(1, "lseek failed");
+
        /* See if we have to break up the transfer... */
        if (smallio) {
                char *bp;       /* pointer into buf */
@@ -173,33 +193,20 @@
                while (left > 0) {
                        n = (left > 8192) ? 8192 : left;
                        rv = read(fd, bp, n);
-                       if (rv < 0) {
-                               fprintf(stderr, "%s: read: %s\n", __progname,
-                                   strerror(errno));
-                               exit(1);
-                       }
-                       if (rv != n) {
-                               fprintf(stderr,
-                                   "%s: read: wanted %d, got %d\n",
-                                   __progname, n, rv);
-                               exit(1);
-                       }
+                       if (rv < 0)
+                               err(1, "read failed");
+                       if (rv != n)
+                               errx(1, "read: wanted %d, got %d", n, rv);
                        bp += n;
                        left -= n;
                }
        } else {
                int rv;
                rv = read(fd, buf, size);
-               if (rv < 0) {
-                       fprintf(stderr, "%s: read: %s\n", __progname,
-                           strerror(errno));
-                       exit(1);
-               }
-               if (rv != size) {
-                       fprintf(stderr, "%s: read: wanted %d, got %d\n",
-                           __progname, size, rv);
-                       exit(1);
-               }
+               if (rv < 0)
+                       err(1, "read failed");
+               if (rv != size)
+                       errx(1, "read: wanted %d, got %d", size, rv);
        }
 }
 /*
@@ -210,11 +217,8 @@
 writeat(off_t blkno, const void *buf, int size)
 {
        /* Seek to the correct place. */
-       if (lseek(fd, blkno * DEV_BSIZE, L_SET) < 0) {
-               fprintf(stderr, "%s: lseek: %s\n", __progname,
-                   strerror(errno));
-               exit(1);
-       }
+       if (lseek(fd, blkno * DEV_BSIZE, L_SET) < 0)
+               err(1, "lseek failed");
        /* See if we have to break up the transfer... */
        if (smallio) {
                const char *bp; /* pointer into buf */
@@ -226,33 +230,20 @@
                while (left > 0) {
                        n = (left > 8192) ? 8192 : left;
                        rv = write(fd, bp, n);
-                       if (rv < 0) {
-                               fprintf(stderr, "%s: write: %s\n", __progname,
-                                   strerror(errno));
-                               exit(1);
-                       }
-                       if (rv != n) {
-                               fprintf(stderr,
-                                   "%s: write: wanted %d, got %d\n",
-                                   __progname, n, rv);
-                               exit(1);
-                       }
+                       if (rv < 0)
+                               err(1, "write failed");
+                       if (rv != n)
+                               errx(1, "write: wanted %d, got %d", n, rv);
                        bp += n;
                        left -= n;
                }
        } else {
                int rv;
                rv = write(fd, buf, size);
-               if (rv < 0) {
-                       fprintf(stderr, "%s: write: %s\n", __progname,
-                           strerror(errno));
-                       exit(1);
-               }
-               if (rv != size) {
-                       fprintf(stderr, "%s: write: wanted %d, got %d\n",
-                           __progname, size, rv);
-                       exit(1);
-               }
+               if (rv < 0)
+                       err(1, "write failed");
+               if (rv != size)
+                       errx(1, "write: wanted %d, got %d", size, rv);
        }
 }
 /*
@@ -272,9 +263,8 @@
        rv = malloc(nb);
        if (rv)
                return (rv);
-       fprintf(stderr, "%s: can't allocate %lu bytes for %s\n",
-                __progname, (unsigned long int) nb, tag);
-       exit(1);
+       err(1, "Can't allocate %lu bytes for %s",
+           (unsigned long int) nb, tag);
 }
 /*
  * Never-fail realloc.
@@ -287,9 +277,8 @@
        rv = realloc(blk, nb);
        if (rv)
                return (rv);
-       fprintf(stderr, "%s: can't reallocate to %lu bytes for %s\n",
-                __progname, (unsigned long int) nb, tag);
-       exit(1);
+       err(1, "Can't re-allocate %lu bytes for %s",
+           (unsigned long int) nb, tag);
 }
 /*
  * Allocate memory that will never be freed or reallocated.  Arguably
@@ -306,9 +295,8 @@
        rv = mmap(0, nb, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
        if (rv != MAP_FAILED)
                return (rv);
-       fprintf(stderr, "%s: can't allocate %lu bytes for %s\n", __progname,
-                (unsigned long int) nb, tag);
-       exit(1);
+       err(1, "Can't map %lu bytes for %s",
+           (unsigned long int) nb, tag);
 }
 /*
  * Load the cgs and csums off disk.  Also allocates the space to load
@@ -474,12 +462,12 @@
        cg->cg_time = newsb->fs_time;
        cg->cg_magic = CG_MAGIC;
        cg->cg_cgx = cgn;
-       cg->cg_ncyl = newsb->fs_cpg;
-       /* fsck whines if the cg->cg_ncyl value in the last cg is fs_cpg
-        * instead of zero, when fs_cpg is the correct value. */
+       cg->cg_old_ncyl = newsb->fs_old_cpg;
+       /* fsck whines if the cg->cg_old_ncyl value in the last cg is fs_old_cpg
+        * instead of zero, when fs_old_cpg is the correct value. */
        /* XXX fix once fsck is fixed */
-       if ((cgn == newsb->fs_ncg - 1) /* && (newsb->fs_ncyl % newsb->fs_cpg) */ ) {
-               cg->cg_ncyl = newsb->fs_ncyl % newsb->fs_cpg;
+       if ((cgn == newsb->fs_ncg - 1) /* && (newsb->fs_old_ncyl % newsb->fs_old_cpg) */ ) {
+               cg->cg_old_ncyl = newsb->fs_old_ncyl % newsb->fs_old_cpg;
        }
        cg->cg_niblk = newsb->fs_ipg;
        cg->cg_ndblk = dmax;
@@ -488,22 +476,23 @@
         * _entire_ cg against a recomputed cg, and whines if there is any
         * mismatch, including the bitmap offsets. */
        /* XXX update this comment when fsck is fixed */
-       cg->cg_btotoff = &cg->cg_space[0] - (unsigned char *) cg;
-       cg->cg_boff = cg->cg_btotoff + (newsb->fs_cpg * sizeof(int32_t));
-       cg->cg_iusedoff = cg->cg_boff +
-           (newsb->fs_cpg * newsb->fs_nrpos * sizeof(int16_t));
+       cg->cg_old_btotoff = &cg->cg_space[0] - (unsigned char *) cg;
+       cg->cg_old_boff = cg->cg_old_btotoff
+           + (newsb->fs_old_cpg * sizeof(int32_t));
+       cg->cg_iusedoff = cg->cg_old_boff +
+           (newsb->fs_old_cpg * newsb->fs_old_nrpos * sizeof(int16_t));
        cg->cg_freeoff = cg->cg_iusedoff + howmany(newsb->fs_ipg, NBBY);
        if (newsb->fs_contigsumsize > 0) {
                cg->cg_nclusterblks = cg->cg_ndblk / newsb->fs_frag;
                cg->cg_clustersumoff = cg->cg_freeoff +
-                   howmany(newsb->fs_cpg * newsb->fs_spc / NSPF(newsb),
+                   howmany(newsb->fs_old_cpg * newsb->fs_old_spc / NSPF(newsb),
                    NBBY) - sizeof(int32_t);
                cg->cg_clustersumoff =
                    roundup(cg->cg_clustersumoff, sizeof(int32_t));
                cg->cg_clusteroff = cg->cg_clustersumoff +



Home | Main Index | Thread Index | Old Index