1 | /** @file
|
---|
2 | FUSE_UNLINK / FUSE_RMDIR 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 | Remove a regular file or a directory, by sending the FUSE_UNLINK or
|
---|
15 | FUSE_RMDIR request to the Virtio Filesystem device.
|
---|
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_UNLINK
|
---|
21 | / FUSE_RMDIR request to. On output, the FUSE request
|
---|
22 | counter "VirtioFs->RequestId" will have been
|
---|
23 | incremented.
|
---|
24 |
|
---|
25 | @param[in] ParentNodeId The inode number of the directory in which Name
|
---|
26 | should be removed.
|
---|
27 |
|
---|
28 | @param[in] Name The single-component filename to remove in the
|
---|
29 | directory identified by ParentNodeId.
|
---|
30 |
|
---|
31 | @param[in] IsDir TRUE if Name refers to a directory, FALSE otherwise.
|
---|
32 |
|
---|
33 | @retval EFI_SUCCESS The file or directory has been removed.
|
---|
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 | VirtioFsFuseRemoveFileOrDir (
|
---|
44 | IN OUT VIRTIO_FS *VirtioFs,
|
---|
45 | IN UINT64 ParentNodeId,
|
---|
46 | IN CHAR8 *Name,
|
---|
47 | IN BOOLEAN IsDir
|
---|
48 | )
|
---|
49 | {
|
---|
50 | VIRTIO_FS_FUSE_REQUEST CommonReq;
|
---|
51 | VIRTIO_FS_IO_VECTOR ReqIoVec[2];
|
---|
52 | VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;
|
---|
53 | VIRTIO_FS_FUSE_RESPONSE CommonResp;
|
---|
54 | VIRTIO_FS_IO_VECTOR RespIoVec[1];
|
---|
55 | VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;
|
---|
56 | EFI_STATUS Status;
|
---|
57 |
|
---|
58 | //
|
---|
59 | // Set up the scatter-gather lists.
|
---|
60 | //
|
---|
61 | ReqIoVec[0].Buffer = &CommonReq;
|
---|
62 | ReqIoVec[0].Size = sizeof CommonReq;
|
---|
63 | ReqIoVec[1].Buffer = Name;
|
---|
64 | ReqIoVec[1].Size = AsciiStrSize (Name);
|
---|
65 | ReqSgList.IoVec = ReqIoVec;
|
---|
66 | ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);
|
---|
67 |
|
---|
68 | RespIoVec[0].Buffer = &CommonResp;
|
---|
69 | RespIoVec[0].Size = sizeof CommonResp;
|
---|
70 | RespSgList.IoVec = RespIoVec;
|
---|
71 | RespSgList.NumVec = ARRAY_SIZE (RespIoVec);
|
---|
72 |
|
---|
73 | //
|
---|
74 | // Validate the scatter-gather lists; calculate the total transfer sizes.
|
---|
75 | //
|
---|
76 | Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);
|
---|
77 | if (EFI_ERROR (Status)) {
|
---|
78 | return Status;
|
---|
79 | }
|
---|
80 |
|
---|
81 | //
|
---|
82 | // Populate the common request header.
|
---|
83 | //
|
---|
84 | Status = VirtioFsFuseNewRequest (
|
---|
85 | VirtioFs,
|
---|
86 | &CommonReq,
|
---|
87 | ReqSgList.TotalSize,
|
---|
88 | IsDir ? VirtioFsFuseOpRmDir : VirtioFsFuseOpUnlink,
|
---|
89 | ParentNodeId
|
---|
90 | );
|
---|
91 | if (EFI_ERROR (Status)) {
|
---|
92 | return Status;
|
---|
93 | }
|
---|
94 |
|
---|
95 | //
|
---|
96 | // Submit the request.
|
---|
97 | //
|
---|
98 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);
|
---|
99 | if (EFI_ERROR (Status)) {
|
---|
100 | return Status;
|
---|
101 | }
|
---|
102 |
|
---|
103 | //
|
---|
104 | // Verify the response (all response buffers are fixed size).
|
---|
105 | //
|
---|
106 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);
|
---|
107 | if (Status == EFI_DEVICE_ERROR) {
|
---|
108 | DEBUG ((DEBUG_ERROR, "%a: Label=\"%s\" ParentNodeId=%Lu Name=\"%a\" "
|
---|
109 | "IsDir=%d Errno=%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name,
|
---|
110 | IsDir, CommonResp.Error));
|
---|
111 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);
|
---|
112 | }
|
---|
113 | return Status;
|
---|
114 | }
|
---|