]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioFsDxe/FuseOpenDir.c
MdePkg/Include: Add STATIC_ASSERT for L'' and L"" strings
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / FuseOpenDir.c
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 (VirtioFs, &CommonReq, ReqSgList.TotalSize,
83 VirtioFsFuseOpOpenDir, NodeId);
84 if (EFI_ERROR (Status)) {
85 return Status;
86 }
87
88 //
89 // Populate the FUSE_OPENDIR-specific fields.
90 //
91 OpenReq.Flags = 0;
92 OpenReq.Unused = 0;
93
94 //
95 // Submit the request.
96 //
97 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
98 if (EFI_ERROR (Status)) {
99 return Status;
100 }
101
102 //
103 // Verify the response (all response buffers are fixed size).
104 //
105 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
106 if (EFI_ERROR (Status)) {
107 if (Status == EFI_DEVICE_ERROR) {
108 DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" NodeId=%Lu Errno=%d\n",
109 __FUNCTION__, VirtioFs->Label, NodeId, CommonResp.Error));
110 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
111 }
112 return Status;
113 }
114
115 //
116 // Output the open file handle.
117 //
118 *FuseHandle = OpenResp.FileHandle;
119 return EFI_SUCCESS;
120 }