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