dmlite
0.6
|
00001 /// @file include/dmlite/cpp/inode.h 00002 /// @brief Low-level access API. 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_INODE_H 00005 #define DMLITE_CPP_INODE_H 00006 00007 #include "../common/config.h" 00008 #include "base.h" 00009 #include "exceptions.h" 00010 #include "utils/extensible.h" 00011 #include "utils/security.h" 00012 00013 #include <dirent.h> 00014 #include <utime.h> 00015 #include <string> 00016 #include <vector> 00017 00018 namespace dmlite { 00019 00020 // Forward declarations. 00021 class StackInstance; 00022 00023 /// Typedef for directories. 00024 struct IDirectory { virtual ~IDirectory(); }; 00025 00026 /// File/directory metadata. 00027 struct ExtendedStat: public Extensible { 00028 enum FileStatus { kOnline = '-', 00029 kMigrated = 'm' 00030 }; 00031 00032 ino_t parent; 00033 struct stat stat; 00034 FileStatus status; 00035 std::string name; 00036 std::string guid; 00037 std::string csumtype; 00038 std::string csumvalue; 00039 Acl acl; 00040 00041 bool operator == (const ExtendedStat&) const; 00042 bool operator != (const ExtendedStat&) const; 00043 bool operator < (const ExtendedStat&) const; 00044 bool operator > (const ExtendedStat&) const; 00045 }; 00046 00047 /// Symbolic link 00048 struct SymLink: public Extensible { 00049 ino_t inode; 00050 std::string link; 00051 00052 bool operator == (const SymLink&) const; 00053 bool operator != (const SymLink&) const; 00054 bool operator < (const SymLink&) const; 00055 bool operator > (const SymLink&) const; 00056 }; 00057 00058 /// File replica metadata 00059 struct Replica: public Extensible { 00060 enum ReplicaStatus { kAvailable = '-', 00061 kBeingPopulated = 'P', 00062 kToBeDeleted = 'D' 00063 }; 00064 enum ReplicaType { kVolatile = 'V', 00065 kPermanent = 'P' 00066 }; 00067 00068 int64_t replicaid; 00069 int64_t fileid; 00070 00071 int64_t nbaccesses; 00072 time_t atime; 00073 time_t ptime; 00074 time_t ltime; 00075 00076 ReplicaStatus status; 00077 ReplicaType type; 00078 00079 std::string server; 00080 std::string rfn; 00081 00082 bool operator == (const Replica&) const; 00083 bool operator != (const Replica&) const; 00084 bool operator < (const Replica&) const; 00085 bool operator > (const Replica&) const; 00086 }; 00087 00088 /// Low-level interface. Based on i-nodes. 00089 /// @note Security checks NOT done on this level. 00090 class INode: public virtual BaseInterface { 00091 public: 00092 /// Destructor 00093 virtual ~INode(); 00094 00095 /// Start a transaction 00096 virtual void begin(void) throw (DmException); 00097 00098 /// Commit a transaction 00099 virtual void commit(void) throw (DmException); 00100 00101 /// Rollback changes 00102 virtual void rollback(void) throw (DmException); 00103 00104 /// Create a new file or directory 00105 /// @param f The file that will be inserted. Its fields must be initialized. 00106 /// @return An stat of the created file. 00107 virtual ExtendedStat create(const ExtendedStat& f) throw (DmException); 00108 00109 /// Create or modify the file inode to point to another file. 00110 /// @param inode The file to modify. 00111 /// @param link The new symbolic link. 00112 /// @note This does NOT create the file. Use create first. 00113 virtual void symlink(ino_t inode, const std::string &link) throw (DmException); 00114 00115 /// Remove a file or directory. It will fail if it is a directory and it is not empty, 00116 /// or if it a file and it has replicas. 00117 /// @param inode The inode of the file. 00118 /// @note This will check for non empty directories. 00119 /// @note This will remove associated comments and replicas. 00120 virtual void unlink(ino_t inode) throw (DmException); 00121 00122 /// Move a file between two directories. 00123 /// @param inode File to be moved. 00124 /// @param dest The new parent. 00125 virtual void move(ino_t inode, ino_t dest) throw (DmException); 00126 00127 /// Change the name of a file. 00128 /// @param inode The inode of the file. 00129 /// @param name New name. 00130 virtual void rename(ino_t inode, const std::string& name) throw (DmException); 00131 00132 /// Do an extended stat of en entry using its inode. 00133 /// @param inode The inode of the file. 00134 /// @return The extended status of the file. 00135 virtual ExtendedStat extendedStat(ino_t inode) throw (DmException); 00136 00137 /// Do an extended stat of an entry using the parent inode and the name. 00138 /// @param parent The parent inode. 00139 /// @param name The file or directory name. 00140 /// @note No security check will be done. 00141 virtual ExtendedStat extendedStat(ino_t parent, 00142 const std::string& name) throw (DmException); 00143 00144 /// Do an extended stat using the GUID. 00145 /// @param guid The file GUID. 00146 virtual ExtendedStat extendedStat(const std::string& guid) throw (DmException); 00147 00148 /// Get the symlink associated with a inode. 00149 /// @param inode The inode of the file. 00150 /// @return A SymLink struct. 00151 /// @note If inode is not a symlink, an exception will be thrown. 00152 virtual SymLink readLink(ino_t inode) throw (DmException); 00153 00154 /// Add a new replica for a file. 00155 /// @param replica Stores the data that is going to be added. fileid must 00156 /// point to the id of the logical file in the catalog. 00157 virtual void addReplica(const Replica& replica) throw (DmException); 00158 00159 /// Delete a replica. 00160 /// @param replica The replica to remove. 00161 virtual void deleteReplica(const Replica& replica) throw (DmException); 00162 00163 /// Get a replica using the replica ID. 00164 /// @param rid The replica ID. 00165 virtual Replica getReplica(int64_t rid) throw (DmException); 00166 00167 /// Get a replica. 00168 /// @param rfn The replica to retrieve. 00169 virtual Replica getReplica(const std::string& rfn) throw (DmException); 00170 00171 /// Modify a replica. 00172 /// @param replica The replica data. 00173 virtual void updateReplica(const Replica& replica) throw (DmException); 00174 00175 /// Get replicas for a file. 00176 /// @param inode The entry inode. 00177 virtual std::vector<Replica> getReplicas(ino_t inode) throw (DmException); 00178 00179 /// Change access and/or modification time. 00180 /// @param inode The inode of the file. 00181 /// @param buf A struct holding the new times. 00182 virtual void utime(ino_t inode, 00183 const struct utimbuf* buf) throw (DmException); 00184 00185 /// Set the mode of a file. 00186 /// @param inode The inode of the file. 00187 /// @param uid The owner. If -1, not changed. 00188 /// @param gid The group. If -1, not changed. 00189 /// @param mode The new mode. S_IFMT bits are cleared, and kept as they 00190 /// are in the DB. 00191 /// @param acl The new ACL. If empty, not changed. 00192 virtual void setMode(ino_t inode, uid_t uid, gid_t gid, mode_t mode, 00193 const Acl& acl) throw (DmException); 00194 00195 /// Set the size of a file. 00196 /// @param inode The inode of the file. 00197 /// @param size The new size. 00198 virtual void setSize(ino_t inode, size_t size) throw (DmException); 00199 00200 /// Set the checksum of a file. 00201 /// @param inode The inode of the file. 00202 /// @param csumtype The checksum type. 00203 /// @param csumvalue The checksum value. 00204 virtual void setChecksum(ino_t inode, const std::string& csumtype, 00205 const std::string& csumvalue) throw (DmException); 00206 00207 /// Get the comment associated to a file. 00208 /// @param inode The inode of the file. 00209 /// @return The comment. 00210 virtual std::string getComment(ino_t inode) throw (DmException); 00211 00212 /// Set the comment associated to a file. 00213 /// @param inode The inode of the file. 00214 /// @param comment The new comment. 00215 virtual void setComment(ino_t inode, 00216 const std::string& comment) throw (DmException); 00217 00218 /// Remove the associated comment. 00219 /// @param inode The file whose comment will be removed. 00220 virtual void deleteComment(ino_t inode) throw (DmException); 00221 00222 /// Set the GUID of a file. 00223 /// @param inode The inode of the file. 00224 /// @param guid The new GUID. 00225 virtual void setGuid(ino_t inode, 00226 const std::string& guid) throw (DmException); 00227 00228 /// Update extended metadata on the catalog. 00229 /// @param attr The extended attributes struct. 00230 virtual void updateExtendedAttributes(ino_t inode, 00231 const Extensible& attr) throw (DmException); 00232 00233 /// Open a directory. 00234 /// @param inode The inode of the directory. 00235 /// @return An opaque pointer to a directory. 00236 virtual IDirectory* openDir(ino_t inode) throw (DmException); 00237 00238 /// Close a directory. 00239 /// @param dir The opaque structure to close. 00240 virtual void closeDir(IDirectory* dir) throw (DmException); 00241 00242 /// Read the next entry. 00243 /// @param dir The opaque structure of a directory. 00244 /// @return NULL when finished. Extended stat of the next entry otherwise. 00245 virtual ExtendedStat* readDirx(IDirectory* dir) throw (DmException); 00246 00247 /// Read the next entry. 00248 /// @param dir The opaque structure of a directory. 00249 /// @return NULL when finished. Extended stat of the next entry otherwise. 00250 virtual struct dirent* readDir (IDirectory* dir) throw (DmException); 00251 }; 00252 00253 /// INodeFactory 00254 class INodeFactory: public virtual BaseFactory { 00255 public: 00256 /// Destructor 00257 virtual ~INodeFactory(); 00258 00259 protected: 00260 // Stack instance is allowed to instantiate INodes 00261 friend class StackInstance; 00262 00263 /// Children of INodeFactory are allowed to instantiate too (decorator) 00264 static INode* createINode(INodeFactory* factory, 00265 PluginManager* pm) throw (DmException); 00266 00267 /// Instantiate a implementation of INode 00268 virtual INode* createINode(PluginManager* pm) throw (DmException); 00269 }; 00270 00271 }; 00272 00273 #endif // DMLITE_CPP_INODE_H