2 FUSE_STATFS 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_STATFS request to the Virtio Filesysem device, for retrieving
13 the attributes of the host-side filesystem that contains NodeId.
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 FUSE_STATFS
19 request to. On output, the FUSE request counter
20 "VirtioFs->RequestId" will have been incremented.
22 @param[in] NodeId The inode whose containing filesystem is to be
23 queried for its attributes.
25 @param[out] FilesysAttr The VIRTIO_FS_FUSE_STATFS_RESPONSE object describing
26 the filesystem that underlies NodeId.
28 @retval EFI_SUCCESS FilesysAttr has been filled in.
30 @return The "errno" value mapped to an EFI_STATUS code, if the
31 Virtio Filesystem device explicitly reported an error.
33 @return Error codes propagated from VirtioFsSgListsValidate(),
34 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
35 VirtioFsFuseCheckResponse().
39 IN OUT VIRTIO_FS
*VirtioFs
,
41 OUT VIRTIO_FS_FUSE_STATFS_RESPONSE
*FilesysAttr
44 VIRTIO_FS_FUSE_REQUEST CommonReq
;
45 VIRTIO_FS_IO_VECTOR ReqIoVec
[1];
46 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList
;
47 VIRTIO_FS_FUSE_RESPONSE CommonResp
;
48 VIRTIO_FS_IO_VECTOR RespIoVec
[2];
49 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList
;
53 // Set up the scatter-gather lists.
55 ReqIoVec
[0].Buffer
= &CommonReq
;
56 ReqIoVec
[0].Size
= sizeof CommonReq
;
57 ReqSgList
.IoVec
= ReqIoVec
;
58 ReqSgList
.NumVec
= ARRAY_SIZE (ReqIoVec
);
60 RespIoVec
[0].Buffer
= &CommonResp
;
61 RespIoVec
[0].Size
= sizeof CommonResp
;
62 RespIoVec
[1].Buffer
= FilesysAttr
;
63 RespIoVec
[1].Size
= sizeof *FilesysAttr
;
64 RespSgList
.IoVec
= RespIoVec
;
65 RespSgList
.NumVec
= ARRAY_SIZE (RespIoVec
);
68 // Validate the scatter-gather lists; calculate the total transfer sizes.
70 Status
= VirtioFsSgListsValidate (VirtioFs
, &ReqSgList
, &RespSgList
);
71 if (EFI_ERROR (Status
)) {
76 // Populate the common request header.
78 Status
= VirtioFsFuseNewRequest (VirtioFs
, &CommonReq
, ReqSgList
.TotalSize
,
79 VirtioFsFuseOpStatFs
, NodeId
);
80 if (EFI_ERROR (Status
)) {
85 // Submit the request.
87 Status
= VirtioFsSgListsSubmit (VirtioFs
, &ReqSgList
, &RespSgList
);
88 if (EFI_ERROR (Status
)) {
93 // Verify the response (all response buffers are fixed size).
95 Status
= VirtioFsFuseCheckResponse (&RespSgList
, CommonReq
.Unique
, NULL
);
96 if (Status
== EFI_DEVICE_ERROR
) {
97 DEBUG ((DEBUG_ERROR
, "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",
98 __FUNCTION__
, VirtioFs
->Label
, NodeId
, CommonResp
.Error
));
99 Status
= VirtioFsErrnoToEfiStatus (CommonResp
.Error
);