VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/VirtioFsDxe/FuseSetAttr.c@ 99396

Last change on this file since 99396 was 89983, checked in by vboxsync, 4 years ago

Devices/EFI: Merge edk-stable202105 and openssl 1.1.1j and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
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**/
53EFI_STATUS
54VirtioFsFuseSetAttr (
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 (VirtioFs, &CommonReq, ReqSgList.TotalSize,
105 VirtioFsFuseOpSetAttr, NodeId);
106 if (EFI_ERROR (Status)) {
107 return Status;
108 }
109
110 //
111 // Populate the FUSE_SETATTR-specific fields.
112 //
113 AttrReq.Valid = 0;
114 AttrReq.Padding = 0;
115 AttrReq.FileHandle = 0;
116 AttrReq.Size = (Size == NULL) ? 0 : *Size;
117 AttrReq.LockOwner = 0;
118 AttrReq.Atime = (Atime == NULL) ? 0 : *Atime;
119 AttrReq.Mtime = (Mtime == NULL) ? 0 : *Mtime;
120 AttrReq.Ctime = 0;
121 AttrReq.AtimeNsec = 0;
122 AttrReq.MtimeNsec = 0;
123 AttrReq.CtimeNsec = 0;
124 AttrReq.Mode = (Mode == NULL) ? 0 : *Mode;
125 AttrReq.Unused4 = 0;
126 AttrReq.Uid = 0;
127 AttrReq.Gid = 0;
128 AttrReq.Unused5 = 0;
129
130 if (Size != NULL) {
131 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE;
132 }
133 if (Atime != NULL) {
134 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME;
135 }
136 if (Mtime != NULL) {
137 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME;
138 }
139 if (Mode != NULL) {
140 AttrReq.Valid |= VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE;
141 }
142
143 //
144 // Submit the request.
145 //
146 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
147 if (EFI_ERROR (Status)) {
148 return Status;
149 }
150
151 //
152 // Verify the response (all response buffers are fixed size).
153 //
154 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
155 if (Status == EFI_DEVICE_ERROR) {
156 DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu", __FUNCTION__,
157 VirtioFs->Label, NodeId));
158 if (Size != NULL) {
159 DEBUG ((DEBUG_ERROR, " Size=0x%Lx", *Size));
160 }
161 if (Atime != NULL) {
162 DEBUG ((DEBUG_ERROR, " Atime=%Lu", *Atime));
163 }
164 if (Mtime != NULL) {
165 DEBUG ((DEBUG_ERROR, " Mtime=%Lu", *Mtime));
166 }
167 if (Mode != NULL) {
168 DEBUG ((DEBUG_ERROR, " Mode=0x%x", *Mode)); // no support for octal :/
169 }
170 DEBUG ((DEBUG_ERROR, " Errno=%d\n", CommonResp.Error));
171 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
172 }
173 return Status;
174}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette