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