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