2 FUSE_UNLINK / FUSE_RMDIR wrapper for the Virtio Filesystem device.
4 Copyright (C) 2020, Red Hat, Inc.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h> // AsciiStrSize()
11 #include "VirtioFsDxe.h"
14 Remove a regular file or a directory, by sending the FUSE_UNLINK or
15 FUSE_RMDIR request to the Virtio Filesystem device.
17 The function may only be called after VirtioFsFuseInitSession() returns
18 successfully and before VirtioFsUninit() is called.
20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_UNLINK
21 / FUSE_RMDIR request to. On output, the FUSE request
22 counter "VirtioFs->RequestId" will have been
25 @param[in] ParentNodeId The inode number of the directory in which Name
28 @param[in] Name The single-component filename to remove in the
29 directory identified by ParentNodeId.
31 @param[in] IsDir TRUE if Name refers to a directory, FALSE otherwise.
33 @retval EFI_SUCCESS The file or directory has been removed.
35 @return The "errno" value mapped to an EFI_STATUS code, if the
36 Virtio Filesystem device explicitly reported an error.
38 @return Error codes propagated from VirtioFsSgListsValidate(),
39 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
40 VirtioFsFuseCheckResponse().
43 VirtioFsFuseRemoveFileOrDir (
44 IN OUT VIRTIO_FS
*VirtioFs
,
45 IN UINT64 ParentNodeId
,
50 VIRTIO_FS_FUSE_REQUEST CommonReq
;
51 VIRTIO_FS_IO_VECTOR ReqIoVec
[2];
52 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList
;
53 VIRTIO_FS_FUSE_RESPONSE CommonResp
;
54 VIRTIO_FS_IO_VECTOR RespIoVec
[1];
55 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList
;
59 // Set up the scatter-gather lists.
61 ReqIoVec
[0].Buffer
= &CommonReq
;
62 ReqIoVec
[0].Size
= sizeof CommonReq
;
63 ReqIoVec
[1].Buffer
= Name
;
64 ReqIoVec
[1].Size
= AsciiStrSize (Name
);
65 ReqSgList
.IoVec
= ReqIoVec
;
66 ReqSgList
.NumVec
= ARRAY_SIZE (ReqIoVec
);
68 RespIoVec
[0].Buffer
= &CommonResp
;
69 RespIoVec
[0].Size
= sizeof CommonResp
;
70 RespSgList
.IoVec
= RespIoVec
;
71 RespSgList
.NumVec
= ARRAY_SIZE (RespIoVec
);
74 // Validate the scatter-gather lists; calculate the total transfer sizes.
76 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
77 if (EFI_ERROR (Status
)) {
82 // Populate the common request header.
84 Status
= VirtioFsFuseNewRequest (
88 IsDir
? VirtioFsFuseOpRmDir
: VirtioFsFuseOpUnlink
,
91 if (EFI_ERROR (Status
)) {
96 // Submit the request.
98 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
99 if (EFI_ERROR (Status
)) {
104 // Verify the response (all response buffers are fixed size).
106 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
107 if (Status
== EFI_DEVICE_ERROR
) {
110 "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "
111 "IsDir=%d Errno=%d\n",
119 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);