VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/VirtioFsDxe/FuseMkDir.c@ 99396

Last change on this file since 99396 was 89983, checked in by vboxsync, 4 years ago

Devices/EFI: Merge edk-stable202105 and openssl 1.1.1j and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1/** @file
2 FUSE_MKDIR 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 <Library/BaseLib.h> // AsciiStrSize()
10
11#include "VirtioFsDxe.h"
12
13/**
14 Send a FUSE_MKDIR request to the Virtio Filesystem device, for creating a
15 directory.
16
17 The function may only be called after VirtioFsFuseInitSession() returns
18 successfully and before VirtioFsUninit() is called.
19
20 @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_MKDIR
21 request to. On output, the FUSE request counter
22 "VirtioFs->RequestId" will have been incremented.
23
24 @param[in] ParentNodeId The inode number of the direct parent directory of
25 the directory to create.
26
27 @param[in] Name The single-component filename of the directory to
28 create, under the parent directory identified by
29 ParentNodeId.
30
31 @param[out] NodeId The inode number of the new directory.
32
33 @retval EFI_SUCCESS The directory has been created.
34
35 @return The "errno" value mapped to an EFI_STATUS code, if the
36 Virtio Filesystem device explicitly reported an error.
37
38 @return Error codes propagated from VirtioFsSgListsValidate(),
39 VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),
40 VirtioFsFuseCheckResponse().
41**/
42EFI_STATUS
43VirtioFsFuseMkDir (
44 IN OUT VIRTIO_FS *VirtioFs,
45 IN UINT64 ParentNodeId,
46 IN CHAR8 *Name,
47 OUT UINT64 *NodeId
48 )
49{
50 VIRTIO_FS_FUSE_REQUEST CommonReq;
51 VIRTIO_FS_FUSE_MKDIR_REQUEST MkDirReq;
52 VIRTIO_FS_IO_VECTOR ReqIoVec[3];
53 VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
54 VIRTIO_FS_FUSE_RESPONSE CommonResp;
55 VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp;
56 VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp;
57 VIRTIO_FS_IO_VECTOR RespIoVec[3];
58 VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
59 EFI_STATUS Status;
60
61 //
62 // Set up the scatter-gather lists.
63 //
64 ReqIoVec[0].Buffer = &CommonReq;
65 ReqIoVec[0].Size = sizeof CommonReq;
66 ReqIoVec[1].Buffer = &MkDirReq;
67 ReqIoVec[1].Size = sizeof MkDirReq;
68 ReqIoVec[2].Buffer = Name;
69 ReqIoVec[2].Size = AsciiStrSize (Name);
70 ReqSgList.IoVec = ReqIoVec;
71 ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
72
73 RespIoVec[0].Buffer = &CommonResp;
74 RespIoVec[0].Size = sizeof CommonResp;
75 RespIoVec[1].Buffer = &NodeResp;
76 RespIoVec[1].Size = sizeof NodeResp;
77 RespIoVec[2].Buffer = &AttrResp;
78 RespIoVec[2].Size = sizeof AttrResp;
79 RespSgList.IoVec = RespIoVec;
80 RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
81
82 //
83 // Validate the scatter-gather lists; calculate the total transfer sizes.
84 //
85 Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
86 if (EFI_ERROR (Status)) {
87 return Status;
88 }
89
90 //
91 // Populate the common request header.
92 //
93 Status = VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.TotalSize,
94 VirtioFsFuseOpMkDir, ParentNodeId);
95 if (EFI_ERROR (Status)) {
96 return Status;
97 }
98
99 //
100 // Populate the FUSE_MKDIR-specific fields.
101 //
102 MkDirReq.Mode = (VIRTIO_FS_FUSE_MODE_PERM_RWXU |
103 VIRTIO_FS_FUSE_MODE_PERM_RWXG |
104 VIRTIO_FS_FUSE_MODE_PERM_RWXO);
105 MkDirReq.Umask = 0;
106
107 //
108 // Submit the request.
109 //
110 Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
111 if (EFI_ERROR (Status)) {
112 return Status;
113 }
114
115 //
116 // Verify the response (all response buffers are fixed size).
117 //
118 Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
119 if (EFI_ERROR (Status)) {
120 if (Status == EFI_DEVICE_ERROR) {
121 DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "
122 "Errno=%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name,
123 CommonResp.Error));
124 Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
125 }
126 return Status;
127 }
128
129 //
130 // Output the NodeId of the new directory.
131 //
132 *NodeId = NodeResp.NodeId;
133 return EFI_SUCCESS;
134}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette