13#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'P', 'f', 's')
21 BOOLEAN FileHandlesOpen;
24#define EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
26 EMU_SIMPLE_FILE_SYSTEM_PRIVATE, \
28 EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
31#define EMU_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'P', 'f', 'i')
40 BOOLEAN IsRootDirectory;
41 BOOLEAN IsDirectoryPath;
42 BOOLEAN IsOpenedByRead;
44 struct dirent *Dirent;
47#define EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
49 EMU_EFI_FILE_PRIVATE, \
51 EMU_EFI_FILE_PRIVATE_SIGNATURE \
74 GasketPosixFileDelete,
77 GasketPosixFileGetPossition,
78 GasketPosixFileSetPossition,
79 GasketPosixFileGetInfo,
80 GasketPosixFileSetInfo,
85 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
86 GasketPosixOpenVolume,
114 Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
116 Status = EFI_OUT_OF_RESOURCES;
118 if (PrivateFile ==
NULL) {
122 PrivateFile->FileName = malloc (
AsciiStrSize (Private->FilePath));
123 if (PrivateFile->FileName ==
NULL) {
128 PrivateFile->FileName,
133 PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;
134 PrivateFile->Thunk = Private->Thunk;
135 PrivateFile->SimpleFileSystem = This;
136 PrivateFile->IsRootDirectory =
TRUE;
137 PrivateFile->IsDirectoryPath =
TRUE;
138 PrivateFile->IsOpenedByRead =
TRUE;
142 PrivateFile->fd = -1;
143 PrivateFile->Dir =
NULL;
144 PrivateFile->Dirent =
NULL;
146 *Root = &PrivateFile->EfiFile;
148 PrivateFile->Dir = opendir (PrivateFile->FileName);
149 if (PrivateFile->Dir ==
NULL) {
150 Status = EFI_ACCESS_DENIED;
156 if (EFI_ERROR (Status)) {
157 if (PrivateFile !=
NULL) {
158 if (PrivateFile->FileName !=
NULL) {
159 free (PrivateFile->FileName);
177 return EFI_ACCESS_DENIED;
181 return EFI_VOLUME_FULL;
184 return EFI_DEVICE_ERROR;
200 for (Pointer = Str; *(Pointer + Count); Pointer++) {
201 *Pointer = *(Pointer + Count);
204 *Pointer = *(Pointer + Count);
208PosixSystemTimeToEfiTime (
209 IN time_t SystemTime,
216 Time->Year =
tm->tm_year;
217 Time->Month =
tm->tm_mon + 1;
218 Time->Day =
tm->tm_mday;
219 Time->Hour =
tm->tm_hour;
220 Time->Minute =
tm->tm_min;
221 Time->Second =
tm->tm_sec;
222 Time->Nanosecond = 0;
224 Time->TimeZone = timezone / 60;
225 Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0) | (
tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
229UnixSimpleFileSystemFileInfo (
243 CHAR16 *BufferFileName;
246 if (FileName !=
NULL) {
247 RealFileName = FileName;
248 }
else if (PrivateFile->IsRootDirectory) {
251 RealFileName = PrivateFile->FileName;
254 TempPointer = RealFileName;
255 while (*TempPointer) {
256 if (*TempPointer ==
'/') {
257 RealFileName = TempPointer + 1;
265 ResultSize = Size + NameSize;
267 if (*BufferSize < ResultSize) {
268 *BufferSize = ResultSize;
269 return EFI_BUFFER_TOO_SMALL;
272 if (stat ((FileName ==
NULL) ? PrivateFile->FileName : FileName, &buf) < 0) {
273 return EFI_DEVICE_ERROR;
281 Info->
Size = ResultSize;
285 PosixSystemTimeToEfiTime (buf.st_ctime, &Info->
CreateTime);
289 if (!(buf.st_mode & S_IWUSR)) {
293 if (S_ISDIR (buf.st_mode)) {
297 BufferFileName = (CHAR16 *)((CHAR8 *)Buffer + Size);
298 while (*RealFileName) {
299 *BufferFileName++ = *RealFileName++;
304 *BufferSize = ResultSize;
314 if ((Buffer ==
NULL) || (Length == 0)) {
318 if (*(UINT8 *)Buffer != 0) {
323 if (!
CompareMem (Buffer, (UINT8 *)Buffer + 1, Length - 1)) {
372 BOOLEAN TrailingDash;
380 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
381 PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
382 NewPrivateFile =
NULL;
383 Status = EFI_OUT_OF_RESOURCES;
389 TrailingDash =
FALSE;
390 if ((
StrCmp (FileName, L
"\\") == 0) ||
391 ((
StrCmp (FileName, L
".") == 0) && PrivateFile->IsRootDirectory))
394 Status = PosixOpenVolume (PrivateFile->SimpleFileSystem, &Root);
395 NewPrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);
399 if (FileName[
StrLen (FileName) - 1] == L
'\\') {
401 FileName[
StrLen (FileName) - 1] = 0;
408 if (NewPrivateFile ==
NULL) {
415 NewPrivateFile->FileName = malloc (Size);
416 if (NewPrivateFile->FileName ==
NULL) {
420 if (*FileName == L
'\\') {
421 AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateRoot->FilePath);
425 AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateFile->FileName);
429 Dst = NewPrivateFile->FileName +
AsciiStrLen (NewPrivateFile->FileName);
430 GuardPointer = NewPrivateFile->FileName +
AsciiStrLen (PrivateRoot->FilePath);
454 while (!LoopFinish) {
457 for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {
458 if ((*ParseFileName ==
'.') &&
459 ((*(ParseFileName + 1) == 0) || (*(ParseFileName + 1) ==
'/')) &&
460 (*(ParseFileName - 1) ==
'/')
466 CutPrefix (ParseFileName - 1, 2);
471 if ((*ParseFileName ==
'.') &&
472 (*(ParseFileName + 1) ==
'.') &&
473 ((*(ParseFileName + 2) == 0) || (*(ParseFileName + 2) ==
'/')) &&
474 (*(ParseFileName - 1) ==
'/')
480 while (ParseFileName != GuardPointer) {
483 if (*ParseFileName ==
'/') {
491 CutPrefix (ParseFileName, Count);
498 if (
AsciiStrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {
499 NewPrivateFile->IsRootDirectory =
TRUE;
500 free (NewPrivateFile->FileName);
501 free (NewPrivateFile);
505 RealFileName = NewPrivateFile->FileName +
AsciiStrLen (NewPrivateFile->FileName) - 1;
506 while (RealFileName > NewPrivateFile->FileName && *RealFileName !=
'/') {
510 TempChar = *(RealFileName - 1);
511 *(RealFileName - 1) = 0;
512 *(RealFileName - 1) = TempChar;
517 NewPrivateFile->IsRootDirectory =
FALSE;
518 NewPrivateFile->fd = -1;
519 NewPrivateFile->Dir =
NULL;
520 if (OpenMode & EFI_FILE_MODE_CREATE) {
521 if (Attributes & EFI_FILE_DIRECTORY) {
522 NewPrivateFile->IsDirectoryPath =
TRUE;
524 NewPrivateFile->IsDirectoryPath =
FALSE;
527 res = stat (NewPrivateFile->FileName, &finfo);
528 if ((res == 0) && S_ISDIR (finfo.st_mode)) {
529 NewPrivateFile->IsDirectoryPath =
TRUE;
531 NewPrivateFile->IsDirectoryPath =
FALSE;
535 if (OpenMode & EFI_FILE_MODE_WRITE) {
536 NewPrivateFile->IsOpenedByRead =
FALSE;
538 NewPrivateFile->IsOpenedByRead =
TRUE;
546 if (NewPrivateFile->IsDirectoryPath) {
547 if ((OpenMode & EFI_FILE_MODE_CREATE)) {
551 if (mkdir (NewPrivateFile->FileName, 0777) != 0) {
552 if (errno != EEXIST) {
554 Status = EFI_ACCESS_DENIED;
560 NewPrivateFile->Dir = opendir (NewPrivateFile->FileName);
561 if (NewPrivateFile->Dir ==
NULL) {
562 if (errno == EACCES) {
563 Status = EFI_ACCESS_DENIED;
565 Status = EFI_NOT_FOUND;
574 NewPrivateFile->fd = open (
575 NewPrivateFile->FileName,
576 ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0) | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR),
579 if (NewPrivateFile->fd < 0) {
580 if (errno == ENOENT) {
581 Status = EFI_NOT_FOUND;
583 Status = EFI_ACCESS_DENIED;
588 if ((OpenMode & EFI_FILE_MODE_CREATE) && (Status ==
EFI_SUCCESS)) {
594 Status = PosixFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
595 if (Status != EFI_BUFFER_TOO_SMALL) {
596 Status = EFI_DEVICE_ERROR;
600 Info = malloc (InfoSize);
605 Status = PosixFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
606 if (EFI_ERROR (Status)) {
611 PosixFileSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);
618 FileName[
StrLen (FileName) + 1] = 0;
619 FileName[
StrLen (FileName)] = L
'\\';
622 if (EFI_ERROR (Status)) {
623 if (NewPrivateFile) {
624 if (NewPrivateFile->FileName) {
625 free (NewPrivateFile->FileName);
628 free (NewPrivateFile);
631 *NewHandle = &NewPrivateFile->EfiFile;
652 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
654 if (PrivateFile->fd >= 0) {
655 close (PrivateFile->fd);
658 if (PrivateFile->Dir !=
NULL) {
659 closedir (PrivateFile->Dir);
662 PrivateFile->fd = -1;
663 PrivateFile->Dir =
NULL;
665 if (PrivateFile->FileName) {
666 free (PrivateFile->FileName);
691 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
692 Status = EFI_WARN_DELETE_FAILURE;
694 if (PrivateFile->IsDirectoryPath) {
695 if (PrivateFile->Dir !=
NULL) {
696 closedir (PrivateFile->Dir);
697 PrivateFile->Dir =
NULL;
700 if (rmdir (PrivateFile->FileName) == 0) {
704 close (PrivateFile->fd);
705 PrivateFile->fd = -1;
707 if (!PrivateFile->IsOpenedByRead) {
708 if (!unlink (PrivateFile->FileName)) {
714 free (PrivateFile->FileName);
748 UINTN FullFileNameSize;
750 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
752 if (!PrivateFile->IsDirectoryPath) {
753 if (PrivateFile->fd < 0) {
754 Status = EFI_DEVICE_ERROR;
758 Res = read (PrivateFile->fd, Buffer, *BufferSize);
760 Status = EFI_DEVICE_ERROR;
772 if (PrivateFile->Dir ==
NULL) {
773 Status = EFI_DEVICE_ERROR;
777 if (PrivateFile->Dirent ==
NULL) {
778 PrivateFile->Dirent = readdir (PrivateFile->Dir);
779 if (PrivateFile->Dirent ==
NULL) {
787 NameSize =
AsciiStrLen (PrivateFile->Dirent->d_name) + 1;
788 ResultSize = Size + 2 * NameSize;
790 if (*BufferSize < ResultSize) {
791 *BufferSize = ResultSize;
792 Status = EFI_BUFFER_TOO_SMALL;
798 *BufferSize = ResultSize;
800 FullFileNameSize =
AsciiStrLen (PrivateFile->FileName) + 1 + NameSize;
801 FullFileName = malloc (FullFileNameSize);
802 if (FullFileName ==
NULL) {
803 Status = EFI_OUT_OF_RESOURCES;
807 AsciiStrCpyS (FullFileName, FullFileNameSize, PrivateFile->FileName);
809 AsciiStrCatS (FullFileName, FullFileNameSize, PrivateFile->Dirent->d_name);
810 Status = UnixSimpleFileSystemFileInfo (
818 PrivateFile->Dirent =
NULL;
852 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
854 if (PrivateFile->fd < 0) {
855 return EFI_DEVICE_ERROR;
858 if (PrivateFile->IsDirectoryPath) {
859 return EFI_UNSUPPORTED;
862 if (PrivateFile->IsOpenedByRead) {
863 return EFI_ACCESS_DENIED;
866 Res = write (PrivateFile->fd, Buffer, *BufferSize);
867 if (Res == (
UINTN)-1) {
868 return ErrnoToEfiStatus ();
886PosixFileSetPossition (
894 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
896 if (PrivateFile->IsDirectoryPath) {
898 return EFI_UNSUPPORTED;
901 if (PrivateFile->Dir ==
NULL) {
902 return EFI_DEVICE_ERROR;
905 rewinddir (PrivateFile->Dir);
908 if (Position == (UINT64)-1) {
909 Pos = lseek (PrivateFile->fd, 0, SEEK_END);
911 Pos = lseek (PrivateFile->fd, Position, SEEK_SET);
914 if (Pos == (off_t)-1) {
915 return ErrnoToEfiStatus ();
933PosixFileGetPossition (
941 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
943 if (PrivateFile->IsDirectoryPath) {
944 Status = EFI_UNSUPPORTED;
946 *Position = (UINT64)lseek (PrivateFile->fd, 0, SEEK_CUR);
947 Status = (*Position == (UINT64)-1) ? ErrnoToEfiStatus () :
EFI_SUCCESS;
986 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
987 PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
990 if (
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
991 Status = UnixSimpleFileSystemFileInfo (PrivateFile,
NULL, BufferSize, Buffer);
992 }
else if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
995 return EFI_BUFFER_TOO_SMALL;
998 UnixStatus = statfs (PrivateFile->FileName, &buf);
999 if (UnixStatus < 0) {
1000 return EFI_DEVICE_ERROR;
1012 FileSystemInfoBuffer->
BlockSize = buf.f_bsize;
1017 PrivateRoot->VolumeLabel
1020 }
else if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1021 if (*BufferSize <
StrSize (PrivateRoot->VolumeLabel)) {
1022 *BufferSize =
StrSize (PrivateRoot->VolumeLabel);
1023 return EFI_BUFFER_TOO_SMALL;
1028 *BufferSize /
sizeof (CHAR16),
1029 PrivateRoot->VolumeLabel
1031 *BufferSize =
StrSize (PrivateRoot->VolumeLabel);
1069 struct stat OldAttr;
1073 BOOLEAN AttrChangeFlag;
1074 BOOLEAN NameChangeFlag;
1075 BOOLEAN SizeChangeFlag;
1076 BOOLEAN TimeChangeFlag;
1077 struct tm NewLastAccessSystemTime;
1078 struct tm NewLastWriteSystemTime;
1080 CHAR8 *AsciiFilePtr;
1081 CHAR16 *UnicodeFilePtr;
1083 struct utimbuf Utime;
1086 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1087 PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
1089 Status = EFI_UNSUPPORTED;
1090 OldFileInfo = NewFileInfo =
NULL;
1091 OldFileName = NewFileName =
NULL;
1092 AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag =
FALSE;
1097 if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
1099 Status = EFI_BAD_BUFFER_SIZE;
1105 free (PrivateRoot->VolumeLabel);
1107 PrivateRoot->VolumeLabel = malloc (
StrSize (NewFileSystemInfo->VolumeLabel));
1108 if (PrivateRoot->VolumeLabel ==
NULL) {
1113 PrivateRoot->VolumeLabel,
1114 StrSize (NewFileSystemInfo->VolumeLabel) / sizeof (CHAR16),
1115 NewFileSystemInfo->VolumeLabel
1125 if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1126 if (BufferSize <
StrSize (PrivateRoot->VolumeLabel)) {
1127 Status = EFI_BAD_BUFFER_SIZE;
1132 PrivateRoot->VolumeLabel,
1133 StrSize (PrivateRoot->VolumeLabel) / sizeof (CHAR16),
1141 if (!
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
1142 Status = EFI_UNSUPPORTED;
1147 Status = EFI_BAD_BUFFER_SIZE;
1160 (NewFileInfo->
Attribute &~(EFI_FILE_VALID_ATTR)) ||
1161 ((
sizeof (
UINTN) == 4) && (NewFileInfo->
Size > 0xFFFFFFFF))
1164 Status = EFI_INVALID_PARAMETER;
1173 Status = UnixSimpleFileSystemFileInfo (PrivateFile,
NULL, &OldInfoSize,
NULL);
1174 if (Status != EFI_BUFFER_TOO_SMALL) {
1175 Status = EFI_DEVICE_ERROR;
1179 OldFileInfo = malloc (OldInfoSize);
1180 if (OldFileInfo ==
NULL) {
1184 Status = UnixSimpleFileSystemFileInfo (PrivateFile,
NULL, &OldInfoSize, OldFileInfo);
1185 if (EFI_ERROR (Status)) {
1189 OldFileName = malloc (
AsciiStrSize (PrivateFile->FileName));
1190 if (OldFileName ==
NULL) {
1197 PrivateFile->FileName
1203 if (NewFileInfo->
FileName[0] ==
'\\') {
1205 NewFileName = malloc (Size);
1206 if (NewFileName ==
NULL) {
1210 AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath);
1211 AsciiFilePtr = NewFileName +
AsciiStrLen (NewFileName);
1212 UnicodeFilePtr = NewFileInfo->
FileName + 1;
1213 *AsciiFilePtr++ =
'/';
1216 NewFileName = malloc (Size);
1217 if (NewFileName ==
NULL) {
1221 AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath);
1222 AsciiFilePtr = NewFileName +
AsciiStrLen (NewFileName);
1223 if ((AsciiFilePtr[-1] !=
'/') && (NewFileInfo->
FileName[0] !=
'/')) {
1225 AsciiFilePtr[0] =
'/';
1226 AsciiFilePtr[1] =
'\0';
1230 UnicodeFilePtr = NewFileInfo->
FileName;
1234 while (*UnicodeFilePtr) {
1235 *AsciiFilePtr++ = *UnicodeFilePtr++;
1244 if ((NewFileInfo->
Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->
Attribute & EFI_FILE_DIRECTORY)) {
1245 Status = EFI_INVALID_PARAMETER;
1249 AttrChangeFlag =
TRUE;
1257 NameChangeFlag =
TRUE;
1264 SizeChangeFlag =
TRUE;
1274 TimeChangeFlag =
TRUE;
1279 TimeChangeFlag =
TRUE;
1284 TimeChangeFlag =
TRUE;
1290 if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {
1298 if (stat (OldFileName, &OldAttr) != 0) {
1299 Status = ErrnoToEfiStatus ();
1306 if (NameChangeFlag) {
1310 if (PrivateFile->IsOpenedByRead) {
1311 Status = EFI_ACCESS_DENIED;
1315 for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L
'/'; CharPointer++) {
1318 if (*CharPointer != 0) {
1319 Status = EFI_ACCESS_DENIED;
1323 UnixStatus = rename (OldFileName, NewFileName);
1324 if (UnixStatus == 0) {
1328 free (PrivateFile->FileName);
1330 PrivateFile->FileName = malloc (
AsciiStrSize (NewFileName));
1331 if (PrivateFile->FileName ==
NULL) {
1336 PrivateFile->FileName,
1341 Status = EFI_DEVICE_ERROR;
1349 if (SizeChangeFlag) {
1350 if (PrivateFile->IsDirectoryPath) {
1351 Status = EFI_UNSUPPORTED;
1355 if (PrivateFile->IsOpenedByRead || OldFileInfo->
Attribute & EFI_FILE_READ_ONLY) {
1356 Status = EFI_ACCESS_DENIED;
1360 if (ftruncate (PrivateFile->fd, NewFileInfo->
FileSize) != 0) {
1361 Status = ErrnoToEfiStatus ();
1369 if (TimeChangeFlag) {
1370 NewLastAccessSystemTime.tm_year = NewFileInfo->
LastAccessTime.Year;
1371 NewLastAccessSystemTime.tm_mon = NewFileInfo->
LastAccessTime.Month;
1372 NewLastAccessSystemTime.tm_mday = NewFileInfo->
LastAccessTime.Day;
1373 NewLastAccessSystemTime.tm_hour = NewFileInfo->
LastAccessTime.Hour;
1374 NewLastAccessSystemTime.tm_min = NewFileInfo->
LastAccessTime.Minute;
1375 NewLastAccessSystemTime.tm_sec = NewFileInfo->
LastAccessTime.Second;
1376 NewLastAccessSystemTime.tm_isdst = 0;
1378 Utime.actime = mktime (&NewLastAccessSystemTime);
1386 NewLastWriteSystemTime.tm_isdst = 0;
1388 Utime.modtime = mktime (&NewLastWriteSystemTime);
1390 if ((Utime.actime == (time_t)-1) || (Utime.modtime == (time_t)-1)) {
1394 if (utime (PrivateFile->FileName, &Utime) == -1) {
1395 Status = ErrnoToEfiStatus ();
1404 NewAttr = OldAttr.st_mode;
1406 if (NewFileInfo->
Attribute & EFI_FILE_READ_ONLY) {
1407 NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH);
1412 if (chmod (NewFileName, NewAttr) != 0) {
1413 Status = ErrnoToEfiStatus ();
1417 if (OldFileInfo !=
NULL) {
1421 if (OldFileName !=
NULL) {
1425 if (NewFileName !=
NULL) {
1454 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1456 if (PrivateFile->IsDirectoryPath) {
1457 return EFI_UNSUPPORTED;
1460 if (PrivateFile->IsOpenedByRead) {
1461 return EFI_ACCESS_DENIED;
1464 if (PrivateFile->fd < 0) {
1465 return EFI_DEVICE_ERROR;
1468 if (fsync (PrivateFile->fd) != 0) {
1469 return ErrnoToEfiStatus ();
1476PosixFileSystmeThunkOpen (
1483 if (This->Private !=
NULL) {
1484 return EFI_ALREADY_STARTED;
1487 if (!
CompareGuid (This->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
1488 return EFI_UNSUPPORTED;
1492 if (Private ==
NULL) {
1493 return EFI_OUT_OF_RESOURCES;
1496 Private->FilePath = malloc (
StrLen (This->ConfigString) + 1);
1497 if (Private->FilePath ==
NULL) {
1499 return EFI_OUT_OF_RESOURCES;
1503 for (i = 0; This->ConfigString[i] != 0; i++) {
1504 Private->FilePath[i] = This->ConfigString[i];
1507 Private->FilePath[i] = 0;
1509 Private->VolumeLabel = malloc (
StrSize (L
"EFI_EMULATED"));
1510 if (Private->VolumeLabel ==
NULL) {
1511 free (Private->FilePath);
1513 return EFI_OUT_OF_RESOURCES;
1517 Private->VolumeLabel,
1518 StrSize (L
"EFI_EMULATED") /
sizeof (CHAR16),
1522 Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
1523 Private->Thunk = This;
1524 CopyMem (&Private->SimpleFileSystem, &gPosixFileSystemProtocol, sizeof (Private->SimpleFileSystem));
1525 Private->FileHandlesOpen =
FALSE;
1527 This->Interface = &Private->SimpleFileSystem;
1528 This->Private = Private;
1533PosixFileSystmeThunkClose (
1539 if (!
CompareGuid (This->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {
1540 return EFI_UNSUPPORTED;
1543 Private = This->Private;
1545 if (Private->FileHandlesOpen) {
1549 return EFI_NOT_READY;
1552 if (This->Private !=
NULL) {
1553 if (Private->VolumeLabel !=
NULL) {
1554 free (Private->VolumeLabel);
1557 free (This->Private);
1558 This->Private =
NULL;
1565 &gEfiSimpleFileSystemProtocolGuid,
1569 GasketPosixFileSystmeThunkOpen,
1570 GasketPosixFileSystmeThunkClose,
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
RETURN_STATUS EFIAPI AsciiStrCatS(IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
struct tm * gmtime(const time_t *)
#define SIZE_OF_EFI_FILE_INFO
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
EFI_TIME ModificationTime