2 FUSE_OPEN 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 Send a FUSE_OPEN request to the Virtio Filesystem device, for opening a
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 FUSE_OPEN
19 request to. On output, the FUSE request counter
20 "VirtioFs->RequestId" will have been incremented.
22 @param[in] NodeId The inode number of the regular file to open.
24 @param[in] ReadWrite If TRUE, open the regular file in read-write mode.
25 If FALSE, open the regular file in read-only mode.
27 @param[out] FuseHandle The open handle to the regular file, returned by the
28 Virtio Filesystem device.
30 @retval EFI_SUCCESS The regular file has been opened.
32 @return The "errno" value mapped to an EFI_STATUS code, if the
33 Virtio Filesystem device explicitly reported an error.
35 @return Error codes propagated from VirtioFsSgListsValidate(),
36 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
37 VirtioFsFuseCheckResponse().
41 IN OUT VIRTIO_FS
*VirtioFs
,
44 OUT UINT64
*FuseHandle
47 VIRTIO_FS_FUSE_REQUEST CommonReq
;
48 VIRTIO_FS_FUSE_OPEN_REQUEST OpenReq
;
49 VIRTIO_FS_IO_VECTOR ReqIoVec
[2];
50 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList
;
51 VIRTIO_FS_FUSE_RESPONSE CommonResp
;
52 VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp
;
53 VIRTIO_FS_IO_VECTOR RespIoVec
[2];
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
= &OpenReq
;
63 ReqIoVec
[1].Size
= sizeof OpenReq
;
64 ReqSgList
.IoVec
= ReqIoVec
;
65 ReqSgList
.NumVec
= ARRAY_SIZE (ReqIoVec
);
67 RespIoVec
[0].Buffer
= &CommonResp
;
68 RespIoVec
[0].Size
= sizeof CommonResp
;
69 RespIoVec
[1].Buffer
= &OpenResp
;
70 RespIoVec
[1].Size
= sizeof OpenResp
;
71 RespSgList
.IoVec
= RespIoVec
;
72 RespSgList
.NumVec
= ARRAY_SIZE (RespIoVec
);
75 // Validate the scatter-gather lists; calculate the total transfer sizes.
77 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
78 if (EFI_ERROR (Status
)) {
83 // Populate the common request header.
85 Status
= VirtioFsFuseNewRequest (
92 if (EFI_ERROR (Status
)) {
97 // Populate the FUSE_OPEN-specific fields.
99 OpenReq
.Flags
= (ReadWrite
?
100 VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR
:
101 VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY
);
105 // Submit the request.
107 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
108 if (EFI_ERROR (Status
)) {
113 // Verify the response (all response buffers are fixed size).
115 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
116 if (EFI_ERROR (Status
)) {
117 if (Status
== EFI_DEVICE_ERROR
) {
120 "%a: Label=\"%s\" NodeId=%Lu ReadWrite=%d "
128 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);
135 // Output the open handle.
137 *FuseHandle
= OpenResp
.FileHandle
;