- PCHify freeldr and cleanup some headers (just a start).
[reactos.git] / reactos / boot / freeldr / freeldr / reactos / 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <freeldr.h>
23
24 BOOL DissectArcPath(CHAR *ArcPath, CHAR *BootPath, ULONG* BootDrive, ULONG* BootPartition)
25 {
26 char *p;
27
28 if (strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
29 return FALSE;
30
31 p = ArcPath + 15;
32 if (strnicmp(p, "fdisk(", 6) == 0)
33 {
34 /*
35 * floppy disk path:
36 * multi(0)disk(0)fdisk(x)\path
37 */
38 p = p + 6;
39 *BootDrive = atoi(p);
40 p = strchr(p, ')');
41 if (p == NULL)
42 return FALSE;
43 p++;
44 *BootPartition = 0xff;
45 }
46 else if (strnicmp(p, "cdrom(", 6) == 0)
47 {
48 /*
49 * cdrom path:
50 * multi(0)disk(0)cdrom(x)\path
51 */
52 p = p + 6;
53 *BootDrive = atoi(p);
54 p = strchr(p, ')');
55 if (p == NULL)
56 return FALSE;
57 p++;
58 *BootPartition = 0xff;
59 }
60 else if (strnicmp(p, "rdisk(", 6) == 0)
61 {
62 /*
63 * hard disk path:
64 * multi(0)disk(0)rdisk(x)partition(y)\path
65 */
66 p = p + 6;
67 *BootDrive = atoi(p) + 0x80;
68 p = strchr(p, ')');
69 if ((p == NULL) || (strnicmp(p, ")partition(", 11) != 0))
70 return FALSE;
71 p = p + 11;
72 *BootPartition = atoi(p);
73 p = strchr(p, ')');
74 if (p == NULL)
75 return FALSE;
76 p++;
77 }
78 else
79 {
80 return FALSE;
81 }
82
83 strcpy(BootPath, p);
84
85 return TRUE;
86 }
87
88 VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, ULONG Disk, ULONG Partition)
89 {
90 char tmp[50];
91
92 strcpy(ArcPath, "multi(0)disk(0)");
93
94 if (Disk < 0x80)
95 {
96 /*
97 * floppy disk path:
98 * multi(0)disk(0)fdisk(x)\path
99 */
100 sprintf(tmp, "fdisk(%d)", (int) Disk);
101 strcat(ArcPath, tmp);
102 }
103 else
104 {
105 /*
106 * hard disk path:
107 * multi(0)disk(0)rdisk(x)partition(y)\path
108 */
109 sprintf(tmp, "rdisk(%d)partition(%d)", (int) (Disk - 0x80), (int) Partition);
110 strcat(ArcPath, tmp);
111 }
112
113 if (SystemFolder[0] == '\\' || SystemFolder[0] == '/')
114 {
115 strcat(ArcPath, SystemFolder);
116 }
117 else
118 {
119 strcat(ArcPath, "\\");
120 strcat(ArcPath, SystemFolder);
121 }
122 }
123
124 ULONG ConvertArcNameToBiosDriveNumber(PCHAR ArcPath)
125 {
126 char * p;
127 ULONG DriveNumber = 0;
128
129 if (strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
130 return 0;
131
132 p = ArcPath + 15;
133 if (strnicmp(p, "fdisk(", 6) == 0)
134 {
135 /*
136 * floppy disk path:
137 * multi(0)disk(0)fdisk(x)\path
138 */
139 p = p + 6;
140 DriveNumber = atoi(p);
141 }
142 else if (strnicmp(p, "rdisk(", 6) == 0)
143 {
144 /*
145 * hard disk path:
146 * multi(0)disk(0)rdisk(x)partition(y)\path
147 */
148 p = p + 6;
149 DriveNumber = atoi(p) + 0x80;
150 }
151
152 return DriveNumber;
153 }