TianoCore EDK2 master
Loading...
Searching...
No Matches
FuseSetAttr.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 *Size OPTIONAL,
58 IN UINT64 *Atime OPTIONAL,
59 IN UINT64 *Mtime OPTIONAL,
60 IN UINT32 *Mode OPTIONAL
61 )
62{
63 VIRTIO_FS_FUSE_REQUEST CommonReq;
65 VIRTIO_FS_IO_VECTOR ReqIoVec[2];
67 VIRTIO_FS_FUSE_RESPONSE CommonResp;
70 VIRTIO_FS_IO_VECTOR RespIoVec[3];
72 EFI_STATUS Status;
73
74 //
75 // Set up the scatter-gather lists.
76 //
77 ReqIoVec[0].Buffer = &CommonReq;
78 ReqIoVec[0].Size = sizeof CommonReq;
79 ReqIoVec[1].Buffer = &AttrReq;
80 ReqIoVec[1].Size = sizeof AttrReq;
81 ReqSgList.IoVec = ReqIoVec;
82 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
83
84 RespIoVec[0].Buffer = &CommonResp;
85 RespIoVec[0].Size = sizeof CommonResp;
86 RespIoVec[1].Buffer = &GetAttrResp;
87 RespIoVec[1].Size = sizeof GetAttrResp;
88 RespIoVec[2].Buffer = &AttrResp;
89 RespIoVec[2].Size = sizeof AttrResp;
90 RespSgList.IoVec = RespIoVec;
91 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
92
93 //
94 // Validate the scatter-gather lists; calculate the total transfer sizes.
95 //
96 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
97 if (EFI_ERROR (Status)) {
98 return Status;
99 }
100
101 //
102 // Populate the common request header.
103 //
104 Status = VirtioFsFuseNewRequest (
105 VirtioFs,
106 &CommonReq,
107 ReqSgList.TotalSize,
108 VirtioFsFuseOpSetAttr,
109 NodeId
110 );
111 if (EFI_ERROR (Status)) {
112 return Status;
113 }
114
115 //
116 // Populate the FUSE_SETATTR-specific fields.
117 //
118 AttrReq.Valid = 0;
119 AttrReq.Padding = 0;
120 AttrReq.FileHandle = 0;
121 AttrReq.Size = (Size == NULL) ? 0 : *Size;
122 AttrReq.LockOwner = 0;
123 AttrReq.Atime = (Atime == NULL) ? 0 : *Atime;
124 AttrReq.Mtime = (Mtime == NULL) ? 0 : *Mtime;
125 AttrReq.Ctime = 0;
126 AttrReq.AtimeNsec = 0;
127 AttrReq.MtimeNsec = 0;
128 AttrReq.CtimeNsec = 0;
129 AttrReq.Mode = (Mode == NULL) ? 0 : *Mode;
130 AttrReq.Unused4 = 0;
131 AttrReq.Uid = 0;
132 AttrReq.Gid = 0;
133 AttrReq.Unused5 = 0;
134
135 if (Size != NULL) {
136 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE;
137 }
138
139 if (Atime != NULL) {
140 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME;
141 }
142
143 if (Mtime != NULL) {
144 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME;
145 }
146
147 if (Mode != NULL) {
148 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE;
149 }
150
151 //
152 // Submit the request.
153 //
154 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
155 if (EFI_ERROR (Status)) {
156 return Status;
157 }
158
159 //
160 // Verify the response (all response buffers are fixed size).
161 //
162 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
163 if (Status == EFI_DEVICE_ERROR) {
164 DEBUG ((
165 DEBUG_ERROR,
166 "%a: Label=\"%s\" NodeId=%Lu",
167 __func__,
168 VirtioFs->Label,
169 NodeId
170 ));
171 if (Size != NULL) {
172 DEBUG ((DEBUG_ERROR, " Size=0x%Lx", *Size));
173 }
174
175 if (Atime != NULL) {
176 DEBUG ((DEBUG_ERROR, " Atime=%Lu", *Atime));
177 }
178
179 if (Mtime != NULL) {
180 DEBUG ((DEBUG_ERROR, " Mtime=%Lu", *Mtime));
181 }
182
183 if (Mode != NULL) {
184 DEBUG ((DEBUG_ERROR, " Mode=0x%x", *Mode)); // no support for octal :/
185 }
186
187 DEBUG ((DEBUG_ERROR, " Errno=%d\n", CommonResp.Error));
188 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
189 }
190
191 return Status;
192}
EFI_STATUS VirtioFsFuseSetAttr(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 *Size OPTIONAL, IN UINT64 *Atime OPTIONAL, IN UINT64 *Mtime OPTIONAL, IN UINT32 *Mode OPTIONAL)
Definition: FuseSetAttr.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
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