]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseUnlink.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseUnlink.c
CommitLineData
0771671c
LE
1/** @file\r
2 FUSE_UNLINK / FUSE_RMDIR 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 <Library/BaseLib.h> // AsciiStrSize()\r
10\r
11#include "VirtioFsDxe.h"\r
12\r
13/**\r
14 Remove a regular file or a directory, by sending the FUSE_UNLINK or\r
15 FUSE_RMDIR request to the Virtio Filesystem device.\r
16\r
17 The function may only be called after VirtioFsFuseInitSession() returns\r
18 successfully and before VirtioFsUninit() is called.\r
19\r
20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_UNLINK\r
21 / FUSE_RMDIR request to. On output, the FUSE request\r
22 counter "VirtioFs->RequestId" will have been\r
23 incremented.\r
24\r
25 @param[in] ParentNodeId The inode number of the directory in which Name\r
26 should be removed.\r
27\r
28 @param[in] Name The single-component filename to remove in the\r
29 directory identified by ParentNodeId.\r
30\r
31 @param[in] IsDir TRUE if Name refers to a directory, FALSE otherwise.\r
32\r
33 @retval EFI_SUCCESS The file or directory has been removed.\r
34\r
35 @return The "errno" value mapped to an EFI_STATUS code, if the\r
36 Virtio Filesystem device explicitly reported an error.\r
37\r
38 @return Error codes propagated from VirtioFsSgListsValidate(),\r
39 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
40 VirtioFsFuseCheckResponse().\r
41**/\r
42EFI_STATUS\r
43VirtioFsFuseRemoveFileOrDir (\r
ac0a286f
MK
44 IN OUT VIRTIO_FS *VirtioFs,\r
45 IN UINT64 ParentNodeId,\r
46 IN CHAR8 *Name,\r
47 IN BOOLEAN IsDir\r
0771671c
LE
48 )\r
49{\r
ac0a286f
MK
50 VIRTIO_FS_FUSE_REQUEST CommonReq;\r
51 VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r
52 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
53 VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
54 VIRTIO_FS_IO_VECTOR RespIoVec[1];\r
55 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
56 EFI_STATUS Status;\r
0771671c
LE
57\r
58 //\r
59 // Set up the scatter-gather lists.\r
60 //\r
61 ReqIoVec[0].Buffer = &CommonReq;\r
62 ReqIoVec[0].Size = sizeof CommonReq;\r
63 ReqIoVec[1].Buffer = Name;\r
64 ReqIoVec[1].Size = AsciiStrSize (Name);\r
65 ReqSgList.IoVec = ReqIoVec;\r
66 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r
67\r
68 RespIoVec[0].Buffer = &CommonResp;\r
69 RespIoVec[0].Size = sizeof CommonResp;\r
70 RespSgList.IoVec = RespIoVec;\r
71 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r
72\r
73 //\r
74 // Validate the scatter-gather lists; calculate the total transfer sizes.\r
75 //\r
76 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
77 if (EFI_ERROR (Status)) {\r
78 return Status;\r
79 }\r
80\r
81 //\r
82 // Populate the common request header.\r
83 //\r
84 Status = VirtioFsFuseNewRequest (\r
85 VirtioFs,\r
86 &CommonReq,\r
87 ReqSgList.TotalSize,\r
88 IsDir ? VirtioFsFuseOpRmDir : VirtioFsFuseOpUnlink,\r
89 ParentNodeId\r
90 );\r
91 if (EFI_ERROR (Status)) {\r
92 return Status;\r
93 }\r
94\r
95 //\r
96 // Submit the request.\r
97 //\r
98 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
99 if (EFI_ERROR (Status)) {\r
100 return Status;\r
101 }\r
102\r
103 //\r
104 // Verify the response (all response buffers are fixed size).\r
105 //\r
106 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
107 if (Status == EFI_DEVICE_ERROR) {\r
ac0a286f
MK
108 DEBUG ((\r
109 DEBUG_ERROR,\r
110 "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "\r
111 "IsDir=%d Errno=%d\n",\r
112 __FUNCTION__,\r
113 VirtioFs->Label,\r
114 ParentNodeId,\r
115 Name,\r
116 IsDir,\r
117 CommonResp.Error\r
118 ));\r
0771671c
LE
119 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
120 }\r
ac0a286f 121\r
0771671c
LE
122 return Status;\r
123}\r