Annotation of Net2/arch/i386/stand/fs.c, revision 1.1.1.4

1.1       root        1: /*
                      2:  * Copyright (c) 1992 William F. Jolitz, TeleMuse
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This software is a component of "386BSD" developed by 
                     16:        William F. Jolitz, TeleMuse.
                     17:  * 4. Neither the name of the developer nor the name "386BSD"
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ 
                     22:  * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS 
                     23:  * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT. 
                     24:  * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT 
                     25:  * NOT MAKE USE THIS WORK.
                     26:  *
                     27:  * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
                     28:  * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN 
                     29:  * REFERENCES SUCH AS THE  "PORTING UNIX TO THE 386" SERIES 
                     30:  * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING 
                     31:  * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND 
                     32:  * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE 
                     33:  * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS 
                     34:  * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
                     35:  *
                     36:  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
                     37:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     38:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     39:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
                     40:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     41:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     42:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     44:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     45:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     46:  * SUCH DAMAGE.
                     47:  *
                     48:  * Routines to sift through a BSD fast filesystem. -wfj
1.1.1.4 ! root       49:  *
        !            50:  *     fs.c,v 1.2 1993/05/22 08:02:17 cgd Exp
1.1       root       51:  */
                     52: 
                     53: #include "param.h"
                     54: #include "fs.h"
                     55: #include "dir.h"
                     56: #include "dinode.h"
                     57: #include "saio.h"
                     58: 
                     59: int bdev;
                     60: char superb[SBSIZE], abuf[MAXBSIZE];
                     61: struct fs *fs;
                     62: 
                     63: /*
                     64:  * Translate name to inode number.
                     65:  */
                     66: namei(s) char *s; {
                     67:        int ino;
                     68:        struct dinode rd;
                     69: /*printf("namei %s\n", s);*/
                     70: 
                     71:        if (!fs) {
                     72:                bread(bdev, SBOFF/DEV_BSIZE, superb, SBSIZE);
                     73:                fs = (struct fs *)superb;
                     74:        }
                     75:        fetchi(2, &rd); 
                     76:        return(ilookup(&rd, s));
                     77: }
                     78: 
                     79: /*
                     80:  * look for a file in this inode.
                     81:  */
                     82: ilookup(dip, s) struct dinode *dip; char *s; {
                     83:        struct direct dirent;
                     84:        int off;
                     85: 
                     86: /*printf("ilookup %x %s %d\n", dip, s, dip->di_size);*/
                     87:        off = 0;
                     88:        do {
                     89:                iread(dip, off, (char *)&dirent, sizeof(struct direct));
                     90:                off += dirent.d_reclen;
                     91: /*printf("%s ", dirent.d_name);*/
                     92:                if (strcmp (dirent.d_name, s) == 0)
                     93:                        return (dirent.d_ino);
                     94:        } while (off < dip->di_size && dirent.d_reclen);
                     95:        return (0);
                     96: }
                     97: 
                     98: /*
                     99:  * Extract an inode and return it.
                    100:  */
                    101: fetchi(i, dip) struct dinode *dip; {
                    102: 
                    103: /*printf("fetchi %d %x\n", i, dip);*/
                    104:        bread(bdev, fsbtodb(fs, itod(fs, i)), abuf, fs->fs_bsize);
                    105:        bcopy (abuf + itoo(fs,i) * sizeof(struct dinode),
                    106:                dip, sizeof(struct dinode));
                    107:        /*printf("mode %o link %d uid %d gid %d size %d [ ",
                    108:        dip->di_mode, dip->di_nlink, dip->di_uid, dip->di_gid, dip->di_size);
                    109:        for (i=0; i < NDADDR; i++)
                    110:                printf("%d ", dip->di_db[i]);
                    111:        printf("] (");
                    112:        for (i=0; i < NIADDR; i++)
                    113:                printf("%d ", dip->di_ib[i]);
                    114:        printf(")\n");*/
                    115: }
                    116: 
                    117: /*
                    118:  * Read data contents of an inode
                    119:  */
                    120: iread(dip, off, p, sz)
                    121:        struct dinode *dip;
                    122:        char *p;
                    123: {
                    124:        daddr_t physblock;
                    125:        int va = sz;
                    126:        char *op, *pp;
                    127: 
                    128: /*printf("iread %x %d %x %d\n", dip, off, p, sz);*/
                    129:        while (sz > 0) {
                    130:                int lbn, bs, o;
                    131: 
                    132:                lbn = lblkno(fs, off);
                    133:                bs = dblksize(fs, dip, lbn);
                    134:                o = blkoff(fs, off);
                    135: 
                    136:                /* logical to physical translation */
                    137:                bmap(dip, lbn, &physblock);
                    138: 
                    139:                /* if sz larger than blksize, i/o direct,
                    140:                   otherwise to local buffer */
                    141:                if (o == 0 && bs <= sz)
                    142:                        bread(bdev, physblock, p, bs);
                    143:                else {
                    144:                        bread(bdev, physblock, abuf, bs);
                    145:                        bs -= o;
                    146:                        bs = bs > sz ? sz : bs;
                    147:                        bcopy(abuf + o, p, bs);
                    148:                }
                    149: /*printf("bs %d sz %d", bs, sz);*/
                    150:                sz -= bs;
                    151:                p += bs;
                    152:                off += bs;
                    153:                if (bs==0) break;
                    154:        }
                    155:        return(va);
                    156: }
                    157: 
                    158: _stop(s) {
1.1.1.2   root      159:        printf("Failed:%s\n", s);
1.1       root      160:        exit(0);
                    161: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.