2 FUSE_RELEASE / FUSE_RELEASEDIR wrapper for the Virtio Filesystem device.
4 Copyright (C) 2020, Red Hat, Inc.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "VirtioFsDxe.h"
12 Close a regular file or a directory that is open, by sending the FUSE_RELEASE
13 or FUSE_RELEASEDIR request to the Virtio Filesystem device.
15 The function may only be called after VirtioFsFuseInitSession() returns
16 successfully and before VirtioFsUninit() is called.
18 @param[in,out] VirtioFs The Virtio Filesystem device to send the
19 FUSE_RELEASE / FUSE_RELEASEDIR request to. On
20 output, the FUSE request counter
21 "VirtioFs->RequestId" will have been incremented.
23 @param[in] NodeId The inode number of the file or directory to close.
25 @param[in] FuseHandle The open handle to the file or directory to close.
27 @param[in] IsDir TRUE if NodeId and FuseHandle refer to a directory,
28 FALSE if NodeId and FuseHandle refer to a regular
31 @retval EFI_SUCCESS The file or directory has been closed.
33 @return The "errno" value mapped to an EFI_STATUS code, if the
34 Virtio Filesystem device explicitly reported an error.
36 @return Error codes propagated from VirtioFsSgListsValidate(),
37 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
38 VirtioFsFuseCheckResponse().
41 VirtioFsFuseReleaseFileOrDir (
42 IN OUT VIRTIO_FS
*VirtioFs
,
48 VIRTIO_FS_FUSE_REQUEST CommonReq
;
49 VIRTIO_FS_FUSE_RELEASE_REQUEST ReleaseReq
;
50 VIRTIO_FS_IO_VECTOR ReqIoVec
[2];
51 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList
;
52 VIRTIO_FS_FUSE_RESPONSE CommonResp
;
53 VIRTIO_FS_IO_VECTOR RespIoVec
[1];
54 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList
;
58 // Set up the scatter-gather lists.
60 ReqIoVec
[0].Buffer
= &CommonReq
;
61 ReqIoVec
[0].Size
= sizeof CommonReq
;
62 ReqIoVec
[1].Buffer
= &ReleaseReq
;
63 ReqIoVec
[1].Size
= sizeof ReleaseReq
;
64 ReqSgList
.IoVec
= ReqIoVec
;
65 ReqSgList
.NumVec
= ARRAY_SIZE (ReqIoVec
);
67 RespIoVec
[0].Buffer
= &CommonResp
;
68 RespIoVec
[0].Size
= sizeof CommonResp
;
69 RespSgList
.IoVec
= RespIoVec
;
70 RespSgList
.NumVec
= ARRAY_SIZE (RespIoVec
);
73 // Validate the scatter-gather lists; calculate the total transfer sizes.
75 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
76 if (EFI_ERROR (Status
)) {
81 // Populate the common request header.
83 Status
= VirtioFsFuseNewRequest (
87 IsDir
? VirtioFsFuseOpReleaseDir
: VirtioFsFuseOpRelease
,
90 if (EFI_ERROR (Status
)) {
95 // Populate the FUSE_RELEASE- / FUSE_RELEASEDIR-specific fields.
97 ReleaseReq
.FileHandle
= FuseHandle
;
99 ReleaseReq
.ReleaseFlags
= 0;
100 ReleaseReq
.LockOwner
= 0;
103 // Submit the request.
105 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
106 if (EFI_ERROR (Status
)) {
111 // Verify the response (all response buffers are fixed size).
113 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
114 if (Status
== EFI_DEVICE_ERROR
) {
117 "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "
118 "IsDir=%d Errno=%d\n",
126 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);