]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_UNLINK / FUSE_RMDIR
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:11:01 +0000 (22:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
The FUSE_UNLINK and FUSE_RMDIR commands only differ in the opcode. Add a
common function for wrapping both.

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-25-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/Include/IndustryStandard/VirtioFs.h
OvmfPkg/VirtioFsDxe/FuseUnlink.c [new file with mode: 0644]
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf

index 8a07b3d2eb9366775514979245608f072019fd13..f49452830abc190f22269885cc7c0becd84ed97f 100644 (file)
@@ -115,6 +115,8 @@ typedef enum {
   VirtioFsFuseOpLookup      =  1,\r
   VirtioFsFuseOpForget      =  2,\r
   VirtioFsFuseOpMkDir       =  9,\r
+  VirtioFsFuseOpUnlink      = 10,\r
+  VirtioFsFuseOpRmDir       = 11,\r
   VirtioFsFuseOpOpen        = 14,\r
   VirtioFsFuseOpRelease     = 18,\r
   VirtioFsFuseOpFsync       = 20,\r
diff --git a/OvmfPkg/VirtioFsDxe/FuseUnlink.c b/OvmfPkg/VirtioFsDxe/FuseUnlink.c
new file mode 100644 (file)
index 0000000..8f84edb
--- /dev/null
@@ -0,0 +1,114 @@
+/** @file\r
+  FUSE_UNLINK / FUSE_RMDIR wrapper for the Virtio Filesystem device.\r
+\r
+  Copyright (C) 2020, Red Hat, Inc.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/BaseLib.h> // AsciiStrSize()\r
+\r
+#include "VirtioFsDxe.h"\r
+\r
+/**\r
+  Remove a regular file or a directory, by sending the FUSE_UNLINK or\r
+  FUSE_RMDIR request to the Virtio Filesystem device.\r
+\r
+  The function may only be called after VirtioFsFuseInitSession() returns\r
+  successfully and before VirtioFsUninit() is called.\r
+\r
+  @param[in,out] VirtioFs  The Virtio Filesystem device to send the FUSE_UNLINK\r
+                           / FUSE_RMDIR request to. On output, the FUSE request\r
+                           counter "VirtioFs->RequestId" will have been\r
+                           incremented.\r
+\r
+  @param[in] ParentNodeId  The inode number of the directory in which Name\r
+                           should be removed.\r
+\r
+  @param[in] Name          The single-component filename to remove in the\r
+                           directory identified by ParentNodeId.\r
+\r
+  @param[in] IsDir         TRUE if Name refers to a directory, FALSE otherwise.\r
+\r
+  @retval EFI_SUCCESS  The file or directory has been removed.\r
+\r
+  @return              The "errno" value mapped to an EFI_STATUS code, if the\r
+                       Virtio Filesystem device explicitly reported an error.\r
+\r
+  @return              Error codes propagated from VirtioFsSgListsValidate(),\r
+                       VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
+                       VirtioFsFuseCheckResponse().\r
+**/\r
+EFI_STATUS\r
+VirtioFsFuseRemoveFileOrDir (\r
+  IN OUT VIRTIO_FS *VirtioFs,\r
+  IN     UINT64    ParentNodeId,\r
+  IN     CHAR8     *Name,\r
+  IN     BOOLEAN   IsDir\r
+  )\r
+{\r
+  VIRTIO_FS_FUSE_REQUEST        CommonReq;\r
+  VIRTIO_FS_IO_VECTOR           ReqIoVec[2];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+  VIRTIO_FS_FUSE_RESPONSE       CommonResp;\r
+  VIRTIO_FS_IO_VECTOR           RespIoVec[1];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
+  EFI_STATUS                    Status;\r
+\r
+  //\r
+  // Set up the scatter-gather lists.\r
+  //\r
+  ReqIoVec[0].Buffer = &CommonReq;\r
+  ReqIoVec[0].Size   = sizeof CommonReq;\r
+  ReqIoVec[1].Buffer = Name;\r
+  ReqIoVec[1].Size   = AsciiStrSize (Name);\r
+  ReqSgList.IoVec    = ReqIoVec;\r
+  ReqSgList.NumVec   = ARRAY_SIZE (ReqIoVec);\r
+\r
+  RespIoVec[0].Buffer = &CommonResp;\r
+  RespIoVec[0].Size   = sizeof CommonResp;\r
+  RespSgList.IoVec    = RespIoVec;\r
+  RespSgList.NumVec   = ARRAY_SIZE (RespIoVec);\r
+\r
+  //\r
+  // Validate the scatter-gather lists; calculate the total transfer sizes.\r
+  //\r
+  Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Populate the common request header.\r
+  //\r
+  Status = VirtioFsFuseNewRequest (\r
+             VirtioFs,\r
+             &CommonReq,\r
+             ReqSgList.TotalSize,\r
+             IsDir ? VirtioFsFuseOpRmDir : VirtioFsFuseOpUnlink,\r
+             ParentNodeId\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Submit the request.\r
+  //\r
+  Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Verify the response (all response buffers are fixed size).\r
+  //\r
+  Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "\r
+      "IsDir=%d Errno=%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name,\r
+      IsDir, CommonResp.Error));\r
+    Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
+  }\r
+  return Status;\r
+}\r
index 6ae5c36f7fd523bd0bdd91f33f5dc4b59406f4ec..0e4f2109eb0291b4c2b9005bb621832fdc99268c 100644 (file)
@@ -267,6 +267,14 @@ VirtioFsFuseMkDir (
      OUT UINT64    *NodeId\r
   );\r
 \r
+EFI_STATUS\r
+VirtioFsFuseRemoveFileOrDir (\r
+  IN OUT VIRTIO_FS *VirtioFs,\r
+  IN     UINT64    ParentNodeId,\r
+  IN     CHAR8     *Name,\r
+  IN     BOOLEAN   IsDir\r
+  );\r
+\r
 EFI_STATUS\r
 VirtioFsFuseOpen (\r
   IN OUT VIRTIO_FS *VirtioFs,\r
index 3552ece6b945b7ee599ffd8dcb4c08f85531a450..2332aa3ee551e00f51d75a139aa2fd9095e254b0 100644 (file)
@@ -93,6 +93,7 @@
   FuseOpenDir.c\r
   FuseOpenOrCreate.c\r
   FuseRelease.c\r
+  FuseUnlink.c\r
   Helpers.c\r
   SimpleFsClose.c\r
   SimpleFsDelete.c\r