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