]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioFsDxe/FuseSetAttr.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseSetAttr.c
1 /** @file
2 FUSE_SETATTR wrapper for the Virtio Filesystem device.
3
4 Copyright (C) 2020, Red Hat, Inc.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 **/
8
9 #include "VirtioFsDxe.h"
10
11 /**
12 Send the FUSE_SETATTR request to the Virtio Filesystem device, for changing
13 the attributes of an inode.
14
15 The function may only be called after VirtioFsFuseInitSession() returns
16 successfully and before VirtioFsUninit() is called.
17
18 @param[in,out] VirtioFs The Virtio Filesystem device to send the
19 FUSE_SETATTR request to. On output, the FUSE request
20 counter "VirtioFs->RequestId" will have been
21 incremented.
22
23 @param[in] NodeId The inode number representing the regular file or
24 directory whose attributes should be changed.
25
26 @param[in] Size The new size to set for the regular file. If NULL,
27 then the file size will not be changed. If NodeId
28 refers to a directory, then the caller is
29 responsible for passing NULL as Size.
30
31 @param[in] Atime The new last access time to set for the regular file
32 or directory (seconds since the Epoch). If NULL,
33 then the last access time is not changed.
34
35 @param[in] Mtime The new last modification time to set for the
36 regular file or directory (seconds since the Epoch).
37 If NULL, then the last modification time is not
38 changed.
39
40 @param[in] Mode The new file mode bits to set for the regular file
41 or directory. If NULL, then the file mode bits are
42 not changed.
43
44 @retval EFI_SUCCESS The attributes have been updated.
45
46 @return The "errno" value mapped to an EFI_STATUS code, if the
47 Virtio Filesystem device explicitly reported an error.
48
49 @return Error codes propagated from VirtioFsSgListsValidate(),
50 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
51 VirtioFsFuseCheckResponse().
52 **/
53 EFI_STATUS
54 VirtioFsFuseSetAttr (
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;
64 VIRTIO_FS_FUSE_SETATTR_REQUEST AttrReq;
65 VIRTIO_FS_IO_VECTOR ReqIoVec[2];
66 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
67 VIRTIO_FS_FUSE_RESPONSE CommonResp;
68 VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp;
69 VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp;
70 VIRTIO_FS_IO_VECTOR RespIoVec[3];
71 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
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 __FUNCTION__,
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 }