TianoCore EDK2 master
Loading...
Searching...
No Matches
FuseInit.c
Go to the documentation of this file.
1
9#include "VirtioFsDxe.h"
10
46 IN OUT VIRTIO_FS *VirtioFs
47 )
48{
49 VIRTIO_FS_FUSE_REQUEST CommonReq;
51 VIRTIO_FS_IO_VECTOR ReqIoVec[2];
53 VIRTIO_FS_FUSE_RESPONSE CommonResp;
55 VIRTIO_FS_IO_VECTOR RespIoVec[2];
57 EFI_STATUS Status;
58
59 //
60 // Initialize the FUSE request counter.
61 //
62 VirtioFs->RequestId = 1;
63
64 //
65 // Set up the scatter-gather lists.
66 //
67 ReqIoVec[0].Buffer = &CommonReq;
68 ReqIoVec[0].Size = sizeof CommonReq;
69 ReqIoVec[1].Buffer = &InitReq;
70 ReqIoVec[1].Size = sizeof InitReq;
71 ReqSgList.IoVec = ReqIoVec;
72 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
73
74 RespIoVec[0].Buffer = &CommonResp;
75 RespIoVec[0].Size = sizeof CommonResp;
76 RespIoVec[1].Buffer = &InitResp;
77 RespIoVec[1].Size = sizeof InitResp;
78 RespSgList.IoVec = RespIoVec;
79 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
80
81 //
82 // Validate the scatter-gather lists; calculate the total transfer sizes.
83 //
84 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
85 if (EFI_ERROR (Status)) {
86 return Status;
87 }
88
89 //
90 // Populate the common request header.
91 //
92 Status = VirtioFsFuseNewRequest (
93 VirtioFs,
94 &CommonReq,
95 ReqSgList.TotalSize,
96 VirtioFsFuseOpInit,
97 0
98 );
99 if (EFI_ERROR (Status)) {
100 return Status;
101 }
102
103 //
104 // Populate the FUSE_INIT-specific fields.
105 //
106 InitReq.Major = VIRTIO_FS_FUSE_MAJOR;
107 InitReq.Minor = VIRTIO_FS_FUSE_MINOR;
108 InitReq.MaxReadahead = 0;
109 InitReq.Flags = VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS;
110
111 //
112 // Submit the request.
113 //
114 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
115 if (EFI_ERROR (Status)) {
116 return Status;
117 }
118
119 //
120 // Verify the response (all response buffers are fixed size).
121 //
122 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
123 if (EFI_ERROR (Status)) {
124 if (Status == EFI_DEVICE_ERROR) {
125 DEBUG ((
126 DEBUG_ERROR,
127 "%a: Label=\"%s\" Errno=%d\n",
128 __func__,
129 VirtioFs->Label,
130 CommonResp.Error
131 ));
132 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
133 }
134
135 return Status;
136 }
137
138 //
139 // Check FUSE interface version / feature compatibility.
140 //
141 if ((InitResp.Major < InitReq.Major) ||
142 ((InitResp.Major == InitReq.Major) && (InitResp.Minor < InitReq.Minor)) ||
143 ((InitResp.Flags & VIRTIO_FS_FUSE_INIT_REQ_F_DO_READDIRPLUS) == 0) ||
144 (InitResp.MaxWrite < SIZE_4KB))
145 {
146 return EFI_UNSUPPORTED;
147 }
148
149 //
150 // Save the maximum write buffer size for FUSE_WRITE requests.
151 //
152 VirtioFs->MaxWrite = InitResp.MaxWrite;
153 return EFI_SUCCESS;
154}
EFI_STATUS VirtioFsFuseInitSession(IN OUT VIRTIO_FS *VirtioFs)
Definition: FuseInit.c:45
#define NULL
Definition: Base.h:319
#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