--- /dev/null
+/** @file\r
+ FUSE_STATFS 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 the FUSE_STATFS request to the Virtio Filesysem device, for retrieving\r
+ the attributes of the host-side filesystem that contains NodeId.\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_STATFS\r
+ request to. On output, the FUSE request counter\r
+ "VirtioFs->RequestId" will have been incremented.\r
+\r
+ @param[in] NodeId The inode whose containing filesystem is to be\r
+ queried for its attributes.\r
+\r
+ @param[out] FilesysAttr The VIRTIO_FS_FUSE_STATFS_RESPONSE object describing\r
+ the filesystem that underlies NodeId.\r
+\r
+ @retval EFI_SUCCESS FilesysAttr has been filled in.\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
+VirtioFsFuseStatFs (\r
+ IN OUT VIRTIO_FS *VirtioFs,\r
+ IN UINT64 NodeId,\r
+ OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr\r
+ )\r
+{\r
+ VIRTIO_FS_FUSE_REQUEST CommonReq;\r
+ VIRTIO_FS_IO_VECTOR ReqIoVec[1];\r
+ VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+ VIRTIO_FS_FUSE_RESPONSE CommonResp;\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
+ 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 = FilesysAttr;\r
+ RespIoVec[1].Size = sizeof *FilesysAttr;\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
+ VirtioFsFuseOpStatFs, NodeId);\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\" NodeId=%Lu Errno=%d\n",\r
+ __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error));\r
+ Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
+ }\r
+ return Status;\r
+}\r