--- /dev/null
+/** @file\r
+ FUSE_GETATTR 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_GETATTR request to the Virtio Filesystem device, for fetching the\r
+ attributes of an inode.\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_GETATTR request to. On output, the FUSE request\r
+ counter "VirtioFs->RequestId" will have been\r
+ incremented.\r
+\r
+ @param[in] NodeId The inode number for which the attributes should be\r
+ retrieved.\r
+\r
+ @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object\r
+ describing the properties of the inode.\r
+\r
+ @retval EFI_SUCCESS FuseAttr 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
+VirtioFsFuseGetAttr (\r
+ IN OUT VIRTIO_FS *VirtioFs,\r
+ IN UINT64 NodeId,\r
+ OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r
+ )\r
+{\r
+ VIRTIO_FS_FUSE_REQUEST CommonReq;\r
+ VIRTIO_FS_FUSE_GETATTR_REQUEST GetAttrReq;\r
+ VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r
+ VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
+ VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
+ VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp;\r
+ VIRTIO_FS_IO_VECTOR RespIoVec[3];\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 = &GetAttrReq;\r
+ ReqIoVec[1].Size = sizeof GetAttrReq;\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 = &GetAttrResp;\r
+ RespIoVec[1].Size = sizeof GetAttrResp;\r
+ RespIoVec[2].Buffer = FuseAttr;\r
+ RespIoVec[2].Size = sizeof *FuseAttr;\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
+ VirtioFsFuseOpGetAttr, NodeId);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Populate the FUSE_GETATTR-specific fields.\r
+ //\r
+ GetAttrReq.GetAttrFlags = 0;\r
+ GetAttrReq.Dummy = 0;\r
+ GetAttrReq.FileHandle = 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 (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