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