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