inode.h

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

Generated on 3 Mar 2013 for dmlite by  doxygen 1.4.7