• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CORE__IO__ROFS_FILESYSTEM_H
17 #define CORE__IO__ROFS_FILESYSTEM_H
18 
19 #include <base/containers/array_view.h>
20 #include <base/containers/string.h>
21 #include <base/containers/string_view.h>
22 #include <base/containers/unordered_map.h>
23 #include <base/containers/vector.h>
24 #include <core/io/intf_directory.h>
25 #include <core/io/intf_file_system.h>
26 #include <core/namespace.h>
27 
CORE_BEGIN_NAMESPACE()28 CORE_BEGIN_NAMESPACE()
29 /** Rofs protocol.
30  * Protocol implementation that wraps a RO constant buffer in memory.
31  */
32 class RoFileSystem final : public IFilesystem {
33 public:
34     RoFileSystem(const void* const blob, size_t blobSize);
35     ~RoFileSystem() override = default;
36     RoFileSystem(RoFileSystem const&) = delete;
37     RoFileSystem& operator=(RoFileSystem const&) = delete;
38 
39     IDirectory::Entry GetEntry(BASE_NS::string_view uri) override;
40     IFile::Ptr OpenFile(BASE_NS::string_view path) override;
41     IFile::Ptr CreateFile(BASE_NS::string_view path) override;
42     bool DeleteFile(BASE_NS::string_view path) override;
43 
44     IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) override;
45     IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) override;
46     bool DeleteDirectory(BASE_NS::string_view path) override;
47 
48     bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) override;
49 
50     BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const override;
51 
52 protected:
53     void Destroy() override
54     {
55         delete this;
56     }
57 
58 private:
59     BASE_NS::unordered_map<BASE_NS::string, BASE_NS::vector<IDirectory::Entry>> directories_;
60     BASE_NS::unordered_map<BASE_NS::string, BASE_NS::array_view<const uint8_t>> files_;
61 };
62 CORE_END_NAMESPACE()
63 
64 #endif // CORE__IO__ROFS_FILESYSTEM_H
65