]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPENDIR
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:10:46 +0000 (22:10 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
Add the VirtioFsFuseOpenDir() function, for sending the FUSE_OPENDIR
command to the Virtio Filesystem device.

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

index 006e0f5debcb834ab3608ed7c29012172caadab5..c4810532551597993471d59f1a15c96a7ed62940 100644 (file)
@@ -81,6 +81,7 @@ typedef struct {
 //\r
 typedef enum {\r
   VirtioFsFuseOpInit        = 26,\r
+  VirtioFsFuseOpOpenDir     = 27,\r
 } VIRTIO_FS_FUSE_OPCODE;\r
 \r
 #pragma pack (1)\r
@@ -127,6 +128,20 @@ typedef struct {
   UINT16 MapAlignment;\r
   UINT32 Unused[8];\r
 } VIRTIO_FS_FUSE_INIT_RESPONSE;\r
+\r
+//\r
+// Headers for VirtioFsFuseOpOpenDir.\r
+//\r
+typedef struct {\r
+  UINT32 Flags;\r
+  UINT32 Unused;\r
+} VIRTIO_FS_FUSE_OPEN_REQUEST;\r
+\r
+typedef struct {\r
+  UINT64 FileHandle;\r
+  UINT32 OpenFlags;\r
+  UINT32 Padding;\r
+} VIRTIO_FS_FUSE_OPEN_RESPONSE;\r
 #pragma pack ()\r
 \r
 #endif // VIRTIO_FS_H_\r
diff --git a/OvmfPkg/VirtioFsDxe/FuseOpenDir.c b/OvmfPkg/VirtioFsDxe/FuseOpenDir.c
new file mode 100644 (file)
index 0000000..eef5226
--- /dev/null
@@ -0,0 +1,120 @@
+/** @file\r
+  FUSE_OPENDIR 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 "VirtioFsDxe.h"\r
+\r
+/**\r
+  Send a FUSE_OPENDIR request to the Virtio Filesystem device, for opening a\r
+  directory.\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\r
+                           FUSE_OPENDIR request to. On output, the FUSE request\r
+                           counter "VirtioFs->RequestId" will have been\r
+                           incremented.\r
+\r
+  @param[in] NodeId        The inode number of the directory to open.\r
+\r
+  @param[out] FuseHandle   The open file handle returned by the Virtio\r
+                           Filesystem device.\r
+\r
+  @retval EFI_SUCCESS  The directory has been opened.\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
+VirtioFsFuseOpenDir (\r
+  IN OUT VIRTIO_FS *VirtioFs,\r
+  IN     UINT64    NodeId,\r
+     OUT UINT64    *FuseHandle\r
+  )\r
+{\r
+  VIRTIO_FS_FUSE_REQUEST        CommonReq;\r
+  VIRTIO_FS_FUSE_OPEN_REQUEST   OpenReq;\r
+  VIRTIO_FS_IO_VECTOR           ReqIoVec[2];\r
+  VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+  VIRTIO_FS_FUSE_RESPONSE       CommonResp;\r
+  VIRTIO_FS_FUSE_OPEN_RESPONSE  OpenResp;\r
+  VIRTIO_FS_IO_VECTOR           RespIoVec[2];\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 = &OpenReq;\r
+  ReqIoVec[1].Size   = sizeof OpenReq;\r
+  ReqSgList.IoVec    = ReqIoVec;\r
+  ReqSgList.NumVec   = ARRAY_SIZE (ReqIoVec);\r
+\r
+  RespIoVec[0].Buffer = &CommonResp;\r
+  RespIoVec[0].Size   = sizeof CommonResp;\r
+  RespIoVec[1].Buffer = &OpenResp;\r
+  RespIoVec[1].Size   = sizeof OpenResp;\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 (VirtioFs, &CommonReq, ReqSgList.TotalSize,\r
+             VirtioFsFuseOpOpenDir, NodeId);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Populate the FUSE_OPENDIR-specific fields.\r
+  //\r
+  OpenReq.Flags  = 0;\r
+  OpenReq.Unused = 0;\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 (EFI_ERROR (Status)) {\r
+    if (Status == EFI_DEVICE_ERROR) {\r
+      DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",\r
+        __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error));\r
+      Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
+    }\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Output the open file handle.\r
+  //\r
+  *FuseHandle = OpenResp.FileHandle;\r
+  return EFI_SUCCESS;\r
+}\r
index b8d46401184336ae777a547046aae0555c13a127..9c47454435ae112c79cb9941872639711c6a58ee 100644 (file)
@@ -163,6 +163,13 @@ VirtioFsFuseInitSession (
   IN OUT VIRTIO_FS *VirtioFs\r
   );\r
 \r
+EFI_STATUS\r
+VirtioFsFuseOpenDir (\r
+  IN OUT VIRTIO_FS *VirtioFs,\r
+  IN     UINT64    NodeId,\r
+     OUT UINT64    *FuseHandle\r
+  );\r
+\r
 //\r
 // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem\r
 // driver.\r
index 8fddc50318f1d43f62956afee28755b9af536d59..051acbdd7199c9d4a7e6966a219469b0a66eaadd 100644 (file)
@@ -83,6 +83,7 @@
 [Sources]\r
   DriverBinding.c\r
   FuseInit.c\r
+  FuseOpenDir.c\r
   Helpers.c\r
   SimpleFsOpenVolume.c\r
   VirtioFsDxe.h\r