Remove the priority part of the priority|flags argument to tsleep(). Only
[dragonfly.git] / sys / i386 / boot / dosboot / sys.c
1 /*\r
2  * Mach Operating System\r
3  * Copyright (c) 1992, 1991 Carnegie Mellon University\r
4  * All Rights Reserved.\r
5  * \r
6  * Permission to use, copy, modify and distribute this software and its\r
7  * documentation is hereby granted, provided that both the copyright\r
8  * notice and this permission notice appear in all copies of the\r
9  * software, derivative works or modified versions, and any portions\r
10  * thereof, and that both notices appear in supporting documentation.\r
11  * \r
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"\r
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR\r
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.\r
15  * \r
16  * Carnegie Mellon requests users of this software to return to\r
17  * \r
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU\r
19  *  School of Computer Science\r
20  *  Carnegie Mellon University\r
21  *  Pittsburgh PA 15213-3890\r
22  * \r
23  * any improvements or extensions that they make and grant Carnegie Mellon\r
24  * the rights to redistribute these changes.\r
25  *\r
26  *      from: Mach, Revision 2.2  92/04/04  11:36:34  rpd\r
27  * $FreeBSD: src/sys/i386/boot/dosboot/sys.c,v 1.5 1999/08/28 00:43:25 peter Exp $\r
28  * $DragonFly: src/sys/i386/boot/dosboot/Attic/sys.c,v 1.2 2003/06/17 04:28:34 dillon Exp $\r
29  */\r
30 #include <stdio.h>\r
31 #include <string.h>\r
32 #include <memory.h>\r
33 \r
34 #define bcopy(a,b,c)    memcpy(b,a,c)\r
35 \r
36 #include "protmod.h"\r
37 #include "boot.h"\r
38 #include "dir.h"\r
39 \r
40 #define BUFSIZE 4096\r
41 #undef MAXBSIZE\r
42 #define MAXBSIZE 8192\r
43 \r
44 void ufs_read(char *buffer, long count);\r
45 static long block_map(long file_block);\r
46 \r
47 char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];\r
48 char mapbuf[MAXBSIZE];\r
49 long mapblock = 0;\r
50 \r
51 void xread(unsigned long addr, long size)\r
52 {\r
53         long count = BUFSIZE;\r
54         while (size > 0l) {\r
55                 if (BUFSIZE > size)\r
56                         count = size;\r
57                 ufs_read(buf, count);\r
58                 pm_copy(buf, addr, count);\r
59                 size -= count;\r
60                 addr += count;\r
61         }\r
62 }\r
63 \r
64 void ufs_read(char *buffer, long count)\r
65 {\r
66         long logno, off, size;\r
67         long cnt2, bnum2;\r
68 \r
69         while (count) {\r
70                 off = blkoff(fs, poff);\r
71                 logno = lblkno(fs, poff);\r
72                 cnt2 = size = blksize(fs, &inode, logno);\r
73                 bnum2 = fsbtodb(fs, block_map(logno)) + boff;\r
74                 cnt = cnt2;\r
75                 bnum = bnum2;\r
76                 if (    (!off)  && (size <= count))\r
77                 {\r
78                         iodest = buffer;\r
79                         devread();\r
80                 }\r
81                 else\r
82                 {\r
83                         iodest = iobuf;\r
84                         size -= off;\r
85                         if (size > count)\r
86                                 size = count;\r
87                         devread();\r
88                         bcopy(iodest+off,buffer,size);\r
89                 }\r
90                 buffer += size;\r
91                 count -= size;\r
92                 poff += size;\r
93         }\r
94 }\r
95 \r
96 static int find(char *path)\r
97 {\r
98         char *rest, ch;\r
99         long block, off, loc, ino = ROOTINO;\r
100         struct direct *dp;\r
101 loop:   iodest = iobuf;\r
102         cnt = fs->fs_bsize;\r
103         bnum = fsbtodb(fs,itod(fs,ino)) + boff;\r
104         devread();\r
105         bcopy(&((struct dinode *)iodest)[ino % fs->fs_inopb],\r
106               &inode.i_din,\r
107               sizeof (struct dinode));\r
108         if (!*path)\r
109                 return 1;\r
110         while (*path == '/')\r
111                 path++;\r
112         if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))\r
113                 return 0;\r
114         for (rest = path; (ch = *rest) && ch != '/'; rest++) ;\r
115         *rest = 0;\r
116         loc = 0;\r
117         do {\r
118                 if (loc >= inode.i_size)\r
119                         return 0;\r
120                 if (!(off = blkoff(fs, loc))) {\r
121                         block = lblkno(fs, loc);\r
122                         cnt = blksize(fs, &inode, block);\r
123                         bnum = fsbtodb(fs, block_map(block)) + boff;\r
124                         iodest = iobuf;\r
125                         devread();\r
126                 }\r
127                 dp = (struct direct *)(iodest + off);\r
128                 loc += dp->d_reclen;\r
129         } while (!dp->d_ino || strcmp(path, dp->d_name));\r
130         ino = dp->d_ino;\r
131         *(path = rest) = ch;\r
132         goto loop;\r
133 }\r
134 \r
135 static long block_map(long file_block)\r
136 {\r
137         if (file_block < NDADDR)\r
138                 return(inode.i_db[file_block]);\r
139         if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {\r
140                 iodest = mapbuf;\r
141                 cnt = fs->fs_bsize;\r
142                 devread();\r
143                 mapblock = bnum;\r
144         }\r
145         return (((long *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);\r
146 }\r
147 \r
148 int openrd(char *name)\r
149 {\r
150         char *cp = name;\r
151 \r
152         dosdev = 0x80;                          /* only 1st HD supported yet */\r
153         inode.i_dev = dosdev;\r
154         /***********************************************\\r
155         * Now we know the disk unit and part,                   *\r
156         * Load disk info, (open the device)                             *\r
157         \***********************************************/\r
158         if (devopen()) return 1;\r
159 \r
160         /***********************************************\\r
161         * Load Filesystem info (mount the device)               *\r
162         \***********************************************/\r
163         iodest = (char *)(fs = (struct fs *)fsbuf);\r
164         cnt = SBSIZE;\r
165         bnum = SBLOCK + boff;\r
166         devread();\r
167         /***********************************************\\r
168         * Find the actual FILE on the mounted device    *\r
169         \***********************************************/\r
170         if (!find(cp)) return 1;\r
171         poff = 0;\r
172         name = cp;\r
173         return 0;\r
174 }\r