]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseStatFs.c
MdePkg/Include: Add STATIC_ASSERT for L'' and L"" strings
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseStatFs.c
CommitLineData
ba118463
LE
1/** @file\r
2 FUSE_STATFS wrapper for the Virtio Filesystem device.\r
3\r
4 Copyright (C) 2020, Red Hat, Inc.\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
9#include "VirtioFsDxe.h"\r
10\r
11/**\r
12 Send the FUSE_STATFS request to the Virtio Filesysem device, for retrieving\r
13 the attributes of the host-side filesystem that contains NodeId.\r
14\r
15 The function may only be called after VirtioFsFuseInitSession() returns\r
16 successfully and before VirtioFsUninit() is called.\r
17\r
18 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_STATFS\r
19 request to. On output, the FUSE request counter\r
20 "VirtioFs->RequestId" will have been incremented.\r
21\r
22 @param[in] NodeId The inode whose containing filesystem is to be\r
23 queried for its attributes.\r
24\r
25 @param[out] FilesysAttr The VIRTIO_FS_FUSE_STATFS_RESPONSE object describing\r
26 the filesystem that underlies NodeId.\r
27\r
28 @retval EFI_SUCCESS FilesysAttr has been filled in.\r
29\r
30 @return The "errno" value mapped to an EFI_STATUS code, if the\r
31 Virtio Filesystem device explicitly reported an error.\r
32\r
33 @return Error codes propagated from VirtioFsSgListsValidate(),\r
34 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
35 VirtioFsFuseCheckResponse().\r
36**/\r
37EFI_STATUS\r
38VirtioFsFuseStatFs (\r
39 IN OUT VIRTIO_FS *VirtioFs,\r
40 IN UINT64 NodeId,\r
41 OUT VIRTIO_FS_FUSE_STATFS_RESPONSE *FilesysAttr\r
42 )\r
43{\r
44 VIRTIO_FS_FUSE_REQUEST CommonReq;\r
45 VIRTIO_FS_IO_VECTOR ReqIoVec[1];\r
46 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
47 VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
48 VIRTIO_FS_IO_VECTOR RespIoVec[2];\r
49 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
50 EFI_STATUS Status;\r
51\r
52 //\r
53 // Set up the scatter-gather lists.\r
54 //\r
55 ReqIoVec[0].Buffer = &CommonReq;\r
56 ReqIoVec[0].Size = sizeof CommonReq;\r
57 ReqSgList.IoVec = ReqIoVec;\r
58 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r
59\r
60 RespIoVec[0].Buffer = &CommonResp;\r
61 RespIoVec[0].Size = sizeof CommonResp;\r
62 RespIoVec[1].Buffer = FilesysAttr;\r
63 RespIoVec[1].Size = sizeof *FilesysAttr;\r
64 RespSgList.IoVec = RespIoVec;\r
65 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r
66\r
67 //\r
68 // Validate the scatter-gather lists; calculate the total transfer sizes.\r
69 //\r
70 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
71 if (EFI_ERROR (Status)) {\r
72 return Status;\r
73 }\r
74\r
75 //\r
76 // Populate the common request header.\r
77 //\r
78 Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,\r
79 VirtioFsFuseOpStatFs, NodeId);\r
80 if (EFI_ERROR (Status)) {\r
81 return Status;\r
82 }\r
83\r
84 //\r
85 // Submit the request.\r
86 //\r
87 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
88 if (EFI_ERROR (Status)) {\r
89 return Status;\r
90 }\r
91\r
92 //\r
93 // Verify the response (all response buffers are fixed size).\r
94 //\r
95 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
96 if (Status == EFI_DEVICE_ERROR) {\r
97 DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",\r
98 __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error));\r
99 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
100 }\r
101 return Status;\r
102}\r