ReactOS  0.4.14-dev-50-g13bb5e2
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 
24 BOOLEAN
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 */
120 BOOLEAN
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 
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
212 UCHAR 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
signed char * PCHAR
Definition: retypes.h:7
BOOLEAN DissectArcPath(IN PCSTR ArcPath, OUT PCSTR *Path OPTIONAL, OUT PUCHAR DriveNumber, OUT PULONG PartitionNumber)
Definition: arcname.c:25
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
unsigned char * PUCHAR
Definition: retypes.h:3
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
GLdouble GLdouble z
Definition: glext.h:5874
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
VOID ConstructArcPath(PCHAR ArcPath, PCHAR SystemFolder, UCHAR Disk, ULONG Partition)
Definition: arcname.c:175
CONST CHAR * PCCH
Definition: ntbasedef.h:399
BOOLEAN DissectArcPath2(IN PCSTR ArcPath, OUT PULONG x, OUT PULONG y, OUT PULONG z, OUT PULONG Partition, OUT PULONG PathSyntax)
Definition: arcname.c:121
unsigned char UCHAR
Definition: xmlstorage.h:181
PRTL_UNICODE_STRING_BUFFER Path
unsigned int * PULONG
Definition: retypes.h:1
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
char * strchr(const char *String, int ch)
Definition: utclib.c:501
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define OUT
Definition: typedefs.h:39
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
const char * PCSTR
Definition: typedefs.h:51
GLfloat GLfloat p
Definition: glext.h:8902
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68