[edk2-devel] [edk2 PATCH 45/48] OvmfPkg/VirtioFsDxe: add helper for determining file size update
Laszlo Ersek
lersek at redhat.com
Wed Dec 16 21:11:22 UTC 2020
Add the VirtioFsGetFuseSizeUpdate() function, for determining whether an
EFI_FILE_PROTOCOL.SetInfo() invocation requests a file size update.
Cc: Ard Biesheuvel <ard.biesheuvel at arm.com>
Cc: Jordan Justen <jordan.l.justen at intel.com>
Cc: Philippe Mathieu-Daudé <philmd at redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++++
OvmfPkg/VirtioFsDxe/Helpers.c | 40 ++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
index 9e6348f9386e..096756302942 100644
--- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
+++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
@@ -277,16 +277,24 @@ VirtioFsFuseAttrToEfiFileInfo (
);
EFI_STATUS
VirtioFsFuseDirentPlusToEfiFileInfo (
IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent,
IN OUT EFI_FILE_INFO *FileInfo
);
+VOID
+VirtioFsGetFuseSizeUpdate (
+ IN EFI_FILE_INFO *Info,
+ IN EFI_FILE_INFO *NewInfo,
+ OUT BOOLEAN *Update,
+ OUT UINT64 *Size
+ );
+
//
// Wrapper functions for FUSE commands (primitives).
//
EFI_STATUS
VirtioFsFuseLookup (
IN OUT VIRTIO_FS *VirtioFs,
IN UINT64 DirNodeId,
diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c
index b741cf753495..838971bd2c85 100644
--- a/OvmfPkg/VirtioFsDxe/Helpers.c
+++ b/OvmfPkg/VirtioFsDxe/Helpers.c
@@ -2168,8 +2168,48 @@ VirtioFsFuseDirentPlusToEfiFileInfo (
FileInfo->FileName[Idx++] = L'\0';
//
// Set the (possibly reduced) size.
//
FileInfo->Size = FileInfoSize;
return EFI_SUCCESS;
}
+
+/**
+ Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo()
+ call, determine whether updating the size of the file is necessary, relative
+ to an EFI_FILE_INFO object describing the current state of the file.
+
+ @param[in] Info The EFI_FILE_INFO describing the current state of the
+ file. The caller is responsible for populating Info on
+ input with VirtioFsFuseAttrToEfiFileInfo(), from the
+ current FUSE attributes of the file. The Info->Size and
+ Info->FileName members are ignored.
+
+ @param[in] NewInfo The EFI_FILE_INFO object received in the
+ EFI_FILE_PROTOCOL.SetInfo() call.
+
+ @param[out] Update Set to TRUE on output if the file size needs to be
+ updated. Set to FALSE otherwise.
+
+ @param[out] Size If Update is set to TRUE, then Size provides the new file
+ size to set. Otherwise, Size is not written to.
+**/
+VOID
+VirtioFsGetFuseSizeUpdate (
+ IN EFI_FILE_INFO *Info,
+ IN EFI_FILE_INFO *NewInfo,
+ OUT BOOLEAN *Update,
+ OUT UINT64 *Size
+ )
+{
+ BOOLEAN IsDirectory;
+
+ IsDirectory = (BOOLEAN)((Info->Attribute & EFI_FILE_DIRECTORY) != 0);
+
+ if (IsDirectory || Info->FileSize == NewInfo->FileSize) {
+ *Update = FALSE;
+ return;
+ }
+ *Update = TRUE;
+ *Size = NewInfo->FileSize;
+}
--
2.19.1.3.g30247aa5d201
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69059): https://edk2.groups.io/g/devel/message/69059
Mute This Topic: https://groups.io/mt/79024600/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list