]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
2 | // This source code is licensed under both the GPLv2 (found in the | |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
5 | ||
6 | #pragma once | |
7 | ||
8 | #ifndef ROCKSDB_LITE | |
9 | ||
10 | #include <utility> | |
11 | ||
12 | #include "rocksdb/file_system.h" | |
13 | ||
14 | namespace ROCKSDB_NAMESPACE { | |
15 | ||
16 | // An abstract FileSystem wrapper that creates a view of an existing | |
17 | // FileSystem by remapping names in some way. | |
18 | // | |
19 | // This class has not been fully analyzed for providing strong security | |
20 | // guarantees. | |
21 | class RemapFileSystem : public FileSystemWrapper { | |
22 | public: | |
23 | explicit RemapFileSystem(const std::shared_ptr<FileSystem>& base); | |
24 | ||
25 | protected: | |
26 | // Returns status and mapped-to path in the wrapped filesystem. | |
27 | // If it returns non-OK status, the returned path should not be used. | |
28 | virtual std::pair<IOStatus, std::string> EncodePath( | |
29 | const std::string& path) = 0; | |
30 | ||
31 | // Similar to EncodePath() except used in cases in which it is OK for | |
32 | // no file or directory on 'path' to already exist, such as if the | |
33 | // operation would create one. However, the parent of 'path' is expected | |
34 | // to exist for the operation to succeed. | |
35 | // Default implementation: call EncodePath | |
36 | virtual std::pair<IOStatus, std::string> EncodePathWithNewBasename( | |
37 | const std::string& path); | |
38 | ||
39 | public: | |
40 | // Left abstract: | |
41 | // const char* Name() const override { ... } | |
42 | static const char* kClassName() { return "RemapFileSystem"; } | |
43 | bool IsInstanceOf(const std::string& id) const override { | |
44 | if (id == kClassName()) { | |
45 | return true; | |
46 | } else { | |
47 | return FileSystemWrapper::IsInstanceOf(id); | |
48 | } | |
49 | } | |
50 | ||
51 | Status RegisterDbPaths(const std::vector<std::string>& paths) override; | |
52 | ||
53 | Status UnregisterDbPaths(const std::vector<std::string>& paths) override; | |
54 | ||
55 | IOStatus NewSequentialFile(const std::string& fname, | |
56 | const FileOptions& options, | |
57 | std::unique_ptr<FSSequentialFile>* result, | |
58 | IODebugContext* dbg) override; | |
59 | ||
60 | IOStatus NewRandomAccessFile(const std::string& fname, | |
61 | const FileOptions& options, | |
62 | std::unique_ptr<FSRandomAccessFile>* result, | |
63 | IODebugContext* dbg) override; | |
64 | ||
65 | IOStatus NewWritableFile(const std::string& fname, const FileOptions& options, | |
66 | std::unique_ptr<FSWritableFile>* result, | |
67 | IODebugContext* dbg) override; | |
68 | ||
69 | IOStatus ReuseWritableFile(const std::string& fname, | |
70 | const std::string& old_fname, | |
71 | const FileOptions& options, | |
72 | std::unique_ptr<FSWritableFile>* result, | |
73 | IODebugContext* dbg) override; | |
74 | ||
75 | IOStatus NewRandomRWFile(const std::string& fname, const FileOptions& options, | |
76 | std::unique_ptr<FSRandomRWFile>* result, | |
77 | IODebugContext* dbg) override; | |
78 | ||
79 | IOStatus NewDirectory(const std::string& dir, const IOOptions& options, | |
80 | std::unique_ptr<FSDirectory>* result, | |
81 | IODebugContext* dbg) override; | |
82 | ||
83 | IOStatus FileExists(const std::string& fname, const IOOptions& options, | |
84 | IODebugContext* dbg) override; | |
85 | ||
86 | IOStatus GetChildren(const std::string& dir, const IOOptions& options, | |
87 | std::vector<std::string>* result, | |
88 | IODebugContext* dbg) override; | |
89 | ||
90 | IOStatus GetChildrenFileAttributes(const std::string& dir, | |
91 | const IOOptions& options, | |
92 | std::vector<FileAttributes>* result, | |
93 | IODebugContext* dbg) override; | |
94 | ||
95 | IOStatus DeleteFile(const std::string& fname, const IOOptions& options, | |
96 | IODebugContext* dbg) override; | |
97 | ||
98 | IOStatus CreateDir(const std::string& dirname, const IOOptions& options, | |
99 | IODebugContext* dbg) override; | |
100 | ||
101 | IOStatus CreateDirIfMissing(const std::string& dirname, | |
102 | const IOOptions& options, | |
103 | IODebugContext* dbg) override; | |
104 | ||
105 | IOStatus DeleteDir(const std::string& dirname, const IOOptions& options, | |
106 | IODebugContext* dbg) override; | |
107 | ||
108 | IOStatus GetFileSize(const std::string& fname, const IOOptions& options, | |
109 | uint64_t* file_size, IODebugContext* dbg) override; | |
110 | ||
111 | IOStatus GetFileModificationTime(const std::string& fname, | |
112 | const IOOptions& options, | |
113 | uint64_t* file_mtime, | |
114 | IODebugContext* dbg) override; | |
115 | ||
116 | IOStatus IsDirectory(const std::string& path, const IOOptions& options, | |
117 | bool* is_dir, IODebugContext* dbg) override; | |
118 | ||
119 | IOStatus RenameFile(const std::string& src, const std::string& dest, | |
120 | const IOOptions& options, IODebugContext* dbg) override; | |
121 | ||
122 | IOStatus LinkFile(const std::string& src, const std::string& dest, | |
123 | const IOOptions& options, IODebugContext* dbg) override; | |
124 | ||
125 | IOStatus LockFile(const std::string& fname, const IOOptions& options, | |
126 | FileLock** lock, IODebugContext* dbg) override; | |
127 | ||
128 | IOStatus NewLogger(const std::string& fname, const IOOptions& options, | |
129 | std::shared_ptr<Logger>* result, | |
130 | IODebugContext* dbg) override; | |
131 | ||
132 | IOStatus GetAbsolutePath(const std::string& db_path, const IOOptions& options, | |
133 | std::string* output_path, | |
134 | IODebugContext* dbg) override; | |
135 | }; | |
136 | ||
137 | } // namespace ROCKSDB_NAMESPACE | |
138 | ||
139 | #endif // ROCKSDB_LITE |