]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseSetAttr.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseSetAttr.c
CommitLineData
647340b0
LE
1/** @file\r
2 FUSE_SETATTR wrapper for the Virtio Filesystem device.\r
3\r
4 Copyright (C) 2020, Red Hat, Inc.\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
9#include "VirtioFsDxe.h"\r
10\r
11/**\r
12 Send the FUSE_SETATTR request to the Virtio Filesystem device, for changing\r
13 the attributes of an inode.\r
14\r
15 The function may only be called after VirtioFsFuseInitSession() returns\r
16 successfully and before VirtioFsUninit() is called.\r
17\r
18 @param[in,out] VirtioFs The Virtio Filesystem device to send the\r
19 FUSE_SETATTR request to. On output, the FUSE request\r
20 counter "VirtioFs->RequestId" will have been\r
21 incremented.\r
22\r
23 @param[in] NodeId The inode number representing the regular file or\r
24 directory whose attributes should be changed.\r
25\r
26 @param[in] Size The new size to set for the regular file. If NULL,\r
27 then the file size will not be changed. If NodeId\r
28 refers to a directory, then the caller is\r
29 responsible for passing NULL as Size.\r
30\r
31 @param[in] Atime The new last access time to set for the regular file\r
32 or directory (seconds since the Epoch). If NULL,\r
33 then the last access time is not changed.\r
34\r
35 @param[in] Mtime The new last modification time to set for the\r
36 regular file or directory (seconds since the Epoch).\r
37 If NULL, then the last modification time is not\r
38 changed.\r
39\r
40 @param[in] Mode The new file mode bits to set for the regular file\r
41 or directory. If NULL, then the file mode bits are\r
42 not changed.\r
43\r
44 @retval EFI_SUCCESS The attributes have been updated.\r
45\r
46 @return The "errno" value mapped to an EFI_STATUS code, if the\r
47 Virtio Filesystem device explicitly reported an error.\r
48\r
49 @return Error codes propagated from VirtioFsSgListsValidate(),\r
50 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r
51 VirtioFsFuseCheckResponse().\r
52**/\r
53EFI_STATUS\r
54VirtioFsFuseSetAttr (\r
ac0a286f
MK
55 IN OUT VIRTIO_FS *VirtioFs,\r
56 IN UINT64 NodeId,\r
57 IN UINT64 *Size OPTIONAL,\r
58 IN UINT64 *Atime OPTIONAL,\r
59 IN UINT64 *Mtime OPTIONAL,\r
60 IN UINT32 *Mode OPTIONAL\r
647340b0
LE
61 )\r
62{\r
ac0a286f
MK
63 VIRTIO_FS_FUSE_REQUEST CommonReq;\r
64 VIRTIO_FS_FUSE_SETATTR_REQUEST AttrReq;\r
65 VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r
66 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r
67 VIRTIO_FS_FUSE_RESPONSE CommonResp;\r
68 VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp;\r
69 VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp;\r
70 VIRTIO_FS_IO_VECTOR RespIoVec[3];\r
71 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r
72 EFI_STATUS Status;\r
647340b0
LE
73\r
74 //\r
75 // Set up the scatter-gather lists.\r
76 //\r
77 ReqIoVec[0].Buffer = &CommonReq;\r
78 ReqIoVec[0].Size = sizeof CommonReq;\r
79 ReqIoVec[1].Buffer = &AttrReq;\r
80 ReqIoVec[1].Size = sizeof AttrReq;\r
81 ReqSgList.IoVec = ReqIoVec;\r
82 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r
83\r
84 RespIoVec[0].Buffer = &CommonResp;\r
85 RespIoVec[0].Size = sizeof CommonResp;\r
86 RespIoVec[1].Buffer = &GetAttrResp;\r
87 RespIoVec[1].Size = sizeof GetAttrResp;\r
88 RespIoVec[2].Buffer = &AttrResp;\r
89 RespIoVec[2].Size = sizeof AttrResp;\r
90 RespSgList.IoVec = RespIoVec;\r
91 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r
92\r
93 //\r
94 // Validate the scatter-gather lists; calculate the total transfer sizes.\r
95 //\r
96 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r
97 if (EFI_ERROR (Status)) {\r
98 return Status;\r
99 }\r
100\r
101 //\r
102 // Populate the common request header.\r
103 //\r
ac0a286f
MK
104 Status = VirtioFsFuseNewRequest (\r
105 VirtioFs,\r
106 &CommonReq,\r
107 ReqSgList.TotalSize,\r
108 VirtioFsFuseOpSetAttr,\r
109 NodeId\r
110 );\r
647340b0
LE
111 if (EFI_ERROR (Status)) {\r
112 return Status;\r
113 }\r
114\r
115 //\r
116 // Populate the FUSE_SETATTR-specific fields.\r
117 //\r
118 AttrReq.Valid = 0;\r
119 AttrReq.Padding = 0;\r
120 AttrReq.FileHandle = 0;\r
121 AttrReq.Size = (Size == NULL) ? 0 : *Size;\r
122 AttrReq.LockOwner = 0;\r
123 AttrReq.Atime = (Atime == NULL) ? 0 : *Atime;\r
124 AttrReq.Mtime = (Mtime == NULL) ? 0 : *Mtime;\r
125 AttrReq.Ctime = 0;\r
126 AttrReq.AtimeNsec = 0;\r
127 AttrReq.MtimeNsec = 0;\r
128 AttrReq.CtimeNsec = 0;\r
129 AttrReq.Mode = (Mode == NULL) ? 0 : *Mode;\r
130 AttrReq.Unused4 = 0;\r
131 AttrReq.Uid = 0;\r
132 AttrReq.Gid = 0;\r
133 AttrReq.Unused5 = 0;\r
134\r
135 if (Size != NULL) {\r
136 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE;\r
137 }\r
ac0a286f 138\r
647340b0
LE
139 if (Atime != NULL) {\r
140 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME;\r
141 }\r
ac0a286f 142\r
647340b0
LE
143 if (Mtime != NULL) {\r
144 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME;\r
145 }\r
ac0a286f 146\r
647340b0
LE
147 if (Mode != NULL) {\r
148 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE;\r
149 }\r
150\r
151 //\r
152 // Submit the request.\r
153 //\r
154 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
155 if (EFI_ERROR (Status)) {\r
156 return Status;\r
157 }\r
158\r
159 //\r
160 // Verify the response (all response buffers are fixed size).\r
161 //\r
162 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
163 if (Status == EFI_DEVICE_ERROR) {\r
ac0a286f
MK
164 DEBUG ((\r
165 DEBUG_ERROR,\r
166 "%a: Label=\"%s\" NodeId=%Lu",\r
167 __FUNCTION__,\r
168 VirtioFs->Label,\r
169 NodeId\r
170 ));\r
647340b0
LE
171 if (Size != NULL) {\r
172 DEBUG ((DEBUG_ERROR, " Size=0x%Lx", *Size));\r
173 }\r
ac0a286f 174\r
647340b0
LE
175 if (Atime != NULL) {\r
176 DEBUG ((DEBUG_ERROR, " Atime=%Lu", *Atime));\r
177 }\r
ac0a286f 178\r
647340b0
LE
179 if (Mtime != NULL) {\r
180 DEBUG ((DEBUG_ERROR, " Mtime=%Lu", *Mtime));\r
181 }\r
ac0a286f 182\r
647340b0
LE
183 if (Mode != NULL) {\r
184 DEBUG ((DEBUG_ERROR, " Mode=0x%x", *Mode)); // no support for octal :/\r
185 }\r
ac0a286f
MK
186\r
187 DEBUG ((DEBUG_ERROR, " Errno=%d\n", CommonResp.Error));\r
647340b0
LE
188 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
189 }\r
ac0a286f 190\r
647340b0
LE
191 return Status;\r
192}\r