]>
Commit | Line | Data |
---|---|---|
b6ce961a LE |
1 | /** @file\r |
2 | FUSE_LOOKUP 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 | Send a FUSE_LOOKUP request to the Virtio Filesystem device, for resolving a\r | |
15 | filename to an inode.\r | |
16 | \r | |
17 | The function returns EFI_NOT_FOUND exclusively if the Virtio Filesystem\r | |
18 | device explicitly responds with ENOENT -- "No such file or directory".\r | |
19 | \r | |
20 | The function may only be called after VirtioFsFuseInitSession() returns\r | |
21 | successfully and before VirtioFsUninit() is called.\r | |
22 | \r | |
23 | @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_LOOKUP\r | |
24 | request to. On output, the FUSE request counter\r | |
25 | "VirtioFs->RequestId" will have been incremented.\r | |
26 | \r | |
27 | @param[in] DirNodeId The inode number of the directory in which Name\r | |
28 | should be resolved to an inode.\r | |
29 | \r | |
30 | @param[in] Name The single-component filename to resolve in the\r | |
31 | directory identified by DirNodeId.\r | |
32 | \r | |
33 | @param[out] NodeId The inode number which Name has been resolved to.\r | |
34 | \r | |
35 | @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object\r | |
36 | describing the properties of the resolved inode.\r | |
37 | \r | |
38 | @retval EFI_SUCCESS Filename to inode resolution successful.\r | |
39 | \r | |
40 | @retval EFI_NOT_FOUND The Virtio Filesystem device explicitly reported\r | |
41 | ENOENT -- "No such file or directory".\r | |
42 | \r | |
43 | @return The "errno" value mapped to an EFI_STATUS code, if the\r | |
44 | Virtio Filesystem device explicitly reported an error\r | |
45 | different from ENOENT. If said mapping resulted in\r | |
46 | EFI_NOT_FOUND, it is remapped to EFI_DEVICE_ERROR.\r | |
47 | \r | |
48 | @return Error codes propagated from VirtioFsSgListsValidate(),\r | |
49 | VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r | |
50 | VirtioFsFuseCheckResponse(). EFI_NOT_FOUND is remapped\r | |
51 | to EFI_DEVICE_ERROR.\r | |
52 | **/\r | |
53 | EFI_STATUS\r | |
54 | VirtioFsFuseLookup (\r | |
ac0a286f MK |
55 | IN OUT VIRTIO_FS *VirtioFs,\r |
56 | IN UINT64 DirNodeId,\r | |
57 | IN CHAR8 *Name,\r | |
58 | OUT UINT64 *NodeId,\r | |
59 | OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr\r | |
b6ce961a LE |
60 | )\r |
61 | {\r | |
ac0a286f MK |
62 | VIRTIO_FS_FUSE_REQUEST CommonReq;\r |
63 | VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r | |
64 | VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r | |
65 | VIRTIO_FS_FUSE_RESPONSE CommonResp;\r | |
66 | VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp;\r | |
67 | VIRTIO_FS_IO_VECTOR RespIoVec[3];\r | |
68 | VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r | |
69 | EFI_STATUS Status;\r | |
b6ce961a LE |
70 | \r |
71 | //\r | |
72 | // Set up the scatter-gather lists.\r | |
73 | //\r | |
74 | ReqIoVec[0].Buffer = &CommonReq;\r | |
75 | ReqIoVec[0].Size = sizeof CommonReq;\r | |
76 | ReqIoVec[1].Buffer = Name;\r | |
77 | ReqIoVec[1].Size = AsciiStrSize (Name);\r | |
78 | ReqSgList.IoVec = ReqIoVec;\r | |
79 | ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r | |
80 | \r | |
81 | RespIoVec[0].Buffer = &CommonResp;\r | |
82 | RespIoVec[0].Size = sizeof CommonResp;\r | |
83 | RespIoVec[1].Buffer = &NodeResp;\r | |
84 | RespIoVec[1].Size = sizeof NodeResp;\r | |
85 | RespIoVec[2].Buffer = FuseAttr;\r | |
86 | RespIoVec[2].Size = sizeof *FuseAttr;\r | |
87 | RespSgList.IoVec = RespIoVec;\r | |
88 | RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r | |
89 | \r | |
90 | //\r | |
91 | // Validate the scatter-gather lists; calculate the total transfer sizes.\r | |
92 | //\r | |
93 | Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r | |
94 | if (EFI_ERROR (Status)) {\r | |
95 | goto Fail;\r | |
96 | }\r | |
97 | \r | |
98 | //\r | |
99 | // Populate the common request header.\r | |
100 | //\r | |
ac0a286f MK |
101 | Status = VirtioFsFuseNewRequest (\r |
102 | VirtioFs,\r | |
103 | &CommonReq,\r | |
104 | ReqSgList.TotalSize,\r | |
105 | VirtioFsFuseOpLookup,\r | |
106 | DirNodeId\r | |
107 | );\r | |
b6ce961a LE |
108 | if (EFI_ERROR (Status)) {\r |
109 | goto Fail;\r | |
110 | }\r | |
111 | \r | |
112 | //\r | |
113 | // Submit the request.\r | |
114 | //\r | |
115 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r | |
116 | if (EFI_ERROR (Status)) {\r | |
117 | goto Fail;\r | |
118 | }\r | |
119 | \r | |
120 | //\r | |
121 | // Verify the response (all response buffers are fixed size).\r | |
122 | //\r | |
123 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r | |
124 | if (EFI_ERROR (Status)) {\r | |
125 | if (Status == EFI_DEVICE_ERROR) {\r | |
126 | DEBUG ((\r | |
127 | ((CommonResp.Error == VIRTIO_FS_FUSE_ERRNO_ENOENT) ?\r | |
128 | DEBUG_VERBOSE :\r | |
129 | DEBUG_ERROR),\r | |
130 | "%a: Label=\"%s\" DirNodeId=%Lu Name=\"%a\" Errno=%d\n",\r | |
131 | __FUNCTION__,\r | |
132 | VirtioFs->Label,\r | |
133 | DirNodeId,\r | |
134 | Name,\r | |
135 | CommonResp.Error\r | |
136 | ));\r | |
137 | if (CommonResp.Error == VIRTIO_FS_FUSE_ERRNO_ENOENT) {\r | |
138 | return EFI_NOT_FOUND;\r | |
139 | }\r | |
ac0a286f | 140 | \r |
b6ce961a LE |
141 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r |
142 | }\r | |
ac0a286f | 143 | \r |
b6ce961a LE |
144 | goto Fail;\r |
145 | }\r | |
146 | \r | |
147 | //\r | |
148 | // Output the NodeId to which Name has been resolved to.\r | |
149 | //\r | |
150 | *NodeId = NodeResp.NodeId;\r | |
151 | return EFI_SUCCESS;\r | |
152 | \r | |
153 | Fail:\r | |
154 | return (Status == EFI_NOT_FOUND) ? EFI_DEVICE_ERROR : Status;\r | |
155 | }\r |