TianoCore EDK2 master
Loading...
Searching...
No Matches
FuseRead.c
Go to the documentation of this file.
1
9#include "VirtioFsDxe.h"
10
90 IN OUT VIRTIO_FS *VirtioFs,
91 IN UINT64 NodeId,
92 IN UINT64 FuseHandle,
93 IN BOOLEAN IsDir,
94 IN UINT64 Offset,
95 IN OUT UINT32 *Size,
96 OUT VOID *Data
97 )
98{
99 VIRTIO_FS_FUSE_REQUEST CommonReq;
101 VIRTIO_FS_IO_VECTOR ReqIoVec[2];
103 VIRTIO_FS_FUSE_RESPONSE CommonResp;
104 VIRTIO_FS_IO_VECTOR RespIoVec[2];
106 EFI_STATUS Status;
107 UINTN TailBufferFill;
108
109 //
110 // Set up the scatter-gather lists.
111 //
112 ReqIoVec[0].Buffer = &CommonReq;
113 ReqIoVec[0].Size = sizeof CommonReq;
114 ReqIoVec[1].Buffer = &ReadReq;
115 ReqIoVec[1].Size = sizeof ReadReq;
116 ReqSgList.IoVec = ReqIoVec;
117 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
118
119 RespIoVec[0].Buffer = &CommonResp;
120 RespIoVec[0].Size = sizeof CommonResp;
121 RespIoVec[1].Buffer = Data;
122 RespIoVec[1].Size = *Size;
123 RespSgList.IoVec = RespIoVec;
124 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
125
126 //
127 // Validate the scatter-gather lists; calculate the total transfer sizes.
128 //
129 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
130 if (EFI_ERROR (Status)) {
131 return Status;
132 }
133
134 //
135 // Populate the common request header.
136 //
137 Status = VirtioFsFuseNewRequest (
138 VirtioFs,
139 &CommonReq,
140 ReqSgList.TotalSize,
141 IsDir ? VirtioFsFuseOpReadDirPlus : VirtioFsFuseOpRead,
142 NodeId
143 );
144 if (EFI_ERROR (Status)) {
145 return Status;
146 }
147
148 //
149 // Populate the FUSE_READ- / FUSE_READDIRPLUS-specific fields.
150 //
151 ReadReq.FileHandle = FuseHandle;
152 ReadReq.Offset = Offset;
153 ReadReq.Size = *Size;
154 ReadReq.ReadFlags = 0;
155 ReadReq.LockOwner = 0;
156 ReadReq.Flags = 0;
157 ReadReq.Padding = 0;
158
159 //
160 // Submit the request.
161 //
162 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
163 if (EFI_ERROR (Status)) {
164 return Status;
165 }
166
167 //
168 // Verify the response. Note that TailBufferFill is variable.
169 //
171 &RespSgList,
172 CommonReq.Unique,
173 &TailBufferFill
174 );
175 if (EFI_ERROR (Status)) {
176 if (Status == EFI_DEVICE_ERROR) {
177 DEBUG ((
178 DEBUG_ERROR,
179 "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "
180 "IsDir=%d Offset=0x%Lx Size=0x%x Data@%p Errno=%d\n",
181 __func__,
182 VirtioFs->Label,
183 NodeId,
184 FuseHandle,
185 IsDir,
186 Offset,
187 *Size,
188 Data,
189 CommonResp.Error
190 ));
191 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
192 }
193
194 return Status;
195 }
196
197 //
198 // Report the actual transfer size.
199 //
200 // Integer overflow in the (UINT32) cast below is not possible; the
201 // VIRTIO_FS_SCATTER_GATHER_LIST functions would have caught that.
202 //
203 *Size = (UINT32)TailBufferFill;
204 return EFI_SUCCESS;
205}
UINT64 UINTN
EFI_STATUS VirtioFsFuseReadFileOrDir(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir, IN UINT64 Offset, IN OUT UINT32 *Size, OUT VOID *Data)
Definition: FuseRead.c:89
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS VirtioFsFuseCheckResponse(IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill)
Definition: Helpers.c:873
EFI_STATUS VirtioFsFuseNewRequest(IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId)
Definition: Helpers.c:790
EFI_STATUS VirtioFsSgListsSubmit(IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL)
Definition: Helpers.c:538
EFI_STATUS VirtioFsErrnoToEfiStatus(IN INT32 Errno)
Definition: Helpers.c:991
EFI_STATUS VirtioFsSgListsValidate(IN VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL)
Definition: Helpers.c:398