TianoCore EDK2 master
Loading...
Searching...
No Matches
FuseOpenOrCreate.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h> // AsciiStrSize()
10
11#include "VirtioFsDxe.h"
12
49 IN OUT VIRTIO_FS *VirtioFs,
50 IN UINT64 ParentNodeId,
51 IN CHAR8 *Name,
52 OUT UINT64 *NodeId,
53 OUT UINT64 *FuseHandle
54 )
55{
56 VIRTIO_FS_FUSE_REQUEST CommonReq;
58 VIRTIO_FS_IO_VECTOR ReqIoVec[3];
60 VIRTIO_FS_FUSE_RESPONSE CommonResp;
64 VIRTIO_FS_IO_VECTOR RespIoVec[4];
66 EFI_STATUS Status;
67
68 //
69 // Set up the scatter-gather lists.
70 //
71 ReqIoVec[0].Buffer = &CommonReq;
72 ReqIoVec[0].Size = sizeof CommonReq;
73 ReqIoVec[1].Buffer = &CreateReq;
74 ReqIoVec[1].Size = sizeof CreateReq;
75 ReqIoVec[2].Buffer = Name;
76 ReqIoVec[2].Size = AsciiStrSize (Name);
77 ReqSgList.IoVec = ReqIoVec;
78 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
79
80 RespIoVec[0].Buffer = &CommonResp;
81 RespIoVec[0].Size = sizeof CommonResp;
82 RespIoVec[1].Buffer = &NodeResp;
83 RespIoVec[1].Size = sizeof NodeResp;
84 RespIoVec[2].Buffer = &AttrResp;
85 RespIoVec[2].Size = sizeof AttrResp;
86 RespIoVec[3].Buffer = &OpenResp;
87 RespIoVec[3].Size = sizeof OpenResp;
88 RespSgList.IoVec = RespIoVec;
89 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
90
91 //
92 // Validate the scatter-gather lists; calculate the total transfer sizes.
93 //
94 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
95 if (EFI_ERROR (Status)) {
96 return Status;
97 }
98
99 //
100 // Populate the common request header.
101 //
102 Status = VirtioFsFuseNewRequest (
103 VirtioFs,
104 &CommonReq,
105 ReqSgList.TotalSize,
106 VirtioFsFuseOpCreate,
107 ParentNodeId
108 );
109 if (EFI_ERROR (Status)) {
110 return Status;
111 }
112
113 //
114 // Populate the FUSE_CREATE-specific fields.
115 //
116 // VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is why this request can never open a
117 // directory (EISDIR). And VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is consistent with
118 // the only OpenMode of EFI_FILE_PROTOCOL.Open() that enables filesystem
119 // object creation -- that is, Create/Read/Write.
120 //
121 CreateReq.Flags = VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR;
122 CreateReq.Mode = (VIRTIO_FS_FUSE_MODE_PERM_RUSR |
123 VIRTIO_FS_FUSE_MODE_PERM_WUSR |
124 VIRTIO_FS_FUSE_MODE_PERM_RGRP |
125 VIRTIO_FS_FUSE_MODE_PERM_WGRP |
126 VIRTIO_FS_FUSE_MODE_PERM_ROTH |
127 VIRTIO_FS_FUSE_MODE_PERM_WOTH);
128 CreateReq.Umask = 0;
129 CreateReq.Padding = 0;
130
131 //
132 // Submit the request.
133 //
134 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
135 if (EFI_ERROR (Status)) {
136 return Status;
137 }
138
139 //
140 // Verify the response (all response buffers are fixed size).
141 //
142 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
143 if (EFI_ERROR (Status)) {
144 if (Status == EFI_DEVICE_ERROR) {
145 DEBUG ((
146 DEBUG_ERROR,
147 "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "
148 "Errno=%d\n",
149 __func__,
150 VirtioFs->Label,
151 ParentNodeId,
152 Name,
153 CommonResp.Error
154 ));
155 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
156 }
157
158 return Status;
159 }
160
161 //
162 // Output the NodeId of the (possibly new) regular file. Also output the open
163 // file handle.
164 //
165 *NodeId = NodeResp.NodeId;
166 *FuseHandle = OpenResp.FileHandle;
167 return EFI_SUCCESS;
168}
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
EFI_STATUS VirtioFsFuseOpenOrCreate(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId, OUT UINT64 *FuseHandle)
#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