]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
Add support for SerialPortLib that maps into POSIX StdIn and StdOut. Add a device...
[mirror_edk2.git] / InOsEmuPkg / EmuSimpleFileSystemDxe / EmuSimpleFileSystem.c
CommitLineData
949f388f 1/*++ @file\r
2 Produce Simple File System abstractions for directories on your PC using Posix APIs.\r
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
5 Developer Studio for them to work.\r
6\r
224e1333 7Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
949f388f 8Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
224e1333 9This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT 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
44EFI_STATUS\r
45EFIAPI\r
46EmuSimpleFileSystemOpen (\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
99EFI_STATUS\r
100EFIAPI\r
101EmuSimpleFileSystemClose (\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
123 \r
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
132 \r
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
137EFI_STATUS\r
138EFIAPI\r
139EmuSimpleFileSystemDelete (\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
152 \r
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
180EFI_STATUS\r
181EFIAPI\r
182EmuSimpleFileSystemRead (\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
195 \r
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
202 \r
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
230EFI_STATUS\r
231EFIAPI\r
232EmuSimpleFileSystemWrite (\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
258 Set a files current position\r
259\r
260 @param This Protocol instance pointer.\r
261 @param Position Byte position from the start of the file.\r
262 \r
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
267EFI_STATUS\r
268EFIAPI\r
269EmuSimpleFileSystemGetPosition (\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
283 \r
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
295 Get a file's current position\r
296\r
297 @param This Protocol instance pointer.\r
298 @param Position Byte position from the start of the file.\r
299 \r
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
304EFI_STATUS\r
305EFIAPI\r
306EmuSimpleFileSystemSetPosition (\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
320 \r
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
348EFI_STATUS\r
349EFIAPI\r
350EmuSimpleFileSystemGetInfo (\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
366 \r
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
393EFI_STATUS\r
394EFIAPI\r
395EmuSimpleFileSystemSetInfo (\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
414 \r
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
419 gBS->RestoreTPL (OldTpl); \r
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
439EFI_STATUS\r
440EFIAPI\r
441EmuSimpleFileSystemFlush (\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
454 \r
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
480EFI_STATUS\r
481EFIAPI\r
482EmuSimpleFileSystemOpenVolume (\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
492 if (This == NULL || Root == NULL) {\r
493 return EFI_INVALID_PARAMETER;\r
494 }\r
495\r
496 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
497\r
498 Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r
499\r
500 PrivateFile = AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE));\r
501 if (PrivateFile == NULL) {\r
502 goto Done;\r
503 }\r
504 \r
505 PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;\r
506 PrivateFile->IoThunk = Private->IoThunk;\r
507 PrivateFile->SimpleFileSystem = This;\r
508 PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
509 PrivateFile->EfiFile.Open = EmuSimpleFileSystemOpen;\r
510 PrivateFile->EfiFile.Close = EmuSimpleFileSystemClose;\r
511 PrivateFile->EfiFile.Delete = EmuSimpleFileSystemDelete;\r
512 PrivateFile->EfiFile.Read = EmuSimpleFileSystemRead;\r
513 PrivateFile->EfiFile.Write = EmuSimpleFileSystemWrite;\r
514 PrivateFile->EfiFile.GetPosition = EmuSimpleFileSystemGetPosition;\r
515 PrivateFile->EfiFile.SetPosition = EmuSimpleFileSystemSetPosition;\r
516 PrivateFile->EfiFile.GetInfo = EmuSimpleFileSystemGetInfo;\r
517 PrivateFile->EfiFile.SetInfo = EmuSimpleFileSystemSetInfo;\r
518 PrivateFile->EfiFile.Flush = EmuSimpleFileSystemFlush;\r
519\r
520 *Root = &PrivateFile->EfiFile;\r
521\r
522 Status = Private->Io->OpenVolume (Private->Io, &PrivateFile->Io);\r
523 if (EFI_ERROR (Status)) {\r
524 goto Done;\r
525 }\r
526 \r
527 AddUnicodeString2 (\r
528 "eng",\r
529 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
530 &Private->ControllerNameTable,\r
531 Private->IoThunk->ConfigString,\r
532 TRUE\r
533 );\r
534\r
535 AddUnicodeString2 (\r
536 "en",\r
537 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
538 &Private->ControllerNameTable,\r
539 Private->IoThunk->ConfigString,\r
540 FALSE\r
541 );\r
542\r
543\r
544Done:\r
545 if (EFI_ERROR (Status)) {\r
546 if (PrivateFile) {\r
547 gBS->FreePool (PrivateFile);\r
548 }\r
549 \r
550 *Root = NULL;\r
551 }\r
552\r
553 gBS->RestoreTPL (OldTpl);\r
554\r
555 return Status;\r
556}\r
557\r
558/**\r
559 Tests to see if this driver supports a given controller. If a child device is provided, \r
560 it further tests to see if this driver supports creating a handle for the specified child device.\r
561\r
562 This function checks to see if the driver specified by This supports the device specified by \r
563 ControllerHandle. Drivers will typically use the device path attached to \r
564 ControllerHandle and/or the services from the bus I/O abstraction attached to \r
565 ControllerHandle to determine if the driver supports ControllerHandle. This function \r
566 may be called many times during platform initialization. In order to reduce boot times, the tests \r
567 performed by this function must be very small, and take as little time as possible to execute. This \r
568 function must not change the state of any hardware devices, and this function must be aware that the \r
569 device specified by ControllerHandle may already be managed by the same driver or a \r
570 different driver. This function must match its calls to AllocatePages() with FreePages(), \r
571 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r
572 Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
573 already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
574 to guarantee the state of ControllerHandle is not modified by this function.\r
575\r
576 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
577 @param[in] ControllerHandle The handle of the controller to test. This handle \r
578 must support a protocol interface that supplies \r
579 an I/O abstraction to the driver.\r
580 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
581 parameter is ignored by device drivers, and is optional for bus \r
582 drivers. For bus drivers, if this parameter is not NULL, then \r
583 the bus driver must determine if the bus controller specified \r
584 by ControllerHandle and the child controller specified \r
585 by RemainingDevicePath are both supported by this \r
586 bus driver.\r
587\r
588 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
589 RemainingDevicePath is supported by the driver specified by This.\r
590 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
591 RemainingDevicePath is already being managed by the driver\r
592 specified by This.\r
593 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
594 RemainingDevicePath is already being managed by a different\r
595 driver or an application that requires exclusive access.\r
596 Currently not implemented.\r
597 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
598 RemainingDevicePath is not supported by the driver specified by This.\r
599**/\r
600EFI_STATUS\r
601EFIAPI\r
602EmuSimpleFileSystemDriverBindingSupported (\r
603 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
604 IN EFI_HANDLE ControllerHandle,\r
605 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
606 )\r
607{\r
608 EFI_STATUS Status;\r
609 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
610\r
611 //\r
612 // Open the IO Abstraction(s) needed to perform the supported test\r
613 //\r
614 Status = gBS->OpenProtocol (\r
615 ControllerHandle,\r
616 &gEmuIoThunkProtocolGuid,\r
617 (VOID **)&EmuIoThunk,\r
618 This->DriverBindingHandle,\r
619 ControllerHandle,\r
620 EFI_OPEN_PROTOCOL_BY_DRIVER\r
621 );\r
622 if (EFI_ERROR (Status)) {\r
623 return Status;\r
624 }\r
625\r
626 //\r
627 // Make sure GUID is for a File System handle.\r
628 //\r
629 Status = EFI_UNSUPPORTED;\r
630 if (CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
631 Status = EFI_SUCCESS;\r
632 }\r
633\r
634 //\r
635 // Close the I/O Abstraction(s) used to perform the supported test\r
636 //\r
637 gBS->CloseProtocol (\r
638 ControllerHandle,\r
639 &gEmuIoThunkProtocolGuid,\r
640 This->DriverBindingHandle,\r
641 ControllerHandle\r
642 );\r
643\r
644 return Status;\r
645}\r
646\r
647\r
648\r
649/**\r
650 Starts a device controller or a bus controller.\r
651\r
652 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
653 As a result, much of the error checking on the parameters to Start() has been moved into this \r
654 common boot service. It is legal to call Start() from other locations, \r
655 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
656 1. ControllerHandle must be a valid EFI_HANDLE.\r
657 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
658 EFI_DEVICE_PATH_PROTOCOL.\r
659 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
660 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r
661\r
662 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
663 @param[in] ControllerHandle The handle of the controller to start. This handle \r
664 must support a protocol interface that supplies \r
665 an I/O abstraction to the driver.\r
666 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
667 parameter is ignored by device drivers, and is optional for bus \r
668 drivers. For a bus driver, if this parameter is NULL, then handles \r
669 for all the children of Controller are created by this driver. \r
670 If this parameter is not NULL and the first Device Path Node is \r
671 not the End of Device Path Node, then only the handle for the \r
672 child device specified by the first Device Path Node of \r
673 RemainingDevicePath is created by this driver.\r
674 If the first Device Path Node of RemainingDevicePath is \r
675 the End of Device Path Node, no child handle is created by this\r
676 driver.\r
677\r
678 @retval EFI_SUCCESS The device was started.\r
679 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
680 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
681 @retval Others The driver failded to start the device.\r
682\r
683**/\r
684EFI_STATUS\r
685EFIAPI\r
686EmuSimpleFileSystemDriverBindingStart (\r
687 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
688 IN EFI_HANDLE ControllerHandle,\r
689 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
690 )\r
691{\r
692 EFI_STATUS Status;\r
693 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
694 EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
949f388f 695\r
696 Private = NULL;\r
697\r
698 //\r
699 // Open the IO Abstraction(s) needed\r
700 //\r
701 Status = gBS->OpenProtocol (\r
702 ControllerHandle,\r
703 &gEmuIoThunkProtocolGuid,\r
704 (VOID **)&EmuIoThunk,\r
705 This->DriverBindingHandle,\r
706 ControllerHandle,\r
707 EFI_OPEN_PROTOCOL_BY_DRIVER\r
708 );\r
709 if (EFI_ERROR (Status)) {\r
710 return Status;\r
711 }\r
712\r
713 //\r
714 // Validate GUID\r
715 //\r
716 if (!CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
717 Status = EFI_UNSUPPORTED;\r
718 goto Done;\r
719 }\r
720\r
7e284acb 721 Private = AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));\r
949f388f 722 if (Private == NULL) {\r
723 goto Done;\r
724 }\r
725\r
726 Status = EmuIoThunk->Open (EmuIoThunk);\r
727 if (EFI_ERROR (Status)) {\r
728 goto Done;\r
729 }\r
730\r
731 Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;\r
732 Private->IoThunk = EmuIoThunk;\r
733 Private->Io = EmuIoThunk->Interface;\r
734 \r
735 Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
736 Private->SimpleFileSystem.OpenVolume = EmuSimpleFileSystemOpenVolume;\r
737\r
738 Private->ControllerNameTable = NULL;\r
739\r
740 AddUnicodeString2 (\r
741 "eng",\r
742 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
743 &Private->ControllerNameTable,\r
744 EmuIoThunk->ConfigString,\r
745 TRUE\r
746 );\r
747 \r
748 AddUnicodeString2 (\r
749 "en",\r
750 gEmuSimpleFileSystemComponentName2.SupportedLanguages,\r
751 &Private->ControllerNameTable,\r
752 EmuIoThunk->ConfigString,\r
753 FALSE\r
754 );\r
755\r
756 Status = gBS->InstallMultipleProtocolInterfaces (\r
757 &ControllerHandle,\r
758 &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r
759 NULL\r
760 );\r
761\r
762Done:\r
763 if (EFI_ERROR (Status)) {\r
764 if (Private != NULL) {\r
765 if (Private->ControllerNameTable != NULL) {\r
766 FreeUnicodeStringTable (Private->ControllerNameTable);\r
767 }\r
768 \r
769 gBS->FreePool (Private);\r
770 \r
771 }\r
772\r
773 gBS->CloseProtocol (\r
774 ControllerHandle,\r
775 &gEmuIoThunkProtocolGuid,\r
776 This->DriverBindingHandle,\r
777 ControllerHandle\r
778 );\r
779 }\r
780\r
781 return Status;\r
782}\r
783\r
784\r
785/**\r
786 Stops a device controller or a bus controller.\r
787 \r
788 The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
789 As a result, much of the error checking on the parameters to Stop() has been moved \r
790 into this common boot service. It is legal to call Stop() from other locations, \r
791 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
792 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
793 same driver's Start() function.\r
794 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
795 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
796 Start() function, and the Start() function must have called OpenProtocol() on\r
797 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
798 \r
799 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
800 @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
801 support a bus specific I/O protocol for the driver \r
802 to use to stop the device.\r
803 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
804 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
805 if NumberOfChildren is 0.\r
806\r
807 @retval EFI_SUCCESS The device was stopped.\r
808 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
809\r
810**/\r
811EFI_STATUS\r
812EFIAPI\r
813EmuSimpleFileSystemDriverBindingStop (\r
814 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
815 IN EFI_HANDLE ControllerHandle,\r
816 IN UINTN NumberOfChildren,\r
817 IN EFI_HANDLE *ChildHandleBuffer\r
818 )\r
819{\r
820 EFI_STATUS Status;\r
821 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
822 EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
823\r
824 //\r
825 // Get our context back\r
826 //\r
827 Status = gBS->OpenProtocol (\r
828 ControllerHandle,\r
829 &gEfiSimpleFileSystemProtocolGuid,\r
830 (VOID **)&SimpleFileSystem,\r
831 This->DriverBindingHandle,\r
832 ControllerHandle,\r
833 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
834 );\r
835 if (EFI_ERROR (Status)) {\r
836 return EFI_UNSUPPORTED;\r
837 }\r
838\r
839 Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
840 Status = Private->IoThunk->Close (Private->IoThunk);\r
841\r
842 //\r
843 // Uninstall the Simple File System Protocol from ControllerHandle\r
844 //\r
845 Status = gBS->UninstallMultipleProtocolInterfaces (\r
846 ControllerHandle,\r
847 &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r
848 NULL\r
849 );\r
850 if (!EFI_ERROR (Status)) {\r
851 Status = gBS->CloseProtocol (\r
852 ControllerHandle,\r
853 &gEmuIoThunkProtocolGuid,\r
854 This->DriverBindingHandle,\r
855 ControllerHandle\r
856 );\r
857 }\r
858\r
859 if (!EFI_ERROR (Status)) {\r
860 //\r
861 // Free our instance data\r
862 //\r
863 FreeUnicodeStringTable (Private->ControllerNameTable);\r
864 gBS->FreePool (Private);\r
865 }\r
866\r
867 return Status;\r
868}\r
869\r
870\r
871EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding = {\r
872 EmuSimpleFileSystemDriverBindingSupported,\r
873 EmuSimpleFileSystemDriverBindingStart,\r
874 EmuSimpleFileSystemDriverBindingStop,\r
875 0xa,\r
876 NULL,\r
877 NULL\r
878};\r
879\r
880\r
881\r
882\r
883/**\r
884 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.\r
885\r
886 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
887 @param[in] SystemTable A pointer to the EFI System Table.\r
888 \r
889 @retval EFI_SUCCESS The entry point is executed successfully.\r
890 @retval other Some error occurs when executing this entry point.\r
891\r
892**/\r
893EFI_STATUS\r
894EFIAPI\r
895InitializeEmuSimpleFileSystem(\r
896 IN EFI_HANDLE ImageHandle,\r
897 IN EFI_SYSTEM_TABLE *SystemTable\r
898 )\r
899{\r
900 EFI_STATUS Status;\r
901\r
902 Status = EfiLibInstallDriverBindingComponentName2 (\r
903 ImageHandle,\r
904 SystemTable,\r
905 &gEmuSimpleFileSystemDriverBinding,\r
906 ImageHandle,\r
907 &gEmuSimpleFileSystemComponentName,\r
908 &gEmuSimpleFileSystemComponentName2\r
909 );\r
910 ASSERT_EFI_ERROR (Status);\r
911\r
912 return Status;\r
913}\r