2 FUSE_SETATTR wrapper for the Virtio Filesystem device.
4 Copyright (C) 2020, Red Hat, Inc.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "VirtioFsDxe.h"
12 Send the FUSE_SETATTR request to the Virtio Filesystem device, for changing
13 the attributes of an inode.
15 The function may only be called after VirtioFsFuseInitSession() returns
16 successfully and before VirtioFsUninit() is called.
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
23 @param[in] NodeId The inode number representing the regular file or
24 directory whose attributes should be changed.
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.
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.
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
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
44 @retval EFI_SUCCESS The attributes have been updated.
46 @return The "errno" value mapped to an EFI_STATUS code, if the
47 Virtio Filesystem device explicitly reported an error.
49 @return Error codes propagated from VirtioFsSgListsValidate(),
50 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
51 VirtioFsFuseCheckResponse().
55 IN OUT VIRTIO_FS
*VirtioFs
,
57 IN UINT64
*Size OPTIONAL
,
58 IN UINT64
*Atime OPTIONAL
,
59 IN UINT64
*Mtime OPTIONAL
,
60 IN UINT32
*Mode OPTIONAL
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
;
75 // Set up the scatter-gather lists.
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
);
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
);
94 // Validate the scatter-gather lists; calculate the total transfer sizes.
96 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
97 if (EFI_ERROR (Status
)) {
102 // Populate the common request header.
104 Status
= VirtioFsFuseNewRequest (
108 VirtioFsFuseOpSetAttr
,
111 if (EFI_ERROR (Status
)) {
116 // Populate the FUSE_SETATTR-specific fields.
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
;
126 AttrReq
.AtimeNsec
= 0;
127 AttrReq
.MtimeNsec
= 0;
128 AttrReq
.CtimeNsec
= 0;
129 AttrReq
.Mode
= (Mode
== NULL
) ? 0 : *Mode
;
136 AttrReq
.Valid
|= VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE
;
140 AttrReq
.Valid
|= VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME
;
144 AttrReq
.Valid
|= VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME
;
148 AttrReq
.Valid
|= VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE
;
152 // Submit the request.
154 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
155 if (EFI_ERROR (Status
)) {
160 // Verify the response (all response buffers are fixed size).
162 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
163 if (Status
== EFI_DEVICE_ERROR
) {
166 "%a: Label=\"%s\" NodeId=%Lu",
172 DEBUG ((DEBUG_ERROR
, " Size=0x%Lx", *Size
));
176 DEBUG ((DEBUG_ERROR
, " Atime=%Lu", *Atime
));
180 DEBUG ((DEBUG_ERROR
, " Mtime=%Lu", *Mtime
));
184 DEBUG ((DEBUG_ERROR
, " Mode=0x%x", *Mode
)); // no support for octal :/
187 DEBUG ((DEBUG_ERROR
, " Errno=%d\n", CommonResp
.Error
));
188 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);