|
|
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
49: */
1.1.1.3 ! root 50: static char rcsid[] = "$Header: /cvsroot/src/sys/arch/i386/stand/Attic/fs.c,v 1.1.1.1 1993/03/21 09:46:02 cgd Exp $";
1.1 root 51:
52: #include "param.h"
53: #include "fs.h"
54: #include "dir.h"
55: #include "dinode.h"
56: #include "saio.h"
57:
58: int bdev;
59: char superb[SBSIZE], abuf[MAXBSIZE];
60: struct fs *fs;
61:
62: /*
63: * Translate name to inode number.
64: */
65: namei(s) char *s; {
66: int ino;
67: struct dinode rd;
68: /*printf("namei %s\n", s);*/
69:
70: if (!fs) {
71: bread(bdev, SBOFF/DEV_BSIZE, superb, SBSIZE);
72: fs = (struct fs *)superb;
73: }
74: fetchi(2, &rd);
75: return(ilookup(&rd, s));
76: }
77:
78: /*
79: * look for a file in this inode.
80: */
81: ilookup(dip, s) struct dinode *dip; char *s; {
82: struct direct dirent;
83: int off;
84:
85: /*printf("ilookup %x %s %d\n", dip, s, dip->di_size);*/
86: off = 0;
87: do {
88: iread(dip, off, (char *)&dirent, sizeof(struct direct));
89: off += dirent.d_reclen;
90: /*printf("%s ", dirent.d_name);*/
91: if (strcmp (dirent.d_name, s) == 0)
92: return (dirent.d_ino);
93: } while (off < dip->di_size && dirent.d_reclen);
94: return (0);
95: }
96:
97: /*
98: * Extract an inode and return it.
99: */
100: fetchi(i, dip) struct dinode *dip; {
101:
102: /*printf("fetchi %d %x\n", i, dip);*/
103: bread(bdev, fsbtodb(fs, itod(fs, i)), abuf, fs->fs_bsize);
104: bcopy (abuf + itoo(fs,i) * sizeof(struct dinode),
105: dip, sizeof(struct dinode));
106: /*printf("mode %o link %d uid %d gid %d size %d [ ",
107: dip->di_mode, dip->di_nlink, dip->di_uid, dip->di_gid, dip->di_size);
108: for (i=0; i < NDADDR; i++)
109: printf("%d ", dip->di_db[i]);
110: printf("] (");
111: for (i=0; i < NIADDR; i++)
112: printf("%d ", dip->di_ib[i]);
113: printf(")\n");*/
114: }
115:
116: /*
117: * Read data contents of an inode
118: */
119: iread(dip, off, p, sz)
120: struct dinode *dip;
121: char *p;
122: {
123: daddr_t physblock;
124: int va = sz;
125: char *op, *pp;
126:
127: /*printf("iread %x %d %x %d\n", dip, off, p, sz);*/
128: while (sz > 0) {
129: int lbn, bs, o;
130:
131: lbn = lblkno(fs, off);
132: bs = dblksize(fs, dip, lbn);
133: o = blkoff(fs, off);
134:
135: /* logical to physical translation */
136: bmap(dip, lbn, &physblock);
137:
138: /* if sz larger than blksize, i/o direct,
139: otherwise to local buffer */
140: if (o == 0 && bs <= sz)
141: bread(bdev, physblock, p, bs);
142: else {
143: bread(bdev, physblock, abuf, bs);
144: bs -= o;
145: bs = bs > sz ? sz : bs;
146: bcopy(abuf + o, p, bs);
147: }
148: /*printf("bs %d sz %d", bs, sz);*/
149: sz -= bs;
150: p += bs;
151: off += bs;
152: if (bs==0) break;
153: }
154: return(va);
155: }
156:
157: _stop(s) {
1.1.1.2 root 158: printf("Failed:%s\n", s);
1.1 root 159: exit(0);
160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.