]>
Commit | Line | Data |
---|---|---|
949f388f | 1 | /*++ @file\r |
2 | Produce Simple File System abstractions for directories on your PC using Posix APIs.\r | |
d18d8a1d | 3 | The configuration of what devices to mount or emulate comes from UNIX\r |
4 | environment variables. The variables must be visible to the Microsoft*\r | |
949f388f | 5 | Developer Studio for them to work.\r |
6 | \r | |
224e1333 | 7 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
949f388f | 8 | Portions copyright (c) 2011, Apple Inc. All rights reserved.\r |
224e1333 | 9 | This program and the accompanying materials\r |
10 | are licensed and made available under the terms and conditions of the BSD License\r | |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
949f388f | 16 | \r |
17 | **/\r | |
18 | \r | |
19 | #include "EmuSimpleFileSystem.h"\r | |
20 | \r | |
21 | \r | |
22 | \r | |
23 | \r | |
24 | /**\r | |
25 | Opens a new file relative to the source file's location.\r | |
26 | \r | |
27 | @param This The protocol instance pointer.\r | |
28 | @param NewHandle Returns File Handle for FileName.\r | |
29 | @param FileName Null terminated string. "\", ".", and ".." are supported.\r | |
30 | @param OpenMode Open mode for file.\r | |
31 | @param Attributes Only used for EFI_FILE_MODE_CREATE.\r | |
32 | \r | |
33 | @retval EFI_SUCCESS The device was opened.\r | |
34 | @retval EFI_NOT_FOUND The specified file could not be found on the device.\r | |
35 | @retval EFI_NO_MEDIA The device has no media.\r | |
36 | @retval EFI_MEDIA_CHANGED The media has changed.\r | |
37 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
38 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
39 | @retval EFI_ACCESS_DENIED The service denied access to the file.\r | |
40 | @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r | |
41 | @retval EFI_VOLUME_FULL The volume is full.\r | |
42 | \r | |
43 | **/\r | |
44 | EFI_STATUS\r | |
45 | EFIAPI\r | |
46 | EmuSimpleFileSystemOpen (\r | |
47 | IN EFI_FILE_PROTOCOL *This,\r | |
48 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
49 | IN CHAR16 *FileName,\r | |
50 | IN UINT64 OpenMode,\r | |
51 | IN UINT64 Attributes\r | |
52 | )\r | |
53 | {\r | |
54 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
55 | \r | |
56 | //\r | |
57 | // Check for obvious invalid parameters.\r | |
58 | //\r | |
59 | if (This == NULL || NewHandle == NULL || FileName == NULL) {\r | |
60 | return EFI_INVALID_PARAMETER;\r | |
61 | }\r | |
62 | \r | |
63 | switch (OpenMode) {\r | |
64 | case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r | |
65 | if (Attributes &~EFI_FILE_VALID_ATTR) {\r | |
66 | return EFI_INVALID_PARAMETER;\r | |
67 | }\r | |
68 | \r | |
69 | if (Attributes & EFI_FILE_READ_ONLY) {\r | |
70 | return EFI_INVALID_PARAMETER;\r | |
71 | }\r | |
72 | \r | |
73 | //\r | |
74 | // fall through\r | |
75 | //\r | |
76 | case EFI_FILE_MODE_READ:\r | |
77 | case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r | |
78 | break;\r | |
79 | \r | |
80 | default:\r | |
81 | return EFI_INVALID_PARAMETER;\r | |
82 | }\r | |
83 | \r | |
84 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r | |
85 | \r | |
86 | return PrivateFile->Io->Open (PrivateFile->Io, NewHandle, FileName, OpenMode, Attributes);\r | |
87 | }\r | |
88 | \r | |
89 | \r | |
90 | \r | |
91 | /**\r | |
92 | Close the file handle\r | |
93 | \r | |
94 | @param This Protocol instance pointer.\r | |
95 | \r | |
96 | @retval EFI_SUCCESS The file was closed.\r | |
97 | \r | |
98 | **/\r | |
99 | EFI_STATUS\r | |
100 | EFIAPI\r | |
101 | EmuSimpleFileSystemClose (\r | |
102 | IN EFI_FILE_PROTOCOL *This\r | |
103 | )\r | |
104 | {\r | |
105 | EFI_STATUS Status;\r | |
106 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
107 | EFI_TPL OldTpl;\r | |
108 | \r | |
109 | if (This == NULL) {\r | |
110 | return EFI_INVALID_PARAMETER;\r | |
111 | }\r | |
112 | \r | |
113 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r | |
114 | \r | |
115 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
116 | \r | |
117 | Status = PrivateFile->Io->Close (PrivateFile->Io);\r | |
118 | if (!EFI_ERROR (Status)) {\r | |
119 | gBS->FreePool (PrivateFile);\r | |
120 | }\r | |
121 | \r | |
122 | gBS->RestoreTPL (OldTpl);\r | |
d18d8a1d | 123 | \r |
949f388f | 124 | return Status;\r |
125 | }\r | |
126 | \r | |
127 | \r | |
128 | /**\r | |
129 | Close and delete the file handle.\r | |
130 | \r | |
131 | @param This Protocol instance pointer.\r | |
d18d8a1d | 132 | \r |
949f388f | 133 | @retval EFI_SUCCESS The file was closed and deleted.\r |
134 | @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.\r | |
135 | \r | |
136 | **/\r | |
137 | EFI_STATUS\r | |
138 | EFIAPI\r | |
139 | EmuSimpleFileSystemDelete (\r | |
140 | IN EFI_FILE_PROTOCOL *This\r | |
141 | )\r | |
142 | {\r | |
143 | EFI_STATUS Status;\r | |
144 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
145 | EFI_TPL OldTpl;\r | |
146 | \r | |
147 | if (This == NULL) {\r | |
148 | return EFI_INVALID_PARAMETER;\r | |
149 | }\r | |
150 | \r | |
151 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 152 | \r |
949f388f | 153 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
154 | \r | |
155 | Status = PrivateFile->Io->Delete (PrivateFile->Io);\r | |
156 | if (!EFI_ERROR (Status)) {\r | |
157 | gBS->FreePool (PrivateFile);\r | |
158 | }\r | |
159 | \r | |
160 | gBS->RestoreTPL (OldTpl);\r | |
161 | \r | |
162 | return Status;\r | |
163 | }\r | |
164 | \r | |
165 | \r | |
166 | /**\r | |
167 | Read data from the file.\r | |
168 | \r | |
169 | @param This Protocol instance pointer.\r | |
170 | @param BufferSize On input size of buffer, on output amount of data in buffer.\r | |
171 | @param Buffer The buffer in which data is read.\r | |
172 | \r | |
173 | @retval EFI_SUCCESS Data was read.\r | |
174 | @retval EFI_NO_MEDIA The device has no media.\r | |
175 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
176 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
177 | @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.\r | |
178 | \r | |
179 | **/\r | |
180 | EFI_STATUS\r | |
181 | EFIAPI\r | |
182 | EmuSimpleFileSystemRead (\r | |
183 | IN EFI_FILE_PROTOCOL *This,\r | |
184 | IN OUT UINTN *BufferSize,\r | |
185 | OUT VOID *Buffer\r | |
186 | )\r | |
187 | {\r | |
188 | EFI_STATUS Status;\r | |
189 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
190 | EFI_TPL OldTpl;\r | |
191 | \r | |
192 | if (This == NULL || BufferSize == NULL) {\r | |
193 | return EFI_INVALID_PARAMETER;\r | |
194 | }\r | |
d18d8a1d | 195 | \r |
949f388f | 196 | if ((*BufferSize != 0) && (Buffer == NULL)) {\r |
197 | // Buffer can be NULL if *BufferSize is zero\r | |
198 | return EFI_INVALID_PARAMETER;\r | |
199 | }\r | |
200 | \r | |
201 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 202 | \r |
949f388f | 203 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
204 | \r | |
205 | Status = PrivateFile->Io->Read (PrivateFile->Io, BufferSize, Buffer);\r | |
206 | \r | |
207 | gBS->RestoreTPL (OldTpl);\r | |
208 | return Status;\r | |
209 | }\r | |
210 | \r | |
211 | \r | |
212 | /**\r | |
213 | Write data to a file.\r | |
214 | \r | |
215 | @param This Protocol instance pointer.\r | |
216 | @param BufferSize On input size of buffer, on output amount of data in buffer.\r | |
217 | @param Buffer The buffer in which data to write.\r | |
218 | \r | |
219 | @retval EFI_SUCCESS Data was written.\r | |
220 | @retval EFI_UNSUPPORTED Writes to Open directory are not supported.\r | |
221 | @retval EFI_NO_MEDIA The device has no media.\r | |
222 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
223 | @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.\r | |
224 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
225 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
226 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
227 | @retval EFI_VOLUME_FULL The volume is full.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | EmuSimpleFileSystemWrite (\r | |
233 | IN EFI_FILE_PROTOCOL *This,\r | |
234 | IN OUT UINTN *BufferSize,\r | |
235 | IN VOID *Buffer\r | |
236 | )\r | |
237 | {\r | |
238 | EFI_STATUS Status;\r | |
239 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
240 | EFI_TPL OldTpl;\r | |
241 | \r | |
242 | if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r | |
243 | return EFI_INVALID_PARAMETER;\r | |
244 | }\r | |
245 | \r | |
246 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
247 | \r | |
248 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r | |
249 | \r | |
250 | Status = PrivateFile->Io->Write (PrivateFile->Io, BufferSize, Buffer);\r | |
251 | \r | |
252 | gBS->RestoreTPL (OldTpl);\r | |
253 | return Status;\r | |
254 | }\r | |
255 | \r | |
256 | \r | |
257 | /**\r | |
4451c6eb | 258 | Get a file's current position\r |
949f388f | 259 | \r |
260 | @param This Protocol instance pointer.\r | |
261 | @param Position Byte position from the start of the file.\r | |
d18d8a1d | 262 | \r |
949f388f | 263 | @retval EFI_SUCCESS Position was updated.\r |
264 | @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.\r | |
265 | \r | |
266 | **/\r | |
267 | EFI_STATUS\r | |
268 | EFIAPI\r | |
269 | EmuSimpleFileSystemGetPosition (\r | |
270 | IN EFI_FILE_PROTOCOL *This,\r | |
271 | OUT UINT64 *Position\r | |
272 | )\r | |
273 | {\r | |
274 | EFI_STATUS Status;\r | |
275 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
276 | EFI_TPL OldTpl;\r | |
277 | \r | |
278 | if (This == NULL || Position == NULL) {\r | |
279 | return EFI_INVALID_PARAMETER;\r | |
280 | }\r | |
281 | \r | |
282 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 283 | \r |
949f388f | 284 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
285 | \r | |
286 | Status = PrivateFile->Io->GetPosition (PrivateFile->Io, Position);\r | |
287 | \r | |
288 | gBS->RestoreTPL (OldTpl);\r | |
289 | return Status;\r | |
290 | }\r | |
291 | \r | |
292 | \r | |
293 | \r | |
294 | /**\r | |
4451c6eb | 295 | Set file's current position\r |
949f388f | 296 | \r |
297 | @param This Protocol instance pointer.\r | |
298 | @param Position Byte position from the start of the file.\r | |
d18d8a1d | 299 | \r |
949f388f | 300 | @retval EFI_SUCCESS Position was updated.\r |
301 | @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..\r | |
302 | \r | |
303 | **/\r | |
304 | EFI_STATUS\r | |
305 | EFIAPI\r | |
306 | EmuSimpleFileSystemSetPosition (\r | |
307 | IN EFI_FILE_PROTOCOL *This,\r | |
308 | IN UINT64 Position\r | |
309 | )\r | |
310 | {\r | |
311 | EFI_STATUS Status;\r | |
312 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
313 | EFI_TPL OldTpl;\r | |
314 | \r | |
315 | if (This == NULL) {\r | |
316 | return EFI_INVALID_PARAMETER;\r | |
317 | }\r | |
318 | \r | |
319 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 320 | \r |
949f388f | 321 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
322 | \r | |
323 | Status = PrivateFile->Io->SetPosition (PrivateFile->Io, Position);\r | |
324 | \r | |
325 | gBS->RestoreTPL (OldTpl);\r | |
326 | return Status;\r | |
327 | }\r | |
328 | \r | |
329 | \r | |
330 | /**\r | |
331 | Get information about a file.\r | |
332 | \r | |
333 | @param This Protocol instance pointer.\r | |
334 | @param InformationType Type of information to return in Buffer.\r | |
335 | @param BufferSize On input size of buffer, on output amount of data in buffer.\r | |
336 | @param Buffer The buffer to return data.\r | |
337 | \r | |
338 | @retval EFI_SUCCESS Data was returned.\r | |
339 | @retval EFI_UNSUPPORTED InformationType is not supported.\r | |
340 | @retval EFI_NO_MEDIA The device has no media.\r | |
341 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
342 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
343 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
344 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
345 | @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.\r | |
346 | \r | |
347 | **/\r | |
348 | EFI_STATUS\r | |
349 | EFIAPI\r | |
350 | EmuSimpleFileSystemGetInfo (\r | |
351 | IN EFI_FILE_PROTOCOL *This,\r | |
352 | IN EFI_GUID *InformationType,\r | |
353 | IN OUT UINTN *BufferSize,\r | |
354 | OUT VOID *Buffer\r | |
355 | )\r | |
356 | {\r | |
357 | EFI_STATUS Status;\r | |
358 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
359 | EFI_TPL OldTpl;\r | |
360 | \r | |
361 | if (This == NULL || InformationType == NULL || BufferSize == NULL) {\r | |
362 | return EFI_INVALID_PARAMETER;\r | |
363 | }\r | |
364 | \r | |
365 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 366 | \r |
949f388f | 367 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
368 | \r | |
369 | Status = PrivateFile->Io->GetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r | |
370 | \r | |
371 | gBS->RestoreTPL (OldTpl);\r | |
372 | return Status;\r | |
373 | }\r | |
374 | \r | |
375 | \r | |
376 | /**\r | |
377 | Set information about a file\r | |
378 | \r | |
379 | @param File Protocol instance pointer.\r | |
380 | @param InformationType Type of information in Buffer.\r | |
381 | @param BufferSize Size of buffer.\r | |
382 | @param Buffer The data to write.\r | |
383 | \r | |
384 | @retval EFI_SUCCESS Data was set.\r | |
385 | @retval EFI_UNSUPPORTED InformationType is not supported.\r | |
386 | @retval EFI_NO_MEDIA The device has no media.\r | |
387 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
388 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
389 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
390 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
391 | \r | |
392 | **/\r | |
393 | EFI_STATUS\r | |
394 | EFIAPI\r | |
395 | EmuSimpleFileSystemSetInfo (\r | |
396 | IN EFI_FILE_PROTOCOL*This,\r | |
397 | IN EFI_GUID *InformationType,\r | |
398 | IN UINTN BufferSize,\r | |
399 | IN VOID *Buffer\r | |
400 | )\r | |
401 | {\r | |
402 | EFI_STATUS Status;\r | |
403 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
404 | EFI_TPL OldTpl;\r | |
405 | \r | |
406 | //\r | |
407 | // Check for invalid parameters.\r | |
408 | //\r | |
409 | if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {\r | |
410 | return EFI_INVALID_PARAMETER;\r | |
411 | }\r | |
412 | \r | |
413 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 414 | \r |
949f388f | 415 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
416 | \r | |
417 | Status = PrivateFile->Io->SetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r | |
418 | \r | |
d18d8a1d | 419 | gBS->RestoreTPL (OldTpl);\r |
949f388f | 420 | return Status;\r |
421 | }\r | |
422 | \r | |
423 | \r | |
424 | /**\r | |
425 | Flush data back for the file handle.\r | |
426 | \r | |
427 | @param This Protocol instance pointer.\r | |
428 | \r | |
429 | @retval EFI_SUCCESS Data was flushed.\r | |
430 | @retval EFI_UNSUPPORTED Writes to Open directory are not supported.\r | |
431 | @retval EFI_NO_MEDIA The device has no media.\r | |
432 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
433 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
434 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
435 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
436 | @retval EFI_VOLUME_FULL The volume is full.\r | |
437 | \r | |
438 | **/\r | |
439 | EFI_STATUS\r | |
440 | EFIAPI\r | |
441 | EmuSimpleFileSystemFlush (\r | |
442 | IN EFI_FILE_PROTOCOL *This\r | |
443 | )\r | |
444 | {\r | |
445 | EFI_STATUS Status;\r | |
446 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
447 | EFI_TPL OldTpl;\r | |
448 | \r | |
449 | if (This == NULL) {\r | |
450 | return EFI_INVALID_PARAMETER;\r | |
451 | }\r | |
452 | \r | |
453 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
d18d8a1d | 454 | \r |
949f388f | 455 | PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r |
456 | \r | |
457 | Status = PrivateFile->Io->Flush (PrivateFile->Io);\r | |
458 | \r | |
459 | gBS->RestoreTPL (OldTpl);\r | |
460 | return Status;\r | |
461 | }\r | |
462 | \r | |
463 | \r | |
464 | \r | |
465 | /**\r | |
466 | Open the root directory on a volume.\r | |
467 | \r | |
468 | @param This Protocol instance pointer.\r | |
469 | @param Root Returns an Open file handle for the root directory\r | |
470 | \r | |
471 | @retval EFI_SUCCESS The device was opened.\r | |
472 | @retval EFI_UNSUPPORTED This volume does not support the file system.\r | |
473 | @retval EFI_NO_MEDIA The device has no media.\r | |
474 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
475 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
476 | @retval EFI_ACCESS_DENIED The service denied access to the file.\r | |
477 | @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r | |
478 | \r | |
479 | **/\r | |
480 | EFI_STATUS\r | |
481 | EFIAPI\r | |
482 | EmuSimpleFileSystemOpenVolume (\r | |
483 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r | |
484 | OUT EFI_FILE_PROTOCOL **Root\r | |
485 | )\r | |
486 | {\r | |
487 | EFI_STATUS Status;\r | |
488 | EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r | |
489 | EMU_EFI_FILE_PRIVATE *PrivateFile;\r | |
490 | EFI_TPL OldTpl;\r | |
491 | \r | |
54e0b04c | 492 | Status = EFI_UNSUPPORTED;\r |
493 | \r | |
949f388f | 494 | if (This == NULL || Root == NULL) {\r |
495 | return EFI_INVALID_PARAMETER;\r | |
496 | }\r | |
497 | \r | |
498 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
499 | \r | |
500 | Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r | |
501 | \r | |
502 | PrivateFile = AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE));\r | |
503 | if (PrivateFile == NULL) {\r | |
dda74d6d | 504 | Status = EFI_OUT_OF_RESOURCES;\r |
949f388f | 505 | goto Done;\r |
506 | }\r | |
d18d8a1d | 507 | \r |
949f388f | 508 | PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;\r |
509 | PrivateFile->IoThunk = Private->IoThunk;\r | |
510 | PrivateFile->SimpleFileSystem = This;\r | |
511 | PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r | |
512 | PrivateFile->EfiFile.Open = EmuSimpleFileSystemOpen;\r | |
513 | PrivateFile->EfiFile.Close = EmuSimpleFileSystemClose;\r | |
514 | PrivateFile->EfiFile.Delete = EmuSimpleFileSystemDelete;\r | |
515 | PrivateFile->EfiFile.Read = EmuSimpleFileSystemRead;\r | |
516 | PrivateFile->EfiFile.Write = EmuSimpleFileSystemWrite;\r | |
517 | PrivateFile->EfiFile.GetPosition = EmuSimpleFileSystemGetPosition;\r | |
518 | PrivateFile->EfiFile.SetPosition = EmuSimpleFileSystemSetPosition;\r | |
519 | PrivateFile->EfiFile.GetInfo = EmuSimpleFileSystemGetInfo;\r | |
520 | PrivateFile->EfiFile.SetInfo = EmuSimpleFileSystemSetInfo;\r | |
521 | PrivateFile->EfiFile.Flush = EmuSimpleFileSystemFlush;\r | |
522 | \r | |
523 | *Root = &PrivateFile->EfiFile;\r | |
524 | \r | |
525 | Status = Private->Io->OpenVolume (Private->Io, &PrivateFile->Io);\r | |
526 | if (EFI_ERROR (Status)) {\r | |
527 | goto Done;\r | |
528 | }\r | |
d18d8a1d | 529 | \r |
949f388f | 530 | AddUnicodeString2 (\r |
531 | "eng",\r | |
532 | gEmuSimpleFileSystemComponentName.SupportedLanguages,\r | |
533 | &Private->ControllerNameTable,\r | |
534 | Private->IoThunk->ConfigString,\r | |
535 | TRUE\r | |
536 | );\r | |
537 | \r | |
538 | AddUnicodeString2 (\r | |
539 | "en",\r | |
540 | gEmuSimpleFileSystemComponentName.SupportedLanguages,\r | |
541 | &Private->ControllerNameTable,\r | |
542 | Private->IoThunk->ConfigString,\r | |
543 | FALSE\r | |
544 | );\r | |
545 | \r | |
546 | \r | |
547 | Done:\r | |
548 | if (EFI_ERROR (Status)) {\r | |
549 | if (PrivateFile) {\r | |
550 | gBS->FreePool (PrivateFile);\r | |
551 | }\r | |
d18d8a1d | 552 | \r |
949f388f | 553 | *Root = NULL;\r |
554 | }\r | |
555 | \r | |
556 | gBS->RestoreTPL (OldTpl);\r | |
557 | \r | |
558 | return Status;\r | |
559 | }\r | |
560 | \r | |
561 | /**\r | |
d18d8a1d | 562 | Tests to see if this driver supports a given controller. If a child device is provided,\r |
949f388f | 563 | it further tests to see if this driver supports creating a handle for the specified child device.\r |
564 | \r | |
d18d8a1d | 565 | This function checks to see if the driver specified by This supports the device specified by\r |
566 | ControllerHandle. Drivers will typically use the device path attached to\r | |
567 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
568 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
569 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
570 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
571 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
572 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
573 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
574 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
575 | Because ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
576 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
949f388f | 577 | to guarantee the state of ControllerHandle is not modified by this function.\r |
578 | \r | |
579 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
d18d8a1d | 580 | @param[in] ControllerHandle The handle of the controller to test. This handle\r |
581 | must support a protocol interface that supplies\r | |
949f388f | 582 | an I/O abstraction to the driver.\r |
d18d8a1d | 583 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
584 | parameter is ignored by device drivers, and is optional for bus\r | |
585 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
586 | the bus driver must determine if the bus controller specified\r | |
587 | by ControllerHandle and the child controller specified\r | |
588 | by RemainingDevicePath are both supported by this\r | |
949f388f | 589 | bus driver.\r |
590 | \r | |
591 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
592 | RemainingDevicePath is supported by the driver specified by This.\r | |
593 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
594 | RemainingDevicePath is already being managed by the driver\r | |
595 | specified by This.\r | |
596 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
597 | RemainingDevicePath is already being managed by a different\r | |
598 | driver or an application that requires exclusive access.\r | |
599 | Currently not implemented.\r | |
600 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
601 | RemainingDevicePath is not supported by the driver specified by This.\r | |
602 | **/\r | |
603 | EFI_STATUS\r | |
604 | EFIAPI\r | |
605 | EmuSimpleFileSystemDriverBindingSupported (\r | |
606 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
607 | IN EFI_HANDLE ControllerHandle,\r | |
608 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
609 | )\r | |
610 | {\r | |
611 | EFI_STATUS Status;\r | |
612 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
613 | \r | |
614 | //\r | |
615 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
616 | //\r | |
617 | Status = gBS->OpenProtocol (\r | |
618 | ControllerHandle,\r | |
619 | &gEmuIoThunkProtocolGuid,\r | |
620 | (VOID **)&EmuIoThunk,\r | |
621 | This->DriverBindingHandle,\r | |
622 | ControllerHandle,\r | |
623 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
624 | );\r | |
625 | if (EFI_ERROR (Status)) {\r | |
626 | return Status;\r | |
627 | }\r | |
628 | \r | |
629 | //\r | |
630 | // Make sure GUID is for a File System handle.\r | |
631 | //\r | |
632 | Status = EFI_UNSUPPORTED;\r | |
633 | if (CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r | |
634 | Status = EFI_SUCCESS;\r | |
635 | }\r | |
636 | \r | |
637 | //\r | |
638 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
639 | //\r | |
640 | gBS->CloseProtocol (\r | |
641 | ControllerHandle,\r | |
642 | &gEmuIoThunkProtocolGuid,\r | |
643 | This->DriverBindingHandle,\r | |
644 | ControllerHandle\r | |
645 | );\r | |
646 | \r | |
647 | return Status;\r | |
648 | }\r | |
649 | \r | |
650 | \r | |
651 | \r | |
652 | /**\r | |
653 | Starts a device controller or a bus controller.\r | |
654 | \r | |
655 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
d18d8a1d | 656 | As a result, much of the error checking on the parameters to Start() has been moved into this\r |
657 | common boot service. It is legal to call Start() from other locations,\r | |
949f388f | 658 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
659 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
660 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
661 | EFI_DEVICE_PATH_PROTOCOL.\r | |
662 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
d18d8a1d | 663 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
949f388f | 664 | \r |
665 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
d18d8a1d | 666 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
667 | must support a protocol interface that supplies\r | |
949f388f | 668 | an I/O abstraction to the driver.\r |
d18d8a1d | 669 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
670 | parameter is ignored by device drivers, and is optional for bus\r | |
671 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
672 | for all the children of Controller are created by this driver.\r | |
673 | If this parameter is not NULL and the first Device Path Node is\r | |
674 | not the End of Device Path Node, then only the handle for the\r | |
675 | child device specified by the first Device Path Node of\r | |
949f388f | 676 | RemainingDevicePath is created by this driver.\r |
d18d8a1d | 677 | If the first Device Path Node of RemainingDevicePath is\r |
949f388f | 678 | the End of Device Path Node, no child handle is created by this\r |
679 | driver.\r | |
680 | \r | |
681 | @retval EFI_SUCCESS The device was started.\r | |
682 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
683 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
684 | @retval Others The driver failded to start the device.\r | |
685 | \r | |
686 | **/\r | |
687 | EFI_STATUS\r | |
688 | EFIAPI\r | |
689 | EmuSimpleFileSystemDriverBindingStart (\r | |
690 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
691 | IN EFI_HANDLE ControllerHandle,\r | |
692 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
693 | )\r | |
694 | {\r | |
695 | EFI_STATUS Status;\r | |
696 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
697 | EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r | |
949f388f | 698 | \r |
699 | Private = NULL;\r | |
700 | \r | |
701 | //\r | |
702 | // Open the IO Abstraction(s) needed\r | |
703 | //\r | |
704 | Status = gBS->OpenProtocol (\r | |
705 | ControllerHandle,\r | |
706 | &gEmuIoThunkProtocolGuid,\r | |
707 | (VOID **)&EmuIoThunk,\r | |
708 | This->DriverBindingHandle,\r | |
709 | ControllerHandle,\r | |
710 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
711 | );\r | |
712 | if (EFI_ERROR (Status)) {\r | |
713 | return Status;\r | |
714 | }\r | |
715 | \r | |
716 | //\r | |
717 | // Validate GUID\r | |
718 | //\r | |
719 | if (!CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r | |
720 | Status = EFI_UNSUPPORTED;\r | |
721 | goto Done;\r | |
722 | }\r | |
723 | \r | |
7e284acb | 724 | Private = AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));\r |
949f388f | 725 | if (Private == NULL) {\r |
dda74d6d | 726 | Status = EFI_OUT_OF_RESOURCES;\r |
949f388f | 727 | goto Done;\r |
728 | }\r | |
729 | \r | |
730 | Status = EmuIoThunk->Open (EmuIoThunk);\r | |
731 | if (EFI_ERROR (Status)) {\r | |
732 | goto Done;\r | |
733 | }\r | |
734 | \r | |
735 | Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;\r | |
736 | Private->IoThunk = EmuIoThunk;\r | |
737 | Private->Io = EmuIoThunk->Interface;\r | |
d18d8a1d | 738 | \r |
949f388f | 739 | Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r |
740 | Private->SimpleFileSystem.OpenVolume = EmuSimpleFileSystemOpenVolume;\r | |
741 | \r | |
742 | Private->ControllerNameTable = NULL;\r | |
743 | \r | |
744 | AddUnicodeString2 (\r | |
745 | "eng",\r | |
746 | gEmuSimpleFileSystemComponentName.SupportedLanguages,\r | |
747 | &Private->ControllerNameTable,\r | |
748 | EmuIoThunk->ConfigString,\r | |
749 | TRUE\r | |
750 | );\r | |
d18d8a1d | 751 | \r |
949f388f | 752 | AddUnicodeString2 (\r |
753 | "en",\r | |
754 | gEmuSimpleFileSystemComponentName2.SupportedLanguages,\r | |
755 | &Private->ControllerNameTable,\r | |
756 | EmuIoThunk->ConfigString,\r | |
757 | FALSE\r | |
758 | );\r | |
759 | \r | |
760 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
761 | &ControllerHandle,\r | |
762 | &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r | |
763 | NULL\r | |
764 | );\r | |
765 | \r | |
766 | Done:\r | |
767 | if (EFI_ERROR (Status)) {\r | |
768 | if (Private != NULL) {\r | |
769 | if (Private->ControllerNameTable != NULL) {\r | |
770 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
771 | }\r | |
d18d8a1d | 772 | \r |
949f388f | 773 | gBS->FreePool (Private);\r |
d18d8a1d | 774 | \r |
949f388f | 775 | }\r |
776 | \r | |
777 | gBS->CloseProtocol (\r | |
778 | ControllerHandle,\r | |
779 | &gEmuIoThunkProtocolGuid,\r | |
780 | This->DriverBindingHandle,\r | |
781 | ControllerHandle\r | |
782 | );\r | |
783 | }\r | |
784 | \r | |
785 | return Status;\r | |
786 | }\r | |
787 | \r | |
788 | \r | |
789 | /**\r | |
790 | Stops a device controller or a bus controller.\r | |
d18d8a1d | 791 | \r |
792 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
793 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
794 | into this common boot service. It is legal to call Stop() from other locations,\r | |
949f388f | 795 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
796 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
797 | same driver's Start() function.\r | |
798 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
799 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
800 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
801 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
d18d8a1d | 802 | \r |
949f388f | 803 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
d18d8a1d | 804 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
805 | support a bus specific I/O protocol for the driver\r | |
949f388f | 806 | to use to stop the device.\r |
807 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
d18d8a1d | 808 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
949f388f | 809 | if NumberOfChildren is 0.\r |
810 | \r | |
811 | @retval EFI_SUCCESS The device was stopped.\r | |
812 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
813 | \r | |
814 | **/\r | |
815 | EFI_STATUS\r | |
816 | EFIAPI\r | |
817 | EmuSimpleFileSystemDriverBindingStop (\r | |
818 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
819 | IN EFI_HANDLE ControllerHandle,\r | |
820 | IN UINTN NumberOfChildren,\r | |
821 | IN EFI_HANDLE *ChildHandleBuffer\r | |
822 | )\r | |
823 | {\r | |
824 | EFI_STATUS Status;\r | |
825 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r | |
826 | EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r | |
827 | \r | |
828 | //\r | |
829 | // Get our context back\r | |
830 | //\r | |
831 | Status = gBS->OpenProtocol (\r | |
832 | ControllerHandle,\r | |
833 | &gEfiSimpleFileSystemProtocolGuid,\r | |
834 | (VOID **)&SimpleFileSystem,\r | |
835 | This->DriverBindingHandle,\r | |
836 | ControllerHandle,\r | |
837 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
838 | );\r | |
839 | if (EFI_ERROR (Status)) {\r | |
840 | return EFI_UNSUPPORTED;\r | |
841 | }\r | |
842 | \r | |
843 | Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r | |
844 | Status = Private->IoThunk->Close (Private->IoThunk);\r | |
845 | \r | |
846 | //\r | |
847 | // Uninstall the Simple File System Protocol from ControllerHandle\r | |
848 | //\r | |
849 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
850 | ControllerHandle,\r | |
851 | &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r | |
852 | NULL\r | |
853 | );\r | |
854 | if (!EFI_ERROR (Status)) {\r | |
855 | Status = gBS->CloseProtocol (\r | |
856 | ControllerHandle,\r | |
857 | &gEmuIoThunkProtocolGuid,\r | |
858 | This->DriverBindingHandle,\r | |
859 | ControllerHandle\r | |
860 | );\r | |
861 | }\r | |
862 | \r | |
863 | if (!EFI_ERROR (Status)) {\r | |
864 | //\r | |
865 | // Free our instance data\r | |
866 | //\r | |
867 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
868 | gBS->FreePool (Private);\r | |
869 | }\r | |
870 | \r | |
871 | return Status;\r | |
872 | }\r | |
873 | \r | |
874 | \r | |
875 | EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding = {\r | |
876 | EmuSimpleFileSystemDriverBindingSupported,\r | |
877 | EmuSimpleFileSystemDriverBindingStart,\r | |
878 | EmuSimpleFileSystemDriverBindingStop,\r | |
879 | 0xa,\r | |
880 | NULL,\r | |
881 | NULL\r | |
882 | };\r | |
883 | \r | |
884 | \r | |
885 | \r | |
886 | \r | |
887 | /**\r | |
888 | The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.\r | |
889 | \r | |
d18d8a1d | 890 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r |
949f388f | 891 | @param[in] SystemTable A pointer to the EFI System Table.\r |
d18d8a1d | 892 | \r |
949f388f | 893 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
894 | @retval other Some error occurs when executing this entry point.\r | |
895 | \r | |
896 | **/\r | |
897 | EFI_STATUS\r | |
898 | EFIAPI\r | |
899 | InitializeEmuSimpleFileSystem(\r | |
900 | IN EFI_HANDLE ImageHandle,\r | |
901 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
902 | )\r | |
903 | {\r | |
904 | EFI_STATUS Status;\r | |
905 | \r | |
906 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
907 | ImageHandle,\r | |
908 | SystemTable,\r | |
909 | &gEmuSimpleFileSystemDriverBinding,\r | |
910 | ImageHandle,\r | |
911 | &gEmuSimpleFileSystemComponentName,\r | |
912 | &gEmuSimpleFileSystemComponentName2\r | |
913 | );\r | |
914 | ASSERT_EFI_ERROR (Status);\r | |
915 | \r | |
916 | return Status;\r | |
917 | }\r |