]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c
9d9325c105ecb7666da8a6f88d0c0cbe0cf88628
[mirror_edk2.git] / UnixPkg / UnixSimpleFileSystemDxe / UnixSimpleFileSystem.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UnixSimpleFileSystem.c
15
16 Abstract:
17
18 Produce Simple File System abstractions for directories on your PC using Posix APIs.
19 The configuration of what devices to mount or emulate comes from UNIX
20 environment variables. The variables must be visible to the Microsoft*
21 Developer Studio for them to work.
22
23 * Other names and brands may be claimed as the property of others.
24
25 --*/
26
27 #include "UnixSimpleFileSystem.h"
28
29 EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding = {
30 UnixSimpleFileSystemDriverBindingSupported,
31 UnixSimpleFileSystemDriverBindingStart,
32 UnixSimpleFileSystemDriverBindingStop,
33 0xa,
34 NULL,
35 NULL
36 };
37
38
39 CHAR16 *
40 EfiStrChr (
41 IN CHAR16 *Str,
42 IN CHAR16 Chr
43 )
44 /*++
45
46 Routine Description:
47
48 Locate the first occurance of a character in a string.
49
50 Arguments:
51
52 Str - Pointer to NULL terminated unicode string.
53 Chr - Character to locate.
54
55 Returns:
56
57 If Str is NULL, then NULL is returned.
58 If Chr is not contained in Str, then NULL is returned.
59 If Chr is contained in Str, then a pointer to the first occurance of Chr in Str is returned.
60
61 --*/
62 {
63 if (Str == NULL) {
64 return Str;
65 }
66
67 while (*Str != '\0' && *Str != Chr) {
68 ++Str;
69 }
70
71 return (*Str == Chr) ? Str : NULL;
72 }
73
74 BOOLEAN
75 IsZero (
76 IN VOID *Buffer,
77 IN UINTN Length
78 )
79 /*++
80
81 Routine Description:
82
83 TODO: Add function description
84
85 Arguments:
86
87 Buffer - TODO: add argument description
88 Length - TODO: add argument description
89
90 Returns:
91
92 TODO: add return values
93
94 --*/
95 {
96 if (Buffer == NULL || Length == 0) {
97 return FALSE;
98 }
99
100 if (*(UINT8 *) Buffer != 0) {
101 return FALSE;
102 }
103
104 if (Length > 1) {
105 if (!CompareMem (Buffer, (UINT8 *) Buffer + 1, Length - 1)) {
106 return FALSE;
107 }
108 }
109
110 return TRUE;
111 }
112
113 VOID
114 CutPrefix (
115 IN CHAR8 *Str,
116 IN UINTN Count
117 )
118 /*++
119
120 Routine Description:
121
122 TODO: Add function description
123
124 Arguments:
125
126 Str - TODO: add argument description
127 Count - TODO: add argument description
128
129 Returns:
130
131 TODO: add return values
132
133 --*/
134 {
135 CHAR8 *Pointer;
136
137 if (AsciiStrLen (Str) < Count) {
138 ASSERT (0);
139 }
140
141 for (Pointer = Str; *(Pointer + Count); Pointer++) {
142 *Pointer = *(Pointer + Count);
143 }
144
145 *Pointer = *(Pointer + Count);
146 }
147
148
149
150 EFI_STATUS
151 EFIAPI
152 UnixSimpleFileSystemDriverBindingSupported (
153 IN EFI_DRIVER_BINDING_PROTOCOL *This,
154 IN EFI_HANDLE ControllerHandle,
155 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
156 )
157 /*++
158
159 Routine Description:
160
161 Check to see if the driver supports a given controller.
162
163 Arguments:
164
165 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
166
167 ControllerHandle - EFI handle of the controller to test.
168
169 RemainingDevicePath - Pointer to remaining portion of a device path.
170
171 Returns:
172
173 EFI_SUCCESS - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver
174 specified by This.
175
176 EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
177 the driver specified by This.
178
179 EFI_ACCESS_DENIED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
180 a different driver or an application that requires exclusive access.
181
182 EFI_UNSUPPORTED - The device specified by ControllerHandle and RemainingDevicePath is not supported by the
183 driver specified by This.
184
185 --*/
186 {
187 EFI_STATUS Status;
188 EFI_UNIX_IO_PROTOCOL *UnixIo;
189
190 //
191 // Open the IO Abstraction(s) needed to perform the supported test
192 //
193 Status = gBS->OpenProtocol (
194 ControllerHandle,
195 &gEfiUnixIoProtocolGuid,
196 (VOID **)&UnixIo,
197 This->DriverBindingHandle,
198 ControllerHandle,
199 EFI_OPEN_PROTOCOL_BY_DRIVER
200 );
201 if (EFI_ERROR (Status)) {
202 return Status;
203 }
204
205 //
206 // Make sure GUID is for a File System handle.
207 //
208 Status = EFI_UNSUPPORTED;
209 if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {
210 Status = EFI_SUCCESS;
211 }
212
213 //
214 // Close the I/O Abstraction(s) used to perform the supported test
215 //
216 gBS->CloseProtocol (
217 ControllerHandle,
218 &gEfiUnixIoProtocolGuid,
219 This->DriverBindingHandle,
220 ControllerHandle
221 );
222
223 return Status;
224 }
225
226 EFI_STATUS
227 EFIAPI
228 UnixSimpleFileSystemDriverBindingStart (
229 IN EFI_DRIVER_BINDING_PROTOCOL *This,
230 IN EFI_HANDLE ControllerHandle,
231 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
232 )
233 /*++
234
235 Routine Description:
236
237 Starts a device controller or a bus controller.
238
239 Arguments:
240
241 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
242
243 ControllerHandle - EFI handle of the controller to start.
244
245 RemainingDevicePath - Pointer to remaining portion of a device path.
246
247 Returns:
248
249 EFI_SUCCESS - The device or bus controller has been started.
250
251 EFI_DEVICE_ERROR - The device could not be started due to a device failure.
252
253 EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.
254
255 --*/
256 {
257 EFI_STATUS Status;
258 EFI_UNIX_IO_PROTOCOL *UnixIo;
259 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
260 INTN i;
261
262 Private = NULL;
263
264 //
265 // Open the IO Abstraction(s) needed
266 //
267 Status = gBS->OpenProtocol (
268 ControllerHandle,
269 &gEfiUnixIoProtocolGuid,
270 (VOID **)&UnixIo,
271 This->DriverBindingHandle,
272 ControllerHandle,
273 EFI_OPEN_PROTOCOL_BY_DRIVER
274 );
275 if (EFI_ERROR (Status)) {
276 return Status;
277 }
278
279 //
280 // Validate GUID
281 //
282 if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {
283 Status = EFI_UNSUPPORTED;
284 goto Done;
285 }
286
287 Status = gBS->AllocatePool (
288 EfiBootServicesData,
289 sizeof (UNIX_SIMPLE_FILE_SYSTEM_PRIVATE),
290 (VOID **)&Private
291 );
292 if (EFI_ERROR (Status)) {
293 goto Done;
294 }
295
296 Private->Signature = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
297 Private->UnixThunk = UnixIo->UnixThunk;
298 Private->FilePath = NULL;
299 Private->VolumeLabel = NULL;
300
301 Status = gBS->AllocatePool (
302 EfiBootServicesData,
303 StrLen (UnixIo->EnvString) + 1,
304 (VOID **)&Private->FilePath
305 );
306
307 if (EFI_ERROR (Status)) {
308 goto Done;
309 }
310
311 for (i = 0; UnixIo->EnvString[i] != 0; i++)
312 Private->FilePath[i] = UnixIo->EnvString[i];
313 Private->FilePath[i] = 0;
314
315 Private->VolumeLabel = NULL;
316 Status = gBS->AllocatePool (
317 EfiBootServicesData,
318 StrSize (L"EFI_EMULATED"),
319 (VOID **)&Private->VolumeLabel
320 );
321
322 if (EFI_ERROR (Status)) {
323 goto Done;
324 }
325
326 StrCpy (Private->VolumeLabel, L"EFI_EMULATED");
327
328 Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
329 Private->SimpleFileSystem.OpenVolume = UnixSimpleFileSystemOpenVolume;
330
331 Private->ControllerNameTable = NULL;
332
333 AddUnicodeString (
334 "eng",
335 gUnixSimpleFileSystemComponentName.SupportedLanguages,
336 &Private->ControllerNameTable,
337 UnixIo->EnvString
338 );
339
340 Status = gBS->InstallMultipleProtocolInterfaces (
341 &ControllerHandle,
342 &gEfiSimpleFileSystemProtocolGuid,
343 &Private->SimpleFileSystem,
344 NULL
345 );
346
347 Done:
348 if (EFI_ERROR (Status)) {
349
350 if (Private != NULL) {
351
352 if (Private->VolumeLabel != NULL)
353 gBS->FreePool (Private->VolumeLabel);
354 if (Private->FilePath != NULL)
355 gBS->FreePool (Private->FilePath);
356 FreeUnicodeStringTable (Private->ControllerNameTable);
357
358 gBS->FreePool (Private);
359 }
360
361 gBS->CloseProtocol (
362 ControllerHandle,
363 &gEfiUnixIoProtocolGuid,
364 This->DriverBindingHandle,
365 ControllerHandle
366 );
367 }
368
369 return Status;
370 }
371
372 EFI_STATUS
373 EFIAPI
374 UnixSimpleFileSystemDriverBindingStop (
375 IN EFI_DRIVER_BINDING_PROTOCOL *This,
376 IN EFI_HANDLE ControllerHandle,
377 IN UINTN NumberOfChildren,
378 IN EFI_HANDLE *ChildHandleBuffer
379 )
380 /*++
381
382 Routine Description:
383
384 TODO: Add function description
385
386 Arguments:
387
388 This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
389
390 ControllerHandle - A handle to the device to be stopped.
391
392 NumberOfChildren - The number of child device handles in ChildHandleBuffer.
393
394 ChildHandleBuffer - An array of child device handles to be freed.
395
396 Returns:
397
398 EFI_SUCCESS - The device has been stopped.
399
400 EFI_DEVICE_ERROR - The device could not be stopped due to a device failure.
401
402 --*/
403 // TODO: EFI_UNSUPPORTED - add return value to function comment
404 {
405 EFI_STATUS Status;
406 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
407 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
408
409 //
410 // Get our context back
411 //
412 Status = gBS->OpenProtocol (
413 ControllerHandle,
414 &gEfiSimpleFileSystemProtocolGuid,
415 (VOID **)&SimpleFileSystem,
416 This->DriverBindingHandle,
417 ControllerHandle,
418 EFI_OPEN_PROTOCOL_GET_PROTOCOL
419 );
420 if (EFI_ERROR (Status)) {
421 return EFI_UNSUPPORTED;
422 }
423
424 Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);
425
426 //
427 // Uninstall the Simple File System Protocol from ControllerHandle
428 //
429 Status = gBS->UninstallMultipleProtocolInterfaces (
430 ControllerHandle,
431 &gEfiSimpleFileSystemProtocolGuid,
432 &Private->SimpleFileSystem,
433 NULL
434 );
435 if (!EFI_ERROR (Status)) {
436 Status = gBS->CloseProtocol (
437 ControllerHandle,
438 &gEfiUnixIoProtocolGuid,
439 This->DriverBindingHandle,
440 ControllerHandle
441 );
442 }
443
444 if (!EFI_ERROR (Status)) {
445 //
446 // Free our instance data
447 //
448 FreeUnicodeStringTable (Private->ControllerNameTable);
449
450 gBS->FreePool (Private);
451 }
452
453 return Status;
454 }
455
456 EFI_STATUS
457 EFIAPI
458 UnixSimpleFileSystemOpenVolume (
459 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
460 OUT EFI_FILE **Root
461 )
462 /*++
463
464 Routine Description:
465
466 Open the root directory on a volume.
467
468 Arguments:
469
470 This - A pointer to the volume to open.
471
472 Root - A pointer to storage for the returned opened file handle of the root directory.
473
474 Returns:
475
476 EFI_SUCCESS - The volume was opened.
477
478 EFI_UNSUPPORTED - The volume does not support the requested file system type.
479
480 EFI_NO_MEDIA - The device has no media.
481
482 EFI_DEVICE_ERROR - The device reported an error.
483
484 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
485
486 EFI_ACCESS_DENIED - The service denied access to the file.
487
488 EFI_OUT_OF_RESOURCES - The file volume could not be opened due to lack of resources.
489
490 EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
491
492 --*/
493 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
494 {
495 EFI_STATUS Status;
496 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
497 UNIX_EFI_FILE_PRIVATE *PrivateFile;
498 EFI_TPL OldTpl;
499
500 if (This == NULL || Root == NULL) {
501 return EFI_INVALID_PARAMETER;
502 }
503 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
504
505 Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
506
507 PrivateFile = NULL;
508 Status = gBS->AllocatePool (
509 EfiBootServicesData,
510 sizeof (UNIX_EFI_FILE_PRIVATE),
511 (VOID **)&PrivateFile
512 );
513 if (EFI_ERROR (Status)) {
514 goto Done;
515 }
516
517 PrivateFile->FileName = NULL;
518 Status = gBS->AllocatePool (
519 EfiBootServicesData,
520 AsciiStrSize (Private->FilePath),
521 (VOID **)&PrivateFile->FileName
522 );
523 if (EFI_ERROR (Status)) {
524 goto Done;
525 }
526
527 AsciiStrCpy (PrivateFile->FileName, Private->FilePath);
528 PrivateFile->Signature = UNIX_EFI_FILE_PRIVATE_SIGNATURE;
529 PrivateFile->UnixThunk = Private->UnixThunk;
530 PrivateFile->SimpleFileSystem = This;
531 PrivateFile->IsRootDirectory = TRUE;
532 PrivateFile->IsDirectoryPath = TRUE;
533 PrivateFile->IsOpenedByRead = TRUE;
534 PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
535 PrivateFile->EfiFile.Open = UnixSimpleFileSystemOpen;
536 PrivateFile->EfiFile.Close = UnixSimpleFileSystemClose;
537 PrivateFile->EfiFile.Delete = UnixSimpleFileSystemDelete;
538 PrivateFile->EfiFile.Read = UnixSimpleFileSystemRead;
539 PrivateFile->EfiFile.Write = UnixSimpleFileSystemWrite;
540 PrivateFile->EfiFile.GetPosition = UnixSimpleFileSystemGetPosition;
541 PrivateFile->EfiFile.SetPosition = UnixSimpleFileSystemSetPosition;
542 PrivateFile->EfiFile.GetInfo = UnixSimpleFileSystemGetInfo;
543 PrivateFile->EfiFile.SetInfo = UnixSimpleFileSystemSetInfo;
544 PrivateFile->EfiFile.Flush = UnixSimpleFileSystemFlush;
545 PrivateFile->fd = -1;
546 PrivateFile->Dir = NULL;
547 PrivateFile->Dirent = NULL;
548
549 *Root = &PrivateFile->EfiFile;
550
551 PrivateFile->Dir = PrivateFile->UnixThunk->OpenDir(PrivateFile->FileName);
552
553 if (PrivateFile->Dir == NULL) {
554 Status = EFI_ACCESS_DENIED;
555 }
556 else {
557 Status = EFI_SUCCESS;
558 }
559
560 Done:
561 if (EFI_ERROR (Status)) {
562 if (PrivateFile) {
563 if (PrivateFile->FileName) {
564 gBS->FreePool (PrivateFile->FileName);
565 }
566
567 gBS->FreePool (PrivateFile);
568 }
569 }
570
571 gBS->RestoreTPL (OldTpl);
572
573 return Status;
574 }
575
576 EFI_STATUS
577 EFIAPI
578 UnixSimpleFileSystemOpen (
579 IN EFI_FILE *This,
580 OUT EFI_FILE **NewHandle,
581 IN CHAR16 *FileName,
582 IN UINT64 OpenMode,
583 IN UINT64 Attributes
584 )
585 /*++
586
587 Routine Description:
588
589 Open a file relative to the source file location.
590
591 Arguments:
592
593 This - A pointer to the source file location.
594
595 NewHandle - Pointer to storage for the new file handle.
596
597 FileName - Pointer to the file name to be opened.
598
599 OpenMode - File open mode information.
600
601 Attributes - File creation attributes.
602
603 Returns:
604
605 EFI_SUCCESS - The file was opened.
606
607 EFI_NOT_FOUND - The file could not be found in the volume.
608
609 EFI_NO_MEDIA - The device has no media.
610
611 EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
612
613 EFI_DEVICE_ERROR - The device reported an error.
614
615 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
616
617 EFI_WRITE_PROTECTED - The volume or file is write protected.
618
619 EFI_ACCESS_DENIED - The service denied access to the file.
620
621 EFI_OUT_OF_RESOURCES - Not enough resources were available to open the file.
622
623 EFI_VOLUME_FULL - There is not enough space left to create the new file.
624
625 --*/
626 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
627 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
628 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
629 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
630 {
631 EFI_FILE *Root;
632 UNIX_EFI_FILE_PRIVATE *PrivateFile;
633 UNIX_EFI_FILE_PRIVATE *NewPrivateFile;
634 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
635 EFI_STATUS Status;
636 CHAR16 *Src;
637 char *Dst;
638 CHAR8 *RealFileName;
639 char *ParseFileName;
640 char *GuardPointer;
641 CHAR8 TempChar;
642 UINTN Count;
643 BOOLEAN TrailingDash;
644 BOOLEAN LoopFinish;
645 UINTN InfoSize;
646 EFI_FILE_INFO *Info;
647
648 TrailingDash = FALSE;
649
650 //
651 // Check for obvious invalid parameters.
652 //
653 if (This == NULL || NewHandle == NULL || FileName == NULL) {
654 return EFI_INVALID_PARAMETER;
655 }
656
657 switch (OpenMode) {
658 case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
659 if (Attributes &~EFI_FILE_VALID_ATTR) {
660 return EFI_INVALID_PARAMETER;
661 }
662
663 if (Attributes & EFI_FILE_READ_ONLY) {
664 return EFI_INVALID_PARAMETER;
665 }
666
667 //
668 // fall through
669 //
670 case EFI_FILE_MODE_READ:
671 case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
672 break;
673
674 default:
675 return EFI_INVALID_PARAMETER;
676 }
677
678
679 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
680 PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
681 NewPrivateFile = NULL;
682
683 //
684 // BUGBUG: assume an open of root
685 // if current location, return current data
686 //
687 if (StrCmp (FileName, L"\\") == 0
688 || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) {
689 //
690 // BUGBUG: assume an open root
691 //
692 OpenRoot:
693 Status = UnixSimpleFileSystemOpenVolume (PrivateFile->SimpleFileSystem, &Root);
694 NewPrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);
695 goto Done;
696 }
697
698 if (FileName[StrLen (FileName) - 1] == L'\\') {
699 TrailingDash = TRUE;
700 FileName[StrLen (FileName) - 1] = 0;
701 }
702
703 //
704 // Attempt to open the file
705 //
706 Status = gBS->AllocatePool (
707 EfiBootServicesData,
708 sizeof (UNIX_EFI_FILE_PRIVATE),
709 (VOID **)&NewPrivateFile
710 );
711
712 if (EFI_ERROR (Status)) {
713 goto Done;
714 }
715
716 CopyMem (NewPrivateFile, PrivateFile, sizeof (UNIX_EFI_FILE_PRIVATE));
717
718 NewPrivateFile->FileName = NULL;
719 Status = gBS->AllocatePool (
720 EfiBootServicesData,
721 AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1,
722 (VOID **)&NewPrivateFile->FileName
723 );
724
725 if (EFI_ERROR (Status)) {
726 goto Done;
727 }
728
729 if (*FileName == L'\\') {
730 AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath);
731 // Skip first '\'.
732 Src = FileName + 1;
733 } else {
734 AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName);
735 Src = FileName;
736 }
737 Dst = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName);
738 GuardPointer = NewPrivateFile->FileName + AsciiStrLen(PrivateRoot->FilePath);
739 *Dst++ = '/';
740 // Convert unicode to ascii and '\' to '/'
741 while (*Src) {
742 if (*Src == '\\')
743 *Dst++ = '/';
744 else
745 *Dst++ = *Src;
746 Src++;
747 }
748 *Dst = 0;
749
750
751 //
752 // Get rid of . and .., except leading . or ..
753 //
754
755 //
756 // GuardPointer protect simplefilesystem root path not be destroyed
757 //
758
759 LoopFinish = FALSE;
760
761 while (!LoopFinish) {
762
763 LoopFinish = TRUE;
764
765 for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {
766 if (*ParseFileName == '.' &&
767 (*(ParseFileName + 1) == 0 || *(ParseFileName + 1) == '/') &&
768 *(ParseFileName - 1) == '/'
769 ) {
770
771 //
772 // cut /.
773 //
774 CutPrefix (ParseFileName - 1, 2);
775 LoopFinish = FALSE;
776 break;
777 }
778
779 if (*ParseFileName == '.' &&
780 *(ParseFileName + 1) == '.' &&
781 (*(ParseFileName + 2) == 0 || *(ParseFileName + 2) == '/') &&
782 *(ParseFileName - 1) == '/'
783 ) {
784
785 ParseFileName--;
786 Count = 3;
787
788 while (ParseFileName != GuardPointer) {
789 ParseFileName--;
790 Count++;
791 if (*ParseFileName == '/') {
792 break;
793 }
794 }
795
796 //
797 // cut /.. and its left directory
798 //
799 CutPrefix (ParseFileName, Count);
800 LoopFinish = FALSE;
801 break;
802 }
803 }
804 }
805
806 if (AsciiStrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {
807 NewPrivateFile->IsRootDirectory = TRUE;
808 gBS->FreePool (NewPrivateFile->FileName);
809 gBS->FreePool (NewPrivateFile);
810 goto OpenRoot;
811 }
812
813 RealFileName = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName) - 1;
814 while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/')
815 RealFileName--;
816
817 TempChar = *(RealFileName - 1);
818 *(RealFileName - 1) = 0;
819
820 *(RealFileName - 1) = TempChar;
821
822
823
824 //
825 // Test whether file or directory
826 //
827 NewPrivateFile->IsRootDirectory = FALSE;
828 NewPrivateFile->fd = -1;
829 NewPrivateFile->Dir = NULL;
830 if (OpenMode & EFI_FILE_MODE_CREATE) {
831 if (Attributes & EFI_FILE_DIRECTORY) {
832 NewPrivateFile->IsDirectoryPath = TRUE;
833 } else {
834 NewPrivateFile->IsDirectoryPath = FALSE;
835 }
836 } else {
837 struct stat finfo;
838 int res = NewPrivateFile->UnixThunk->Stat (NewPrivateFile->FileName, &finfo);
839 if (res == 0 && S_ISDIR(finfo.st_mode))
840 NewPrivateFile->IsDirectoryPath = TRUE;
841 else
842 NewPrivateFile->IsDirectoryPath = FALSE;
843 }
844
845 if (OpenMode & EFI_FILE_MODE_WRITE) {
846 NewPrivateFile->IsOpenedByRead = FALSE;
847 } else {
848 NewPrivateFile->IsOpenedByRead = TRUE;
849 }
850
851 Status = EFI_SUCCESS;
852
853 //
854 // deal with directory
855 //
856 if (NewPrivateFile->IsDirectoryPath) {
857
858 if ((OpenMode & EFI_FILE_MODE_CREATE)) {
859 //
860 // Create a directory
861 //
862 if (NewPrivateFile->UnixThunk->MkDir (NewPrivateFile->FileName, 0777) != 0) {
863 INTN LastError;
864
865 LastError = PrivateFile->UnixThunk->GetErrno ();
866 if (LastError != EEXIST) {
867 //gBS->FreePool (TempFileName);
868 Status = EFI_ACCESS_DENIED;
869 goto Done;
870 }
871 }
872 }
873
874 NewPrivateFile->Dir = NewPrivateFile->UnixThunk->OpenDir
875 (NewPrivateFile->FileName);
876
877 if (NewPrivateFile->Dir == NULL) {
878 if (PrivateFile->UnixThunk->GetErrno () == EACCES) {
879 Status = EFI_ACCESS_DENIED;
880 } else {
881 Status = EFI_NOT_FOUND;
882 }
883
884 goto Done;
885 }
886
887 } else {
888 //
889 // deal with file
890 //
891 NewPrivateFile->fd = NewPrivateFile->UnixThunk->Open
892 (NewPrivateFile->FileName,
893 ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0)
894 | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR),
895 0666);
896 if (NewPrivateFile->fd < 0) {
897 if (PrivateFile->UnixThunk->GetErrno () == ENOENT) {
898 Status = EFI_NOT_FOUND;
899 } else {
900 Status = EFI_ACCESS_DENIED;
901 }
902 }
903 }
904
905 if ((OpenMode & EFI_FILE_MODE_CREATE) && Status == EFI_SUCCESS) {
906 //
907 // Set the attribute
908 //
909 InfoSize = 0;
910 Info = NULL;
911
912 Status = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
913
914 if (Status != EFI_BUFFER_TOO_SMALL) {
915 Status = EFI_DEVICE_ERROR;
916 goto Done;
917 }
918
919 Status = gBS->AllocatePool (
920 EfiBootServicesData,
921 InfoSize,
922 (VOID **)&Info
923 );
924
925 if (EFI_ERROR (Status)) {
926 goto Done;
927 }
928
929 Status = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
930
931 if (EFI_ERROR (Status)) {
932 goto Done;
933 }
934
935 Info->Attribute = Attributes;
936
937 UnixSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);
938 }
939
940 Done: ;
941 if (TrailingDash) {
942 FileName[StrLen (FileName) + 1] = 0;
943 FileName[StrLen (FileName)] = L'\\';
944 }
945
946 if (EFI_ERROR (Status)) {
947 if (NewPrivateFile) {
948 if (NewPrivateFile->FileName) {
949 gBS->FreePool (NewPrivateFile->FileName);
950 }
951
952 gBS->FreePool (NewPrivateFile);
953 }
954 } else {
955 *NewHandle = &NewPrivateFile->EfiFile;
956 }
957
958 return Status;
959 }
960
961 EFI_STATUS
962 EFIAPI
963 UnixSimpleFileSystemClose (
964 IN EFI_FILE *This
965 )
966 /*++
967
968 Routine Description:
969
970 Close the specified file handle.
971
972 Arguments:
973
974 This - Pointer to a returned opened file handle.
975
976 Returns:
977
978 EFI_SUCCESS - The file handle has been closed.
979
980 --*/
981 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
982 {
983 UNIX_EFI_FILE_PRIVATE *PrivateFile;
984 EFI_TPL OldTpl;
985
986 if (This == NULL) {
987 return EFI_INVALID_PARAMETER;
988 }
989
990 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
991
992 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
993
994 if (PrivateFile->fd >= 0) {
995 PrivateFile->UnixThunk->Close (PrivateFile->fd);
996 }
997 if (PrivateFile->Dir != NULL) {
998 PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);
999 }
1000
1001 PrivateFile->fd = -1;
1002 PrivateFile->Dir = NULL;
1003
1004 if (PrivateFile->FileName) {
1005 gBS->FreePool (PrivateFile->FileName);
1006 }
1007
1008 gBS->FreePool (PrivateFile);
1009
1010 gBS->RestoreTPL (OldTpl);
1011
1012 return EFI_SUCCESS;
1013 }
1014
1015 EFI_STATUS
1016 EFIAPI
1017 UnixSimpleFileSystemDelete (
1018 IN EFI_FILE *This
1019 )
1020 /*++
1021
1022 Routine Description:
1023
1024 Close and delete a file.
1025
1026 Arguments:
1027
1028 This - Pointer to a returned opened file handle.
1029
1030 Returns:
1031
1032 EFI_SUCCESS - The file handle was closed and deleted.
1033
1034 EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.
1035
1036 --*/
1037 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1038 {
1039 EFI_STATUS Status;
1040 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1041 EFI_TPL OldTpl;
1042
1043 if (This == NULL) {
1044 return EFI_INVALID_PARAMETER;
1045 }
1046
1047 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1048
1049 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1050
1051 Status = EFI_WARN_DELETE_FAILURE;
1052
1053 if (PrivateFile->IsDirectoryPath) {
1054 if (PrivateFile->Dir != NULL) {
1055 PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);
1056 PrivateFile->Dir = NULL;
1057 }
1058
1059 if (PrivateFile->UnixThunk->RmDir (PrivateFile->FileName) == 0) {
1060 Status = EFI_SUCCESS;
1061 }
1062 } else {
1063 PrivateFile->UnixThunk->Close (PrivateFile->fd);
1064 PrivateFile->fd = -1;
1065
1066 if (!PrivateFile->IsOpenedByRead) {
1067 if (!PrivateFile->UnixThunk->UnLink (PrivateFile->FileName)) {
1068 Status = EFI_SUCCESS;
1069 }
1070 }
1071 }
1072
1073 gBS->FreePool (PrivateFile->FileName);
1074 gBS->FreePool (PrivateFile);
1075
1076 gBS->RestoreTPL (OldTpl);
1077
1078 return Status;
1079 }
1080
1081 VOID
1082 UnixSystemTimeToEfiTime (
1083 EFI_UNIX_THUNK_PROTOCOL *UnixThunk,
1084 IN time_t SystemTime,
1085 OUT EFI_TIME *Time
1086 )
1087 /*++
1088
1089 Routine Description:
1090
1091 TODO: Add function description
1092
1093 Arguments:
1094
1095 SystemTime - TODO: add argument description
1096 TimeZone - TODO: add argument description
1097 Time - TODO: add argument description
1098
1099 Returns:
1100
1101 TODO: add return values
1102
1103 --*/
1104 {
1105 struct tm *tm;
1106 tm = UnixThunk->GmTime (&SystemTime);
1107 Time->Year = tm->tm_year;
1108 Time->Month = tm->tm_mon;
1109 Time->Day = tm->tm_mday;
1110 Time->Hour = tm->tm_hour;
1111 Time->Minute = tm->tm_min;
1112 Time->Second = tm->tm_sec;
1113 Time->Nanosecond = 0;
1114
1115 Time->TimeZone = UnixThunk->GetTimeZone ();
1116
1117 if (UnixThunk->GetDayLight ()) {
1118 Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;
1119 }
1120 }
1121
1122 EFI_STATUS
1123 UnixSimpleFileSystemFileInfo (
1124 UNIX_EFI_FILE_PRIVATE *PrivateFile,
1125 IN CHAR8 *FileName,
1126 IN OUT UINTN *BufferSize,
1127 OUT VOID *Buffer
1128 )
1129 /*++
1130
1131 Routine Description:
1132
1133 TODO: Add function description
1134
1135 Arguments:
1136
1137 PrivateFile - TODO: add argument description
1138 BufferSize - TODO: add argument description
1139 Buffer - TODO: add argument description
1140
1141 Returns:
1142
1143 TODO: add return values
1144
1145 --*/
1146 {
1147 EFI_STATUS Status;
1148 UINTN Size;
1149 UINTN NameSize;
1150 UINTN ResultSize;
1151 EFI_FILE_INFO *Info;
1152 CHAR8 *RealFileName;
1153 CHAR8 *TempPointer;
1154 CHAR16 *BufferFileName;
1155 struct stat buf;
1156
1157 if (FileName != NULL) {
1158 RealFileName = FileName;
1159 }
1160 else if (PrivateFile->IsRootDirectory) {
1161 RealFileName = "";
1162 } else {
1163 RealFileName = PrivateFile->FileName;
1164 }
1165
1166 TempPointer = RealFileName;
1167 while (*TempPointer) {
1168 if (*TempPointer == '/') {
1169 RealFileName = TempPointer + 1;
1170 }
1171
1172 TempPointer++;
1173 }
1174
1175 Size = SIZE_OF_EFI_FILE_INFO;
1176 NameSize = AsciiStrSize (RealFileName) * 2;
1177 ResultSize = Size + NameSize;
1178
1179 if (*BufferSize < ResultSize) {
1180 *BufferSize = ResultSize;
1181 return EFI_BUFFER_TOO_SMALL;
1182 }
1183 if (PrivateFile->UnixThunk->Stat (
1184 FileName == NULL ? PrivateFile->FileName : FileName,
1185 &buf) < 0)
1186 return EFI_DEVICE_ERROR;
1187
1188 Status = EFI_SUCCESS;
1189
1190 Info = Buffer;
1191 ZeroMem (Info, ResultSize);
1192
1193 Info->Size = ResultSize;
1194 Info->FileSize = buf.st_size;
1195 Info->PhysicalSize = MultU64x32 (buf.st_blocks, buf.st_blksize);
1196
1197 UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_ctime, &Info->CreateTime);
1198 UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_atime, &Info->LastAccessTime);
1199 UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_mtime, &Info->ModificationTime);
1200
1201 if (!(buf.st_mode & S_IWUSR)) {
1202 Info->Attribute |= EFI_FILE_READ_ONLY;
1203 }
1204
1205 if (S_ISDIR(buf.st_mode)) {
1206 Info->Attribute |= EFI_FILE_DIRECTORY;
1207 }
1208
1209
1210 BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size);
1211 while (*RealFileName)
1212 *BufferFileName++ = *RealFileName++;
1213 *BufferFileName = 0;
1214
1215 *BufferSize = ResultSize;
1216 return Status;
1217 }
1218
1219 EFI_STATUS
1220 EFIAPI
1221 UnixSimpleFileSystemRead (
1222 IN EFI_FILE *This,
1223 IN OUT UINTN *BufferSize,
1224 OUT VOID *Buffer
1225 )
1226 /*++
1227
1228 Routine Description:
1229
1230 Read data from a file.
1231
1232 Arguments:
1233
1234 This - Pointer to a returned open file handle.
1235
1236 BufferSize - On input, the size of the Buffer. On output, the number of bytes stored in the Buffer.
1237
1238 Buffer - Pointer to the first byte of the read Buffer.
1239
1240 Returns:
1241
1242 EFI_SUCCESS - The data was read.
1243
1244 EFI_NO_MEDIA - The device has no media.
1245
1246 EFI_DEVICE_ERROR - The device reported an error.
1247
1248 EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
1249
1250 EFI_BUFFER_TOO_SMALL - The supplied buffer size was too small to store the current directory entry.
1251 *BufferSize has been updated with the size needed to complete the request.
1252
1253 --*/
1254 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1255 {
1256 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1257 EFI_STATUS Status;
1258 INTN Res;
1259 UINTN Size;
1260 UINTN NameSize;
1261 UINTN ResultSize;
1262 CHAR8 *FullFileName;
1263 EFI_TPL OldTpl;
1264
1265 if (This == NULL || BufferSize == NULL || Buffer == NULL) {
1266 return EFI_INVALID_PARAMETER;
1267 }
1268
1269 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1270
1271 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1272
1273 if (!PrivateFile->IsDirectoryPath) {
1274
1275 if (PrivateFile->fd < 0) {
1276 Status = EFI_DEVICE_ERROR;
1277 goto Done;
1278 }
1279
1280 Res = PrivateFile->UnixThunk->Read (
1281 PrivateFile->fd,
1282 Buffer,
1283 *BufferSize);
1284 if (Res < 0) {
1285 Status = EFI_DEVICE_ERROR;
1286 goto Done;
1287 }
1288 *BufferSize = Res;
1289 Status = EFI_SUCCESS;
1290 goto Done;
1291 }
1292
1293 //
1294 // Read on a directory.
1295 //
1296 if (PrivateFile->Dir == NULL) {
1297 Status = EFI_DEVICE_ERROR;
1298 goto Done;
1299 }
1300
1301 if (PrivateFile->Dirent == NULL) {
1302 PrivateFile->Dirent = PrivateFile->UnixThunk->ReadDir (PrivateFile->Dir);
1303 if (PrivateFile->Dirent == NULL) {
1304 *BufferSize = 0;
1305 Status = EFI_SUCCESS;
1306 goto Done;
1307 }
1308 }
1309
1310 Size = SIZE_OF_EFI_FILE_INFO;
1311 NameSize = AsciiStrLen (PrivateFile->Dirent->d_name) + 1;
1312 ResultSize = Size + 2 * NameSize;
1313
1314 if (*BufferSize < ResultSize) {
1315 *BufferSize = ResultSize;
1316 Status = EFI_BUFFER_TOO_SMALL;
1317 goto Done;
1318 }
1319 Status = EFI_SUCCESS;
1320
1321 *BufferSize = ResultSize;
1322
1323 Status = gBS->AllocatePool (
1324 EfiBootServicesData,
1325 AsciiStrLen(PrivateFile->FileName) + 1 + NameSize,
1326 (VOID **)&FullFileName
1327 );
1328
1329 if (EFI_ERROR (Status)) {
1330 goto Done;
1331 }
1332
1333 AsciiStrCpy(FullFileName, PrivateFile->FileName);
1334 AsciiStrCat(FullFileName, "/");
1335 AsciiStrCat(FullFileName, PrivateFile->Dirent->d_name);
1336 Status = UnixSimpleFileSystemFileInfo (PrivateFile,
1337 FullFileName,
1338 BufferSize,
1339 Buffer);
1340 gBS->FreePool (FullFileName);
1341
1342 PrivateFile->Dirent = NULL;
1343
1344 Done:
1345 gBS->RestoreTPL (OldTpl);
1346
1347 return Status;
1348 }
1349
1350 EFI_STATUS
1351 EFIAPI
1352 UnixSimpleFileSystemWrite (
1353 IN EFI_FILE *This,
1354 IN OUT UINTN *BufferSize,
1355 IN VOID *Buffer
1356 )
1357 /*++
1358
1359 Routine Description:
1360
1361 Write data to a file.
1362
1363 Arguments:
1364
1365 This - Pointer to an opened file handle.
1366
1367 BufferSize - On input, the number of bytes in the Buffer to write to the file. On output, the number of bytes
1368 of data written to the file.
1369
1370 Buffer - Pointer to the first by of data in the buffer to write to the file.
1371
1372 Returns:
1373
1374 EFI_SUCCESS - The data was written to the file.
1375
1376 EFI_UNSUPPORTED - Writes to an open directory are not supported.
1377
1378 EFI_NO_MEDIA - The device has no media.
1379
1380 EFI_DEVICE_ERROR - The device reported an error.
1381
1382 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
1383
1384 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
1385
1386 EFI_ACCESS_DENIED - The file was opened read-only.
1387
1388 EFI_VOLUME_FULL - The volume is full.
1389
1390 --*/
1391 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1392 {
1393 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1394 UINTN Res;
1395 EFI_STATUS Status;
1396 EFI_TPL OldTpl;
1397
1398 if (This == NULL || BufferSize == NULL || Buffer == NULL) {
1399 return EFI_INVALID_PARAMETER;
1400 }
1401
1402 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1403
1404 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1405
1406 if (PrivateFile->fd < 0) {
1407 return EFI_DEVICE_ERROR;
1408 }
1409
1410 if (PrivateFile->IsDirectoryPath) {
1411 return EFI_UNSUPPORTED;
1412 }
1413
1414 if (PrivateFile->IsOpenedByRead) {
1415 return EFI_ACCESS_DENIED;
1416 }
1417
1418 Res = PrivateFile->UnixThunk->Write (
1419 PrivateFile->fd,
1420 Buffer,
1421 *BufferSize);
1422 if (Res == (UINTN)-1) {
1423 Status = EFI_DEVICE_ERROR;
1424 goto Done;
1425 }
1426 *BufferSize = Res;
1427 Status = EFI_SUCCESS;
1428
1429 Done:
1430 gBS->RestoreTPL (OldTpl);
1431 return Status;
1432
1433 //
1434 // bugbug: need to access unix error reporting
1435 //
1436 }
1437
1438 EFI_STATUS
1439 EFIAPI
1440 UnixSimpleFileSystemSetPosition (
1441 IN EFI_FILE *This,
1442 IN UINT64 Position
1443 )
1444 /*++
1445
1446 Routine Description:
1447
1448 Set a file's current position.
1449
1450 Arguments:
1451
1452 This - Pointer to an opened file handle.
1453
1454 Position - The byte position from the start of the file to set.
1455
1456 Returns:
1457
1458 EFI_SUCCESS - The file position has been changed.
1459
1460 EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.
1461
1462 --*/
1463 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1464 {
1465 EFI_STATUS Status;
1466 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1467 UINT64 Pos;
1468 EFI_TPL OldTpl;
1469
1470 if (This == NULL) {
1471 return EFI_INVALID_PARAMETER;
1472 }
1473
1474 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1475
1476 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1477
1478 if (PrivateFile->IsDirectoryPath) {
1479 if (Position != 0) {
1480 Status = EFI_UNSUPPORTED;
1481 goto Done;
1482 }
1483
1484 if (PrivateFile->Dir == NULL) {
1485 Status = EFI_DEVICE_ERROR;
1486 goto Done;
1487 }
1488 PrivateFile->UnixThunk->RewindDir (PrivateFile->Dir);
1489 Status = EFI_SUCCESS;
1490 goto Done;
1491 } else {
1492 if (Position == (UINT64) -1) {
1493 Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_END);
1494 } else {
1495 Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, Position, SEEK_SET);
1496 }
1497 Status = (Pos == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;
1498 }
1499
1500 Done:
1501 gBS->RestoreTPL (OldTpl);
1502 return Status;
1503 }
1504
1505 EFI_STATUS
1506 EFIAPI
1507 UnixSimpleFileSystemGetPosition (
1508 IN EFI_FILE *This,
1509 OUT UINT64 *Position
1510 )
1511 /*++
1512
1513 Routine Description:
1514
1515 Get a file's current position.
1516
1517 Arguments:
1518
1519 This - Pointer to an opened file handle.
1520
1521 Position - Pointer to storage for the current position.
1522
1523 Returns:
1524
1525 EFI_SUCCESS - The file position has been reported.
1526
1527 EFI_UNSUPPORTED - Not valid for directories.
1528
1529 --*/
1530 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1531 {
1532 EFI_STATUS Status;
1533 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1534 EFI_TPL OldTpl;
1535
1536 if (This == NULL || Position == NULL) {
1537 return EFI_INVALID_PARAMETER;
1538 }
1539
1540 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1541
1542 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1543
1544 if (PrivateFile->IsDirectoryPath) {
1545 Status = EFI_UNSUPPORTED;
1546 } else {
1547 *Position = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_CUR);
1548 Status = (*Position == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;
1549 }
1550
1551 gBS->RestoreTPL (OldTpl);
1552 return Status;
1553 }
1554
1555 EFI_STATUS
1556 EFIAPI
1557 UnixSimpleFileSystemGetInfo (
1558 IN EFI_FILE *This,
1559 IN EFI_GUID *InformationType,
1560 IN OUT UINTN *BufferSize,
1561 OUT VOID *Buffer
1562 )
1563 /*++
1564
1565 Routine Description:
1566
1567 Return information about a file or volume.
1568
1569 Arguments:
1570
1571 This - Pointer to an opened file handle.
1572
1573 InformationType - GUID describing the type of information to be returned.
1574
1575 BufferSize - On input, the size of the information buffer. On output, the number of bytes written to the
1576 information buffer.
1577
1578 Buffer - Pointer to the first byte of the information buffer.
1579
1580 Returns:
1581
1582 EFI_SUCCESS - The requested information has been written into the buffer.
1583
1584 EFI_UNSUPPORTED - The InformationType is not known.
1585
1586 EFI_NO_MEDIA - The device has no media.
1587
1588 EFI_DEVICE_ERROR - The device reported an error.
1589
1590 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
1591
1592 EFI_BUFFER_TOO_SMALL - The buffer size was too small to contain the requested information. The buffer size has
1593 been updated with the size needed to complete the requested operation.
1594
1595 --*/
1596 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1597 {
1598 EFI_STATUS Status;
1599 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1600 EFI_FILE_SYSTEM_INFO *FileSystemInfoBuffer;
1601 INTN UnixStatus;
1602 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
1603 struct statfs buf;
1604 EFI_TPL OldTpl;
1605
1606 if (This == NULL || InformationType == NULL || BufferSize == NULL) {
1607 return EFI_INVALID_PARAMETER;
1608 }
1609
1610 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1611
1612 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1613 PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
1614
1615 Status = EFI_UNSUPPORTED;
1616
1617 if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {
1618 Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, BufferSize, Buffer);
1619 } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
1620 if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {
1621 *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
1622 Status = EFI_BUFFER_TOO_SMALL;
1623 goto Done;
1624 }
1625
1626 UnixStatus = PrivateFile->UnixThunk->StatFs (PrivateFile->FileName, &buf);
1627 if (UnixStatus < 0) {
1628 Status = EFI_DEVICE_ERROR;
1629 goto Done;
1630 }
1631
1632 FileSystemInfoBuffer = (EFI_FILE_SYSTEM_INFO *) Buffer;
1633 FileSystemInfoBuffer->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
1634 FileSystemInfoBuffer->ReadOnly = FALSE;
1635
1636 //
1637 // Succeeded
1638 //
1639 FileSystemInfoBuffer->VolumeSize = MultU64x32 (buf.f_blocks, buf.f_bsize);
1640 FileSystemInfoBuffer->FreeSpace = MultU64x32 (buf.f_bavail, buf.f_bsize);
1641 FileSystemInfoBuffer->BlockSize = buf.f_bsize;
1642
1643
1644 StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel);
1645 *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
1646 Status = EFI_SUCCESS;
1647 } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1648 if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
1649 *BufferSize = StrSize (PrivateRoot->VolumeLabel);
1650 Status = EFI_BUFFER_TOO_SMALL;
1651 goto Done;
1652 }
1653
1654 StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);
1655 *BufferSize = StrSize (PrivateRoot->VolumeLabel);
1656 Status = EFI_SUCCESS;
1657 }
1658
1659 Done:
1660 gBS->RestoreTPL (OldTpl);
1661 return Status;
1662 }
1663
1664 EFI_STATUS
1665 EFIAPI
1666 UnixSimpleFileSystemSetInfo (
1667 IN EFI_FILE *This,
1668 IN EFI_GUID *InformationType,
1669 IN UINTN BufferSize,
1670 IN VOID *Buffer
1671 )
1672 /*++
1673
1674 Routine Description:
1675
1676 Set information about a file or volume.
1677
1678 Arguments:
1679
1680 This - Pointer to an opened file handle.
1681
1682 InformationType - GUID identifying the type of information to set.
1683
1684 BufferSize - Number of bytes of data in the information buffer.
1685
1686 Buffer - Pointer to the first byte of data in the information buffer.
1687
1688 Returns:
1689
1690 EFI_SUCCESS - The file or volume information has been updated.
1691
1692 EFI_UNSUPPORTED - The information identifier is not recognised.
1693
1694 EFI_NO_MEDIA - The device has no media.
1695
1696 EFI_DEVICE_ERROR - The device reported an error.
1697
1698 EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
1699
1700 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
1701
1702 EFI_ACCESS_DENIED - The file was opened read-only.
1703
1704 EFI_VOLUME_FULL - The volume is full.
1705
1706 EFI_BAD_BUFFER_SIZE - The buffer size is smaller than the type indicated by InformationType.
1707
1708 --*/
1709 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1710 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
1711 {
1712 UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
1713 UNIX_EFI_FILE_PRIVATE *PrivateFile;
1714 EFI_FILE_INFO *OldFileInfo;
1715 EFI_FILE_INFO *NewFileInfo;
1716 EFI_STATUS Status;
1717 UINTN OldInfoSize;
1718 EFI_TPL OldTpl;
1719 mode_t NewAttr;
1720 struct stat OldAttr;
1721 CHAR8 *OldFileName;
1722 CHAR8 *NewFileName;
1723 CHAR8 *CharPointer;
1724 BOOLEAN AttrChangeFlag;
1725 BOOLEAN NameChangeFlag;
1726 BOOLEAN SizeChangeFlag;
1727 BOOLEAN TimeChangeFlag;
1728 struct tm NewLastAccessSystemTime;
1729 struct tm NewLastWriteSystemTime;
1730 EFI_FILE_SYSTEM_INFO *NewFileSystemInfo;
1731 CHAR8 *AsciiFilePtr;
1732 CHAR16 *UnicodeFilePtr;
1733 INTN UnixStatus;
1734
1735 //
1736 // Check for invalid parameters.
1737 //
1738 if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {
1739 return EFI_INVALID_PARAMETER;
1740 }
1741
1742 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1743
1744 //
1745 // Initialise locals.
1746 //
1747 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1748 PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
1749
1750 Status = EFI_UNSUPPORTED;
1751 OldFileInfo = NewFileInfo = NULL;
1752 OldFileName = NewFileName = NULL;
1753 AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag = FALSE;
1754
1755 //
1756 // Set file system information.
1757 //
1758 if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
1759 if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {
1760 Status = EFI_BAD_BUFFER_SIZE;
1761 goto Done;
1762 }
1763
1764 NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;
1765
1766 gBS->FreePool (PrivateRoot->VolumeLabel);
1767
1768 PrivateRoot->VolumeLabel = NULL;
1769 Status = gBS->AllocatePool (
1770 EfiBootServicesData,
1771 StrSize (NewFileSystemInfo->VolumeLabel),
1772 (VOID **)&PrivateRoot->VolumeLabel
1773 );
1774
1775 if (EFI_ERROR (Status)) {
1776 goto Done;
1777 }
1778
1779 StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);
1780
1781 Status = EFI_SUCCESS;
1782 goto Done;
1783 }
1784
1785 //
1786 // Set volume label information.
1787 //
1788 if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1789 if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
1790 Status = EFI_BAD_BUFFER_SIZE;
1791 goto Done;
1792 }
1793
1794 StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);
1795
1796 Status = EFI_SUCCESS;
1797 goto Done;
1798 }
1799
1800 if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) {
1801 Status = EFI_UNSUPPORTED;
1802 goto Done;
1803 }
1804
1805 if (BufferSize < SIZE_OF_EFI_FILE_INFO) {
1806 Status = EFI_BAD_BUFFER_SIZE;
1807 goto Done;
1808 }
1809
1810 //
1811 // Set file/directory information.
1812 //
1813
1814 //
1815 // Check for invalid set file information parameters.
1816 //
1817 NewFileInfo = (EFI_FILE_INFO *) Buffer;
1818
1819 if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) ||
1820 (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||
1821 (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)
1822 ) {
1823 Status = EFI_INVALID_PARAMETER;
1824 goto Done;
1825 }
1826
1827 //
1828 // bugbug: - This is not safe. We need something like EfiStrMaxSize()
1829 // that would have an additional parameter that would be the size
1830 // of the string array just in case there are no NULL characters in
1831 // the string array.
1832 //
1833 //
1834 // Get current file information so we can determine what kind
1835 // of change request this is.
1836 //
1837 OldInfoSize = 0;
1838 Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, NULL);
1839
1840 if (Status != EFI_BUFFER_TOO_SMALL) {
1841 Status = EFI_DEVICE_ERROR;
1842 goto Done;
1843 }
1844
1845 Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize,
1846 (VOID **)&OldFileInfo);
1847
1848 if (EFI_ERROR (Status)) {
1849 goto Done;
1850 }
1851
1852 Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, OldFileInfo);
1853
1854 if (EFI_ERROR (Status)) {
1855 goto Done;
1856 }
1857
1858 Status = gBS->AllocatePool (
1859 EfiBootServicesData,
1860 AsciiStrSize (PrivateFile->FileName),
1861 (VOID **)&OldFileName
1862 );
1863
1864 if (EFI_ERROR (Status)) {
1865 goto Done;
1866 }
1867
1868 AsciiStrCpy (OldFileName, PrivateFile->FileName);
1869
1870 //
1871 // Make full pathname from new filename and rootpath.
1872 //
1873 if (NewFileInfo->FileName[0] == '\\') {
1874 Status = gBS->AllocatePool (
1875 EfiBootServicesData,
1876 AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1,
1877 (VOID **)&NewFileName
1878 );
1879
1880 if (EFI_ERROR (Status)) {
1881 goto Done;
1882 }
1883
1884 AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
1885 AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
1886 UnicodeFilePtr = NewFileInfo->FileName + 1;
1887 *AsciiFilePtr++ ='/';
1888 } else {
1889 Status = gBS->AllocatePool (
1890 EfiBootServicesData,
1891 AsciiStrLen (PrivateFile->FileName) + 1 + StrLen (NewFileInfo->FileName) + 1,
1892 (VOID **)&NewFileName
1893 );
1894
1895 if (EFI_ERROR (Status)) {
1896 goto Done;
1897 }
1898
1899 AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
1900 AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
1901 while (AsciiFilePtr > NewFileName && AsciiFilePtr[-1] != '/') {
1902 AsciiFilePtr--;
1903 }
1904 UnicodeFilePtr = NewFileInfo->FileName;
1905 }
1906 // Convert to ascii.
1907 while (*UnicodeFilePtr) {
1908 *AsciiFilePtr++ = *UnicodeFilePtr++;
1909 }
1910 *AsciiFilePtr = 0;
1911
1912
1913 //
1914 // Is there an attribute change request?
1915 //
1916 if (NewFileInfo->Attribute != OldFileInfo->Attribute) {
1917 if ((NewFileInfo->Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->Attribute & EFI_FILE_DIRECTORY)) {
1918 Status = EFI_INVALID_PARAMETER;
1919 goto Done;
1920 }
1921
1922 AttrChangeFlag = TRUE;
1923 }
1924
1925 //
1926 // Is there a name change request?
1927 // bugbug: - Need EfiStrCaseCmp()
1928 //
1929 if (StrCmp (NewFileInfo->FileName, OldFileInfo->FileName)) {
1930 NameChangeFlag = TRUE;
1931 }
1932
1933 //
1934 // Is there a size change request?
1935 //
1936 if (NewFileInfo->FileSize != OldFileInfo->FileSize) {
1937 SizeChangeFlag = TRUE;
1938 }
1939
1940 //
1941 // Is there a time stamp change request?
1942 //
1943 if (!IsZero (&NewFileInfo->CreateTime, sizeof (EFI_TIME)) &&
1944 CompareMem (&NewFileInfo->CreateTime, &OldFileInfo->CreateTime, sizeof (EFI_TIME))
1945 ) {
1946 TimeChangeFlag = TRUE;
1947 } else if (!IsZero (&NewFileInfo->LastAccessTime, sizeof (EFI_TIME)) &&
1948 CompareMem (&NewFileInfo->LastAccessTime, &OldFileInfo->LastAccessTime, sizeof (EFI_TIME))
1949 ) {
1950 TimeChangeFlag = TRUE;
1951 } else if (!IsZero (&NewFileInfo->ModificationTime, sizeof (EFI_TIME)) &&
1952 CompareMem (&NewFileInfo->ModificationTime, &OldFileInfo->ModificationTime, sizeof (EFI_TIME))
1953 ) {
1954 TimeChangeFlag = TRUE;
1955 }
1956
1957 //
1958 // All done if there are no change requests being made.
1959 //
1960 if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {
1961 Status = EFI_SUCCESS;
1962 goto Done;
1963 }
1964
1965 //
1966 // Set file or directory information.
1967 //
1968 if (PrivateFile->UnixThunk->Stat (OldFileName, &OldAttr) != 0) {
1969 Status = EFI_DEVICE_ERROR;
1970 goto Done;
1971 }
1972
1973 //
1974 // Name change.
1975 //
1976 if (NameChangeFlag) {
1977 //
1978 // Close the handles first
1979 //
1980 if (PrivateFile->IsOpenedByRead) {
1981 Status = EFI_ACCESS_DENIED;
1982 goto Done;
1983 }
1984
1985 for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L'/'; CharPointer++) {
1986 }
1987
1988 if (*CharPointer != 0) {
1989 Status = EFI_ACCESS_DENIED;
1990 goto Done;
1991 }
1992
1993 UnixStatus = PrivateFile->UnixThunk->Rename (OldFileName, NewFileName);
1994
1995 if (UnixStatus == 0) {
1996 //
1997 // modify file name
1998 //
1999 gBS->FreePool (PrivateFile->FileName);
2000
2001 Status = gBS->AllocatePool (
2002 EfiBootServicesData,
2003 AsciiStrSize (NewFileName),
2004 (VOID **)&PrivateFile->FileName
2005 );
2006
2007 if (EFI_ERROR (Status)) {
2008 goto Done;
2009 }
2010
2011 AsciiStrCpy (PrivateFile->FileName, NewFileName);
2012 } else {
2013 Status = EFI_DEVICE_ERROR;
2014 goto Done;
2015 }
2016 }
2017
2018 //
2019 // Size change
2020 //
2021 if (SizeChangeFlag) {
2022 if (PrivateFile->IsDirectoryPath) {
2023 Status = EFI_UNSUPPORTED;
2024 goto Done;
2025 }
2026
2027 if (PrivateFile->IsOpenedByRead || OldFileInfo->Attribute & EFI_FILE_READ_ONLY) {
2028 Status = EFI_ACCESS_DENIED;
2029 goto Done;
2030 }
2031
2032 if (PrivateFile->UnixThunk->FTruncate (PrivateFile->fd, NewFileInfo->FileSize) != 0) {
2033 Status = EFI_DEVICE_ERROR;
2034 goto Done;
2035 }
2036
2037 }
2038
2039 //
2040 // Time change
2041 //
2042 if (TimeChangeFlag) {
2043 struct utimbuf utime;
2044
2045 NewLastAccessSystemTime.tm_year = NewFileInfo->LastAccessTime.Year;
2046 NewLastAccessSystemTime.tm_mon = NewFileInfo->LastAccessTime.Month;
2047 NewLastAccessSystemTime.tm_mday = NewFileInfo->LastAccessTime.Day;
2048 NewLastAccessSystemTime.tm_hour = NewFileInfo->LastAccessTime.Hour;
2049 NewLastAccessSystemTime.tm_min = NewFileInfo->LastAccessTime.Minute;
2050 NewLastAccessSystemTime.tm_sec = NewFileInfo->LastAccessTime.Second;
2051 NewLastAccessSystemTime.tm_isdst = 0;
2052
2053 utime.actime = PrivateFile->UnixThunk->MkTime (&NewLastAccessSystemTime);
2054
2055 NewLastWriteSystemTime.tm_year = NewFileInfo->ModificationTime.Year;
2056 NewLastWriteSystemTime.tm_mon = NewFileInfo->ModificationTime.Month;
2057 NewLastWriteSystemTime.tm_mday = NewFileInfo->ModificationTime.Day;
2058 NewLastWriteSystemTime.tm_hour = NewFileInfo->ModificationTime.Hour;
2059 NewLastWriteSystemTime.tm_min = NewFileInfo->ModificationTime.Minute;
2060 NewLastWriteSystemTime.tm_sec = NewFileInfo->ModificationTime.Second;
2061 NewLastWriteSystemTime.tm_isdst = 0;
2062
2063 utime.modtime = PrivateFile->UnixThunk->MkTime (&NewLastWriteSystemTime);
2064
2065 if (utime.actime == (time_t)-1 || utime.modtime == (time_t)-1) {
2066 goto Done;
2067 }
2068
2069 if (PrivateFile->UnixThunk->UTime (PrivateFile->FileName, &utime) == -1) {
2070 goto Done;
2071 }
2072 }
2073
2074 //
2075 // No matter about AttrChangeFlag, Attribute must be set.
2076 // Because operation before may cause attribute change.
2077 //
2078 NewAttr = OldAttr.st_mode;
2079
2080 if (NewFileInfo->Attribute & EFI_FILE_READ_ONLY) {
2081 NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH);
2082 } else {
2083 NewAttr |= S_IRUSR;
2084 }
2085
2086 UnixStatus = PrivateFile->UnixThunk->Chmod (NewFileName, NewAttr);
2087
2088 if (UnixStatus != 0) {
2089 Status = EFI_DEVICE_ERROR;
2090 }
2091
2092 Done:
2093 if (OldFileInfo != NULL) {
2094 gBS->FreePool (OldFileInfo);
2095 }
2096
2097 if (OldFileName != NULL) {
2098 gBS->FreePool (OldFileName);
2099 }
2100
2101 if (NewFileName != NULL) {
2102 gBS->FreePool (NewFileName);
2103 }
2104
2105 gBS->RestoreTPL (OldTpl);
2106
2107 return Status;
2108 }
2109
2110 EFI_STATUS
2111 EFIAPI
2112 UnixSimpleFileSystemFlush (
2113 IN EFI_FILE *This
2114 )
2115 /*++
2116
2117 Routine Description:
2118
2119 Flush all modified data to the media.
2120
2121 Arguments:
2122
2123 This - Pointer to an opened file handle.
2124
2125 Returns:
2126
2127 EFI_SUCCESS - The data has been flushed.
2128
2129 EFI_NO_MEDIA - The device has no media.
2130
2131 EFI_DEVICE_ERROR - The device reported an error.
2132
2133 EFI_VOLUME_CORRUPTED - The file system structures have been corrupted.
2134
2135 EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
2136
2137 EFI_ACCESS_DENIED - The file was opened read-only.
2138
2139 EFI_VOLUME_FULL - The volume is full.
2140
2141 --*/
2142 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
2143 {
2144 UNIX_EFI_FILE_PRIVATE *PrivateFile;
2145 EFI_STATUS Status;
2146 EFI_TPL OldTpl;
2147
2148 if (This == NULL) {
2149 return EFI_INVALID_PARAMETER;
2150 }
2151
2152 Status = EFI_SUCCESS;
2153 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2154
2155 PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
2156
2157
2158 if (PrivateFile->IsDirectoryPath) {
2159 goto Done;
2160 }
2161
2162 if (PrivateFile->IsOpenedByRead) {
2163 Status = EFI_ACCESS_DENIED;
2164 goto Done;
2165 }
2166
2167 if (PrivateFile->fd < 0) {
2168 Status = EFI_DEVICE_ERROR;
2169 goto Done;
2170 }
2171
2172 PrivateFile->UnixThunk->FSync (PrivateFile->fd) == 0 ? EFI_SUCCESS : EFI_DEVICE_ERROR;
2173
2174 Done:
2175 gBS->RestoreTPL (OldTpl);
2176
2177 return Status;
2178
2179 //
2180 // bugbug: - Use Unix error reporting.
2181 //
2182 }
2183
2184