Coverage Report

Created: 2024-07-27 06:53

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