2 FUSE_LOOKUP 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 Send a FUSE_LOOKUP request to the Virtio Filesystem device, for resolving a
17 The function returns EFI_NOT_FOUND exclusively if the Virtio Filesystem
18 device explicitly responds with ENOENT -- "No such file or directory".
20 The function may only be called after VirtioFsFuseInitSession() returns
21 successfully and before VirtioFsUninit() is called.
23 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_LOOKUP
24 request to. On output, the FUSE request counter
25 "VirtioFs->RequestId" will have been incremented.
27 @param[in] DirNodeId The inode number of the directory in which Name
28 should be resolved to an inode.
30 @param[in] Name The single-component filename to resolve in the
31 directory identified by DirNodeId.
33 @param[out] NodeId The inode number which Name has been resolved to.
35 @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object
36 describing the properties of the resolved inode.
38 @retval EFI_SUCCESS Filename to inode resolution successful.
40 @retval EFI_NOT_FOUND The Virtio Filesystem device explicitly reported
41 ENOENT -- "No such file or directory".
43 @return The "errno" value mapped to an EFI_STATUS code, if the
44 Virtio Filesystem device explicitly reported an error
45 different from ENOENT. If said mapping resulted in
46 EFI_NOT_FOUND, it is remapped to EFI_DEVICE_ERROR.
48 @return Error codes propagated from VirtioFsSgListsValidate(),
49 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
50 VirtioFsFuseCheckResponse(). EFI_NOT_FOUND is remapped
55 IN OUT VIRTIO_FS
*VirtioFs
,
59 OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE
*FuseAttr
62 VIRTIO_FS_FUSE_REQUEST CommonReq
;
63 VIRTIO_FS_IO_VECTOR ReqIoVec
[2];
64 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList
;
65 VIRTIO_FS_FUSE_RESPONSE CommonResp
;
66 VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp
;
67 VIRTIO_FS_IO_VECTOR RespIoVec
[3];
68 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList
;
72 // Set up the scatter-gather lists.
74 ReqIoVec
[0].Buffer
= &CommonReq
;
75 ReqIoVec
[0].Size
= sizeof CommonReq
;
76 ReqIoVec
[1].Buffer
= Name
;
77 ReqIoVec
[1].Size
= AsciiStrSize (Name
);
78 ReqSgList
.IoVec
= ReqIoVec
;
79 ReqSgList
.NumVec
= ARRAY_SIZE (ReqIoVec
);
81 RespIoVec
[0].Buffer
= &CommonResp
;
82 RespIoVec
[0].Size
= sizeof CommonResp
;
83 RespIoVec
[1].Buffer
= &NodeResp
;
84 RespIoVec
[1].Size
= sizeof NodeResp
;
85 RespIoVec
[2].Buffer
= FuseAttr
;
86 RespIoVec
[2].Size
= sizeof *FuseAttr
;
87 RespSgList
.IoVec
= RespIoVec
;
88 RespSgList
.NumVec
= ARRAY_SIZE (RespIoVec
);
91 // Validate the scatter-gather lists; calculate the total transfer sizes.
93 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
94 if (EFI_ERROR (Status
)) {
99 // Populate the common request header.
101 Status
= VirtioFsFuseNewRequest (
105 VirtioFsFuseOpLookup
,
108 if (EFI_ERROR (Status
)) {
113 // Submit the request.
115 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
116 if (EFI_ERROR (Status
)) {
121 // Verify the response (all response buffers are fixed size).
123 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
124 if (EFI_ERROR (Status
)) {
125 if (Status
== EFI_DEVICE_ERROR
) {
127 ((CommonResp
.Error
== VIRTIO_FS_FUSE_ERRNO_ENOENT
) ?
130 "%a: Label=\"%s\" DirNodeId=%Lu Name=\"%a\" Errno=%d\n",
137 if (CommonResp
.Error
== VIRTIO_FS_FUSE_ERRNO_ENOENT
) {
138 return EFI_NOT_FOUND
;
141 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);
148 // Output the NodeId to which Name has been resolved to.
150 *NodeId
= NodeResp
.NodeId
;
154 return (Status
== EFI_NOT_FOUND
) ? EFI_DEVICE_ERROR
: Status
;