]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseRelease.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseRelease.c
CommitLineData
72d4f133
LE
1/** @file\r
2 FUSE_RELEASE / FUSE_RELEASEDIR 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 Close a regular file or a directory that is open, by sending the FUSE_RELEASE\r
13 or FUSE_RELEASEDIR request to the Virtio Filesystem device.\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_RELEASE / FUSE_RELEASEDIR request to. On\r
20 output, the FUSE request counter\r
21 "VirtioFs->RequestId" will have been incremented.\r
22\r
23 @param[in] NodeId The inode number of the file or directory to close.\r
24\r
25 @param[in] FuseHandle The open handle to the file or directory to close.\r
26\r
27 @param[in] IsDir TRUE if NodeId and FuseHandle refer to a directory,\r
28 FALSE if NodeId and FuseHandle refer to a regular\r
29 file.\r
30\r
31 @retval EFI_SUCCESS The file or directory has been closed.\r
32\r
33 @return The "errno" value mapped to an EFI_STATUS code, if the\r
34 Virtio Filesystem device explicitly reported an error.\r
35\r
36 @return Error codes propagated from VirtioFsSgListsValidate(),\r
37 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
38 VirtioFsFuseCheckResponse().\r
39**/\r
40EFI_STATUS\r
41VirtioFsFuseReleaseFileOrDir (\r
ac0a286f
MK
42 IN OUT VIRTIO_FS *VirtioFs,\r
43 IN UINT64 NodeId,\r
44 IN UINT64 FuseHandle,\r
45 IN BOOLEAN IsDir\r
72d4f133
LE
46 )\r
47{\r
ac0a286f
MK
48 VIRTIO_FS_FUSE_REQUEST CommonReq;\r
49 VIRTIO_FS_FUSE_RELEASE_REQUEST ReleaseReq;\r
50 VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r
51 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
52 VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
53 VIRTIO_FS_IO_VECTOR RespIoVec[1];\r
54 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
55 EFI_STATUS Status;\r
72d4f133
LE
56\r
57 //\r
58 // Set up the scatter-gather lists.\r
59 //\r
60 ReqIoVec[0].Buffer = &CommonReq;\r
61 ReqIoVec[0].Size = sizeof CommonReq;\r
62 ReqIoVec[1].Buffer = &ReleaseReq;\r
63 ReqIoVec[1].Size = sizeof ReleaseReq;\r
64 ReqSgList.IoVec = ReqIoVec;\r
65 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r
66\r
67 RespIoVec[0].Buffer = &CommonResp;\r
68 RespIoVec[0].Size = sizeof CommonResp;\r
69 RespSgList.IoVec = RespIoVec;\r
70 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r
71\r
72 //\r
73 // Validate the scatter-gather lists; calculate the total transfer sizes.\r
74 //\r
75 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
76 if (EFI_ERROR (Status)) {\r
77 return Status;\r
78 }\r
79\r
80 //\r
81 // Populate the common request header.\r
82 //\r
83 Status = VirtioFsFuseNewRequest (\r
84 VirtioFs,\r
85 &CommonReq,\r
86 ReqSgList.TotalSize,\r
87 IsDir ? VirtioFsFuseOpReleaseDir : VirtioFsFuseOpRelease,\r
88 NodeId\r
89 );\r
90 if (EFI_ERROR (Status)) {\r
91 return Status;\r
92 }\r
93\r
94 //\r
95 // Populate the FUSE_RELEASE- / FUSE_RELEASEDIR-specific fields.\r
96 //\r
97 ReleaseReq.FileHandle = FuseHandle;\r
98 ReleaseReq.Flags = 0;\r
99 ReleaseReq.ReleaseFlags = 0;\r
100 ReleaseReq.LockOwner = 0;\r
101\r
102 //\r
103 // Submit the request.\r
104 //\r
105 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
106 if (EFI_ERROR (Status)) {\r
107 return Status;\r
108 }\r
109\r
110 //\r
111 // Verify the response (all response buffers are fixed size).\r
112 //\r
113 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
114 if (Status == EFI_DEVICE_ERROR) {\r
ac0a286f
MK
115 DEBUG ((\r
116 DEBUG_ERROR,\r
117 "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "\r
118 "IsDir=%d Errno=%d\n",\r
119 __FUNCTION__,\r
120 VirtioFs->Label,\r
121 NodeId,\r
122 FuseHandle,\r
123 IsDir,\r
124 CommonResp.Error\r
125 ));\r
72d4f133
LE
126 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
127 }\r
ac0a286f 128\r
72d4f133
LE
129 return Status;\r
130}\r