]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: add helper for determining file size update
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:11:22 +0000 (22:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
Add the VirtioFsGetFuseSizeUpdate() function, for determining whether an
EFI_FILE_PROTOCOL.SetInfo() invocation requests a file size update.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-46-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/VirtioFsDxe/Helpers.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h

index fd1e00693f60d27bcf2ae7f43f959604f6866dc2..d13bd8c6c9d2a730bc1ee3183f9c3d38ddb7ffcf 100644 (file)
@@ -2173,3 +2173,43 @@ VirtioFsFuseDirentPlusToEfiFileInfo (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo()\r
+  call, determine whether updating the size of the file is necessary, relative\r
+  to an EFI_FILE_INFO object describing the current state of the file.\r
+\r
+  @param[in] Info     The EFI_FILE_INFO describing the current state of the\r
+                      file. The caller is responsible for populating Info on\r
+                      input with VirtioFsFuseAttrToEfiFileInfo(), from the\r
+                      current FUSE attributes of the file. The Info->Size and\r
+                      Info->FileName members are ignored.\r
+\r
+  @param[in] NewInfo  The EFI_FILE_INFO object received in the\r
+                      EFI_FILE_PROTOCOL.SetInfo() call.\r
+\r
+  @param[out] Update  Set to TRUE on output if the file size needs to be\r
+                      updated. Set to FALSE otherwise.\r
+\r
+  @param[out] Size    If Update is set to TRUE, then Size provides the new file\r
+                      size to set. Otherwise, Size is not written to.\r
+**/\r
+VOID\r
+VirtioFsGetFuseSizeUpdate (\r
+  IN     EFI_FILE_INFO *Info,\r
+  IN     EFI_FILE_INFO *NewInfo,\r
+     OUT BOOLEAN       *Update,\r
+     OUT UINT64        *Size\r
+  )\r
+{\r
+  BOOLEAN IsDirectory;\r
+\r
+  IsDirectory = (BOOLEAN)((Info->Attribute & EFI_FILE_DIRECTORY) != 0);\r
+\r
+  if (IsDirectory || Info->FileSize == NewInfo->FileSize) {\r
+    *Update = FALSE;\r
+    return;\r
+  }\r
+  *Update = TRUE;\r
+  *Size = NewInfo->FileSize;\r
+}\r
index 9e6348f9386e738ab7b454e6ceec1352d168c994..0967563029423118eef421cb288ab6998acc84f0 100644 (file)
@@ -282,6 +282,14 @@ VirtioFsFuseDirentPlusToEfiFileInfo (
   IN OUT EFI_FILE_INFO                      *FileInfo\r
   );\r
 \r
+VOID\r
+VirtioFsGetFuseSizeUpdate (\r
+  IN     EFI_FILE_INFO *Info,\r
+  IN     EFI_FILE_INFO *NewInfo,\r
+     OUT BOOLEAN       *Update,\r
+     OUT UINT64        *Size\r
+  );\r
+\r
 //\r
 // Wrapper functions for FUSE commands (primitives).\r
 //\r