ReactOS 0.4.15-dev-5667-ged97270
arcname.c
Go to the documentation of this file.
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
26 IN PCSTR ArcPath,
28 OUT PUCHAR DriveNumber,
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 *Path = ArcPath + 10;
43
44 return TRUE;
45 }
46
47 /* NOTE: We are currently limited when handling multi()disk() paths!! */
48 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
49 return FALSE;
50
51 p = ArcPath + 15;
52 if (_strnicmp(p, "fdisk(", 6) == 0)
53 {
54 /*
55 * Floppy disk path:
56 * multi(0)disk(0)fdisk(x)\path
57 */
58 p = p + 6;
59 *DriveNumber = atoi(p);
60 p = strchr(p, ')');
61 if (p == NULL)
62 return FALSE;
63 ++p;
64 *PartitionNumber = 0;
65 }
66 else if (_strnicmp(p, "cdrom(", 6) == 0)
67 {
68 /*
69 * Cdrom path:
70 * multi(0)disk(0)cdrom(x)\path
71 */
72 p = p + 6;
73 *DriveNumber = atoi(p) + 0x80;
74 p = strchr(p, ')');
75 if (p == NULL)
76 return FALSE;
77 ++p;
78 *PartitionNumber = 0xff;
79 }
80 else if (_strnicmp(p, "rdisk(", 6) == 0)
81 {
82 /*
83 * Hard disk path:
84 * multi(0)disk(0)rdisk(x)[partition(y)][\path]
85 */
86 p = p + 6;
87 *DriveNumber = atoi(p) + 0x80;
88 p = strchr(p, ')');
89 if (p == NULL)
90 return FALSE;
91 ++p;
92 /* The partition is optional */
93 if (_strnicmp(p, "partition(", 10) == 0)
94 {
95 p = p + 10;
97 p = strchr(p, ')');
98 if (p == NULL)
99 return FALSE;
100 ++p;
101 }
102 else
103 {
104 *PartitionNumber = 0;
105 }
106 }
107 else
108 {
109 return FALSE;
110 }
111
112 /* Get the path (optional) */
113 if (Path)
114 *Path = p;
115
116 return TRUE;
117}
118
119/* PathSyntax: scsi() = 0, multi() = 1, ramdisk() = 2 */
122 IN PCSTR ArcPath,
123 OUT PULONG x,
124 OUT PULONG y,
125 OUT PULONG z,
126 OUT PULONG Partition,
127 OUT PULONG PathSyntax)
128{
129 /* Detect ramdisk() */
130 if (_strnicmp(ArcPath, "ramdisk(0)", 10) == 0)
131 {
132 *x = *y = *z = 0;
133 *Partition = 1;
134 *PathSyntax = 2;
135 return TRUE;
136 }
137 /* Detect scsi()disk()rdisk()partition() */
138 else if (sscanf(ArcPath, "scsi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
139 {
140 *PathSyntax = 0;
141 return TRUE;
142 }
143 /* Detect scsi()cdrom()fdisk() */
144 else if (sscanf(ArcPath, "scsi(%lu)cdrom(%lu)fdisk(%lu)", x, y, z) == 3)
145 {
146 *Partition = 0;
147 *PathSyntax = 0;
148 return TRUE;
149 }
150 /* Detect multi()disk()rdisk()partition() */
151 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)rdisk(%lu)partition(%lu)", x, y, z, Partition) == 4)
152 {
153 *PathSyntax = 1;
154 return TRUE;
155 }
156 /* Detect multi()disk()cdrom() */
157 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)cdrom(%lu)", x, y, z) == 3)
158 {
159 *Partition = 1;
160 *PathSyntax = 1;
161 return TRUE;
162 }
163 /* Detect multi()disk()fdisk() */
164 else if (sscanf(ArcPath, "multi(%lu)disk(%lu)fdisk(%lu)", x, y, z) == 3)
165 {
166 *Partition = 1;
167 *PathSyntax = 1;
168 return TRUE;
169 }
170
171 /* Unknown syntax */
172 return FALSE;
173}
174
175VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, UCHAR Disk, ULONG Partition)
176{
177 char tmp[50];
178
179 strcpy(ArcPath, "multi(0)disk(0)");
180
181 if (Disk < 0x80)
182 {
183 /*
184 * Floppy disk path:
185 * multi(0)disk(0)fdisk(x)\path
186 */
187 sprintf(tmp, "fdisk(%d)", (int) Disk);
188 strcat(ArcPath, tmp);
189 }
190 else
191 {
192 /*
193 * Hard disk path:
194 * multi(0)disk(0)rdisk(x)partition(y)\path
195 */
196 sprintf(tmp, "rdisk(%d)partition(%d)", (int) (Disk - 0x80), (int) Partition);
197 strcat(ArcPath, tmp);
198 }
199
200 if (SystemFolder[0] == '\\' || SystemFolder[0] == '/')
201 {
202 strcat(ArcPath, SystemFolder);
203 }
204 else
205 {
206 strcat(ArcPath, "\\");
207 strcat(ArcPath, SystemFolder);
208 }
209}
210
211#if 0
212UCHAR ConvertArcNameToBiosDriveNumber(PCHAR ArcPath)
213{
214 char * p;
215 UCHAR DriveNumber = 0;
216
217 if (_strnicmp(ArcPath, "multi(0)disk(0)", 15) != 0)
218 return 0;
219
220 p = ArcPath + 15;
221 if (_strnicmp(p, "fdisk(", 6) == 0)
222 {
223 /*
224 * Floppy disk path:
225 * multi(0)disk(0)fdisk(x)\path
226 */
227 p = p + 6;
228 DriveNumber = atoi(p);
229 }
230 else if (_strnicmp(p, "rdisk(", 6) == 0)
231 {
232 /*
233 * Hard disk path:
234 * multi(0)disk(0)rdisk(x)partition(y)\path
235 */
236 p = p + 6;
237 DriveNumber = atoi(p) + 0x80;
238 }
239
240 return DriveNumber;
241}
242#endif
unsigned char BOOLEAN
PRTL_UNICODE_STRING_BUFFER Path
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strchr(const char *String, int ch)
Definition: utclib.c:501
BOOLEAN DissectArcPath(IN PCSTR ArcPath, OUT PCSTR *Path OPTIONAL, OUT PUCHAR DriveNumber, OUT PULONG PartitionNumber)
Definition: arcname.c:25
BOOLEAN DissectArcPath2(IN PCSTR ArcPath, OUT PULONG x, OUT PULONG y, OUT PULONG z, OUT PULONG Partition, OUT PULONG PathSyntax)
Definition: arcname.c:121
VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, UCHAR Disk, ULONG Partition)
Definition: arcname.c:175
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLfloat GLfloat p
Definition: glext.h:8902
GLdouble GLdouble z
Definition: glext.h:5874
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
CONST CHAR * PCCH
Definition: ntbasedef.h:392
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
uint32_t * PULONG
Definition: typedefs.h:59
const char * PCSTR
Definition: typedefs.h:52
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061
unsigned char UCHAR
Definition: xmlstorage.h:181