2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, Revision 2.2 92/04/04 11:36:34 rpd
27 * fromL Id: sys.c,v 1.21 1997/06/09 05:10:56 bde Exp
32 #include <sys/param.h>
35 #include <ufs/ffs/fs.h>
36 #include <ufs/ufs/quota.h>
37 #include <ufs/ufs/inode.h>
39 #include <sys/dirent.h>
48 /* #define BUFSIZE 4096 */
49 #define BUFSIZE MAXBSIZE
51 static char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
55 #define MAPBUFSIZE BUFSIZE
56 static char buf[BUFSIZE], fsbuf[BUFSIZE], iobuf[BUFSIZE];
58 static char mapbuf[MAPBUFSIZE];
64 #define STARTBYTE 8192 /* Where on the media the kernel starts */
67 static int block_map(int file_block);
68 static int find(char *path);
71 readit(char *buffer, int count)
78 if (poff + count > inode.i_size)
79 count = inode.i_size - poff;
80 while (count > 0 && poff < inode.i_size) {
82 off = blkoff(fs_copy, poff);
83 logno = lblkno(fs_copy, poff);
84 cnt2 = size = blksize(fs_copy, &inode, logno);
85 bnum2 = fsbtodb(fs_copy, block_map(logno)) + boff;
86 if ( (!off) && (size <= count)) {
87 devread(buffer, bnum2, cnt2);
92 devread(iobuf, bnum2, cnt2);
93 bcopy(iobuf+off, buffer, size);
107 int block, off, loc, ino = ROOTINO;
111 list_only = (path[0] == '?' && path[1] == '\0');
113 devread(iobuf, fsbtodb(fs, ino_to_fsba(fs, ino)) + boff, fs->fs_bsize);
114 bcopy((void *)&((struct dinode *)iobuf)[ino % fs->fs_inopb],
115 (void *)&inode.i_din,
116 sizeof (struct dinode));
121 if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
123 for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
127 if (loc >= inode.i_size) {
135 if (!(off = blkoff(fs, loc))) {
136 block = lblkno(fs, loc);
137 devread(iobuf, fsbtodb(fs, block_map(block)) + boff,
138 blksize(fs, &inode, block));
140 dp = (struct dirent *)(iobuf + off);
142 if (dp->d_fileno && list_only) {
146 } while (!dp->d_fileno || strcmp(path, dp->d_name));
154 block_map(int file_block)
157 if (file_block < NDADDR)
158 return(inode.i_db[file_block]);
159 if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
160 devread(mapbuf, bnum, fs->fs_bsize);
163 return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
168 #define max(a, b) ((a) > (b) ? (a) : (b))
171 * Sanity checks for old file systems.
173 * XXX - goes away some day.
181 fs->fs_npsect = max(fs->fs_npsect, fs->fs_nsect); /* XXX */
182 fs->fs_interleave = max(fs->fs_interleave, 1); /* XXX */
183 if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */
184 fs->fs_nrpos = 8; /* XXX */
185 if (fs->fs_inodefmt < FS_44INODEFMT) { /* XXX */
186 quad_t sizepb = fs->fs_bsize; /* XXX */
188 fs->fs_maxfilesize = fs->fs_bsize * NDADDR - 1; /* XXX */
189 for (i = 0; i < NIADDR; i++) { /* XXX */
190 sizepb *= NINDIR(fs); /* XXX */
191 fs->fs_maxfilesize += sizepb; /* XXX */
193 fs->fs_qbmask = ~fs->fs_bmask; /* XXX */
194 fs->fs_qfmask = ~fs->fs_fmask; /* XXX */
209 * Load Filesystem info (mount the device).
211 devread((char *)(fs = (struct fs *)fsbuf), SBLOCK + boff, SBSIZE);
218 * Find the actual FILE on the mounted device.
219 * Make a copy of the name since find() is destructive.
221 strcpy(namecopy, name);
222 ret = find(namecopy);