# 2.11BSD#431 - /usr/src/sbin/fsck/setup.c

##### Functions

    setup             X

       1: /*
       2:  * Copyright (c) 1980 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #if !defined(lint) && defined(DOSCCS)
       8: static char sccsid[] = "@(#)setup.c	5.3.1 (2.11BSD) 1996/2/3";
       9: #endif not lint
      10:
      11: #include <stdio.h>
      12: #include <sys/param.h>
      13: #include <sys/file.h>
      14: #include <sys/inode.h>
      15: #include <sys/fs.h>
      16: #include <sys/stat.h>
      17: #include "fsck.h"
      18:
      19: setup(dev)
      20:     char *dev;
      21: {
      22:     dev_t rootdev;
      23:     off_t smapsz, totsz, lncntsz;
      24:     daddr_t bcnt, nscrblk;
      25:     struct stat statb;
      26:     u_int msize;
      27:     char *mbase;
      28:     int i, j, n;
      29:     long size;
      30:     BUFAREA *bp;
      31:     char junk[80 + sizeof (".XXXXX") + 1];
      32:
      33:     if (stat("/", &statb) < 0)
      34:         errexit("Can't stat root\n");
      35:     rootdev = statb.st_dev;
      36:     if (stat(dev, &statb) < 0) {
      37:         printf("Can't stat %s\n", dev);
      38:         return (0);
      39:     }
      40:     rawflg = 0;
      41:     if ((statb.st_mode & S_IFMT) == S_IFBLK)
      42:         ;
      43:     else if ((statb.st_mode & S_IFMT) == S_IFCHR)
      44:         rawflg++;
      45:     else {
      46:         if (reply("file is not a block or character device; OK") == 0)
      47:             return (0);
      48:     }
      49:     if (rootdev == statb.st_rdev)
      50:         hotroot++;
      51:     if ((dfile.rfdes = open(dev, 0)) < 0) {
      52:         printf("Can't open %s\n", dev);
      53:         return (0);
      54:     }
      55:     if (preen == 0)
      56:         printf("** %s", dev);
      57:     if (nflag || (dfile.wfdes = open(dev, 1)) < 0) {
      58:         dfile.wfdes = -1;
      59:         if (preen)
      60:             pfatal("NO WRITE ACCESS");
      61:         printf(" (NO WRITE)");
      62:     }
      63:     if (preen == 0)
      64:         printf("\n");
      65:     dfile.mod = 0;
      66:     lfdir = 0;
      67:     initbarea(&sblk);
      68:     initbarea(&fileblk);
      69:     initbarea(&inoblk);
      70:     /*
      71: 	 * Read in the super block and its summary info.
      72: 	 */
      73:     if (bread(&dfile, (char *)&sblock, SBLOCK, SBSIZE) != 0)
      74:         return (0);
      75:     sblk.b_bno = SBLOCK;
      76:     sblk.b_size = SBSIZE;
      77:
      78:     imax = ((ino_t)sblock.fs_isize - (SUPERB+1)) * INOPB;
      79:     fmin = (daddr_t)sblock.fs_isize;    /* first data blk num */
      80:     fmax = sblock.fs_fsize;     /* first invalid blk num */
      81:     startib = fmax;
      82:     if(fmin >= fmax ||
      83:         (imax/INOPB) != ((ino_t)sblock.fs_isize-(SUPERB+1))) {
      84:         pfatal("Size check: fsize %ld isize %d",
      85:             sblock.fs_fsize,sblock.fs_isize);
      86:         printf("\n");
      87:         ckfini();
      88:         return(0);
      89:     }
      90:     if (preen == 0)
      91:         printf("File System: %.12s\n\n", sblock.fs_fsmnt);
      92:     /*
      93: 	 * allocate and initialize the necessary maps
      94: 	 */
      95:     bmapsz = roundup(howmany(fmax,BITSPB),sizeof(*lncntp));
      96:     smapsz = roundup(howmany((long)(imax+1),STATEPB),sizeof(*lncntp));
      97:     lncntsz = (long)(imax+1) * sizeof(*lncntp);
      98:     if(bmapsz > smapsz+lncntsz)
      99:         smapsz = bmapsz-lncntsz;
     100:     totsz = bmapsz+smapsz+lncntsz;
     101:     msize = memsize;
     102:     mbase = membase;
     103:     bzero(mbase,msize);
     104:     muldup = enddup = duplist;
     105:     zlnp = zlnlist;
     106:
     107:     if((off_t)msize < totsz) {
     108:         bmapsz = roundup(bmapsz,DEV_BSIZE);
     109:         smapsz = roundup(smapsz,DEV_BSIZE);
     110:         lncntsz = roundup(lncntsz,DEV_BSIZE);
     111:         nscrblk = (bmapsz+smapsz+lncntsz)>>DEV_BSHIFT;
     112:         if(scrfile[0] == 0) {
     113:             pfatal("\nNEED SCRATCH FILE (%ld BLKS)\n",nscrblk);
     114:             do {
     115:                 printf("ENTER FILENAME:  ");
     116:                 if((n = getline(stdin, scrfile,
     117:                         sizeof(scrfile) - 6)) == EOF)
     118:                     errexit("\n");
     119:             } while(n == 0);
     120:         }
     121:         strcpy(junk, scrfile);
     122:         strcat(junk, ".XXXXX");
     123:         sfile.wfdes = mkstemp(junk);
     124:         if ((sfile.wfdes < 0)
     125:             || ((sfile.rfdes = open(junk,0)) < 0)) {
     126:             printf("Can't create %s\n", junk);
     127:             ckfini();
     128:             return(0);
     129:         }
     130:         unlink(junk);   /* make it invisible incase we exit */
     131:         if (hotroot && (fstat(sfile.wfdes,&statb)==0)
     132:             && ((statb.st_mode & S_IFMT) == S_IFREG)
     133:             && (statb.st_dev==rootdev))
     134:              pfatal("TMP FILE (%s) ON ROOT WHEN CHECKING ROOT", junk);
     135:         bp = &((BUFAREA *)mbase)[(msize/sizeof(BUFAREA))];
     136:         poolhead = NULL;
     137:         while(--bp >= (BUFAREA *)mbase) {
     138:             initbarea(bp);
     139:             bp->b_next = poolhead;
     140:             poolhead = bp;
     141:         }
     142:         bp = poolhead;
     143:         for(bcnt = 0; bcnt < nscrblk; bcnt++) {
     144:             bp->b_bno = bcnt;
     145:             dirty(bp);
     146:             flush(&sfile,bp);
     147:         }
     148:         blockmap = freemap = statemap = (char *) NULL;
     149:         lncntp = (short *) NULL;
     150:         bmapblk = 0;
     151:         smapblk = bmapblk + bmapsz / DEV_BSIZE;
     152:         lncntblk = smapblk + smapsz / DEV_BSIZE;
     153:         fmapblk = smapblk;
     154:     }
     155:     else {
     156:         poolhead = NULL;
     157:         blockmap = mbase;
     158:         statemap = &mbase[bmapsz];
     159:         freemap = statemap;
     160:         lncntp = (short *)&statemap[smapsz];
     161:     }
     162:     return(1);
     163: }

#### Defined functions

setup defined in line 19; used 1 times

- in /usr/src/sbin/fsck/main.c line 173

#### Defined variables

sccsid defined in line 8; never used

Last modified: 1996-02-04 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 733 |