dmlite  0.6
Catalog.h
Go to the documentation of this file.
1 /// @file core/builtin/Catalog.h
2 /// @brief Implementation of a Catalog using other plugins, as INode.
3 /// @details Intended to ease the development of database backends.
4 /// @author Alejandro Álvarez Ayllon <aalvarez@cern.ch>
5 #ifndef BUILTIN_CATALOG_H
6 #define BUILTIN_CATALOG_H
7 
8 #include <dmlite/cpp/catalog.h>
9 #include <dmlite/cpp/inode.h>
10 #include <dmlite/cpp/poolmanager.h>
11 #include <dmlite/cpp/pooldriver.h>
12 
13 namespace dmlite {
14 
15  struct BuiltInDir: public Directory {
16  virtual ~BuiltInDir() {};
19  };
20 
21  class BuiltInCatalog: public Catalog {
22  public:
23  BuiltInCatalog(bool updateATime, unsigned symLinkLimit) throw (DmException);
24  ~BuiltInCatalog();
25 
26  std::string getImplId(void) const throw();
27 
28  void setStackInstance(StackInstance* si) throw (DmException);
29 
30  void setSecurityContext(const SecurityContext*) throw (DmException);
31 
32  void changeDir (const std::string&) throw (DmException);
33  std::string getWorkingDir (void) throw (DmException);
34 
35  DmStatus extendedStat(ExtendedStat &xstat,
36  const std::string& path,
37  bool followSym) throw (DmException);
38 
39  ExtendedStat extendedStat(const std::string& path,
40  bool followSym = true) throw (DmException);
41  ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException);
42 
43 
44 
45  bool access(const std::string& path, int mode) throw (DmException);
46  bool accessReplica(const std::string& replica, int mode) throw (DmException);
47 
48  void addReplica (const Replica& replica) throw (DmException);
49  void deleteReplica(const Replica& replica) throw (DmException);
50 
51  std::vector<Replica> getReplicas(const std::string& path) throw (DmException);
52  Location get(const std::string& path) throw (DmException);
53 
54  Location put(const std::string& path) throw (DmException);
55  void putDone(const std::string& host, const std::string& rfn,
56  const std::map<std::string, std::string>& params) throw (DmException);
57 
58  void symlink(const std::string& oldpath,
59  const std::string& newpath) throw (DmException);
60  std::string readLink(const std::string& path) throw (DmException);
61 
62  void unlink(const std::string& path) throw (DmException);
63 
64  void create(const std::string& path, mode_t mode) throw (DmException);
65 
66  void makeDir (const std::string& path, mode_t mode) throw (DmException);
67  void removeDir(const std::string& path) throw (DmException);
68 
69  void rename(const std::string& oldPath,
70  const std::string& newPath) throw (DmException);
71 
72  mode_t umask(mode_t mask) throw ();
73 
74  void setMode (const std::string& path, mode_t mode) throw (DmException);
75  void setOwner (const std::string& path, uid_t newUid, gid_t newGid,
76  bool followSymLink = true) throw (DmException);
77 
78  void setSize (const std::string& path, size_t newSize) throw (DmException);
79 
80  void setAcl(const std::string& path, const Acl& acls) throw (DmException);
81 
82  void utime(const std::string& path, const struct utimbuf* buf) throw (DmException);
83 
84  std::string getComment(const std::string& path) throw (DmException);
85  void setComment(const std::string& path,
86  const std::string& comment) throw (DmException);
87 
88  void setGuid(const std::string& path,
89  const std::string &guid) throw (DmException);
90 
91  void updateExtendedAttributes(const std::string& path,
92  const Extensible& attr) throw (DmException);
93 
94  Directory* openDir (const std::string& path) throw (DmException);
95  void closeDir(Directory* dir) throw (DmException);
96  struct dirent* readDir (Directory* dir) throw (DmException);
97  ExtendedStat* readDirx(Directory* dir) throw (DmException);
98 
99  Replica getReplicaByRFN(const std::string& rfn) throw (DmException);
100  void updateReplica(const Replica& replica) throw (DmException);
101 
102  protected:
103  /// Get the parent of a directory.
104  /// @param path The path to split.
105  /// @param parentPath Where to put the parent path.
106  /// @param name Where to put the file name (stripping last /).
107  /// @return The parent metadata.
108  ExtendedStat getParent(const std::string& path, std::string* parentPath,
109  std::string* name) throw (DmException);
110 
111  /// Update access time (if updateATime is true)
112  void updateAccessTime(const ExtendedStat& meta) throw (DmException);
113 
114  /// Traverse backwards to check permissions.
115  /// @param meta The file at the end
116  /// @note Throws an exception if it is not possible.
117  void traverseBackwards(const ExtendedStat& meta) throw (DmException);
118 
119  /// addFileSizeToParents
120  /// Add (or subtract) the size of the given file from
121  /// all its parent directories
122  /// @param fname The logical file name (SFN) of the file in question
123  /// @param subtract If true then subtract instead of adding
124  void addFileSizeToParents(const std::string &fname, bool subtract) throw (DmException);
125 
126  /// addFileSizeToParents
127  /// Add (or subtract) the size of the given file from
128  /// all its parent directories
129  /// @param st The stat information about the file in question
130  /// @param subtract If true then subtract instead of adding
131  void addFileSizeToParents(const ExtendedStat &statinfo, bool subtract) throw (DmException);
132 
133  private:
135 
137 
138  std::string cwdPath_;
139  ino_t cwd_;
140 
141  mode_t umask_;
143  unsigned symLinkLimit_;
144  };
145 
146  /// Plug-ins must implement a concrete factory to be instantiated.
148  public:
151 
152  void configure(const std::string&, const std::string&) throw (DmException);
153 
154  Catalog* createCatalog(PluginManager*) throw (DmException);
155 
156  private:
158  unsigned symLinkLimit_;
159  };
160 
161 };
162 
163 #endif // BUILTIN_CATALOG_H
File/directory metadata.
Definition: inode.h:29
unsigned symLinkLimit_
Definition: Catalog.h:143
Definition: security.h:51
Definition: status.h:17
Plug-ins must implement a concrete factory to be instantiated.
Definition: catalog.h:237
virtual ~BuiltInDir()
Definition: Catalog.h:16
Definition: dmlite.h:161
Security context. To be created by the Authn.
Definition: authn.h:64
Represent the complete location of a file.
Definition: pooldriver.h:42
Base exception class.
Definition: exceptions.h:17
File replica metadata.
Definition: inode.h:70
Plug-ins must implement a concrete factory to be instantiated.
Definition: Catalog.h:147
Definition: Catalog.h:21
CatalogInterface can only be instantiated through this class.
Definition: dmlite.h:42
Interface for Catalog (Namespaces).
Definition: catalog.h:30
ino_t cwd_
Definition: Catalog.h:139
bool updateATime_
Definition: Catalog.h:157
IDirectory * idir
Definition: Catalog.h:16
Pool API.
unsigned symLinkLimit_
Definition: Catalog.h:158
Helpful typedef for KeyValue containers.
Definition: extensible.h:20
bool updateATime_
Definition: Catalog.h:142
Definition: Catalog.h:15
std::string cwdPath_
Definition: Catalog.h:138
mode_t umask_
Definition: Catalog.h:141
const SecurityContext * secCtx_
Definition: Catalog.h:136
Namespace for the dmlite C++ API.
Definition: authn.h:15
StackInstance * si_
Definition: Catalog.h:134
Low-level access API.
ExtendedStat dir
Definition: Catalog.h:18
Catalog API.
Pool handling API.
Typedef for directories.
Definition: inode.h:26
Typedef for directories.
Definition: catalog.h:27