]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioFsDxe/FuseGetAttr.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseGetAttr.c
1 /** @file
2 FUSE_GETATTR 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 a FUSE_GETATTR request to the Virtio Filesystem device, for fetching the
13 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_GETATTR request to. On output, the FUSE request
20 counter "VirtioFs->RequestId" will have been
21 incremented.
22
23 @param[in] NodeId The inode number for which the attributes should be
24 retrieved.
25
26 @param[out] FuseAttr The VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object
27 describing the properties of the inode.
28
29 @retval EFI_SUCCESS FuseAttr has been filled in.
30
31 @return The "errno" value mapped to an EFI_STATUS code, if the
32 Virtio Filesystem device explicitly reported an error.
33
34 @return Error codes propagated from VirtioFsSgListsValidate(),
35 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
36 VirtioFsFuseCheckResponse().
37 **/
38 EFI_STATUS
39 VirtioFsFuseGetAttr (
40 IN OUT VIRTIO_FS *VirtioFs,
41 IN UINT64 NodeId,
42 OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr
43 )
44 {
45 VIRTIO_FS_FUSE_REQUEST CommonReq;
46 VIRTIO_FS_FUSE_GETATTR_REQUEST GetAttrReq;
47 VIRTIO_FS_IO_VECTOR ReqIoVec[2];
48 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
49 VIRTIO_FS_FUSE_RESPONSE CommonResp;
50 VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp;
51 VIRTIO_FS_IO_VECTOR RespIoVec[3];
52 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
53 EFI_STATUS Status;
54
55 //
56 // Set up the scatter-gather lists.
57 //
58 ReqIoVec[0].Buffer = &CommonReq;
59 ReqIoVec[0].Size = sizeof CommonReq;
60 ReqIoVec[1].Buffer = &GetAttrReq;
61 ReqIoVec[1].Size = sizeof GetAttrReq;
62 ReqSgList.IoVec = ReqIoVec;
63 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
64
65 RespIoVec[0].Buffer = &CommonResp;
66 RespIoVec[0].Size = sizeof CommonResp;
67 RespIoVec[1].Buffer = &GetAttrResp;
68 RespIoVec[1].Size = sizeof GetAttrResp;
69 RespIoVec[2].Buffer = FuseAttr;
70 RespIoVec[2].Size = sizeof *FuseAttr;
71 RespSgList.IoVec = RespIoVec;
72 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
73
74 //
75 // Validate the scatter-gather lists; calculate the total transfer sizes.
76 //
77 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
78 if (EFI_ERROR (Status)) {
79 return Status;
80 }
81
82 //
83 // Populate the common request header.
84 //
85 Status = VirtioFsFuseNewRequest (
86 VirtioFs,
87 &CommonReq,
88 ReqSgList.TotalSize,
89 VirtioFsFuseOpGetAttr,
90 NodeId
91 );
92 if (EFI_ERROR (Status)) {
93 return Status;
94 }
95
96 //
97 // Populate the FUSE_GETATTR-specific fields.
98 //
99 GetAttrReq.GetAttrFlags = 0;
100 GetAttrReq.Dummy = 0;
101 GetAttrReq.FileHandle = 0;
102
103 //
104 // Submit the request.
105 //
106 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
107 if (EFI_ERROR (Status)) {
108 return Status;
109 }
110
111 //
112 // Verify the response (all response buffers are fixed size).
113 //
114 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
115 if (Status == EFI_DEVICE_ERROR) {
116 DEBUG ((
117 DEBUG_ERROR,
118 "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",
119 __FUNCTION__,
120 VirtioFs->Label,
121 NodeId,
122 CommonResp.Error
123 ));
124 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
125 }
126
127 return Status;
128 }