+++ /dev/null
-/** @file\r
- Implement the opendir, closedir, and readdir functions.\r
-\r
- Copyright (c) 2011, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "internal.h"\r
-#include <Library/ShellLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/BaseLib.h>\r
-\r
-typedef struct {\r
- UINT32 Signature;\r
- SHELL_FILE_HANDLE DirHandle;\r
- EFI_FILE_INFO *FileInfo;\r
- struct dirent *DirentStructure;\r
-} DIR_STRUCTURE;\r
- \r
-DIR * opendir(const char * AsciiFileName)\r
-{\r
- EFI_STATUS Status;\r
- DIR_STRUCTURE *DirStruct;\r
- CHAR16 *FileName;\r
-\r
- DirStruct = (DIR_STRUCTURE*)AllocateZeroPool(sizeof(DIR_STRUCTURE));\r
- if (DirStruct == NULL) {\r
- errno = ENOMEM;\r
- return NULL;\r
- }\r
-\r
- FileName = (CHAR16*)AllocateZeroPool((1+AsciiStrLen(AsciiFileName))*sizeof(CHAR16));\r
- if (FileName == NULL) {\r
- FreePool(DirStruct);\r
- errno = ENOMEM;\r
- return NULL;\r
- }\r
- AsciiStrToUnicodeStr(AsciiFileName, FileName);\r
-\r
- Status = ShellOpenFileByName(FileName, &DirStruct->DirHandle, EFI_FILE_MODE_READ, 0);\r
- FreePool(FileName);\r
- if (EFI_ERROR(Status)) {\r
- errno = ENOENT;\r
- FreePool(DirStruct);\r
- return NULL;\r
- }\r
- DirStruct->Signature = 0x08675309;\r
- return ((DIR*)DirStruct);\r
-}\r
-\r
-int closedir(DIR * DirPointer)\r
-{\r
- DIR_STRUCTURE *DirStruct;\r
-\r
- if (DirPointer == NULL) {\r
- return 0;\r
- }\r
-\r
- DirStruct = (DIR_STRUCTURE*)DirPointer;\r
- if (DirStruct->Signature != 0x08675309) {\r
- return 0;\r
- }\r
-\r
- ShellCloseFile(DirStruct->DirHandle);\r
- SHELL_FREE_NON_NULL(DirStruct->FileInfo);\r
- SHELL_FREE_NON_NULL(DirStruct->DirentStructure);\r
- SHELL_FREE_NON_NULL(DirStruct);\r
- \r
- return 0;\r
-}\r
-\r
-struct dirent * readdir(DIR * DirPointer)\r
-{\r
- DIR_STRUCTURE *DirStruct;\r
- EFI_STATUS Status;\r
- BOOLEAN NoFile;\r
-\r
- NoFile = FALSE;\r
-\r
- if (DirPointer == NULL) {\r
- errno = EBADF;\r
- return NULL;\r
- }\r
-\r
- DirStruct = (DIR_STRUCTURE*)DirPointer;\r
- if (DirStruct->Signature != 0x08675309) {\r
- errno = EBADF;\r
- return NULL;\r
- }\r
-\r
- if (DirStruct->FileInfo == NULL) {\r
- Status = ShellFindFirstFile(DirStruct->DirHandle, &(DirStruct->FileInfo));\r
- } else {\r
- Status = ShellFindNextFile(DirStruct->DirHandle, DirStruct->FileInfo, &NoFile);\r
- }\r
-\r
- if (EFI_ERROR(Status)) {\r
- errno = ENOENT;\r
- return NULL;\r
- }\r
-\r
- if (NoFile) {\r
- return (NULL);\r
- }\r
-\r
- SHELL_FREE_NON_NULL(DirStruct->DirentStructure);\r
-\r
- DirStruct->DirentStructure = AllocateZeroPool(sizeof(DIR_STRUCTURE)+(StrSize(DirStruct->FileInfo->FileName)));\r
- if (DirStruct->DirentStructure == NULL) {\r
- errno = ENOMEM;\r
- return NULL;\r
- }\r
-\r
- StrCpy(DirStruct->FileInfo->FileName, DirStruct->DirentStructure->FileName);\r
-\r
- DirStruct->DirentStructure->FileSize = DirStruct->FileInfo->FileSize;\r
- DirStruct->DirentStructure->PhysicalSize = DirStruct->FileInfo->PhysicalSize;\r
- DirStruct->DirentStructure->Attribute = DirStruct->FileInfo->Attribute;\r
- DirStruct->DirentStructure->CreateTime.tv_sec = Efi2Time(&DirStruct->FileInfo->CreateTime);\r
- DirStruct->DirentStructure->CreateTime.tv_nsec = DirStruct->FileInfo->CreateTime.Nanosecond;\r
- DirStruct->DirentStructure->LastAccessTime.tv_nsec = Efi2Time(&DirStruct->FileInfo->LastAccessTime);\r
- DirStruct->DirentStructure->LastAccessTime.tv_sec = DirStruct->FileInfo->LastAccessTime.Nanosecond;\r
- DirStruct->DirentStructure->ModificationTime.tv_sec = Efi2Time(&DirStruct->FileInfo->ModificationTime);\r
- DirStruct->DirentStructure->ModificationTime.tv_nsec = DirStruct->FileInfo->ModificationTime.Nanosecond;\r
- DirStruct->DirentStructure->Size = StrSize(DirStruct->DirentStructure->FileName) + sizeof(DIR_STRUCTURE);\r
-\r
- return (DirStruct->DirentStructure);\r
-}\r