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 | **/
|
---|
42 | EFI_STATUS
|
---|
43 | VirtioFsFuseMkDir (
|
---|
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 (
|
---|
94 | VirtioFs,
|
---|
95 | &CommonReq,
|
---|
96 | ReqSgList.TotalSize,
|
---|
97 | VirtioFsFuseOpMkDir,
|
---|
98 | ParentNodeId
|
---|
99 | );
|
---|
100 | if (EFI_ERROR (Status)) {
|
---|
101 | return Status;
|
---|
102 | }
|
---|
103 |
|
---|
104 | //
|
---|
105 | // Populate the FUSE_MKDIR-specific fields.
|
---|
106 | //
|
---|
107 | MkDirReq.Mode = (VIRTIO_FS_FUSE_MODE_PERM_RWXU |
|
---|
108 | VIRTIO_FS_FUSE_MODE_PERM_RWXG |
|
---|
109 | VIRTIO_FS_FUSE_MODE_PERM_RWXO);
|
---|
110 | MkDirReq.Umask = 0;
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Submit the request.
|
---|
114 | //
|
---|
115 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
|
---|
116 | if (EFI_ERROR (Status)) {
|
---|
117 | return Status;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Verify the response (all response buffers are fixed size).
|
---|
122 | //
|
---|
123 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
|
---|
124 | if (EFI_ERROR (Status)) {
|
---|
125 | if (Status == EFI_DEVICE_ERROR) {
|
---|
126 | DEBUG ((
|
---|
127 | DEBUG_ERROR,
|
---|
128 | "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "
|
---|
129 | "Errno=%d\n",
|
---|
130 | __func__,
|
---|
131 | VirtioFs->Label,
|
---|
132 | ParentNodeId,
|
---|
133 | Name,
|
---|
134 | CommonResp.Error
|
---|
135 | ));
|
---|
136 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
|
---|
137 | }
|
---|
138 |
|
---|
139 | return Status;
|
---|
140 | }
|
---|
141 |
|
---|
142 | //
|
---|
143 | // Output the NodeId of the new directory.
|
---|
144 | //
|
---|
145 | *NodeId = NodeResp.NodeId;
|
---|
146 | return EFI_SUCCESS;
|
---|
147 | }
|
---|