TianoCore EDK2 master
Loading...
Searching...
No Matches
FuseWrite.c
Go to the documentation of this file.
1
9#include "VirtioFsDxe.h"
10
55 IN OUT VIRTIO_FS *VirtioFs,
56 IN UINT64 NodeId,
57 IN UINT64 FuseHandle,
58 IN UINT64 Offset,
59 IN OUT UINT32 *Size,
60 IN VOID *Data
61 )
62{
63 VIRTIO_FS_FUSE_REQUEST CommonReq;
65 VIRTIO_FS_IO_VECTOR ReqIoVec[3];
67 VIRTIO_FS_FUSE_RESPONSE CommonResp;
69 VIRTIO_FS_IO_VECTOR RespIoVec[2];
71 EFI_STATUS Status;
72
73 //
74 // Honor the write buffer size limit of the Virtio Filesystem device.
75 //
76 if (*Size > VirtioFs->MaxWrite) {
77 return EFI_BAD_BUFFER_SIZE;
78 }
79
80 //
81 // Set up the scatter-gather lists.
82 //
83 ReqIoVec[0].Buffer = &CommonReq;
84 ReqIoVec[0].Size = sizeof CommonReq;
85 ReqIoVec[1].Buffer = &WriteReq;
86 ReqIoVec[1].Size = sizeof WriteReq;
87 ReqIoVec[2].Buffer = Data;
88 ReqIoVec[2].Size = *Size;
89 ReqSgList.IoVec = ReqIoVec;
90 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
91
92 RespIoVec[0].Buffer = &CommonResp;
93 RespIoVec[0].Size = sizeof CommonResp;
94 RespIoVec[1].Buffer = &WriteResp;
95 RespIoVec[1].Size = sizeof WriteResp;
96 RespSgList.IoVec = RespIoVec;
97 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
98
99 //
100 // Validate the scatter-gather lists; calculate the total transfer sizes.
101 //
102 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
103 if (EFI_ERROR (Status)) {
104 return Status;
105 }
106
107 //
108 // Populate the common request header.
109 //
110 Status = VirtioFsFuseNewRequest (
111 VirtioFs,
112 &CommonReq,
113 ReqSgList.TotalSize,
114 VirtioFsFuseOpWrite,
115 NodeId
116 );
117 if (EFI_ERROR (Status)) {
118 return Status;
119 }
120
121 //
122 // Populate the FUSE_WRITE-specific fields.
123 //
124 WriteReq.FileHandle = FuseHandle;
125 WriteReq.Offset = Offset;
126 WriteReq.Size = *Size;
127 WriteReq.WriteFlags = 0;
128 WriteReq.LockOwner = 0;
129 WriteReq.Flags = 0;
130 WriteReq.Padding = 0;
131
132 //
133 // Submit the request.
134 //
135 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
136 if (EFI_ERROR (Status)) {
137 return Status;
138 }
139
140 //
141 // Verify the response (all response buffers are fixed size).
142 //
143 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
144 if (EFI_ERROR (Status)) {
145 if (Status == EFI_DEVICE_ERROR) {
146 DEBUG ((
147 DEBUG_ERROR,
148 "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "
149 "Offset=0x%Lx Size=0x%x Data@%p Errno=%d\n",
150 __func__,
151 VirtioFs->Label,
152 NodeId,
153 FuseHandle,
154 Offset,
155 *Size,
156 Data,
157 CommonResp.Error
158 ));
159 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
160 }
161
162 return Status;
163 }
164
165 //
166 // Report the actual transfer size.
167 //
168 *Size = WriteResp.Size;
169 return EFI_SUCCESS;
170}
EFI_STATUS VirtioFsFuseWrite(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN UINT64 Offset, IN OUT UINT32 *Size, IN VOID *Data)
Definition: FuseWrite.c:54
#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