]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseOpenDir.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseOpenDir.c
CommitLineData
b62a0c56
LE
1/** @file\r
2 FUSE_OPENDIR 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 a FUSE_OPENDIR request to the Virtio Filesystem device, for opening a\r
13 directory.\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\r
19 FUSE_OPENDIR request to. On output, the FUSE request\r
20 counter "VirtioFs->RequestId" will have been\r
21 incremented.\r
22\r
23 @param[in] NodeId The inode number of the directory to open.\r
24\r
25 @param[out] FuseHandle The open file handle returned by the Virtio\r
26 Filesystem device.\r
27\r
28 @retval EFI_SUCCESS The directory has been opened.\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
38VirtioFsFuseOpenDir (\r
ac0a286f
MK
39 IN OUT VIRTIO_FS *VirtioFs,\r
40 IN UINT64 NodeId,\r
41 OUT UINT64 *FuseHandle\r
b62a0c56
LE
42 )\r
43{\r
ac0a286f
MK
44 VIRTIO_FS_FUSE_REQUEST CommonReq;\r
45 VIRTIO_FS_FUSE_OPEN_REQUEST OpenReq;\r
46 VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r
47 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
48 VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
49 VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp;\r
50 VIRTIO_FS_IO_VECTOR RespIoVec[2];\r
51 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
52 EFI_STATUS Status;\r
b62a0c56
LE
53\r
54 //\r
55 // Set up the scatter-gather lists.\r
56 //\r
57 ReqIoVec[0].Buffer = &CommonReq;\r
58 ReqIoVec[0].Size = sizeof CommonReq;\r
59 ReqIoVec[1].Buffer = &OpenReq;\r
60 ReqIoVec[1].Size = sizeof OpenReq;\r
61 ReqSgList.IoVec = ReqIoVec;\r
62 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r
63\r
64 RespIoVec[0].Buffer = &CommonResp;\r
65 RespIoVec[0].Size = sizeof CommonResp;\r
66 RespIoVec[1].Buffer = &OpenResp;\r
67 RespIoVec[1].Size = sizeof OpenResp;\r
68 RespSgList.IoVec = RespIoVec;\r
69 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r
70\r
71 //\r
72 // Validate the scatter-gather lists; calculate the total transfer sizes.\r
73 //\r
74 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
75 if (EFI_ERROR (Status)) {\r
76 return Status;\r
77 }\r
78\r
79 //\r
80 // Populate the common request header.\r
81 //\r
ac0a286f
MK
82 Status = VirtioFsFuseNewRequest (\r
83 VirtioFs,\r
84 &CommonReq,\r
85 ReqSgList.TotalSize,\r
86 VirtioFsFuseOpOpenDir,\r
87 NodeId\r
88 );\r
b62a0c56
LE
89 if (EFI_ERROR (Status)) {\r
90 return Status;\r
91 }\r
92\r
93 //\r
94 // Populate the FUSE_OPENDIR-specific fields.\r
95 //\r
96 OpenReq.Flags = 0;\r
97 OpenReq.Unused = 0;\r
98\r
99 //\r
100 // Submit the request.\r
101 //\r
102 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
103 if (EFI_ERROR (Status)) {\r
104 return Status;\r
105 }\r
106\r
107 //\r
108 // Verify the response (all response buffers are fixed size).\r
109 //\r
110 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
111 if (EFI_ERROR (Status)) {\r
112 if (Status == EFI_DEVICE_ERROR) {\r
ac0a286f
MK
113 DEBUG ((\r
114 DEBUG_ERROR,\r
115 "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",\r
116 __FUNCTION__,\r
117 VirtioFs->Label,\r
118 NodeId,\r
119 CommonResp.Error\r
120 ));\r
b62a0c56
LE
121 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
122 }\r
ac0a286f 123\r
b62a0c56
LE
124 return Status;\r
125 }\r
126\r
127 //\r
128 // Output the open file handle.\r
129 //\r
130 *FuseHandle = OpenResp.FileHandle;\r
131 return EFI_SUCCESS;\r
132}\r