00001 /// @file include/dmlite/cpp/catalog.h 00002 /// @brief Catalog API. 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_CATALOG_H 00005 #define DMLITE_CPP_CATALOG_H 00006 00007 #include "dmlite/common/config.h" 00008 #include "base.h" 00009 #include "exceptions.h" 00010 #include "status.h" 00011 #include "inode.h" 00012 #include "utils/extensible.h" 00013 00014 #include <dirent.h> 00015 #include <sys/stat.h> 00016 #include <string> 00017 #include <vector> 00018 #include <utime.h> 00019 00020 namespace dmlite { 00021 00022 // Forward declarations. 00023 class StackInstance; 00024 class PluginManager; 00025 00026 /// Typedef for directories. 00027 struct Directory { virtual ~Directory(); }; 00028 00029 /// Interface for Catalog (Namespaces). 00030 class Catalog: public virtual BaseInterface { 00031 public: 00032 /// Destructor. 00033 virtual ~Catalog(); 00034 00035 /// Change the working dir. Future not-absolute paths will use this as root. 00036 /// @param path The new working dir. 00037 virtual void changeDir(const std::string& path) throw (DmException); 00038 00039 /// Get the current working dir. 00040 /// @return The current working dir. 00041 virtual std::string getWorkingDir(void) throw (DmException); 00042 00043 /// Do an extended stat of a file or directory. 00044 /// @param path The path of the file or directory. 00045 /// @param followSym If true, symlinks will be followed. 00046 /// @return The extended status of the file. 00047 virtual ExtendedStat extendedStat(const std::string& path, 00048 bool followSym = true) throw (DmException); 00049 00050 /// Do an extended stat of a file or directory. Exception-safe version, returns a status 00051 /// @param path The path of the file or directory. 00052 /// @param followSym If true, symlinks will be followed. 00053 /// @param xstat The extended status of the file. 00054 /// @return A status object 00055 virtual DmStatus extendedStat(ExtendedStat &xstat, 00056 const std::string& path, 00057 bool followSym = true) throw (DmException); 00058 00059 /// Do an extended stat of a logical file using an associated replica file name. 00060 /// @param rfn The replica. 00061 /// @return The extended status of the file. 00062 virtual ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException); 00063 00064 /// Checks wether the process would be allowed to read, write, or check existence. 00065 /// @param lfn Logical filename. 00066 /// @param mode A mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. 00067 /// @return true if the file can be accessed. 00068 /// @note If the file does not exist, an exception will be thrown. 00069 virtual bool access(const std::string& path, int mode) throw (DmException); 00070 00071 /// Checks wether the process would be allowed to read, write, or check existence. 00072 /// @param rfn Replica filename. 00073 /// @param mode A mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. 00074 /// @return true if the file can be accessed. 00075 /// @note If the file does not exist, an exception will be thrown. 00076 virtual bool accessReplica(const std::string& replica, int mode) throw (DmException); 00077 00078 /// Add a new replica for a file. 00079 /// @param replica Stores the data that is going to be added. fileid must 00080 /// point to the id of the logical file in the catalog. 00081 virtual void addReplica(const Replica& replica) throw (DmException); 00082 00083 /// Delete a replica. 00084 /// @param replica The replica to remove. 00085 virtual void deleteReplica(const Replica& replica) throw (DmException); 00086 00087 /// Get replicas for a file. 00088 /// @param path The file for which replicas will be retrieved. 00089 virtual std::vector<Replica> getReplicas(const std::string& path) throw (DmException); 00090 00091 /// Creates a new symlink. 00092 /// @param path The existing path. 00093 /// @param symlink The new access path. 00094 virtual void symlink(const std::string& path, 00095 const std::string& symlink) throw (DmException); 00096 00097 /// Returns the path pointed by the symlink path 00098 /// @param path The symlink file. 00099 /// @return The symlink target. 00100 virtual std::string readLink(const std::string& path) throw (DmException); 00101 00102 /// Remove a file. 00103 /// @param path The path to remove. 00104 virtual void unlink(const std::string& path) throw (DmException); 00105 00106 /// Creates an entry in the catalog. 00107 /// @param path The new file. 00108 /// @param mode The creation mode. 00109 virtual void create(const std::string& path, 00110 mode_t mode) throw (DmException); 00111 00112 /// Sets the calling process’s file mode creation mask to mask & 0777. 00113 /// @param mask The new mask. 00114 /// @return The value of the previous mask. 00115 virtual mode_t umask(mode_t mask) throw (); 00116 00117 /// Set the mode of a file. 00118 /// @param path The file to modify. 00119 /// @param mode The new mode as an integer (i.e. 0755) 00120 virtual void setMode(const std::string& path, 00121 mode_t mode) throw (DmException); 00122 00123 /// Set the owner of a file. 00124 /// @param path The file to modify. 00125 /// @param newUid The uid of the new owneer. 00126 /// @param newGid The gid of the new group. 00127 /// @param followSymLink If set to true, symbolic links will be followed. 00128 virtual void setOwner(const std::string& path, uid_t newUid, gid_t newGid, 00129 bool followSymLink = true) throw (DmException); 00130 00131 /// Set the size of a file. 00132 /// @param path The file to modify. 00133 /// @param newSize The new file size. 00134 virtual void setSize(const std::string& path, 00135 size_t newSize) throw (DmException); 00136 00137 /// Set the checksum of a file. 00138 /// @param path The file to modify. 00139 /// @param csumtype The checksum type cc 00140 /// @param csumvalue The checksum value. 00141 virtual void setChecksum(const std::string& path, 00142 const std::string& csumtype, 00143 const std::string& csumvalue) throw (DmException); 00144 00145 /// Get the checksum of a file, eventually waiting for it to be calculated. 00146 /// @param path The file to query 00147 /// @param csumtype The checksum type (CS, AD or MD. We can also pass a long checksum name (e.g. checksum.adler32)). 00148 /// @param csumvalue The checksum value. 00149 /// @param forcerecalc Force recalculation of the checksum (may take long and throw EAGAIN) 00150 /// @param waitsecs Seconds to wait for a checksum to be calculated. Throws EAGAIN if timeouts. Set to 0 for blocking behavior. 00151 virtual void getChecksum(const std::string& path, 00152 const std::string& csumtype, 00153 std::string& csumvalue, 00154 const std::string& pfn, const bool forcerecalc = false, const int waitsecs = 0) throw (DmException); 00155 00156 /// Set the ACLs 00157 /// @param path The file to modify. 00158 /// @param acl The Access Control List. 00159 virtual void setAcl(const std::string& path, 00160 const Acl& acl) throw (DmException); 00161 00162 /// Set access and/or modification time. 00163 /// @param path The file path. 00164 /// @param buf A struct holding the new times. 00165 virtual void utime(const std::string& path, 00166 const struct utimbuf* buf) throw (DmException); 00167 00168 /// Get the comment associated with a file. 00169 /// @param path The file or directory. 00170 /// @return The associated comment. 00171 virtual std::string getComment(const std::string& path) throw (DmException); 00172 00173 /// Set the comment associated with a file. 00174 /// @param path The file or directory. 00175 /// @param comment The new comment. 00176 virtual void setComment(const std::string& path, 00177 const std::string& comment) throw (DmException); 00178 00179 /// Set GUID of a file. 00180 /// @param path The file. 00181 /// @param guid The new GUID. 00182 virtual void setGuid(const std::string& path, 00183 const std::string &guid) throw (DmException); 00184 00185 /// Update extended metadata on the catalog. 00186 /// @param path The file to update. 00187 /// @param attr The extended attributes struct. 00188 virtual void updateExtendedAttributes(const std::string& path, 00189 const Extensible& attr) throw (DmException); 00190 00191 /// Open a directory for reading. 00192 /// @param path The directory to open. 00193 /// @return A pointer to a handle that can be used for later calls. 00194 virtual Directory* openDir(const std::string& path) throw (DmException); 00195 00196 /// Close a directory opened previously. 00197 /// @param dir The directory handle as returned by NsInterface::openDir. 00198 virtual void closeDir(Directory* dir) throw (DmException); 00199 00200 /// Read next entry from a directory (simple read). 00201 /// @param dir The directory handle as returned by NsInterface::openDir. 00202 /// @return 0x00 on failure or end of directory. 00203 virtual struct dirent* readDir(Directory* dir) throw (DmException); 00204 00205 /// Read next entry from a directory (stat information added). 00206 /// @param dir The directory handle as returned by NsInterface::openDir. 00207 /// @return 0x00 on failure (and errno is set) or end of directory. 00208 virtual ExtendedStat* readDirx(Directory* dir) throw (DmException); 00209 00210 /// Create a new empty directory. 00211 /// @param path The path of the new directory. 00212 /// @param mode The creation mode. 00213 virtual void makeDir(const std::string& path, 00214 mode_t mode) throw (DmException); 00215 00216 /// Rename a file or directory. 00217 /// @param oldPath The old name. 00218 /// @param newPath The new name. 00219 virtual void rename(const std::string& oldPath, 00220 const std::string& newPath) throw (DmException); 00221 00222 /// Remove a directory. 00223 /// @param path The path of the directory to remove. 00224 virtual void removeDir(const std::string& path) throw (DmException); 00225 00226 /// Get a replica. 00227 /// @param rfn The replica file name. 00228 virtual Replica getReplicaByRFN(const std::string& rfn) throw (DmException); 00229 00230 /// Update a replica. 00231 /// @param replica The replica to modify. 00232 /// @return 0 on success, error code otherwise. 00233 virtual void updateReplica(const Replica& replica) throw (DmException); 00234 }; 00235 00236 /// Plug-ins must implement a concrete factory to be instantiated. 00237 class CatalogFactory: public virtual BaseFactory { 00238 public: 00239 /// Virtual destructor 00240 virtual ~CatalogFactory(); 00241 00242 protected: 00243 // Stack instance is allowed to instantiate catalogs 00244 friend class StackInstance; 00245 00246 /// Children of CatalogFactory are allowed to instantiate too (decorator) 00247 static Catalog* createCatalog(CatalogFactory* factory, 00248 PluginManager* pm) throw (DmException); 00249 00250 /// Instantiate a implementation of Catalog 00251 virtual Catalog* createCatalog(PluginManager* pm) throw (DmException); 00252 }; 00253 00254 }; 00255 00256 #endif // DMLITE_CPP_CATALOG_H