[FREELDR] Limit the usage of DiskStopFloppyMotor() in hardware/platform-specific...
[reactos.git] / boot / freeldr / freeldr / arcname.c
1 /*
2 * FreeLoader - arcname.c
3 *
4 * Copyright (C) 2001 Brian Palmer <brianp@sginet.com>
5 * Copyright (C) 2001 Eric Kohl
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <freeldr.h>
23
24 BOOLEAN
25 DissectArcPath(
26 IN PCSTR ArcPath,
27 OUT PCSTR* Path OPTIONAL,
28 OUT PUCHAR DriveNumber,
29 OUT PULONG PartitionNumber)
30 {
31 PCCH p;
32
33 /* Detect ramdisk path */
34 if (_strnicmp(ArcPath, "ramdisk(0)", 10) == 0)
35 {
36 /* Magic value for ramdisks */
37 *DriveNumber = 0x49;
38 *PartitionNumber = 1;
39
40 /* Get the path (optional) */
41 if (Path)
42 {
43 p = ArcPath + 11;
44 *Path = p;
45 }
46 return TRUE;
47 }
48
49 /* NOTE: We are currently limited when handling multi()disk() paths!! */
50 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
51 return FALSE;
52
53 p = ArcPath + 15;
54 if (_strnicmp(p, "fdisk(", 6) == 0)
55 {
56 /*
57 * Floppy disk path:
58 * multi(0)disk(0)fdisk(x)\path
59 */
60 p = p + 6;
61 *DriveNumber = atoi(p);
62 p = strchr(p, ')');
63 if (p == NULL)
64 return FALSE;
65 ++p;
66 *PartitionNumber = 0;
67 }
68 else if (_strnicmp(p, "cdrom(", 6) == 0)
69 {
70 /*
71 * Cdrom path:
72 * multi(0)disk(0)cdrom(x)\path
73 */
74 p = p + 6;
75 *DriveNumber = atoi(p) + 0x80;
76 p = strchr(p, ')');
77 if (p == NULL)
78 return FALSE;
79 ++p;
80 *PartitionNumber = 0xff;
81 }
82 else if (_strnicmp(p, "rdisk(", 6) == 0)
83 {
84 /*
85 * Hard disk path:
86 * multi(0)disk(0)rdisk(x)[partition(y)][\path]
87 */
88 p = p + 6;
89 *DriveNumber = atoi(p) + 0x80;
90 p = strchr(p, ')');
91 if (p == NULL)
92 return FALSE;
93 ++p;
94 /* The partition is optional */
95 if (_strnicmp(p, "partition(", 10) == 0)
96 {
97 p = p + 10;
98 *PartitionNumber = atoi(p);
99 p = strchr(p, ')');
100 if (p == NULL)
101 return FALSE;
102 ++p;
103 }
104 else
105 {
106 *PartitionNumber = 0;
107 }
108 }
109 else
110 {
111 return FALSE;
112 }
113
114 /* Get the path (optional) */
115 if (Path)
116 *Path = p;
117
118 return TRUE;
119 }
120
121 /* PathSyntax: scsi() = 0, multi() = 1, ramdisk() = 2 */
122 BOOLEAN
123 DissectArcPath2(
124 IN PCSTR ArcPath,
125 OUT PULONG x,
126 OUT PULONG y,
127 OUT PULONG z,
128 OUT PULONG Partition,
129 OUT PULONG PathSyntax)
130 {
131 /* Detect ramdisk() */
132 if (_strnicmp(ArcPath, "ramdisk(0)", 10) == 0)
133 {
134 *x = *y = *z = 0;
135 *Partition = 1;
136 *PathSyntax = 2;
137 return TRUE;
138 }
139 /* Detect scsi()disk()rdisk()partition() */
140 else if (sscanf(ArcPath, "scsi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
141 {
142 *PathSyntax = 0;
143 return TRUE;
144 }
145 /* Detect scsi()cdrom()fdisk() */
146 else if (sscanf(ArcPath, "scsi(%lu)cdrom(%lu)fdisk(%lu)", x, y, z) == 3)
147 {
148 *Partition = 0;
149 *PathSyntax = 0;
150 return TRUE;
151 }
152 /* Detect multi()disk()rdisk()partition() */
153 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
154 {
155 *PathSyntax = 1;
156 return TRUE;
157 }
158 /* Detect multi()disk()cdrom() */
159 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)cdrom(%lu)", x, y, z) == 3)
160 {
161 *Partition = 1;
162 *PathSyntax = 1;
163 return TRUE;
164 }
165 /* Detect multi()disk()fdisk() */
166 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)fdisk(%lu)", x, y, z) == 3)
167 {
168 *Partition = 1;
169 *PathSyntax = 1;
170 return TRUE;
171 }
172
173 /* Unknown syntax */
174 return FALSE;
175 }
176
177 VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, UCHAR Disk, ULONG Partition)
178 {
179 char tmp[50];
180
181 strcpy(ArcPath, "multi(0)disk(0)");
182
183 if (Disk < 0x80)
184 {
185 /*
186 * Floppy disk path:
187 * multi(0)disk(0)fdisk(x)\path
188 */
189 sprintf(tmp, "fdisk(%d)", (int) Disk);
190 strcat(ArcPath, tmp);
191 }
192 else
193 {
194 /*
195 * Hard disk path:
196 * multi(0)disk(0)rdisk(x)partition(y)\path
197 */
198 sprintf(tmp, "rdisk(%d)partition(%d)", (int) (Disk - 0x80), (int) Partition);
199 strcat(ArcPath, tmp);
200 }
201
202 if (SystemFolder[0] == '\\' || SystemFolder[0] == '/')
203 {
204 strcat(ArcPath, SystemFolder);
205 }
206 else
207 {
208 strcat(ArcPath, "\\");
209 strcat(ArcPath, SystemFolder);
210 }
211 }
212
213 #if 0
214 UCHAR ConvertArcNameToBiosDriveNumber(PCHAR ArcPath)
215 {
216 char * p;
217 UCHAR DriveNumber = 0;
218
219 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
220 return 0;
221
222 p = ArcPath + 15;
223 if (_strnicmp(p, "fdisk(", 6) == 0)
224 {
225 /*
226 * Floppy disk path:
227 * multi(0)disk(0)fdisk(x)\path
228 */
229 p = p + 6;
230 DriveNumber = atoi(p);
231 }
232 else if (_strnicmp(p, "rdisk(", 6) == 0)
233 {
234 /*
235 * Hard disk path:
236 * multi(0)disk(0)rdisk(x)partition(y)\path
237 */
238 p = p + 6;
239 DriveNumber = atoi(p) + 0x80;
240 }
241
242 return DriveNumber;
243 }
244 #endif