Hi Jaben, On Tue, December 30, 2014 12:31 pm, Carsey, Jaben wrote: > Maybe if UdfClose() fails, report that error and donât continue?
Do you mean 1) just use return code from UdfClose() (when it fails) other than always returning EFI_WARN_DELETE_FAILURE or 2) abort (or assert) it and operations on the driver are no longer allowed? I think I'm missing something here... Could you please give me a real example of that? Thanks, Paulo > > From: Paulo Alcantara [mailto:pca...@gmail.com] > Sent: Monday, December 29, 2014 3:01 PM > To: edk2-devel@lists.sourceforge.net > Subject: Re: [edk2] [PATCH 2/3] MdeModulePkg: Initial UDF/ECMA-167 file > system support > > > Hi Jaben, > > On Dec 29, 2014 3:51 PM, "Carsey, Jaben" > <jaben.car...@intel.com<mailto:jaben.car...@intel.com>> wrote: >> >> I am not sure if you need to worry about someone calling your API with a >> different file system. It's definitely easier to be safe. >> >> Do you really want to just return an error in that case since the FAT32 >> file system might be able to actually do the delete? > > OK, I agree with you. We can't definitely fix all mistakes the programmer > can do, so I think its OK and more clearer to call UdfClose() directly in > UdfDelete(). > > I should be sending a v2 of this series with that change. > > Thank you for pointing it out and testing it! Thats really appreciable. > > Please, let me know of any issue you find. > > Thanks, > > Paulo > >> >> -Jaben >> >> > -----Original Message----- >> > From: Paulo Alcantara >> [mailto:pca...@zytor.com<mailto:pca...@zytor.com>] >> > Sent: Monday, December 29, 2014 10:31 AM >> > To: >> edk2-devel@lists.sourceforge.net<mailto:edk2-devel@lists.sourceforge.net> >> > Subject: Re: [edk2] [PATCH 2/3] MdeModulePkg: Initial UDF/ECMA-167 >> file >> > system support >> > >> > Hi Jaben, >> > >> > On Mon, December 29, 2014 2:55 pm, Carsey, Jaben wrote: >> > > Thanks for the clarifications... I had comments below, but >> generally >> > > seems ok. >> > > >> > >> -----Original Message----- >> > >> From: Paulo Alcantara >> [mailto:pca...@zytor.com<mailto:pca...@zytor.com>] >> > >> Sent: Monday, December 29, 2014 9:21 AM >> > >> To: >> edk2-devel@lists.sourceforge.net<mailto:edk2-devel@lists.sourceforge.net> >> > >> Subject: Re: [edk2] [PATCH 2/3] MdeModulePkg: Initial UDF/ECMA-167 >> > file >> > >> system support >> > >> >> > >> Hi Jaben, >> > >> >> > >> On Mon, December 29, 2014 1:42 pm, Carsey, Jaben wrote: >> > >> >> > >> > Few questions: >> > >> > 1) Why is the "close" portion of the UdfDelete so different from >> the >> > >> > UdfClose API? Since the file will never be deleted, I would >> have >> > >> assumed >> > >> > the close portions would be identical... >> > >> >> > >> The UdfDelete() function already calls UdfClose() through the >> function >> > >> pointer "PrivFileData->FileIo.Close", so no need to replicate it. >> > >> >> > >> Sounds correct to you? >> > > >> > > Seems fine. Why not just use the API directly instead of decoding >> the >> > > structure? >> > > ::UdfClose(This); >> > >> > Well, that'd be OK to call directly UdfClose(), but I was thinking in >> the >> > following scenario: >> > >> > Let's supppose we have two file handles: FileHandle1 and FileHandle2, >> and >> > both file handles are for different filesystems (FileHandle1: FAT32; >> > FileHandle2: UDF). >> > >> > Therefore, one would write the following code: >> > >> > ... >> > FileHandle2->Close(FileHandle1); >> > ... >> > >> > UdfClose() would be called instead of calling the FAT-specific >> Close() >> > function which belongs to FileHandle1, so I think that would be safer >> than >> > calling UdfClose() directly. >> > >> > Do you think I really need to take care of such situation like that? >> > >> > If no, then I'd agree with you and call UdfClose() directly in >> UdfDelete() >> > which makes code clearer. >> > >> > >> > 2) Both UdfRead and UdfWrite always fail. What is the expected >> use of >> > >> > this driver? >> > >> >> > >> UdfRead() is failing because you haven't applied the third patch >> which >> > >> implements it. >> > > >> > > Ah. Found it now. I didn't notice that was what the next patch >> did. >> > > >> > >> >> > >> Apply the 3 patches and give it a try again, please. Additionally, >> make >> > >> sure your media contains an UDF volume which corresponds to rev >> 2.00 or >> > >> higher. >> > >> >> > >> e.g. from a USB stick: >> > >> >> > >> $ mkudffs -b 512 --media-type=hd /dev/sdX >> > >> >> > >> (since the revision was omitted, it will default to 0x0201) >> > >> >> > >> This driver provides read-only functionality to UDF volumes through >> the >> > >> EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and EFI_FILE_PROTOCOL >> > protocols. >> > >> >> > >> > 3) why sometimes use CORRUPT and sometimes the >> > WRITE_PROTECTED >> > >> error? Why >> > >> > not always use the second one... >> > >> >> > >> the EFI_VOLUME_CORRUPTED make more sense to me when an specific >> > bit >> > >> of >> > >> data on the volume doesn't seem to be valid. There are only three >> places >> > >> where EFI_WRITE_PROTECTED is used: UdfFlush(), UdfSetInfo() and >> > >> UdfOpen() >> > >> (when trying to open a file in non-read mode) so, if you look at >> them, I >> > >> haven't parsed any filesystem's metadata but all related to mode >> > >> operation... >> > >> >> > >> Sounds correct to you? >> > > >> > > Seems ok. Looks like most corrupted returns were removed by patch >> 3. >> > >> > Yep. >> > >> > Thanks, >> > >> > Paulo >> > >> > > >> > >> >> > >> Thanks, >> > >> >> > >> Paulo >> > >> >> > >> > >> > >> > -Jaben >> > >> > >> > >> >> -----Original Message----- >> > >> >> From: Paulo Alcantara >> [mailto:pca...@gmail.com<mailto:pca...@gmail.com>] >> > >> >> Sent: Monday, December 29, 2014 4:25 AM >> > >> >> To: >> edk2-devel@lists.sourceforge.net<mailto:edk2-devel@lists.sourceforge.net> >> > >> >> Subject: [edk2] [PATCH 2/3] MdeModulePkg: Initial UDF/ECMA-167 >> file >> > >> >> system support >> > >> >> >> > >> >> A new child device handle will be installed if the Controller >> handle >> > >> >> which >> > >> >> has BlockIo and DiskIo contains an UDF 2.00 (or higher) volume >> in it. >> > >> >> >> > >> >> Find root directory, lookup and open operations on regular, >> directory >> > >> >> and >> > >> >> symlink files are supported. >> > >> >> >> > >> >> Contributed-under: TianoCore Contribution Agreement 1.0 >> > >> >> Signed-off-by: Paulo Alcantara >> <pca...@zytor.com<mailto:pca...@zytor.com>> >> > >> >> --- >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/ComponentName.c | 185 ++ >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/File.c | 660 >> +++++ >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/FileName.c | 195 ++ >> > >> >> .../Universal/Disk/UdfDxe/FileSystemOperations.c | 2535 >> > >> >> ++++++++++++++++++++ >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/Udf.c | 411 ++++ >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/Udf.h | 1243 >> > ++++++++++ >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf | 66 + >> > >> >> 7 files changed, 5295 insertions(+) >> > >> >> create mode 100644 >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/ComponentName.c >> > >> >> create mode 100644 MdeModulePkg/Universal/Disk/UdfDxe/File.c >> > >> >> create mode 100644 >> > MdeModulePkg/Universal/Disk/UdfDxe/FileName.c >> > >> >> create mode 100644 >> > >> >> MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c >> > >> >> create mode 100644 MdeModulePkg/Universal/Disk/UdfDxe/Udf.c >> > >> >> create mode 100644 MdeModulePkg/Universal/Disk/UdfDxe/Udf.h >> > >> >> create mode 100644 >> > MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf >> > >> >> >> > >> >> diff --git >> > a/MdeModulePkg/Universal/Disk/UdfDxe/ComponentName.c >> > >> >> b/MdeModulePkg/Universal/Disk/UdfDxe/ComponentName.c >> > >> >> new file mode 100644 >> > >> >> index 0000000..b07b92f >> > >> >> --- /dev/null >> > >> >> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/ComponentName.c >> > >> >> @@ -0,0 +1,185 @@ >> > >> >> +/** @file >> > >> >> + UEFI Component Name protocol for UDF/ECMA-167 filesystem >> > driver. >> > >> >> + >> > >> >> +Copyright (c) 2014 Paulo Alcantara >> <pca...@zytor.com<mailto:pca...@zytor.com>><BR> >> > >> >> +This program and the accompanying materials >> > >> >> +are licensed and made available under the terms and conditions >> of >> > >> the >> > >> >> BSD >> > >> >> License >> > >> >> +which accompanies this distribution. The full text of the >> license >> > >> may >> > >> >> be >> > >> >> found at >> > >> >> +http://opensource.org/licenses/bsd-license.php >> > >> >> + >> > >> >> +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS >> > IS" >> > >> >> BASIS, >> > >> >> +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER >> > >> >> EXPRESS OR IMPLIED. >> > >> >> + >> > >> >> +**/ >> > >> >> + >> > >> >> +#include "Udf.h" >> > >> >> + >> > >> >> +// >> > >> >> +// EFI Component Name Protocol >> > >> >> +// >> > >> >> +GLOBAL_REMOVE_IF_UNREFERENCED >> > >> >> EFI_COMPONENT_NAME_PROTOCOL gUdfComponentName = { >> > >> >> + UdfComponentNameGetDriverName, >> > >> >> + UdfComponentNameGetControllerName, >> > >> >> + "eng" >> > >> >> +}; >> > >> >> + >> > >> >> +// >> > >> >> +// EFI Component Name 2 Protocol >> > >> >> +// >> > >> >> +GLOBAL_REMOVE_IF_UNREFERENCED >> > >> >> EFI_COMPONENT_NAME2_PROTOCOL gUdfComponentName2 = { >> > >> >> + (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) >> > >> >> UdfComponentNameGetDriverName, >> > >> >> + (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) >> > >> >> UdfComponentNameGetControllerName, >> > >> >> + "en" >> > >> >> +}; >> > >> >> + >> > >> >> +// >> > >> >> +// Driver name table for Udf module. >> > >> >> +// It is shared by the implementation of ComponentName & >> > >> >> ComponentName2 Protocol. >> > >> >> +// >> > >> >> +GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE >> > >> >> mUdfDriverNameTable[] = { >> > >> >> + { >> > >> >> + "eng;en", >> > >> >> + L"UDF Filesystem Driver" >> > >> >> + }, >> > >> >> + { >> > >> >> + NULL, >> > >> >> + NULL >> > >> >> + } >> > >> >> +}; >> > >> >> + >> > >> >> +/** >> > >> >> + Retrieves a Unicode string that is the user readable name of >> the >> > >> >> driver. >> > >> >> + >> > >> >> + This function retrieves the user readable name of a driver in >> the >> > >> >> form of a >> > >> >> + Unicode string. If the driver specified by This has a user >> > >> readable >> > >> >> name in >> > >> >> + the language specified by Language, then a pointer to the >> driver >> > >> name >> > >> >> is >> > >> >> + returned in DriverName, and EFI_SUCCESS is returned. If the >> driver >> > >> >> specified >> > >> >> + by This does not support the language specified by Language, >> > >> >> + then EFI_UNSUPPORTED is returned. >> > >> >> + >> > >> >> + @param This[in] A pointer to the >> > >> >> EFI_COMPONENT_NAME2_PROTOCOL or >> > >> >> + EFI_COMPONENT_NAME_PROTOCOL >> > >> instance. >> > >> >> + >> > >> >> + @param Language[in] A pointer to a Null-terminated >> ASCII >> > >> >> string >> > >> >> + array indicating the language. >> This >> > >> is >> > >> >> the >> > >> >> + language of the driver name >> that the >> > >> >> caller is >> > >> >> + requesting, and it must match >> one of >> > >> >> the >> > >> >> + languages specified in >> > >> >> SupportedLanguages. The >> > >> >> + number of languages supported >> by a >> > >> >> driver is up >> > >> >> + to the driver writer. Language >> is >> > >> >> specified >> > >> >> + in RFC 4646 or ISO 639-2 >> language >> > >> code >> > >> >> format. >> > >> >> + >> > >> >> + @param DriverName[out] A pointer to the Unicode string >> to >> > >> >> return. >> > >> >> + This Unicode string is the name >> of >> > >> the >> > >> >> + driver specified by This in >> the >> > >> >> language >> > >> >> + specified by Language. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The Unicode string for the >> Driver >> > >> >> specified by >> > >> >> + This and the language specified >> by >> > >> >> Language was >> > >> >> + returned in DriverName. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER Language is NULL. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER DriverName is NULL. >> > >> >> + >> > >> >> + @retval EFI_UNSUPPORTED The driver specified by This >> does >> > >> not >> > >> >> support >> > >> >> + the language specified by >> Language. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfComponentNameGetDriverName ( >> > >> >> + IN EFI_COMPONENT_NAME_PROTOCOL *This, >> > >> >> + IN CHAR8 *Language, >> > >> >> + OUT CHAR16 **DriverName >> > >> >> + ) >> > >> >> +{ >> > >> >> + return LookupUnicodeString2 ( >> > >> >> + Language, >> > >> >> + This->SupportedLanguages, >> > >> >> + mUdfDriverNameTable, >> > >> >> + DriverName, >> > >> >> + (BOOLEAN)(This == &gUdfComponentName) >> > >> >> + ); >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Retrieves a Unicode string that is the user readable name of >> the >> > >> >> controller >> > >> >> + that is being managed by a driver. >> > >> >> + >> > >> >> + This function retrieves the user readable name of the >> controller >> > >> >> specified >> > >> >> by >> > >> >> + ControllerHandle and ChildHandle in the form of a Unicode >> string. >> > >> If >> > >> >> the >> > >> >> + driver specified by This has a user readable name in the >> language >> > >> >> specified >> > >> >> by >> > >> >> + Language, then a pointer to the controller name is returned >> in >> > >> >> ControllerName, >> > >> >> + and EFI_SUCCESS is returned. If the driver specified by This >> is >> > >> not >> > >> >> currently >> > >> >> + managing the controller specified by ControllerHandle and >> > >> >> ChildHandle, >> > >> >> + then EFI_UNSUPPORTED is returned. If the driver specified by >> This >> > >> >> does >> > >> >> not >> > >> >> + support the language specified by Language, then >> > EFI_UNSUPPORTED >> > >> is >> > >> >> returned. >> > >> >> + >> > >> >> + @param This[in] A pointer to the >> > >> >> EFI_COMPONENT_NAME2_PROTOCOL or >> > >> >> + EFI_COMPONENT_NAME_PROTOCOL >> > >> instance. >> > >> >> + >> > >> >> + @param ControllerHandle[in] The handle of a controller that >> the >> > >> >> driver >> > >> >> + specified by This is managing. >> This >> > >> >> handle >> > >> >> + specifies the controller whose >> name >> > >> is >> > >> >> to be >> > >> >> + returned. >> > >> >> + >> > >> >> + @param ChildHandle[in] The handle of the child >> controller >> > >> to >> > >> >> retrieve >> > >> >> + the name of. This is an >> optional >> > >> >> parameter that >> > >> >> + may be NULL. It will be NULL >> for >> > >> >> device >> > >> >> + drivers. It will also be NULL >> for a >> > >> >> bus drivers >> > >> >> + that wish to retrieve the name >> of >> > >> the >> > >> >> bus >> > >> >> + controller. It will not be >> NULL for >> > >> a >> > >> >> bus >> > >> >> + driver that wishes to retrieve >> the >> > >> name >> > >> >> of a >> > >> >> + child controller. >> > >> >> + >> > >> >> + @param Language[in] A pointer to a Null-terminated >> ASCII >> > >> >> string >> > >> >> + array indicating the language. >> This >> > >> is >> > >> >> the >> > >> >> + language of the driver name >> that the >> > >> >> caller is >> > >> >> + requesting, and it must match >> one of >> > >> >> the >> > >> >> + languages specified in >> > >> >> SupportedLanguages. The >> > >> >> + number of languages supported >> by a >> > >> >> driver is up >> > >> >> + to the driver writer. Language >> is >> > >> >> specified in >> > >> >> + RFC 4646 or ISO 639-2 language >> code >> > >> >> format. >> > >> >> + >> > >> >> + @param ControllerName[out] A pointer to the Unicode string >> to >> > >> >> return. >> > >> >> + This Unicode string is the name >> of >> > >> the >> > >> >> + controller specified by >> > >> >> ControllerHandle and >> > >> >> + ChildHandle in the language >> > >> specified >> > >> >> by >> > >> >> + Language from the point of view >> of >> > >> the >> > >> >> driver >> > >> >> + specified by This. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The Unicode string for the >> user >> > >> >> readable name >> > >> >> in >> > >> >> + the language specified by >> Language >> > >> for >> > >> >> the >> > >> >> + driver specified by This was >> > >> returned >> > >> >> in >> > >> >> + DriverName. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it >> is >> > >> not >> > >> a >> > >> >> valid >> > >> >> + EFI_HANDLE. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER Language is NULL. >> > >> >> + >> > >> >> + @retval EFI_INVALID_PARAMETER ControllerName is NULL. >> > >> >> + >> > >> >> + @retval EFI_UNSUPPORTED The driver specified by This is >> not >> > >> >> currently >> > >> >> + managing the controller >> specified by >> > >> >> + ControllerHandle and >> ChildHandle. >> > >> >> + >> > >> >> + @retval EFI_UNSUPPORTED The driver specified by This >> does >> > >> not >> > >> >> support >> > >> >> + the language specified by >> Language. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfComponentNameGetControllerName ( >> > >> >> + IN EFI_COMPONENT_NAME_PROTOCOL *This, >> > >> >> + IN EFI_HANDLE ControllerHandle, >> > >> >> + IN EFI_HANDLE ChildHandle OPTIONAL, >> > >> >> + IN CHAR8 *Language, >> > >> >> + OUT CHAR16 **ControllerName >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_UNSUPPORTED; >> > >> >> +} >> > >> >> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c >> > >> >> b/MdeModulePkg/Universal/Disk/UdfDxe/File.c >> > >> >> new file mode 100644 >> > >> >> index 0000000..f32dcf0 >> > >> >> --- /dev/null >> > >> >> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c >> > >> >> @@ -0,0 +1,660 @@ >> > >> >> +/** @file >> > >> >> + UDF/ECMA-167 filesystem driver. >> > >> >> + >> > >> >> +Copyright (c) 2014 Paulo Alcantara >> <pca...@zytor.com<mailto:pca...@zytor.com>><BR> >> > >> >> +This program and the accompanying materials >> > >> >> +are licensed and made available under the terms and conditions >> of >> > >> the >> > >> >> BSD >> > >> >> License >> > >> >> +which accompanies this distribution. The full text of the >> license >> > >> may >> > >> >> be >> > >> >> found at >> > >> >> +http://opensource.org/licenses/bsd-license.php >> > >> >> + >> > >> >> +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS >> > IS" >> > >> >> BASIS, >> > >> >> +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER >> > >> >> EXPRESS OR IMPLIED. >> > >> >> + >> > >> >> +**/ >> > >> >> + >> > >> >> +#include "Udf.h" >> > >> >> + >> > >> >> +EFI_FILE_PROTOCOL gUdfFileIoOps = { >> > >> >> + EFI_FILE_PROTOCOL_REVISION, >> > >> >> + UdfOpen, >> > >> >> + UdfClose, >> > >> >> + UdfDelete, >> > >> >> + UdfRead, >> > >> >> + UdfWrite, >> > >> >> + UdfGetPosition, >> > >> >> + UdfSetPosition, >> > >> >> + UdfGetInfo, >> > >> >> + UdfSetInfo, >> > >> >> + UdfFlush, >> > >> >> + NULL, >> > >> >> + NULL, >> > >> >> + NULL, >> > >> >> + NULL >> > >> >> +}; >> > >> >> + >> > >> >> +#define _ROOT_FILE(_PrivData) (_PrivData)->Root >> > >> >> +#define _PARENT_FILE(_PrivData) \ >> > >> >> + ((_PrivData)->IsRootDirectory ? (_PrivData)->Root : >> > >> >> &(_PrivData)->File) >> > >> >> +#define _FILE(_PrivData) _PARENT_FILE(_PrivData) >> > >> >> + >> > >> >> +/** >> > >> >> + Open the root directory on a volume. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param Root Returns an Open file handle for the root >> directory >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The device was opened. >> > >> >> + @retval EFI_UNSUPPORTED This volume does not support the >> file >> > >> >> system. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_ACCESS_DENIED The service denied access to >> the >> > >> file. >> > >> >> + @retval EFI_OUT_OF_RESOURCES The volume was not opened due >> > to >> > >> lack >> > >> >> of resources. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfOpenVolume ( >> > >> >> + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, >> > >> >> + OUT EFI_FILE_PROTOCOL **Root >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_TPL OldTpl; >> > >> >> + EFI_STATUS Status; >> > >> >> + PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData; >> > >> >> + PRIVATE_UDF_FILE_DATA *PrivFileData; >> > >> >> + >> > >> >> + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); >> > >> >> + >> > >> >> + if (!This || !Root) { >> > >> >> + Status = EFI_INVALID_PARAMETER; >> > >> >> + goto Error_Invalid_Params; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (This); >> > >> >> + >> > >> >> + if (!PrivFsData->OpenFiles) { >> > >> >> + // >> > >> >> + // There is no more open files. Read volume information >> again >> > >> since >> > >> >> it was >> > >> >> + // cleaned up on the last UdfClose() call. >> > >> >> + // >> > >> >> + Status = ReadUdfVolumeInformation ( >> > >> >> + PrivFsData->BlockIo, >> > >> >> + PrivFsData->DiskIo, >> > >> >> + &PrivFsData->Volume >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Read_Udf_Volume; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + CleanupFileInformation (&PrivFsData->Root); >> > >> >> + >> > >> >> + // >> > >> >> + // Find root directory file. >> > >> >> + // >> > >> >> + Status = FindRootDirectory ( >> > >> >> + PrivFsData->BlockIo, >> > >> >> + PrivFsData->DiskIo, >> > >> >> + &PrivFsData->Volume, >> > >> >> + &PrivFsData->Root >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Find_Root_Dir; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData = >> > >> >> + (PRIVATE_UDF_FILE_DATA *)AllocateZeroPool ( >> > >> >> + sizeof >> > >> (PRIVATE_UDF_FILE_DATA) >> > >> >> + ); >> > >> >> + if (!PrivFileData) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Priv_File_Data; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData->Signature = >> > PRIVATE_UDF_FILE_DATA_SIGNATURE; >> > >> >> + PrivFileData->SimpleFs = This; >> > >> >> + PrivFileData->Root = &PrivFsData->Root; >> > >> >> + PrivFileData->IsRootDirectory = TRUE; >> > >> >> + >> > >> >> + CopyMem ( >> > >> >> + (VOID *)&PrivFileData->FileIo, >> > >> >> + (VOID *)&gUdfFileIoOps, >> > >> >> + sizeof (EFI_FILE_PROTOCOL) >> > >> >> + ); >> > >> >> + >> > >> >> + *Root = &PrivFileData->FileIo; >> > >> >> + >> > >> >> + PrivFsData->OpenFiles++; >> > >> >> + >> > >> >> + gBS->RestoreTPL (OldTpl); >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> + >> > >> >> +Error_Alloc_Priv_File_Data: >> > >> >> + CleanupFileInformation (&PrivFsData->Root); >> > >> >> + >> > >> >> +Error_Find_Root_Dir: >> > >> >> + CleanupVolumeInformation (&PrivFsData->Volume); >> > >> >> + >> > >> >> +Error_Read_Udf_Volume: >> > >> >> +Error_Invalid_Params: >> > >> >> + gBS->RestoreTPL (OldTpl); >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Opens a new file relative to the source file's location. >> > >> >> + >> > >> >> + @param This The protocol instance pointer. >> > >> >> + @param NewHandle Returns File Handle for FileName. >> > >> >> + @param FileName Null terminated string. "\", ".", and ".." >> are >> > >> >> supported. >> > >> >> + @param OpenMode Open mode for file. >> > >> >> + @param Attributes Only used for EFI_FILE_MODE_CREATE. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The device was opened. >> > >> >> + @retval EFI_NOT_FOUND The specified file could not be >> found >> > >> on >> > >> >> the >> > >> >> device. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_MEDIA_CHANGED The media has changed. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_ACCESS_DENIED The service denied access to >> the >> > >> file. >> > >> >> + @retval EFI_OUT_OF_RESOURCES The volume was not opened due >> > to >> > >> lack >> > >> >> of resources. >> > >> >> + @retval EFI_VOLUME_FULL The volume is full. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfOpen ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + OUT EFI_FILE_PROTOCOL **NewHandle, >> > >> >> + IN CHAR16 *FileName, >> > >> >> + IN UINT64 OpenMode, >> > >> >> + IN UINT64 Attributes >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_TPL OldTpl; >> > >> >> + EFI_STATUS Status; >> > >> >> + PRIVATE_UDF_FILE_DATA *PrivFileData; >> > >> >> + PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData; >> > >> >> + CHAR16 FilePath[UDF_PATH_LENGTH] = { 0 >> }; >> > >> >> + UDF_FILE_INFO File; >> > >> >> + PRIVATE_UDF_FILE_DATA *NewPrivFileData; >> > >> >> + CHAR16 *TempFileName; >> > >> >> + >> > >> >> + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); >> > >> >> + >> > >> >> + if (!This || !NewHandle || !FileName) { >> > >> >> + Status = EFI_INVALID_PARAMETER; >> > >> >> + goto Error_Invalid_Params; >> > >> >> + } >> > >> >> + >> > >> >> + if (OpenMode != EFI_FILE_MODE_READ) { >> > >> >> + Status = EFI_WRITE_PROTECTED; >> > >> >> + goto Error_Invalid_Params; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This); >> > >> >> + >> > >> >> + PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS >> > >> (PrivFileData- >> > >> >> >SimpleFs); >> > >> >> + >> > >> >> + // >> > >> >> + // Build full path >> > >> >> + // >> > >> >> + if (FileName[0] == L'\\') { >> > >> >> + StrCpy (FilePath, FileName); >> > >> >> + } else { >> > >> >> + StrCpy (FilePath, PrivFileData->AbsoluteFileName); >> > >> >> + StrCat (FilePath, L"\\"); >> > >> >> + StrCat (FilePath, FileName); >> > >> >> + } >> > >> >> + >> > >> >> + MangleFileName (FilePath); >> > >> >> + if (!FilePath[0]) { >> > >> >> + Status = EFI_NOT_FOUND; >> > >> >> + goto Error_Bad_FileName; >> > >> >> + } >> > >> >> + >> > >> >> + Status = FindFile ( >> > >> >> + PrivFsData->BlockIo, >> > >> >> + PrivFsData->DiskIo, >> > >> >> + &PrivFsData->Volume, >> > >> >> + FilePath, >> > >> >> + _ROOT_FILE (PrivFileData), >> > >> >> + _PARENT_FILE (PrivFileData), >> > >> >> + >> > >> &_PARENT_FILE(PrivFileData)->FileIdentifierDesc->Icb, >> > >> >> + &File >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Find_File; >> > >> >> + } >> > >> >> + >> > >> >> + NewPrivFileData = >> > >> >> + (PRIVATE_UDF_FILE_DATA *)AllocateZeroPool ( >> > >> >> + sizeof >> > >> (PRIVATE_UDF_FILE_DATA) >> > >> >> + ); >> > >> >> + if (!NewPrivFileData) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_New_Priv_File_Data; >> > >> >> + } >> > >> >> + >> > >> >> + CopyMem ( >> > >> >> + (VOID *)NewPrivFileData, >> > >> >> + (VOID *)PrivFileData, >> > >> >> + sizeof (PRIVATE_UDF_FILE_DATA) >> > >> >> + ); >> > >> >> + CopyMem ( >> > >> >> + (VOID *)&NewPrivFileData->File, >> > >> >> + &File, >> > >> >> + sizeof (UDF_FILE_INFO) >> > >> >> + ); >> > >> >> + >> > >> >> + NewPrivFileData->IsRootDirectory = FALSE; >> > >> >> + >> > >> >> + StrCpy (NewPrivFileData->AbsoluteFileName, FilePath); >> > >> >> + FileName = NewPrivFileData->AbsoluteFileName; >> > >> >> + >> > >> >> + while ((TempFileName = StrStr (FileName, L"\\"))) { >> > >> >> + FileName = TempFileName + 1; >> > >> >> + } >> > >> >> + >> > >> >> + StrCpy (NewPrivFileData->FileName, FileName); >> > >> >> + Status = GetFileSize ( >> > >> >> + PrivFsData->BlockIo, >> > >> >> + PrivFsData->DiskIo, >> > >> >> + &PrivFsData->Volume, >> > >> >> + &NewPrivFileData->File, >> > >> >> + &NewPrivFileData->FileSize >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Get_File_Size; >> > >> >> + } >> > >> >> + >> > >> >> + NewPrivFileData->FilePosition = 0; >> > >> >> + ZeroMem ( >> > >> >> + (VOID *)&NewPrivFileData->ReadDirInfo, >> > >> >> + sizeof (UDF_READ_DIRECTORY_INFO) >> > >> >> + ); >> > >> >> + >> > >> >> + *NewHandle = &NewPrivFileData->FileIo; >> > >> >> + >> > >> >> + PrivFsData->OpenFiles++; >> > >> >> + >> > >> >> + gBS->RestoreTPL (OldTpl); >> > >> >> + >> > >> >> + return Status; >> > >> >> + >> > >> >> +Error_Get_File_Size: >> > >> >> + FreePool ((VOID *)NewPrivFileData); >> > >> >> + >> > >> >> +Error_Alloc_New_Priv_File_Data: >> > >> >> + CleanupFileInformation (&File); >> > >> >> + >> > >> >> +Error_Find_File: >> > >> >> +Error_Bad_FileName: >> > >> >> +Error_Invalid_Params: >> > >> >> + gBS->RestoreTPL (OldTpl); >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Read data from the file. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param BufferSize On input size of buffer, on output amount >> of >> > >> data >> > >> >> in >> > >> >> buffer. >> > >> >> + @param Buffer The buffer in which data is read. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Data was read. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_BUFFER_TO_SMALL BufferSize is too small. >> BufferSize >> > >> >> contains required size. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfRead ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + IN OUT UINTN *BufferSize, >> > >> >> + OUT VOID *Buffer >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_VOLUME_CORRUPTED; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Close the file handle. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The file was closed. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfClose ( >> > >> >> + IN EFI_FILE_PROTOCOL *This >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_TPL OldTpl; >> > >> >> + EFI_STATUS Status; >> > >> >> + PRIVATE_UDF_FILE_DATA *PrivFileData; >> > >> >> + PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData; >> > >> >> + >> > >> >> + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); >> > >> >> + >> > >> >> + Status = EFI_SUCCESS; >> > >> >> + >> > >> >> + if (!This) { >> > >> >> + Status = EFI_INVALID_PARAMETER; >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This); >> > >> >> + >> > >> >> + PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS >> > >> (PrivFileData- >> > >> >> >SimpleFs); >> > >> >> + >> > >> >> + if (!PrivFileData->IsRootDirectory) { >> > >> >> + CleanupFileInformation (&PrivFileData->File); >> > >> >> + >> > >> >> + if (PrivFileData->ReadDirInfo.DirectoryData) { >> > >> >> + FreePool (PrivFileData->ReadDirInfo.DirectoryData); >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + if (!--PrivFsData->OpenFiles) { >> > >> >> + CleanupVolumeInformation (&PrivFsData->Volume); >> > >> >> + } >> > >> >> + >> > >> >> + FreePool ((VOID *)PrivFileData); >> > >> >> + >> > >> >> +Exit: >> > >> >> + gBS->RestoreTPL (OldTpl); >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Close and delete the file handle. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS The file was closed and >> deleted. >> > >> >> + @retval EFI_WARN_DELETE_FAILURE The handle was closed but >> the >> > >> file >> > >> >> was not deleted. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfDelete ( >> > >> >> + IN EFI_FILE_PROTOCOL *This >> > >> >> + ) >> > >> >> +{ >> > >> >> + PRIVATE_UDF_FILE_DATA *PrivFileData; >> > >> >> + >> > >> >> + if (!This) { >> > >> >> + return EFI_INVALID_PARAMETER; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This); >> > >> >> + >> > >> >> + (VOID)PrivFileData->FileIo.Close(This); >> > >> >> + >> > >> >> + return EFI_WARN_DELETE_FAILURE; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Write data to a file. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param BufferSize On input size of buffer, on output amount >> of >> > >> data >> > >> >> in >> > >> >> buffer. >> > >> >> + @param Buffer The buffer in which data to write. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Data was written. >> > >> >> + @retval EFI_UNSUPPORTED Writes to Open directory are >> not >> > >> >> supported. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_DEVICE_ERROR An attempt was made to write to >> a >> > >> >> deleted >> > >> >> file. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_WRITE_PROTECTED The device is write protected. >> > >> >> + @retval EFI_ACCESS_DENIED The file was open for read >> only. >> > >> >> + @retval EFI_VOLUME_FULL The volume is full. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfWrite ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + IN OUT UINTN *BufferSize, >> > >> >> + IN VOID *Buffer >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_UNSUPPORTED; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Get file's current position. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param Position Byte position from the start of the file. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Position was updated. >> > >> >> + @retval EFI_UNSUPPORTED Seek request for directories is not >> > >> valid. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfGetPosition ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + OUT UINT64 *Position >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_UNSUPPORTED; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Set file's current position. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param Position Byte position from the start of the file. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Position was updated. >> > >> >> + @retval EFI_UNSUPPORTED Seek request for non-zero is not >> valid >> > on >> > >> >> open. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfSetPosition ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + IN UINT64 Position >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_UNSUPPORTED; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Get information about a file. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + @param InformationType Type of information to return in >> Buffer. >> > >> >> + @param BufferSize On input size of buffer, on output >> amount >> > >> of >> > >> >> data in >> > >> >> buffer. >> > >> >> + @param Buffer The buffer to return data. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Data was returned. >> > >> >> + @retval EFI_UNSUPPORTED InformationType is not >> supported. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_WRITE_PROTECTED The device is write protected. >> > >> >> + @retval EFI_ACCESS_DENIED The file was open for read >> only. >> > >> >> + @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required >> > size >> > >> >> returned in BufferSize. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfGetInfo ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + IN EFI_GUID *InformationType, >> > >> >> + IN OUT UINTN *BufferSize, >> > >> >> + OUT VOID *Buffer >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + PRIVATE_UDF_FILE_DATA *PrivFileData; >> > >> >> + PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData; >> > >> >> + EFI_FILE_SYSTEM_INFO *FileSystemInfo; >> > >> >> + UINTN FileSystemInfoLength; >> > >> >> + CHAR16 *String; >> > >> >> + UDF_FILE_SET_DESCRIPTOR *FileSetDesc; >> > >> >> + UINTN Index; >> > >> >> + UINT8 *OstaCompressed; >> > >> >> + UINT8 CompressionId; >> > >> >> + UINT64 VolumeSize; >> > >> >> + UINT64 FreeSpaceSize; >> > >> >> + CHAR16 VolumeLabel[64]; >> > >> >> + >> > >> >> + if (!This || !InformationType || !BufferSize || (*BufferSize >> && >> > >> >> !Buffer)) { >> > >> >> + return EFI_INVALID_PARAMETER; >> > >> >> + } >> > >> >> + >> > >> >> + PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This); >> > >> >> + >> > >> >> + PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS >> > >> (PrivFileData- >> > >> >> >SimpleFs); >> > >> >> + >> > >> >> + Status = EFI_UNSUPPORTED; >> > >> >> + >> > >> >> + if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { >> > >> >> + Status = SetFileInfo ( >> > >> >> + _FILE (PrivFileData), >> > >> >> + PrivFileData->FileSize, >> > >> >> + PrivFileData->FileName, >> > >> >> + BufferSize, >> > >> >> + Buffer >> > >> >> + ); >> > >> >> + } else if (CompareGuid (InformationType, >> &gEfiFileSystemInfoGuid)) >> > >> { >> > >> >> + String = VolumeLabel; >> > >> >> + >> > >> >> + FileSetDesc = PrivFsData->Volume.FileSetDescs[0]; >> > >> >> + >> > >> >> + OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0]; >> > >> >> + >> > >> >> + CompressionId = OstaCompressed[0]; >> > >> >> + if (!IS_VALID_COMPRESSION_ID (CompressionId)) { >> > >> >> + return EFI_VOLUME_CORRUPTED; >> > >> >> + } >> > >> >> + >> > >> >> + for (Index = 1; Index < 128; Index++) { >> > >> >> + if (CompressionId == 16) { >> > >> >> + *String = *(UINT8 *)(OstaCompressed + Index) << 8; >> > >> >> + Index++; >> > >> >> + } else { >> > >> >> + *String = 0; >> > >> >> + } >> > >> >> + >> > >> >> + if (Index < 128) { >> > >> >> + *String |= *(UINT8 *)(OstaCompressed + Index); >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Unlike FID Identifiers, Logical Volume Identifier is >> stored >> > >> in >> > >> >> a >> > >> >> + // NULL-terminated OSTA compressed format, so we must >> check >> > >> for >> > >> >> the >> > >> >> NULL >> > >> >> + // character. >> > >> >> + // >> > >> >> + if (!*String) { >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + String++; >> > >> >> + } >> > >> >> + >> > >> >> + *String = L'\0'; >> > >> >> + >> > >> >> + FileSystemInfoLength = StrSize (VolumeLabel) + >> > >> >> + sizeof (EFI_FILE_SYSTEM_INFO); >> > >> >> + if (*BufferSize < FileSystemInfoLength) { >> > >> >> + *BufferSize = FileSystemInfoLength; >> > >> >> + return EFI_BUFFER_TOO_SMALL; >> > >> >> + } >> > >> >> + >> > >> >> + FileSystemInfo = (EFI_FILE_SYSTEM_INFO *)Buffer; >> > >> >> + StrCpy (FileSystemInfo->VolumeLabel, VolumeLabel); >> > >> >> + Status = GetVolumeSize ( >> > >> >> + PrivFsData->BlockIo, >> > >> >> + PrivFsData->DiskIo, >> > >> >> + &PrivFsData->Volume, >> > >> >> + &VolumeSize, >> > >> >> + &FreeSpaceSize >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + FileSystemInfo->Size = FileSystemInfoLength; >> > >> >> + FileSystemInfo->ReadOnly = TRUE; >> > >> >> + FileSystemInfo->BlockSize = LV_BLOCK_SIZE ( >> > >> >> + &PrivFsData->Volume, >> > >> >> + UDF_DEFAULT_LV_NUM >> > >> >> + ); >> > >> >> + FileSystemInfo->VolumeSize = VolumeSize; >> > >> >> + FileSystemInfo->FreeSpace = FreeSpaceSize; >> > >> >> + >> > >> >> + *BufferSize = FileSystemInfoLength; >> > >> >> + Status = EFI_SUCCESS; >> > >> >> + } >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Set information about a file. >> > >> >> + >> > >> >> + @param File Protocol instance pointer. >> > >> >> + @param InformationType Type of information in Buffer. >> > >> >> + @param BufferSize Size of buffer. >> > >> >> + @param Buffer The data to write. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Data was set. >> > >> >> + @retval EFI_UNSUPPORTED InformationType is not >> supported. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_WRITE_PROTECTED The device is write protected. >> > >> >> + @retval EFI_ACCESS_DENIED The file was open for read >> only. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfSetInfo ( >> > >> >> + IN EFI_FILE_PROTOCOL *This, >> > >> >> + IN EFI_GUID *InformationType, >> > >> >> + IN UINTN BufferSize, >> > >> >> + IN VOID *Buffer >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_WRITE_PROTECTED; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Flush data back for the file handle. >> > >> >> + >> > >> >> + @param This Protocol instance pointer. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS Data was flushed. >> > >> >> + @retval EFI_UNSUPPORTED Writes to Open directory are >> not >> > >> >> supported. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_WRITE_PROTECTED The device is write protected. >> > >> >> + @retval EFI_ACCESS_DENIED The file was open for read >> only. >> > >> >> + @retval EFI_VOLUME_FULL The volume is full. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +EFIAPI >> > >> >> +UdfFlush ( >> > >> >> + IN EFI_FILE_PROTOCOL *This >> > >> >> + ) >> > >> >> +{ >> > >> >> + return EFI_WRITE_PROTECTED; >> > >> >> +} >> > >> >> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileName.c >> > >> >> b/MdeModulePkg/Universal/Disk/UdfDxe/FileName.c >> > >> >> new file mode 100644 >> > >> >> index 0000000..2e91703 >> > >> >> --- /dev/null >> > >> >> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileName.c >> > >> >> @@ -0,0 +1,195 @@ >> > >> >> +/** @file >> > >> >> + UDF/ECMA-167 filesystem driver. >> > >> >> + >> > >> >> +Copyright (c) 2014 Paulo Alcantara >> <pca...@zytor.com<mailto:pca...@zytor.com>><BR> >> > >> >> +This program and the accompanying materials >> > >> >> +are licensed and made available under the terms and conditions >> of >> > >> the >> > >> >> BSD >> > >> >> License >> > >> >> +which accompanies this distribution. The full text of the >> license >> > >> may >> > >> >> be >> > >> >> found at >> > >> >> +http://opensource.org/licenses/bsd-license.php >> > >> >> + >> > >> >> +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS >> > IS" >> > >> >> BASIS, >> > >> >> +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER >> > >> >> EXPRESS OR IMPLIED. >> > >> >> + >> > >> >> +**/ >> > >> >> + >> > >> >> +#include "Udf.h" >> > >> >> + >> > >> >> +CHAR16 * >> > >> >> +TrimString ( >> > >> >> + IN CHAR16 *String >> > >> >> + ) >> > >> >> +{ >> > >> >> + CHAR16 *TempString; >> > >> >> + >> > >> >> + for ( ; (*String) && (*String == L' '); String++) { >> > >> >> + ; >> > >> >> + } >> > >> >> + >> > >> >> + TempString = String + StrLen (String) - 1; >> > >> >> + while ((TempString >= String) && (*TempString == L' ')) { >> > >> >> + TempString--; >> > >> >> + } >> > >> >> + >> > >> >> + *(TempString + 1) = L'\0'; >> > >> >> + >> > >> >> + return String; >> > >> >> +} >> > >> >> + >> > >> >> +VOID >> > >> >> +ReplaceLeft ( >> > >> >> + IN CHAR16 *Destination, >> > >> >> + IN CONST CHAR16 *Source >> > >> >> + ) >> > >> >> +{ >> > >> >> + CONST CHAR16 *EndString; >> > >> >> + >> > >> >> + EndString = Source + StrLen (Source); >> > >> >> + while (Source <= EndString) { >> > >> >> + *Destination++ = *Source++; >> > >> >> + } >> > >> >> +} >> > >> >> + >> > >> >> +CHAR16 * >> > >> >> +ExcludeTrailingBackslashes ( >> > >> >> + IN CHAR16 *String >> > >> >> + ) >> > >> >> +{ >> > >> >> + CHAR16 *TempString; >> > >> >> + >> > >> >> + switch (*(String + 1)) { >> > >> >> + case L'\\': >> > >> >> + break; >> > >> >> + case L'\0': >> > >> >> + default: >> > >> >> + String++; >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + TempString = String; >> > >> >> + while ((*TempString) && (*TempString == L'\\')) { >> > >> >> + TempString++; >> > >> >> + } >> > >> >> + >> > >> >> + if (TempString - 1 > String) { >> > >> >> + ReplaceLeft (String + 1, TempString); >> > >> >> + } >> > >> >> + >> > >> >> + String++; >> > >> >> + >> > >> >> +Exit: >> > >> >> + return String; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Mangle a filename by cutting off trailing whitespaces, "\\", >> "." >> > >> and >> > >> >> "..". >> > >> >> + >> > >> >> + @param[in] FileName Filename. >> > >> >> + >> > >> >> + @retval @p FileName Filename mangled. >> > >> >> + >> > >> >> +**/ >> > >> >> +CHAR16 * >> > >> >> +MangleFileName ( >> > >> >> + IN CHAR16 *FileName >> > >> >> + ) >> > >> >> +{ >> > >> >> + CHAR16 *FileNameSavedPointer; >> > >> >> + CHAR16 *TempFileName; >> > >> >> + UINTN BackslashesNo; >> > >> >> + >> > >> >> + if (!FileName || !*FileName) { >> > >> >> + FileName = NULL; >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + FileName = TrimString (FileName); >> > >> >> + if (!*FileName) { >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + if ((StrLen (FileName) > 1) && (FileName[StrLen (FileName) - >> 1] == >> > >> >> L'\\')) { >> > >> >> + FileName[StrLen (FileName) - 1] = L'\0'; >> > >> >> + } >> > >> >> + >> > >> >> + FileNameSavedPointer = FileName; >> > >> >> + >> > >> >> + if (FileName[0] == L'.') { >> > >> >> + if (FileName[1] == L'.') { >> > >> >> + if (!FileName[2]) { >> > >> >> + goto Exit; >> > >> >> + } else { >> > >> >> + FileName += 2; >> > >> >> + } >> > >> >> + } else if (!FileName[1]) { >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + while (*FileName) { >> > >> >> + if (*FileName == L'\\') { >> > >> >> + FileName = ExcludeTrailingBackslashes (FileName); >> > >> >> + } else if (*FileName == L'.') { >> > >> >> + switch (*(FileName + 1)) { >> > >> >> + case L'\0': >> > >> >> + *FileName = L'\0'; >> > >> >> + break; >> > >> >> + case L'\\': >> > >> >> + TempFileName = FileName + 1; >> > >> >> + TempFileName = ExcludeTrailingBackslashes >> (TempFileName); >> > >> >> + ReplaceLeft (FileName, TempFileName); >> > >> >> + break; >> > >> >> + case '.': >> > >> >> + if ((*(FileName - 1) != L'\\') && ((*(FileName + 2) != >> L'\\') || >> > >> >> + (*(FileName + 2) != >> L'\0'))) { >> > >> >> + FileName++; >> > >> >> + continue; >> > >> >> + } >> > >> >> + >> > >> >> + BackslashesNo = 0; >> > >> >> + TempFileName = FileName - 1; >> > >> >> + while (TempFileName >= FileNameSavedPointer) { >> > >> >> + if (*TempFileName == L'\\') { >> > >> >> + if (++BackslashesNo == 2) { >> > >> >> + break; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + TempFileName--; >> > >> >> + } >> > >> >> + >> > >> >> + TempFileName++; >> > >> >> + >> > >> >> + if ((*TempFileName == L'.') && (*(TempFileName + 1) == >> L'.')) { >> > >> >> + FileName += 2; >> > >> >> + } else { >> > >> >> + if (*(FileName + 2)) { >> > >> >> + ReplaceLeft (TempFileName, FileName + 3); >> > >> >> + if (*(TempFileName - 1) == L'\\') { >> > >> >> + FileName = TempFileName; >> > >> >> + ExcludeTrailingBackslashes (TempFileName - 1); >> > >> >> + TempFileName = FileName; >> > >> >> + } >> > >> >> + } else { >> > >> >> + *TempFileName = L'\0'; >> > >> >> + } >> > >> >> + >> > >> >> + FileName = TempFileName; >> > >> >> + } >> > >> >> + >> > >> >> + break; >> > >> >> + default: >> > >> >> + FileName++; >> > >> >> + } >> > >> >> + } else { >> > >> >> + FileName++; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + FileName = FileNameSavedPointer; >> > >> >> + if ((StrLen (FileName) > 1) && (FileName [StrLen (FileName) - >> 1] >> > >> == >> > >> >> L'\\')) { >> > >> >> + FileName [StrLen (FileName) - 1] = L'\0'; >> > >> >> + } >> > >> >> + >> > >> >> +Exit: >> > >> >> + return FileName; >> > >> >> +} >> > >> >> diff --git >> > >> a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c >> > >> >> b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c >> > >> >> new file mode 100644 >> > >> >> index 0000000..65a7af1 >> > >> >> --- /dev/null >> > >> >> +++ >> > b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c >> > >> >> @@ -0,0 +1,2535 @@ >> > >> >> +/** @file >> > >> >> + UDF/ECMA-167 filesystem driver. >> > >> >> + >> > >> >> +Copyright (c) 2014 Paulo Alcantara >> <pca...@zytor.com<mailto:pca...@zytor.com>><BR> >> > >> >> +This program and the accompanying materials >> > >> >> +are licensed and made available under the terms and conditions >> of >> > >> the >> > >> >> BSD >> > >> >> License >> > >> >> +which accompanies this distribution. The full text of the >> license >> > >> may >> > >> >> be >> > >> >> found at >> > >> >> +http://opensource.org/licenses/bsd-license.php >> > >> >> + >> > >> >> +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS >> > IS" >> > >> >> BASIS, >> > >> >> +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER >> > >> >> EXPRESS OR IMPLIED. >> > >> >> + >> > >> >> +**/ >> > >> >> + >> > >> >> +#include "Udf.h" >> > >> >> + >> > >> >> +// >> > >> >> +// This driver *only* supports UDF revision 2.00 or higher. >> > >> >> +// >> > >> >> +// Note the "NSR03" identifier. >> > >> >> +// >> > >> >> +UDF_STANDARD_IDENTIFIER >> > >> >> gUdfStandardIdentifiers[NR_STANDARD_IDENTIFIERS] = { >> > >> >> + { { 'B', 'E', 'A', '0', '1' } }, >> > >> >> + { { 'N', 'S', 'R', '0', '3' } }, >> > >> >> + { { 'T', 'E', 'A', '0', '1' } }, >> > >> >> +}; >> > >> >> + >> > >> >> +EFI_STATUS >> > >> >> +FindAnchorVolumeDescriptorPointer ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER >> > *AnchorPoint >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT32 BlockSize; >> > >> >> + EFI_LBA EndLBA; >> > >> >> + >> > >> >> + BlockSize = BlockIo->Media->BlockSize; >> > >> >> + EndLBA = BlockIo->Media->LastBlock; >> > >> >> + >> > >> >> + // >> > >> >> + // Look for an AVDP at LBA 256. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (0x100ULL, BlockSize), >> > >> >> + sizeof >> > >> >> (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), >> > >> >> + (VOID *)AnchorPoint >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_AVDP (AnchorPoint)) { >> > >> >> + return EFI_SUCCESS; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Look for an AVDP at last LBA - 256. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (EndLBA - 0x100ULL, >> BlockSize), >> > >> >> + sizeof >> > >> >> (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), >> > >> >> + (VOID *)AnchorPoint >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_AVDP (AnchorPoint)) { >> > >> >> + return EFI_SUCCESS; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Look for an AVDP at last LBA. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (EndLBA, BlockSize), >> > >> >> + sizeof >> > >> >> (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), >> > >> >> + (VOID *)AnchorPoint >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_AVDP (AnchorPoint)) { >> > >> >> + return EFI_SUCCESS; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // There is no AVDP on this disk, so it's not an UDF volume >> and we >> > >> >> cannot >> > >> >> + // start Main Volume Descriptor Sequence. >> > >> >> + // >> > >> >> + return EFI_VOLUME_CORRUPTED; >> > >> >> +} >> > >> >> + >> > >> >> +EFI_STATUS >> > >> >> +StartMainVolumeDescriptorSequence ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint, >> > >> >> + OUT UDF_VOLUME_INFO *Volume >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT32 BlockSize; >> > >> >> + UDF_EXTENT_AD *ExtentAd; >> > >> >> + UINT64 StartingLsn; >> > >> >> + UINT64 EndingLsn; >> > >> >> + VOID *Buffer; >> > >> >> + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; >> > >> >> + UDF_PARTITION_DESCRIPTOR *PartitionDesc; >> > >> >> + UINTN Index; >> > >> >> + UINT32 LogicalBlockSize; >> > >> >> + >> > >> >> + // >> > >> >> + // We've alreay found an ADVP on the volume. It contains the >> > >> extent >> > >> >> + // (MainVolumeDescriptorSequenceExtent) where the Main >> > Volume >> > >> >> Descriptor >> > >> >> + // Sequence starts. Therefore, we'll look for Logical Volume >> > >> >> Descriptors >> > >> >> and >> > >> >> + // Partitions Descriptors and save them in memory >> accordingly. >> > >> >> + // >> > >> >> + // Note also that each descriptor will be aligned on a block >> size >> > >> >> (BlockSize) >> > >> >> + // boundary, so we need to read one block at a time. >> > >> >> + // >> > >> >> + BlockSize = BlockIo->Media->BlockSize; >> > >> >> + ExtentAd = &AnchorPoint- >> > >MainVolumeDescriptorSequenceExtent; >> > >> >> + StartingLsn = (UINT64)ExtentAd->ExtentLocation; >> > >> >> + EndingLsn = StartingLsn + DivU64x32 ( >> > >> >> + >> (UINT64)ExtentAd->ExtentLength, >> > >> >> + BlockSize >> > >> >> + ); >> > >> >> + >> > >> >> + Volume->LogicalVolDescs = >> > >> >> + (UDF_LOGICAL_VOLUME_DESCRIPTOR **)AllocateZeroPool >> > >> (ExtentAd- >> > >> >> >ExtentLength); >> > >> >> + if (!Volume->LogicalVolDescs) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + >> > >> >> + Volume->PartitionDescs = >> > >> >> + (UDF_PARTITION_DESCRIPTOR **)AllocateZeroPool (ExtentAd- >> > >> >> >ExtentLength); >> > >> >> + if (!Volume->PartitionDescs) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Pds; >> > >> >> + } >> > >> >> + >> > >> >> + Buffer = AllocateZeroPool (BlockSize); >> > >> >> + if (!Buffer) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Buf; >> > >> >> + } >> > >> >> + >> > >> >> + Volume->LogicalVolDescsNo = 0; >> > >> >> + Volume->PartitionDescsNo = 0; >> > >> >> + >> > >> >> + while (StartingLsn <= EndingLsn) { >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (StartingLsn, >> BlockSize), >> > >> >> + BlockSize, >> > >> >> + Buffer >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Read_Disk_Blk; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_TD (Buffer)) { >> > >> >> + // >> > >> >> + // Found a Terminating Descriptor. Stop the sequence >> then. >> > >> >> + // >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_LVD (Buffer)) { >> > >> >> + // >> > >> >> + // Found a Logical Volume Descriptor. >> > >> >> + // >> > >> >> + LogicalVolDesc = >> > >> >> + (UDF_LOGICAL_VOLUME_DESCRIPTOR *) >> > >> >> + AllocateZeroPool (sizeof >> (UDF_LOGICAL_VOLUME_DESCRIPTOR)); >> > >> >> + if (!LogicalVolDesc) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Lvd; >> > >> >> + } >> > >> >> + >> > >> >> + CopyMem ( >> > >> >> + (VOID *)LogicalVolDesc, >> > >> >> + Buffer, >> > >> >> + sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR) >> > >> >> + ); >> > >> >> + >> > >> >> + Volume->LogicalVolDescs[Volume->LogicalVolDescsNo] = >> > >> >> LogicalVolDesc; >> > >> >> + Volume->LogicalVolDescsNo++; >> > >> >> + } else if (IS_PD (Buffer)) { >> > >> >> + // >> > >> >> + // Found a Partition Descriptor. >> > >> >> + // >> > >> >> + PartitionDesc = >> > >> >> + (UDF_PARTITION_DESCRIPTOR *) >> > >> >> + AllocateZeroPool (sizeof (UDF_PARTITION_DESCRIPTOR)); >> > >> >> + if (!PartitionDesc) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Pd; >> > >> >> + } >> > >> >> + >> > >> >> + CopyMem ( >> > >> >> + (VOID *)PartitionDesc, >> > >> >> + Buffer, >> > >> >> + sizeof (UDF_PARTITION_DESCRIPTOR) >> > >> >> + ); >> > >> >> + >> > >> >> + Volume->PartitionDescs[Volume->PartitionDescsNo] = >> > >> PartitionDesc; >> > >> >> + Volume->PartitionDescsNo++; >> > >> >> + } >> > >> >> + >> > >> >> + StartingLsn++; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // When an UDF volume (revision 2.00 or higher) contains a >> File >> > >> Entry >> > >> >> rather >> > >> >> + // than an Extended File Entry (which is not recommended as >> per >> > >> >> spec), >> > >> >> we need >> > >> >> + // to make sure the size of a FE will be _at least_ 2048 >> > >> >> + // (UDF_LOGICAL_SECTOR_SIZE) bytes long to keep backward >> > >> >> compatibility. >> > >> >> + // >> > >> >> + LogicalBlockSize = LV_BLOCK_SIZE (Volume, >> > UDF_DEFAULT_LV_NUM); >> > >> >> + if (LogicalBlockSize >= UDF_LOGICAL_SECTOR_SIZE) { >> > >> >> + Volume->FileEntrySize = LogicalBlockSize; >> > >> >> + } else { >> > >> >> + Volume->FileEntrySize = UDF_LOGICAL_SECTOR_SIZE; >> > >> >> + } >> > >> >> + >> > >> >> + FreePool (Buffer); >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> + >> > >> >> +Error_Alloc_Pd: >> > >> >> +Error_Alloc_Lvd: >> > >> >> + for (Index = 0; Index < Volume->PartitionDescsNo; Index++) { >> > >> >> + FreePool ((VOID *)Volume->PartitionDescs[Index]); >> > >> >> + } >> > >> >> + >> > >> >> + for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) >> { >> > >> >> + FreePool ((VOID *)Volume->LogicalVolDescs[Index]); >> > >> >> + } >> > >> >> + >> > >> >> +Error_Read_Disk_Blk: >> > >> >> + FreePool (Buffer); >> > >> >> + >> > >> >> +Error_Alloc_Buf: >> > >> >> + FreePool ((VOID *)Volume->PartitionDescs); >> > >> >> + Volume->PartitionDescs = NULL; >> > >> >> + >> > >> >> +Error_Alloc_Pds: >> > >> >> + FreePool ((VOID *)Volume->LogicalVolDescs); >> > >> >> + Volume->LogicalVolDescs = NULL; >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Return a Partition Descriptor given a Long Allocation >> Descriptor. >> > >> >> This is >> > >> >> +// necessary to calculate the right extent (LongAd) offset >> which is >> > >> >> added up >> > >> >> +// with partition's starting location. >> > >> >> +// >> > >> >> +UDF_PARTITION_DESCRIPTOR * >> > >> >> +GetPdFromLongAd ( >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + UINTN Index; >> > >> >> + UDF_PARTITION_DESCRIPTOR *PartitionDesc; >> > >> >> + UINT16 PartitionNum; >> > >> >> + >> > >> >> + for (Index = 0; Index < Volume->PartitionDescsNo; Index++) { >> > >> >> + PartitionDesc = Volume->PartitionDescs[Index]; >> > >> >> + >> > >> >> + PartitionNum = PartitionDesc->PartitionNumber; >> > >> >> + if (PartitionNum == >> > >> >> LongAd->ExtentLocation.PartitionReferenceNumber) >> > >> >> { >> > >> >> + return PartitionDesc; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + return NULL; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Return logical sector number of the given Long Allocation >> > >> >> Descriptor. >> > >> >> +// >> > >> >> +UINT64 >> > >> >> +GetLongAdLsn ( >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + UDF_PARTITION_DESCRIPTOR *PartitionDesc; >> > >> >> + >> > >> >> + PartitionDesc = GetPdFromLongAd (Volume, LongAd); >> > >> >> + >> > >> >> + return (UINT64)PartitionDesc->PartitionStartingLocation + >> > >> >> + LongAd->ExtentLocation.LogicalBlockNumber; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Return logical sector number of the given Short Allocation >> > >> >> Descriptor. >> > >> >> +// >> > >> >> +UINT64 >> > >> >> +GetShortAdLsn ( >> > >> >> + IN UDF_PARTITION_DESCRIPTOR *PartitionDesc, >> > >> >> + IN UDF_SHORT_ALLOCATION_DESCRIPTOR *ShortAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + return (UINT64)PartitionDesc->PartitionStartingLocation + >> > >> >> + ShortAd->ExtentPosition; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Find File Set Descriptor of the given Logical Volume >> Descriptor. >> > >> >> +// >> > >> >> +// The found FSD will contain the extent >> (LogicalVolumeContentsUse) >> > >> >> where our >> > >> >> +// root directory is. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +FindFileSetDescriptor ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UINTN LogicalVolDescNo, >> > >> >> + OUT UDF_FILE_SET_DESCRIPTOR *FileSetDesc >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT64 Lsn; >> > >> >> + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; >> > >> >> + >> > >> >> + LogicalVolDesc = Volume->LogicalVolDescs[LogicalVolDescNo]; >> > >> >> + Lsn = GetLongAdLsn ( >> > >> >> + Volume, >> > >> >> + >> > >> &LogicalVolDesc->LogicalVolumeContentsUse >> > >> >> + ); >> > >> >> + >> > >> >> + // >> > >> >> + // Read extent (Long Ad). >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (Lsn, >> > >> >> LogicalVolDesc->LogicalBlockSize), >> > >> >> + sizeof (UDF_FILE_SET_DESCRIPTOR), >> > >> >> + (VOID *)FileSetDesc >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Check if the read extent contains a valid FSD's tag >> identifier. >> > >> >> + // >> > >> >> + if (!IS_FSD (FileSetDesc)) { >> > >> >> + return EFI_VOLUME_CORRUPTED; >> > >> >> + } >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Get all File Set Descriptors for each Logical Volume >> Descriptor. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetFileSetDescriptors ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN OUT UDF_VOLUME_INFO *Volume >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINTN Index; >> > >> >> + UDF_FILE_SET_DESCRIPTOR *FileSetDesc; >> > >> >> + UINTN Count; >> > >> >> + >> > >> >> + Volume->FileSetDescs = >> > >> >> + (UDF_FILE_SET_DESCRIPTOR **)AllocateZeroPool ( >> > >> >> + >> > >> Volume->LogicalVolDescsNo * >> > >> >> + sizeof >> > >> >> (UDF_FILE_SET_DESCRIPTOR) >> > >> >> + ); >> > >> >> + if (!Volume->FileSetDescs) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + >> > >> >> + for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) >> { >> > >> >> + FileSetDesc = AllocateZeroPool (sizeof >> > >> (UDF_FILE_SET_DESCRIPTOR)); >> > >> >> + if (!FileSetDesc) { >> > >> >> + Status = EFI_OUT_OF_RESOURCES; >> > >> >> + goto Error_Alloc_Fsd; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Find a FSD for this LVD. >> > >> >> + // >> > >> >> + Status = FindFileSetDescriptor ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + Volume, >> > >> >> + Index, >> > >> >> + FileSetDesc >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Find_Fsd; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Got one. Save it. >> > >> >> + // >> > >> >> + Volume->FileSetDescs[Index] = FileSetDesc; >> > >> >> + } >> > >> >> + >> > >> >> + Volume->FileSetDescsNo = Volume->LogicalVolDescsNo; >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> + >> > >> >> +Error_Find_Fsd: >> > >> >> + Count = Index + 1; >> > >> >> + for (Index = 0; Index < Count; Index++) { >> > >> >> + FreePool ((VOID *)Volume->FileSetDescs[Index]); >> > >> >> + } >> > >> >> + >> > >> >> + FreePool ((VOID *)Volume->FileSetDescs); >> > >> >> + Volume->FileSetDescs = NULL; >> > >> >> + >> > >> >> +Error_Alloc_Fsd: >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Read Volume and File Structure of an UDF file system. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +ReadVolumeFileStructure ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + OUT UDF_VOLUME_INFO *Volume >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; >> > >> >> + >> > >> >> + // >> > >> >> + // Find an AVDP. >> > >> >> + // >> > >> >> + Status = FindAnchorVolumeDescriptorPointer ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + &AnchorPoint >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // AVDP has been found. Start MVDS. >> > >> >> + // >> > >> >> + Status = StartMainVolumeDescriptorSequence ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + &AnchorPoint, >> > >> >> + Volume >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Calculate length of the given File Identifier Descriptor. >> > >> >> +// >> > >> >> +UINT64 >> > >> >> +GetFidDescriptorLength ( >> > >> >> + IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc >> > >> >> + ) >> > >> >> +{ >> > >> >> + return (UINT64)( >> > >> >> + (INTN)((OFFSET_OF >> (UDF_FILE_IDENTIFIER_DESCRIPTOR, >> > >> >> Data[0]) + >> > >> >> 3 + >> > >> >> + FileIdentifierDesc->LengthOfFileIdentifier >> + >> > >> >> + >> FileIdentifierDesc->LengthOfImplementationUse) >> 2) << >> > >> >> 2 >> > >> >> + ); >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Duplicate a given File Identifier Descriptor. >> > >> >> +// >> > >> >> +VOID >> > >> >> +DuplicateFid ( >> > >> >> + IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc, >> > >> >> + OUT UDF_FILE_IDENTIFIER_DESCRIPTOR **NewFileIdentifierDesc >> > >> >> + ) >> > >> >> +{ >> > >> >> + *NewFileIdentifierDesc = >> > >> >> + (UDF_FILE_IDENTIFIER_DESCRIPTOR *)AllocateCopyPool ( >> > >> >> + GetFidDescriptorLength >> > >> >> (FileIdentifierDesc), >> > >> >> + FileIdentifierDesc >> > >> >> + ); >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Duplicate either a given File Entry or a given Extended >> File >> > >> Entry. >> > >> >> +// >> > >> >> +VOID >> > >> >> +DuplicateFe ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN VOID *FileEntry, >> > >> >> + OUT VOID **NewFileEntry >> > >> >> + ) >> > >> >> +{ >> > >> >> + *NewFileEntry = AllocateCopyPool (Volume->FileEntrySize, >> > >> FileEntry); >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Get raw data + length of the given File Entry or Extended >> File >> > >> >> Entry. >> > >> >> +// >> > >> >> +// The file's recorded data can contain either real file >> content >> > >> >> (inline) or >> > >> >> +// a sequence of extents (or Allocation Descriptors) which >> tells >> > >> where >> > >> >> file's >> > >> >> +// content is stored in. >> > >> >> +// >> > >> >> +// NOTE: The FE/EFE can be thought it was an inode. >> > >> >> +// >> > >> >> +VOID >> > >> >> +GetFileEntryData ( >> > >> >> + IN VOID *FileEntryData, >> > >> >> + OUT VOID **Data, >> > >> >> + OUT UINT64 *Length >> > >> >> + ) >> > >> >> +{ >> > >> >> + UDF_EXTENDED_FILE_ENTRY *ExtendedFileEntry; >> > >> >> + UDF_FILE_ENTRY *FileEntry; >> > >> >> + >> > >> >> + if (IS_EFE (FileEntryData)) { >> > >> >> + ExtendedFileEntry = (UDF_EXTENDED_FILE_ENTRY >> *)FileEntryData; >> > >> >> + >> > >> >> + *Length = ExtendedFileEntry->InformationLength; >> > >> >> + *Data = (VOID *)((UINT8 *)&ExtendedFileEntry->Data[0] + >> > >> >> + >> ExtendedFileEntry->LengthOfExtendedAttributes); >> > >> >> + } else if (IS_FE (FileEntryData)) { >> > >> >> + FileEntry = (UDF_FILE_ENTRY *)FileEntryData; >> > >> >> + >> > >> >> + *Length = FileEntry->InformationLength; >> > >> >> + *Data = (VOID *)((UINT8 *)&FileEntry->Data[0] + >> > >> >> + FileEntry->LengthOfExtendedAttributes); >> > >> >> + } >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Get Allocation Descriptors' data information from the given >> > >> FE/EFE. >> > >> >> +// >> > >> >> +VOID >> > >> >> +GetAdsInformation ( >> > >> >> + IN VOID *FileEntryData, >> > >> >> + OUT VOID **AdsData, >> > >> >> + OUT UINT64 *Length >> > >> >> + ) >> > >> >> +{ >> > >> >> + UDF_EXTENDED_FILE_ENTRY *ExtendedFileEntry; >> > >> >> + UDF_FILE_ENTRY *FileEntry; >> > >> >> + >> > >> >> + if (IS_EFE (FileEntryData)) { >> > >> >> + ExtendedFileEntry = (UDF_EXTENDED_FILE_ENTRY >> *)FileEntryData; >> > >> >> + >> > >> >> + *Length = >> ExtendedFileEntry->LengthOfAllocationDescriptors; >> > >> >> + *AdsData = (VOID *)((UINT8 *)&ExtendedFileEntry->Data[0] + >> > >> >> + >> ExtendedFileEntry->LengthOfExtendedAttributes); >> > >> >> + } else if (IS_FE (FileEntryData)) { >> > >> >> + FileEntry = (UDF_FILE_ENTRY *)FileEntryData; >> > >> >> + >> > >> >> + *Length = FileEntry->LengthOfAllocationDescriptors; >> > >> >> + *AdsData = (VOID *)((UINT8 *)&FileEntry->Data[0] + >> > >> >> + FileEntry->LengthOfExtendedAttributes); >> > >> >> + } >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Read next Short Allocation Descriptor from the given file's >> data. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetLongAdFromAds ( >> > >> >> + IN VOID *Data, >> > >> >> + IN OUT UINT64 *Offset, >> > >> >> + IN UINT64 Length, >> > >> >> + OUT UDF_LONG_ALLOCATION_DESCRIPTOR **FoundLongAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd; >> > >> >> + UDF_EXTENT_FLAGS ExtentFlags; >> > >> >> + >> > >> >> + for (;;) { >> > >> >> + if (*Offset >= Length) { >> > >> >> + // >> > >> >> + // No more Long Allocation Descriptors. >> > >> >> + // >> > >> >> + return EFI_DEVICE_ERROR; >> > >> >> + } >> > >> >> + >> > >> >> + LongAd = >> > >> >> + (UDF_LONG_ALLOCATION_DESCRIPTOR *)((UINT8 *)Data + >> > *Offset); >> > >> >> + >> > >> >> + // >> > >> >> + // If it's either an indirect AD (Extended Alllocation >> > >> Descriptor) >> > >> >> or an >> > >> >> + // allocated AD, then return it. >> > >> >> + // >> > >> >> + ExtentFlags = GET_EXTENT_FLAGS (LONG_ADS_SEQUENCE, >> > LongAd); >> > >> >> + if (ExtentFlags == EXTENT_IS_NEXT_EXTENT || >> > >> >> + ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) { >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // This AD is either not recorded but allocated, or not >> recorded >> > >> >> and not >> > >> >> + // allocated. Skip it. >> > >> >> + // >> > >> >> + *Offset += AD_LENGTH (LONG_ADS_SEQUENCE); >> > >> >> + } >> > >> >> + >> > >> >> + *FoundLongAd = LongAd; >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Read next Short Allocation Descriptor from the given file's >> data. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetShortAdFromAds ( >> > >> >> + IN VOID *Data, >> > >> >> + IN OUT UINT64 *Offset, >> > >> >> + IN UINT64 Length, >> > >> >> + OUT UDF_SHORT_ALLOCATION_DESCRIPTOR **FoundShortAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + UDF_SHORT_ALLOCATION_DESCRIPTOR *ShortAd; >> > >> >> + UDF_EXTENT_FLAGS ExtentFlags; >> > >> >> + >> > >> >> + for (;;) { >> > >> >> + if (*Offset >= Length) { >> > >> >> + // >> > >> >> + // No more Short Allocation Descriptors. >> > >> >> + // >> > >> >> + return EFI_DEVICE_ERROR; >> > >> >> + } >> > >> >> + >> > >> >> + ShortAd = >> > >> >> + (UDF_SHORT_ALLOCATION_DESCRIPTOR *)((UINT8 *)Data + >> > >> *Offset); >> > >> >> + >> > >> >> + // >> > >> >> + // If it's either an indirect AD (Extended Alllocation >> > >> Descriptor) >> > >> >> or an >> > >> >> + // allocated AD, then return it. >> > >> >> + // >> > >> >> + ExtentFlags = GET_EXTENT_FLAGS (SHORT_ADS_SEQUENCE, >> > ShortAd); >> > >> >> + if (ExtentFlags == EXTENT_IS_NEXT_EXTENT || >> > >> >> + ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) { >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // This AD is either not recorded but allocated, or not >> recorded >> > >> >> and not >> > >> >> + // allocated. Skip it. >> > >> >> + // >> > >> >> + *Offset += AD_LENGTH (SHORT_ADS_SEQUENCE); >> > >> >> + } >> > >> >> + >> > >> >> + *FoundShortAd = ShortAd; >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Get either a Short Allocation Descriptor or a Long >> Allocation >> > >> >> Descriptor >> > >> >> from >> > >> >> +// the given file's data. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetAllocationDescriptor ( >> > >> >> + IN UDF_FE_RECORDING_FLAGS RecordingFlags, >> > >> >> + IN VOID *Data, >> > >> >> + IN OUT UINT64 *Offset, >> > >> >> + IN UINT64 Length, >> > >> >> + OUT VOID **FoundAd >> > >> >> + ) >> > >> >> +{ >> > >> >> + if (RecordingFlags == LONG_ADS_SEQUENCE) { >> > >> >> + return GetLongAdFromAds ( >> > >> >> + Data, >> > >> >> + Offset, >> > >> >> + Length, >> > >> >> + (UDF_LONG_ALLOCATION_DESCRIPTOR >> **)FoundAd >> > >> >> + ); >> > >> >> + } else if (RecordingFlags == SHORT_ADS_SEQUENCE) { >> > >> >> + return GetShortAdFromAds ( >> > >> >> + Data, >> > >> >> + Offset, >> > >> >> + Length, >> > >> >> + (UDF_SHORT_ALLOCATION_DESCRIPTOR >> **)FoundAd >> > >> >> + ); >> > >> >> + } >> > >> >> + >> > >> >> + return EFI_DEVICE_ERROR; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Return logical sector number of either Short or Long >> Allocation >> > >> >> Descriptor. >> > >> >> +// >> > >> >> +UINT64 >> > >> >> +GetAllocationDescriptorLsn ( >> > >> >> + IN UDF_FE_RECORDING_FLAGS RecordingFlags, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, >> > >> >> + IN VOID *Ad >> > >> >> + ) >> > >> >> +{ >> > >> >> + if (RecordingFlags == LONG_ADS_SEQUENCE) { >> > >> >> + return GetLongAdLsn (Volume, >> > >> (UDF_LONG_ALLOCATION_DESCRIPTOR >> > >> >> *)Ad); >> > >> >> + } else if (RecordingFlags == SHORT_ADS_SEQUENCE) { >> > >> >> + return GetShortAdLsn ( >> > >> >> + GetPdFromLongAd (Volume, ParentIcb), >> > >> >> + (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad >> > >> >> + ); >> > >> >> + } >> > >> >> + >> > >> >> + return 0; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Return offset + length of a given indirect Allocation >> Descriptor >> > >> >> (AED). >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetAedAdsOffset ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, >> > >> >> + IN UDF_FE_RECORDING_FLAGS RecordingFlags, >> > >> >> + IN VOID *Ad, >> > >> >> + OUT UINT64 *Offset, >> > >> >> + OUT UINT64 *Length >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT32 ExtentLength; >> > >> >> + UINT64 Lsn; >> > >> >> + VOID *Data; >> > >> >> + UINT32 LogicalBlockSize; >> > >> >> + UDF_ALLOCATION_EXTENT_DESCRIPTOR *AllocExtDesc; >> > >> >> + >> > >> >> + ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad); >> > >> >> + Lsn = GetAllocationDescriptorLsn ( >> > >> >> + RecordingFlags, >> > >> >> + Volume, >> > >> >> + ParentIcb, >> > >> >> + Ad >> > >> >> + ); >> > >> >> + >> > >> >> + Data = AllocatePool (ExtentLength); >> > >> >> + if (!Data) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + >> > >> >> + LogicalBlockSize = LV_BLOCK_SIZE (Volume, >> > UDF_DEFAULT_LV_NUM); >> > >> >> + >> > >> >> + // >> > >> >> + // Read extent. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (Lsn, LogicalBlockSize), >> > >> >> + ExtentLength, >> > >> >> + Data >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Check if read extent contains a valid tag identifier for >> AED. >> > >> >> + // >> > >> >> + AllocExtDesc = (UDF_ALLOCATION_EXTENT_DESCRIPTOR *)Data; >> > >> >> + if (!IS_AED (AllocExtDesc)) { >> > >> >> + Status = EFI_VOLUME_CORRUPTED; >> > >> >> + goto Exit; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Get AED's block offset and its length. >> > >> >> + // >> > >> >> + *Offset = MultU64x32 (Lsn, LogicalBlockSize) + >> > >> >> + sizeof (UDF_ALLOCATION_EXTENT_DESCRIPTOR); >> > >> >> + *Length = AllocExtDesc->LengthOfAllocationDescriptors; >> > >> >> + >> > >> >> +Exit: >> > >> >> + if (Data) { >> > >> >> + FreePool (Data); >> > >> >> + } >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Read Allocation Extent Descriptor into memory. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GetAedAdsData ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, >> > >> >> + IN UDF_FE_RECORDING_FLAGS RecordingFlags, >> > >> >> + IN VOID *Ad, >> > >> >> + OUT VOID **Data, >> > >> >> + OUT UINT64 *Length >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT64 Offset; >> > >> >> + >> > >> >> + // >> > >> >> + // Get AED's offset + length. >> > >> >> + // >> > >> >> + Status = GetAedAdsOffset ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + Volume, >> > >> >> + ParentIcb, >> > >> >> + RecordingFlags, >> > >> >> + Ad, >> > >> >> + &Offset, >> > >> >> + Length >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + return Status; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Allocate buffer to read in AED's data. >> > >> >> + // >> > >> >> + *Data = AllocatePool (*Length); >> > >> >> + if (!Data) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Read it. >> > >> >> + // >> > >> >> + return DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + Offset, >> > >> >> + *Length, >> > >> >> + *Data >> > >> >> + ); >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Function used to serialise reads of Allocation Descriptors. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +GrowUpBufferToNextAd ( >> > >> >> + IN UDF_FE_RECORDING_FLAGS RecordingFlags, >> > >> >> + IN VOID *Ad, >> > >> >> + IN OUT VOID **Buffer, >> > >> >> + IN UINT64 Length >> > >> >> + ) >> > >> >> +{ >> > >> >> + UINT32 ExtentLength; >> > >> >> + >> > >> >> + ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad); >> > >> >> + >> > >> >> + if (!*Buffer) { >> > >> >> + *Buffer = AllocatePool (ExtentLength); >> > >> >> + if (!*Buffer) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + } else { >> > >> >> + *Buffer = ReallocatePool (Length, Length + ExtentLength, >> > >> *Buffer); >> > >> >> + if (!*Buffer) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Read data or size of either a File Entry or an Extended >> File >> > >> Entry. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +ReadFile ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, >> > >> >> + IN VOID *FileEntryData, >> > >> >> + IN OUT UDF_READ_FILE_INFO *ReadFileInfo >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT32 LogicalBlockSize; >> > >> >> + VOID *Data; >> > >> >> + UINT64 Length; >> > >> >> + VOID *Ad; >> > >> >> + UINT64 AdOffset; >> > >> >> + UINT64 Lsn; >> > >> >> + BOOLEAN DoFreeAed; >> > >> >> + UINT64 FilePosition; >> > >> >> + UINT64 Offset; >> > >> >> + UINT64 DataOffset; >> > >> >> + UINT64 BytesLeft; >> > >> >> + UINT64 DataLength; >> > >> >> + BOOLEAN FinishedSeeking; >> > >> >> + UINT32 ExtentLength; >> > >> >> + UDF_FE_RECORDING_FLAGS RecordingFlags; >> > >> >> + >> > >> >> + LogicalBlockSize = LV_BLOCK_SIZE (Volume, >> > UDF_DEFAULT_LV_NUM); >> > >> >> + DoFreeAed = FALSE; >> > >> >> + >> > >> >> + switch (ReadFileInfo->Flags) { >> > >> >> + case READ_FILE_GET_FILESIZE: >> > >> >> + case READ_FILE_ALLOCATE_AND_READ: >> > >> >> + // >> > >> >> + // Initialise ReadFileInfo structure for starting get >> file's >> > >> size >> > >> >> or read >> > >> >> + // file's recorded data. >> > >> >> + // >> > >> >> + ReadFileInfo->ReadLength = 0; >> > >> >> + ReadFileInfo->FileData = NULL; >> > >> >> + break; >> > >> >> + case READ_FILE_SEEK_AND_READ: >> > >> >> + // >> > >> >> + // About to seek a file and/or read its data. >> > >> >> + // >> > >> >> + Length = ReadFileInfo->FileSize - >> ReadFileInfo->FilePosition; >> > >> >> + if (ReadFileInfo->FileDataSize > Length) { >> > >> >> + // >> > >> >> + // About to read beyond the EOF -- truncate it. >> > >> >> + // >> > >> >> + ReadFileInfo->FileDataSize = Length; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Initialise data to start seeking and/or reading a >> file. >> > >> >> + // >> > >> >> + BytesLeft = ReadFileInfo->FileDataSize; >> > >> >> + DataOffset = 0; >> > >> >> + FilePosition = 0; >> > >> >> + FinishedSeeking = FALSE; >> > >> >> + >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + RecordingFlags = GET_FE_RECORDING_FLAGS (FileEntryData); >> > >> >> + switch (RecordingFlags) { >> > >> >> + case INLINE_DATA: >> > >> >> + // >> > >> >> + // There is no extents for this FE/EFE. All its data is >> > >> inline. >> > >> >> + // >> > >> >> + GetFileEntryData (FileEntryData, &Data, &Length); >> > >> >> + >> > >> >> + if (ReadFileInfo->Flags == READ_FILE_GET_FILESIZE) { >> > >> >> + ReadFileInfo->ReadLength = Length; >> > >> >> + } else if (ReadFileInfo->Flags == >> > READ_FILE_ALLOCATE_AND_READ) >> > >> { >> > >> >> + // >> > >> >> + // Allocate buffer for starting read data. >> > >> >> + // >> > >> >> + ReadFileInfo->FileData = AllocatePool (Length); >> > >> >> + if (!ReadFileInfo->FileData) { >> > >> >> + return EFI_OUT_OF_RESOURCES; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Read all inline data into ReadFileInfo->FileData >> > >> >> + // >> > >> >> + CopyMem (ReadFileInfo->FileData, Data, Length); >> > >> >> + ReadFileInfo->ReadLength = Length; >> > >> >> + } else if (ReadFileInfo->Flags == >> READ_FILE_SEEK_AND_READ) { >> > >> >> + // >> > >> >> + // If FilePosition is non-zero, seek file to >> FilePosition, >> > >> read >> > >> >> + // FileDataSize bytes and then updates FilePosition. >> > >> >> + // >> > >> >> + CopyMem ( >> > >> >> + ReadFileInfo->FileData, >> > >> >> + (VOID *)((UINT8 *)Data + >> ReadFileInfo->FilePosition), >> > >> >> + ReadFileInfo->FileDataSize >> > >> >> + ); >> > >> >> + >> > >> >> + ReadFileInfo->FilePosition += >> ReadFileInfo->FileDataSize; >> > >> >> + } >> > >> >> + >> > >> >> + break; >> > >> >> + case LONG_ADS_SEQUENCE: >> > >> >> + case SHORT_ADS_SEQUENCE: >> > >> >> + // >> > >> >> + // This FE/EFE contains a run of Allocation Descriptors. >> Get >> > >> data >> > >> >> + size >> > >> >> + // for start reading them. >> > >> >> + // >> > >> >> + GetAdsInformation (FileEntryData, &Data, &Length); >> > >> >> + AdOffset = 0; >> > >> >> + >> > >> >> + for (;;) { >> > >> >> + // >> > >> >> + // Read AD. >> > >> >> + // >> > >> >> + Status = GetAllocationDescriptor ( >> > >> >> + RecordingFlags, >> > >> >> + Data, >> > >> >> + &AdOffset, >> > >> >> + Length, >> > >> >> + &Ad >> > >> >> + ); >> > >> >> + if (Status == EFI_DEVICE_ERROR) { >> > >> >> + Status = EFI_SUCCESS; >> > >> >> + goto Done; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Check if AD is an indirect one. If so, read >> Allocation >> > >> >> Extent >> > >> >> + // Descriptor and read their extents (ADs). >> > >> >> + // >> > >> >> + if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == >> > >> >> EXTENT_IS_NEXT_EXTENT) { >> > >> >> + if (!DoFreeAed) { >> > >> >> + DoFreeAed = TRUE; >> > >> >> + } else { >> > >> >> + FreePool (Data); >> > >> >> + } >> > >> >> + >> > >> >> + Status = GetAedAdsData ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + Volume, >> > >> >> + ParentIcb, >> > >> >> + RecordingFlags, >> > >> >> + Ad, >> > >> >> + &Data, >> > >> >> + &Length >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Get_Aed; >> > >> >> + } >> > >> >> + >> > >> >> + AdOffset = 0; >> > >> >> + continue; >> > >> >> + } >> > >> >> + >> > >> >> + ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad); >> > >> >> + >> > >> >> + Lsn = GetAllocationDescriptorLsn ( >> > >> >> + RecordingFlags, >> > >> >> + Volume, >> > >> >> + ParentIcb, >> > >> >> + Ad >> > >> >> + ); >> > >> >> + >> > >> >> + switch (ReadFileInfo->Flags) { >> > >> >> + case READ_FILE_GET_FILESIZE: >> > >> >> + ReadFileInfo->ReadLength += ExtentLength; >> > >> >> + break; >> > >> >> + case READ_FILE_ALLOCATE_AND_READ: >> > >> >> + // >> > >> >> + // Increase FileData (if necessary) to read next >> extent. >> > >> >> + // >> > >> >> + Status = GrowUpBufferToNextAd ( >> > >> >> + RecordingFlags, >> > >> >> + Ad, >> > >> >> + &ReadFileInfo->FileData, >> > >> >> + ReadFileInfo->ReadLength >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Alloc_Buffer_To_Next_Ad; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Read extent's data into FileData. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + MultU64x32 (Lsn, >> LogicalBlockSize), >> > >> >> + ExtentLength, >> > >> >> + (VOID *)((UINT8 >> *)ReadFileInfo->FileData >> > >> >> + >> > >> >> + >> ReadFileInfo->ReadLength) >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Read_Disk_Blk; >> > >> >> + } >> > >> >> + >> > >> >> + ReadFileInfo->ReadLength += ExtentLength; >> > >> >> + break; >> > >> >> + case READ_FILE_SEEK_AND_READ: >> > >> >> + // >> > >> >> + // Seek file first before reading in its data. >> > >> >> + // >> > >> >> + if (FinishedSeeking) { >> > >> >> + Offset = 0; >> > >> >> + goto Skip_File_Seek; >> > >> >> + } >> > >> >> + >> > >> >> + if (FilePosition + ExtentLength < >> ReadFileInfo->FilePosition) { >> > >> >> + FilePosition += ExtentLength; >> > >> >> + goto Skip_Ad; >> > >> >> + } >> > >> >> + >> > >> >> + if (FilePosition + ExtentLength > >> ReadFileInfo->FilePosition) { >> > >> >> + Offset = ReadFileInfo->FilePosition - >> FilePosition; >> > >> >> + if (Offset < 0) { >> > >> >> + Offset = -(Offset); >> > >> >> + } >> > >> >> + } else { >> > >> >> + Offset = 0; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Done with seeking file. Start reading its data. >> > >> >> + // >> > >> >> + FinishedSeeking = TRUE; >> > >> >> + >> > >> >> +Skip_File_Seek: >> > >> >> + // >> > >> >> + // Make sure we don't read more data than really >> wanted. >> > >> >> + // >> > >> >> + if (ExtentLength - Offset > BytesLeft) { >> > >> >> + DataLength = BytesLeft; >> > >> >> + } else { >> > >> >> + DataLength = ExtentLength - Offset; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Read extent's data into FileData. >> > >> >> + // >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + Offset + MultU64x32 (Lsn, >> > >> >> LogicalBlockSize), >> > >> >> + DataLength, >> > >> >> + (VOID *)((UINT8 >> *)ReadFileInfo->FileData >> > >> >> + >> > >> >> + DataOffset) >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Read_Disk_Blk; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Update current file's position. >> > >> >> + // >> > >> >> + DataOffset += DataLength; >> > >> >> + ReadFileInfo->FilePosition += DataLength; >> > >> >> + >> > >> >> + BytesLeft -= DataLength; >> > >> >> + if (!BytesLeft) { >> > >> >> + // >> > >> >> + // There is no more file data to read. >> > >> >> + // >> > >> >> + Status = EFI_SUCCESS; >> > >> >> + goto Done; >> > >> >> + } >> > >> >> + >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> +Skip_Ad: >> > >> >> + // >> > >> >> + // Point to the next AD (extent). >> > >> >> + // >> > >> >> + AdOffset += AD_LENGTH (RecordingFlags); >> > >> >> + } >> > >> >> + >> > >> >> + break; >> > >> >> + case EXTENDED_ADS_SEQUENCE: >> > >> >> + // Not supported. Haven't got a volume with that yet. >> > >> >> + Status = EFI_UNSUPPORTED; >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> +Done: >> > >> >> + if (DoFreeAed) { >> > >> >> + FreePool (Data); >> > >> >> + } >> > >> >> + >> > >> >> + return Status; >> > >> >> + >> > >> >> +Error_Read_Disk_Blk: >> > >> >> +Error_Alloc_Buffer_To_Next_Ad: >> > >> >> + if (ReadFileInfo->Flags != READ_FILE_SEEK_AND_READ) { >> > >> >> + FreePool (ReadFileInfo->FileData); >> > >> >> + } >> > >> >> + >> > >> >> + if (DoFreeAed) { >> > >> >> + FreePool (Data); >> > >> >> + } >> > >> >> + >> > >> >> +Error_Get_Aed: >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +// >> > >> >> +// Find a file by its filename from the given Parent file. >> > >> >> +// >> > >> >> +EFI_STATUS >> > >> >> +InternalFindFile ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >> > >> >> + IN UDF_VOLUME_INFO *Volume, >> > >> >> + IN CHAR16 *FileName, >> > >> >> + IN UDF_FILE_INFO *Parent, >> > >> >> + IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb, >> > >> >> + OUT UDF_FILE_INFO *File >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc; >> > >> >> + UDF_READ_DIRECTORY_INFO ReadDirInfo; >> > >> >> + BOOLEAN Found; >> > >> >> + UINTN FileNameLength; >> > >> >> + CHAR16 >> > >> FoundFileName[UDF_FILENAME_LENGTH]; >> > >> >> + VOID *CompareFileEntry; >> > >> >> + >> > >> >> + // >> > >> >> + // Check if parent file is really directory. >> > >> >> + // >> > >> >> + if (!IS_FE_DIRECTORY (Parent->FileEntry)) { >> > >> >> + return EFI_NOT_FOUND; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // If FileName is current file or working directory, just >> > >> duplicate >> > >> >> Parent's >> > >> >> + // FE/EFE and FID descriptors. >> > >> >> + // >> > >> >> + if (!StrCmp (FileName, L".")) { >> > >> >> + DuplicateFe (BlockIo, Volume, Parent->FileEntry, >> > >> &File->FileEntry); >> > >> >> + DuplicateFid (Parent->FileIdentifierDesc, >> > >> >> &File->FileIdentifierDesc); >> > >> >> + >> > >> >> + return EFI_SUCCESS; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Start directory listing. >> > >> >> + // >> > >> >> + ZeroMem ((VOID *)&ReadDirInfo, sizeof >> > >> (UDF_READ_DIRECTORY_INFO)); >> > >> >> + Found = FALSE; >> > >> >> + FileNameLength = StrLen (FileName); >> > >> >> + >> > >> >> + for (;;) { >> > >> >> + Status = ReadDirectoryEntry ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + Volume, >> > >> >> + Parent->FileIdentifierDesc ? >> > >> >> + &Parent->FileIdentifierDesc->Icb : >> > >> >> + Icb, >> > >> >> + Parent->FileEntry, >> > >> >> + &ReadDirInfo, >> > >> >> + &FileIdentifierDesc >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + if (Status == EFI_DEVICE_ERROR) { >> > >> >> + Status = EFI_NOT_FOUND; >> > >> >> + } >> > >> >> + >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + if (IS_FID_PARENT_FILE (FileIdentifierDesc)) { >> > >> >> + // >> > >> >> + // This FID contains the location (FE/EFE) of the parent >> > >> >> directory of this >> > >> >> + // directory (Parent), and if FileName is either ".." or >> "\\", >> > >> >> then it's >> > >> >> + // the expected FID. >> > >> >> + // >> > >> >> + if (!StrCmp (FileName, L"..") || !StrCmp (FileName, >> L"\\")) { >> > >> >> + Found = TRUE; >> > >> >> + break; >> > >> >> + } >> > >> >> + } else { >> > >> >> + // >> > >> >> + // Check if both filename lengths match each other. >> Otherwise, >> > >> we >> > >> >> don't >> > >> >> + // need to read in FID's filename. >> > >> >> + // >> > >> >> + if (FileNameLength != >> > >> FileIdentifierDesc->LengthOfFileIdentifier >> > >> >> - 1) { >> > >> >> + goto Skip_Fid; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // OK - their filename lengths match. Now, compare if >> their >> > >> >> filenames. >> > >> >> + // >> > >> >> + Status = GetFileNameFromFid (FileIdentifierDesc, >> > >> FoundFileName); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + break; >> > >> >> + } >> > >> >> + >> > >> >> + if (!StrCmp (FileName, FoundFileName)) { >> > >> >> + // >> > >> >> + // FID has been found. Prepare to find its respective >> > >> FE/EFE. >> > >> >> + // >> > >> >> + Found = TRUE; >> > >> >> + break; >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> +Skip_Fid: >> > >> >> + FreePool ((VOID *)FileIdentifierDesc); >> > >> >> + } >> > >> >> + >> > >> >> + if (ReadDirInfo.DirectoryData) { >> > >> >> + // >> > >> >> + // Free all allocated resources for the directory listing. >> > >> >> + // >> > >> >> + FreePool (ReadDirInfo.DirectoryData); >> > >> >> + } >> > >> >> + >> > >> >> + if (Found) { >> > >> >> + Status = EFI_SUCCESS; >> > >> >> + >> > >> >> + File->FileIdentifierDesc = FileIdentifierDesc; >> > >> >> + >> > >> >> + // >> > >> >> + // If the requested file is root directory, then the FE/EFE >> was >> > >> >> already >> > >> >> + // retrieved in UdfOpenVolume() function, thus no need to >> find >> > >> it >> > >> >> again. >> > >> >> + // >> > >> >> + // Otherwise, find FE/EFE from the respective FID. >> > >> >> + // >> > >> >> + if (StrCmp (FileName, L"\\")) { >> > >> >> + Status = FindFileEntry ( >> > >> >> + BlockIo, >> > >> >> + DiskIo, >> > >> >> + Volume, >> > >> >> + &FileIdentifierDesc->Icb, >> > >> >> + &CompareFileEntry >> > >> >> + ); >> > >> >> + if (EFI_ERROR (Status)) { >> > >> >> + goto Error_Find_Fe; >> > >> >> + } >> > >> >> + >> > >> >> + // >> > >> >> + // Make sure that both Parent's FE/EFE and found FE/EFE >> are >> > >> not >> > >> >> equal. >> > >> >> + // >> > >> >> + if (CompareMem ( >> > >> >> + (VOID *)Parent->FileEntry, >> > >> >> + (VOID *)CompareFileEntry, >> > >> >> + Volume->FileEntrySize >> > >> >> + ) >> > >> >> + ) { >> > >> >> + File->FileEntry = CompareFileEntry; >> > >> >> + } else { >> > >> >> + FreePool ((VOID *)FileIdentifierDesc); >> > >> >> + FreePool ((VOID *)CompareFileEntry); >> > >> >> + Status = EFI_NOT_FOUND; >> > >> >> + } >> > >> >> + } >> > >> >> + } >> > >> >> + >> > >> >> + return Status; >> > >> >> + >> > >> >> +Error_Find_Fe: >> > >> >> + FreePool ((VOID *)FileIdentifierDesc); >> > >> >> + >> > >> >> + return Status; >> > >> >> +} >> > >> >> + >> > >> >> +/** >> > >> >> + Check if medium contains an UDF file system. >> > >> >> + >> > >> >> + @param[in] BlockIo BlockIo interface. >> > >> >> + @param[in] DiskIo DiskIo interface. >> > >> >> + >> > >> >> + @retval EFI_SUCCESS UDF file system found. >> > >> >> + @retval EFI_UNSUPPORTED UDF file system not found. >> > >> >> + @retval EFI_NO_MEDIA The device has no media. >> > >> >> + @retval EFI_DEVICE_ERROR The device reported an error. >> > >> >> + @retval EFI_VOLUME_CORRUPTED The file system structures are >> > >> >> corrupted. >> > >> >> + @retval EFI_OUT_OF_RESOURCES The scan was not successful due >> > to >> > >> lack >> > >> >> of >> > >> >> + resources. >> > >> >> + >> > >> >> +**/ >> > >> >> +EFI_STATUS >> > >> >> +SupportUdfFileSystem ( >> > >> >> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >> > >> >> + IN EFI_DISK_IO_PROTOCOL *DiskIo >> > >> >> + ) >> > >> >> +{ >> > >> >> + EFI_STATUS Status; >> > >> >> + UINT64 Offset; >> > >> >> + UINT64 EndDiskOffset; >> > >> >> + UDF_VOLUME_DESCRIPTOR VolDescriptor; >> > >> >> + UDF_VOLUME_DESCRIPTOR >> TerminatingVolDescriptor; >> > >> >> + UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; >> > >> >> + >> > >> >> + ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof >> > >> >> (UDF_VOLUME_DESCRIPTOR)); >> > >> >> + >> > >> >> + // >> > >> >> + // Start Volume Recognition Sequence >> > >> >> + // >> > >> >> + EndDiskOffset = BlockIo->Media->LastBlock * >> > >> >> BlockIo->Media->BlockSize; >> > >> >> + >> > >> >> + for (Offset = UDF_VRS_START_OFFSET; Offset < EndDiskOffset; >> > >> >> + Offset += UDF_LOGICAL_SECTOR_SIZE) { >> > >> >> + Status = DiskIo->ReadDisk ( >> > >> >> + DiskIo, >> > >> >> + BlockIo->Media->MediaId, >> > >> >> + >> ... > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming! The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is > your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. > http://goparallel.sourceforge.net_______________________________________________ > edk2-devel mailing list > edk2-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/edk2-devel > -- Paulo Alcantara, C.E.S.A.R Speaking for myself only. ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel