]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/FuseSetAttr.c
OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_SETATTR
[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
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
61 )\r
62{\r
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
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
104 Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,\r
105 VirtioFsFuseOpSetAttr, NodeId);\r
106 if (EFI_ERROR (Status)) {\r
107 return Status;\r
108 }\r
109\r
110 //\r
111 // Populate the FUSE_SETATTR-specific fields.\r
112 //\r
113 AttrReq.Valid = 0;\r
114 AttrReq.Padding = 0;\r
115 AttrReq.FileHandle = 0;\r
116 AttrReq.Size = (Size == NULL) ? 0 : *Size;\r
117 AttrReq.LockOwner = 0;\r
118 AttrReq.Atime = (Atime == NULL) ? 0 : *Atime;\r
119 AttrReq.Mtime = (Mtime == NULL) ? 0 : *Mtime;\r
120 AttrReq.Ctime = 0;\r
121 AttrReq.AtimeNsec = 0;\r
122 AttrReq.MtimeNsec = 0;\r
123 AttrReq.CtimeNsec = 0;\r
124 AttrReq.Mode = (Mode == NULL) ? 0 : *Mode;\r
125 AttrReq.Unused4 = 0;\r
126 AttrReq.Uid = 0;\r
127 AttrReq.Gid = 0;\r
128 AttrReq.Unused5 = 0;\r
129\r
130 if (Size != NULL) {\r
131 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE;\r
132 }\r
133 if (Atime != NULL) {\r
134 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME;\r
135 }\r
136 if (Mtime != NULL) {\r
137 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME;\r
138 }\r
139 if (Mode != NULL) {\r
140 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE;\r
141 }\r
142\r
143 //\r
144 // Submit the request.\r
145 //\r
146 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r
147 if (EFI_ERROR (Status)) {\r
148 return Status;\r
149 }\r
150\r
151 //\r
152 // Verify the response (all response buffers are fixed size).\r
153 //\r
154 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r
155 if (Status == EFI_DEVICE_ERROR) {\r
156 DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu", __FUNCTION__,\r
157 VirtioFs->Label, NodeId));\r
158 if (Size != NULL) {\r
159 DEBUG ((DEBUG_ERROR, " Size=0x%Lx", *Size));\r
160 }\r
161 if (Atime != NULL) {\r
162 DEBUG ((DEBUG_ERROR, " Atime=%Lu", *Atime));\r
163 }\r
164 if (Mtime != NULL) {\r
165 DEBUG ((DEBUG_ERROR, " Mtime=%Lu", *Mtime));\r
166 }\r
167 if (Mode != NULL) {\r
168 DEBUG ((DEBUG_ERROR, " Mode=0x%x", *Mode)); // no support for octal :/\r
169 }\r
170 DEBUG ((DEBUG_ERROR, " Errno=%d\n", CommonResp.Error));\r
171 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r
172 }\r
173 return Status;\r
174}\r