Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[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 DissectArcPath(CHAR *ArcPath, CHAR *BootPath, UCHAR* BootDrive, ULONG* BootPartition)
25 {
26 char *p;
27
28 /* Detect ramdisk path */
29 if (_strnicmp(ArcPath, "ramdisk(0)", 10) == 0)
30 {
31 /* Magic value for ramdisks */
32 *BootDrive = 0x49;
33 *BootPartition = 1;
34
35 /* Get the path */
36 p = ArcPath + 11;
37 strcpy(BootPath, p);
38 return TRUE;
39 }
40
41 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
42 return FALSE;
43
44 p = ArcPath + 15;
45 if (_strnicmp(p, "fdisk(", 6) == 0)
46 {
47 /*
48 * Floppy disk path:
49 * multi(0)disk(0)fdisk(x)\path
50 */
51 p = p + 6;
52 *BootDrive = atoi(p);
53 p = strchr(p, ')');
54 if (p == NULL)
55 return FALSE;
56 p++;
57 *BootPartition = 0;
58 }
59 else if (_strnicmp(p, "cdrom(", 6) == 0)
60 {
61 /*
62 * Cdrom path:
63 * multi(0)disk(0)cdrom(x)\path
64 */
65 p = p + 6;
66 *BootDrive = atoi(p) + 0x80;
67 p = strchr(p, ')');
68 if (p == NULL)
69 return FALSE;
70 p++;
71 *BootPartition = 0xff;
72 }
73 else if (_strnicmp(p, "rdisk(", 6) == 0)
74 {
75 /*
76 * Hard disk path:
77 * multi(0)disk(0)rdisk(x)partition(y)\path
78 */
79 p = p + 6;
80 *BootDrive = atoi(p) + 0x80;
81 p = strchr(p, ')');
82 if ((p == NULL) || (_strnicmp(p, ")partition(", 11) != 0))
83 return FALSE;
84 p = p + 11;
85 *BootPartition = atoi(p);
86 p = strchr(p, ')');
87 if (p == NULL)
88 return FALSE;
89 p++;
90 }
91 else
92 {
93 return FALSE;
94 }
95
96 strcpy(BootPath, p);
97
98 return TRUE;
99 }
100
101 /* PathSyntax: scsi() = 0, multi() = 1, ramdisk() = 2 */
102 BOOLEAN
103 DissectArcPath2(
104 IN CHAR* ArcPath,
105 OUT ULONG* x,
106 OUT ULONG* y,
107 OUT ULONG* z,
108 OUT ULONG* Partition,
109 OUT ULONG *PathSyntax)
110 {
111 /* Detect ramdisk() */
112 if (_strnicmp(ArcPath, "ramdisk(0)", 10) == 0)
113 {
114 *x = *y = *z = 0;
115 *Partition = 1;
116 *PathSyntax = 2;
117 return TRUE;
118 }
119 /* Detect scsi()disk()rdisk()partition() */
120 else if (sscanf(ArcPath, "scsi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
121 {
122 *PathSyntax = 0;
123 return TRUE;
124 }
125 /* Detect scsi()cdrom()fdisk() */
126 else if (sscanf(ArcPath, "scsi(%lu)cdrom(%lu)fdisk(%lu)", x, y, z) == 3)
127 {
128 *Partition = 0;
129 *PathSyntax = 0;
130 return TRUE;
131 }
132 /* Detect multi()disk()rdisk()partition() */
133 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
134 {
135 *PathSyntax = 1;
136 return TRUE;
137 }
138 /* Detect multi()disk()cdrom() */
139 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)cdrom(%lu)", x, y, z) == 3)
140 {
141 *Partition = 1;
142 *PathSyntax = 1;
143 return TRUE;
144 }
145 /* Detect multi()disk()fdisk() */
146 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)fdisk(%lu)", x, y, z) == 3)
147 {
148 *Partition = 1;
149 *PathSyntax = 1;
150 return TRUE;
151 }
152
153 /* Unknown syntax */
154 return FALSE;
155 }
156
157 VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, UCHAR Disk, ULONG Partition)
158 {
159 char tmp[50];
160
161 strcpy(ArcPath, "multi(0)disk(0)");
162
163 if (Disk < 0x80)
164 {
165 /*
166 * Floppy disk path:
167 * multi(0)disk(0)fdisk(x)\path
168 */
169 sprintf(tmp, "fdisk(%d)", (int) Disk);
170 strcat(ArcPath, tmp);
171 }
172 else
173 {
174 /*
175 * Hard disk path:
176 * multi(0)disk(0)rdisk(x)partition(y)\path
177 */
178 sprintf(tmp, "rdisk(%d)partition(%d)", (int) (Disk - 0x80), (int) Partition);
179 strcat(ArcPath, tmp);
180 }
181
182 if (SystemFolder[0] == '\\' || SystemFolder[0] == '/')
183 {
184 strcat(ArcPath, SystemFolder);
185 }
186 else
187 {
188 strcat(ArcPath, "\\");
189 strcat(ArcPath, SystemFolder);
190 }
191 }
192
193 #if 0
194 UCHAR ConvertArcNameToBiosDriveNumber(PCHAR ArcPath)
195 {
196 char * p;
197 UCHAR DriveNumber = 0;
198
199 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
200 return 0;
201
202 p = ArcPath + 15;
203 if (_strnicmp(p, "fdisk(", 6) == 0)
204 {
205 /*
206 * Floppy disk path:
207 * multi(0)disk(0)fdisk(x)\path
208 */
209 p = p + 6;
210 DriveNumber = atoi(p);
211 }
212 else if (_strnicmp(p, "rdisk(", 6) == 0)
213 {
214 /*
215 * Hard disk path:
216 * multi(0)disk(0)rdisk(x)partition(y)\path
217 */
218 p = p + 6;
219 DriveNumber = atoi(p) + 0x80;
220 }
221
222 return DriveNumber;
223 }
224 #endif