From: "Pedro Falcato" <pedro.falcato@gmail.com>
To: devel@edk2.groups.io
Cc: Pedro Falcato <pedro.falcato@gmail.com>,
Leif Lindholm <leif@nuviainc.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: [edk2-platforms PATCH v2 4/5] Ext4Pkg: Add handling of EFI_FILE_SYSTEM_VOLUME_LABEL GetInfo().
Date: Sat, 21 Aug 2021 15:47:09 +0100 [thread overview]
Message-ID: <20210821144711.39546-5-pedro.falcato@gmail.com> (raw)
In-Reply-To: <20210821144711.39546-1-pedro.falcato@gmail.com>
This commit adds support for EFI_FILE_SYSTEM_VOLUME_LABEL requests
in GetInfo().
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
---
Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c | 1 -
Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 17 ++++
Features/Ext4Pkg/Ext4Dxe/File.c | 155 ++++++++++++++++++++++-------
3 files changed, 138 insertions(+), 35 deletions(-)
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c
index 71360ea894d2..ea2e048d7762 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c
@@ -6,7 +6,6 @@
**/
#include "Ext4Dxe.h"
-#include "Uefi/UefiBaseType.h"
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mExt4DriverNameTable[] = {
{
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
index db938c25244d..64eab455db4a 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
@@ -1100,4 +1100,21 @@ Ext4CalculateBlockGroupDescChecksum (
#define EXT4_HAS_GDT_CSUM(Partition) \
EXT4_HAS_RO_COMPAT (Partition, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+/**
+ Retrieves the volume name.
+
+ @param[in] Part Pointer to the opened partition.
+ @param[out] Info Pointer to a CHAR16*.
+ @param[out] BufferSize Pointer to a UINTN, where the string length
+ of the name will be put.
+
+ @return Status of the volume name request.
+**/
+EFI_STATUS
+Ext4GetVolumeName (
+ IN EXT4_PARTITION *Partition,
+ OUT CHAR16 **OutVolName,
+ OUT UINTN *VolNameLen
+ );
+
#endif
diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/File.c
index 021d10b1edfb..4ad7cad8dcf5 100644
--- a/Features/Ext4Pkg/Ext4Dxe/File.c
+++ b/Features/Ext4Pkg/Ext4Dxe/File.c
@@ -35,7 +35,9 @@ Ext4DuplicateFile (
STATIC
EFI_STATUS
GetPathSegment (
- IN CONST CHAR16 *Path, OUT CHAR16 *PathSegment, OUT UINTN *Length
+ IN CONST CHAR16 *Path,
+ OUT CHAR16 *PathSegment,
+ OUT UINTN *Length
)
{
CONST CHAR16 *Start;
@@ -514,7 +516,9 @@ Ext4SetPosition (
**/
EFI_STATUS
Ext4GetFileInfo (
- IN EXT4_FILE *File, OUT EFI_FILE_INFO *Info, IN OUT UINTN *BufferSize
+ IN EXT4_FILE *File,
+ OUT EFI_FILE_INFO *Info,
+ IN OUT UINTN *BufferSize
)
{
UINTN FileNameLen;
@@ -557,35 +561,33 @@ Ext4GetFileInfo (
}
/**
- Retrieves information about the filesystem and stores it in the EFI_FILE_SYSTEM_INFO format.
+ Retrieves the volume name.
@param[in] Part Pointer to the opened partition.
- @param[out] Info Pointer to a EFI_FILE_SYSTEM_INFO.
- @param[in out] BufferSize Pointer to the buffer size
+ @param[out] Info Pointer to a CHAR16*.
+ @param[out] BufferSize Pointer to a UINTN, where the string length
+ of the name will be put.
- @return Status of the file information request.
+ @return Status of the volume name request.
**/
-STATIC
EFI_STATUS
-Ext4GetFilesystemInfo (
- IN EXT4_PARTITION *Part, OUT EFI_FILE_SYSTEM_INFO *Info, IN OUT UINTN *BufferSize
+Ext4GetVolumeName (
+ IN EXT4_PARTITION *Partition,
+ OUT CHAR16 **OutVolName,
+ OUT UINTN *VolNameLen
)
{
- // Length of s_volume_name + null terminator
- CHAR8 TempVolName[16 + 1];
- CHAR16 *VolumeName;
- UINTN VolNameLength;
- EFI_STATUS Status;
- UINTN NeededLength;
- EXT4_BLOCK_NR TotalBlocks;
- EXT4_BLOCK_NR FreeBlocks;
+ CHAR8 TempVolName[16 + 1];
+ CHAR16 *VolumeName;
+ UINTN VolNameLength;
+ EFI_STATUS Status;
VolNameLength = 0;
VolumeName = NULL;
// s_volume_name is only valid on dynamic revision; old filesystems don't support this
- if (Part->SuperBlock.s_rev_level == EXT4_DYNAMIC_REV) {
- CopyMem (TempVolName, (CONST CHAR8 *)Part->SuperBlock.s_volume_name, 16);
+ if (Partition->SuperBlock.s_rev_level == EXT4_DYNAMIC_REV) {
+ CopyMem (TempVolName, (CONST CHAR8 *)Partition->SuperBlock.s_volume_name, 16);
TempVolName[16] = '\0';
Status = UTF8StrToUCS2 (TempVolName, &VolumeName);
@@ -595,23 +597,56 @@ Ext4GetFilesystemInfo (
}
VolNameLength = StrLen (VolumeName);
+ } else {
+ VolumeName = AllocateZeroPool (sizeof (CHAR16));
+ VolNameLength = 0;
+ }
+
+ *OutVolName = VolumeName;
+ *VolNameLen = VolNameLength;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieves information about the filesystem and stores it in the EFI_FILE_SYSTEM_INFO format.
+
+ @param[in] Part Pointer to the opened partition.
+ @param[out] Info Pointer to a EFI_FILE_SYSTEM_INFO.
+ @param[in out] BufferSize Pointer to the buffer size
+
+ @return Status of the file information request.
+**/
+STATIC
+EFI_STATUS
+Ext4GetFilesystemInfo (
+ IN EXT4_PARTITION *Part,
+ OUT EFI_FILE_SYSTEM_INFO *Info,
+ IN OUT UINTN *BufferSize
+ )
+{
+ // Length of s_volume_name + null terminator
+ EFI_STATUS Status;
+ UINTN NeededLength;
+ EXT4_BLOCK_NR TotalBlocks;
+ EXT4_BLOCK_NR FreeBlocks;
+ CHAR16 *VolumeName;
+ UINTN VolNameLength;
+
+ Status = Ext4GetVolumeName (Part, &VolumeName, &VolNameLength);
+
+ if (EFI_ERROR (Status)) {
+ return Status;
}
NeededLength = SIZE_OF_EFI_FILE_SYSTEM_INFO;
- if (VolumeName != NULL) {
- NeededLength += StrSize (VolumeName);
- } else {
- // If we don't have a volume name, we set VolumeLabel to a single null terminator
- NeededLength += sizeof (CHAR16);
- }
+ NeededLength += StrSize (VolumeName);
if (*BufferSize < NeededLength) {
*BufferSize = NeededLength;
- if (VolumeName != NULL) {
- FreePool (VolumeName);
- }
+ FreePool (VolumeName);
return EFI_BUFFER_TOO_SMALL;
}
@@ -630,16 +665,60 @@ Ext4GetFilesystemInfo (
Info->VolumeSize = MultU64x32 (TotalBlocks, Part->BlockSize);
Info->FreeSpace = MultU64x32 (FreeBlocks, Part->BlockSize);
- if (VolumeName != NULL) {
- StrCpyS (Info->VolumeLabel, VolNameLength + 1, VolumeName);
- } else {
- Info->VolumeLabel[0] = L'\0';
+ StrCpyS (Info->VolumeLabel, VolNameLength + 1, VolumeName);
+
+ FreePool (VolumeName);
+
+ *BufferSize = NeededLength;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieves the volume label and stores it in the EFI_FILE_SYSTEM_VOLUME_LABEL format.
+
+ @param[in] Part Pointer to the opened partition.
+ @param[out] Info Pointer to a EFI_FILE_SYSTEM_VOLUME_LABEL.
+ @param[in out] BufferSize Pointer to the buffer size
+
+ @return Status of the file information request.
+**/
+STATIC
+EFI_STATUS
+Ext4GetVolumeLabelInfo (
+ IN EXT4_PARTITION *Part,
+ OUT EFI_FILE_SYSTEM_VOLUME_LABEL *Info,
+ IN OUT UINTN *BufferSize
+ )
+{
+ // Length of s_volume_name + null terminator
+ CHAR16 *VolumeName;
+ UINTN VolNameLength;
+ EFI_STATUS Status;
+ UINTN NeededLength;
+
+ Status = Ext4GetVolumeName (Part, &VolumeName, &VolNameLength);
+
+ if (EFI_ERROR (Status)) {
+ return Status;
}
- if (VolumeName != NULL) {
+ NeededLength = (VolNameLength + 1) * sizeof (CHAR16);
+
+ if (NeededLength > *BufferSize) {
+ *BufferSize = NeededLength;
+
FreePool (VolumeName);
+
+ return EFI_BUFFER_TOO_SMALL;
}
+ Status = StrCpyS (Info->VolumeLabel, VolNameLength + 1, VolumeName);
+
+ ASSERT_EFI_ERROR (Status);
+
+ FreePool (VolumeName);
+
*BufferSize = NeededLength;
return EFI_SUCCESS;
@@ -674,12 +753,20 @@ Ext4GetInfo (
OUT VOID *Buffer
)
{
+ EXT4_PARTITION *Partition;
+
+ Partition = ((EXT4_FILE *)This)->Partition;
+
if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {
return Ext4GetFileInfo ((EXT4_FILE *)This, Buffer, BufferSize);
}
if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
- return Ext4GetFilesystemInfo (((EXT4_FILE *)This)->Partition, Buffer, BufferSize);
+ return Ext4GetFilesystemInfo (Partition, Buffer, BufferSize);
+ }
+
+ if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+ return Ext4GetVolumeLabelInfo (Partition, Buffer, BufferSize);
}
return EFI_UNSUPPORTED;
--
2.33.0
next prev parent reply other threads:[~2021-08-21 14:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-21 14:47 [edk2-platforms PATCH v2 0/5] Ext4Pkg: Fix bugs Pedro Falcato
2021-08-21 14:47 ` [edk2-platforms PATCH v2 1/5] Ext4Pkg: Fix incorrect usage of Ext4InitExtentsMap Pedro Falcato
2021-08-21 14:47 ` [edk2-platforms PATCH v2 2/5] Ext4Pkg: Hide "." and ".." entries from Read() callers Pedro Falcato
2021-08-21 14:47 ` [edk2-platforms PATCH v2 3/5] Ext4Pkg: Add a directory entry tree Pedro Falcato
2021-08-21 14:47 ` Pedro Falcato [this message]
2021-08-21 14:47 ` [edk2-platforms PATCH v2 5/5] Ext4Pkg: Sanity check more EXT4_DIR_ENTRY values Pedro Falcato
2021-08-24 1:41 ` [edk2-platforms PATCH v2 0/5] Ext4Pkg: Fix bugs Michael D Kinney
2021-08-24 1:58 ` Michael D Kinney
2021-08-24 1:59 ` Michael D Kinney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210821144711.39546-5-pedro.falcato@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox