catalog.h

Go to the documentation of this file.
00001 /** @file   include/dmlite/c/catalog.h
00002  *  @brief  C wrapper for DMLite Catalog API.
00003  *  @author Alejandro Álvarez Ayllon <aalvarez@cern.ch>
00004  */
00005 #ifndef DMLITE_CATALOG_H
00006 #define DMLITE_CATALOG_H
00007 
00008 #include "dmlite.h"
00009 #include "inode.h"
00010 #include "utils.h"
00011 
00012 #ifdef  __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 typedef struct dmlite_dir dmlite_dir;
00017   
00018 /**
00019  * @brief         Changes the working dir.
00020  * @param context The DM context.
00021  * @param path    The new working dir.
00022  * @return        0 on success, error code otherwise.
00023  */
00024 int dmlite_chdir(dmlite_context* context, const char* path);
00025 
00026 /**
00027  * @brief         Gets the current working directory.
00028  * @param context The DM context.
00029  * @param buffer  If not NULL, the path will be stored here. <b>malloc</b> will be used otherwise.
00030  * @param size    The buffer size.
00031  * @return        A pointer to a string with the current working dir.
00032  */
00033 char* dmlite_getcwd(dmlite_context* context, char* buffer, size_t size);
00034 
00035 /**
00036  * @brief         Sets the file mode creation mask.
00037  * @param context The DM context.
00038  * @param mask    The new mask.
00039  * @return        The previous mask.
00040  */
00041 mode_t dmlite_umask(dmlite_context* context, mode_t mask);
00042 
00043 /**
00044  * @brief         Does a stat of a file or directory.
00045  * @param context The DM context.
00046  * @param path    The path.
00047  * @param buf     Where to put the retrieved information.
00048  * @return        0 on success, error code otherwise.
00049  */
00050 int dmlite_stat(dmlite_context* context, const char* path, struct stat* buf);
00051 
00052 /**
00053  * @brief         Does a stat of a file, directory, or symbolic link (does not follow).
00054  * @param context The DM context.
00055  * @param path    The path.
00056  * @param buf     Where to put the retrieved information.
00057  * @return        0 on success, error code otherwise.
00058  */
00059 int dmlite_statl(dmlite_context* context, const char* path, struct stat* buf);
00060 
00061 /**
00062  * @brief         Does an extended stat of a file, directory or symbolic link.
00063  * @param context The DM context.
00064  * @param path    The path.
00065  * @param buf     Where to put the retrieved information.
00066  * @return        0 on success, error code otherwise.
00067  */
00068 int dmlite_statx(dmlite_context* context, const char* path, dmlite_xstat* buf);
00069 
00070 /**
00071  * @brief            Adds a new replica to an entry.
00072  * @param context    The DM context.
00073  * @param replica    The replica to add.
00074  * @return           0 on success, error code otherwise.
00075  */
00076 int dmlite_addreplica(dmlite_context* context, const dmlite_replica* replica);
00077 
00078 /**
00079  * @brief         Deletes a replica.
00080  * @param context The DM context.
00081  * @param replica The replica to delete.
00082  * @return        0 on success, error code otherwise.
00083  */
00084 int dmlite_delreplica(dmlite_context* context, const dmlite_replica* replica);
00085 
00086 /**
00087  * @brief              Gets the replicas of a file.
00088  * @param context      The DM context.
00089  * @param path         The logical file name.
00090  * @param nReplicas    The number of entries will be put here.
00091  * @param fileReplicas An array with nEntries elements will be stored here. <b>Use dmlite_replicas_free to free it.</b>
00092  * @return             0 on success, error code otherwise.
00093  */
00094 int dmlite_getreplicas(dmlite_context* context, const char* path, unsigned *nReplicas,
00095                        dmlite_replica** fileReplicas);
00096 
00097 /**
00098  * @brief              Frees a replica list.
00099  * @param context      The DM context.
00100  * @param nReplicas    The number of replicas contained in the array.
00101  * @param fileReplicas The array to free.
00102  * @return             0 on success, error code otherwise.
00103  */
00104 int dmlite_replicas_free(dmlite_context* context,
00105                          unsigned nReplicas, dmlite_replica* fileReplicas);
00106 
00107 /**
00108  * @brief         Creates a symlink
00109  * @param context The DM context.
00110  * @param oldPath The old path.
00111  * @param newPath The new path.
00112  * @return        0 on success, error code otherwise.
00113  */
00114 int dmlite_symlink(dmlite_context* context,
00115                    const char* oldPath, const char* newPath);
00116 
00117 /**
00118  * @brief         Reads a symlink.
00119  * @param context The DM context.
00120  * @param path    The symlink file.
00121  * @param buf     Where to put the symlink target.
00122  * @param bufsize The size of the memory pointed by buf.
00123   * @return       0 on success, error code otherwise.
00124  */
00125 int dmlite_readlink(dmlite_context* context, const char* path,
00126                     char* buf, size_t bufsize);
00127 
00128 /**
00129  * @brief         Removes a file.
00130  * @param context The DM context.
00131  * @param path    The logical file name.
00132  * @return        0 on success, error code otherwise.
00133  */
00134 int dmlite_unlink(dmlite_context* context, const char* path);
00135 
00136 
00137 /**
00138  * @brief         Creates a file in the catalog (no replicas).
00139  * @param context The DM context.
00140  * @param path    The logical file name.
00141  * @param mode    The creation mode.
00142  * @return        0 on success, error code otherwise.
00143  */
00144 int dmlite_create(dmlite_context* context, const char* path, mode_t mode);
00145 
00146 /**
00147  * @brief         Changes the mode of a file or directory.
00148  * @param context The DM context.
00149  * @param path    The logical path.
00150  * @param mode    The new mode.
00151  * @return        0 on success, error code otherwise.
00152  */
00153 int dmlite_chmod(dmlite_context* context, const char* path, mode_t mode);
00154 
00155 /**
00156  * @brief         Changes the owner of a file or directory.
00157  * @param context The DM context.
00158  * @param path    The logical path.
00159  * @param newUid  The new owner.
00160  * @param newGid  The new group.
00161  * @return        0 on success, error code otherwise.
00162  */
00163 int dmlite_chown(dmlite_context* context, const char* path, uid_t newUid, gid_t newGid);
00164 
00165 /**
00166  * @brief         Changes the owner of a file, directory or symlink (does not follow).
00167  * @param context The DM context.
00168  * @param path    The logical path.
00169  * @param newUid  The new owner.
00170  * @param newGid  The new group.
00171  * @return        0 on success, error code otherwise.
00172  */
00173 int dmlite_lchown(dmlite_context* context, const char* path, uid_t newUid, gid_t newGid);
00174 
00175 /**
00176  * @brief          Changes the size of a file in the catalog.
00177  * @param context  The DM context.
00178  * @param path     The logical path.
00179  * @param filesize The new file size.
00180  * @return         0 on success, error code otherwise.
00181  */
00182 int dmlite_setfsize(dmlite_context* context, const char* path, uint64_t filesize);
00183 
00184 /**
00185  * @brief           Changes the size and checksum of a file in the catalog.
00186  * @param context   The DM context.
00187  * @param path      The logical path.
00188  * @param filesize  The new file size.
00189  * @param csumtype  The new checksum type (CS, AD or MD).
00190  * @param csumvalue The new checksum value.
00191  * @return          0 on success, error code otherwise.
00192  */
00193 int dmlite_setfsizec(dmlite_context* context, const char* path, uint64_t filesize,
00194                  const char* csumtype, const char* csumvalue);
00195 
00196 /**
00197  * @brief          Changes the ACL of a file.
00198  * @param context  The DM context.
00199  * @param path     The logical path.
00200  * @param nEntries The number of entries in the acl array.
00201  * @param acl      An ACL array.
00202  * @return         0 on success, error code otherwise.
00203  */
00204 int dmlite_setacl(dmlite_context* context, const char* path, unsigned nEntries, dmlite_aclentry* acl);
00205 
00206 /**
00207  * @brief         Changes access and/or modification time
00208  * @param context The DM context.
00209  * @param path    The file path.
00210  * @param buf     A struct holding the new times.
00211  * @return        0 on success, error code otherwise.
00212  */
00213 int dmlite_utime(dmlite_context* context, const char* path, const struct utimbuf* buf);
00214 
00215 /**
00216  * @brief         Gets the comment associated with a file.
00217  * @param context The DM context.
00218  * @param path    The logical path.
00219  * @param comment Where to put the retrieved comment. It must be at least of size COMMENT_MAX.
00220  * @param bufsize Size of the memory zone pointed by comment.
00221  * @return        0 on success, error code otherwise.
00222  */
00223 int dmlite_getcomment(dmlite_context* context, const char* path,
00224                       char* comment, size_t bufsize);
00225 
00226 /**
00227  * @brief         Sets the comment associated with a file.
00228  * @param context The DM context.
00229  * @param path    The logical path.
00230  * @param comment The comment to associate. '\\0' terminated string.
00231  * @return        0 on success, error code otherwise.
00232  */
00233 int dmlite_setcomment(dmlite_context* context, const char* path, const char* comment);
00234 
00235 /**
00236  * @brief         Sets the file Grid Unique Identifier.
00237  * @param context The DM context.
00238  * @param path    The logical path.
00239  * @param guid    The new GUID.
00240  * @return        0 on success, error code otherwise.
00241  */
00242 int dmlite_setguid(dmlite_context* context, const char* path, const char* guid);
00243 
00244 /**
00245  * @brief         Updates the file extended attributes.
00246  * @param context The DM context.
00247  * @param path    The logical path.
00248  * @param xattr   The new set of extended attributes.
00249  * @return        0 on success, error code otherwise.
00250  */
00251 int dmlite_update_xattr(dmlite_context* context, const char* path,
00252                         const dmlite_any_dict* xattr);
00253 
00254 /**
00255  * @brief           Gets the id of a group.
00256  * @param context   The DM context.
00257  * @param groupName The group name.
00258  * @param gid       Where to put the group ID.
00259  * @return          0 on success, error code otherwise.
00260  */
00261 int dmlite_getgrpbynam(dmlite_context* context, const char* groupName, gid_t* gid);
00262 
00263 /**
00264  * @brief          Get the user id.
00265  * @param context  The DM context.
00266  * @param userName The user name.
00267  * @param uid      Where to put the user ID.
00268  * @return         0 on success, error code otherwise.
00269  */
00270 int dmlite_getusrbynam(dmlite_context* context, const char* userName, uid_t* uid);
00271 
00272 /**
00273  * @brief         Opens a directory to read it later.
00274  * @param context The DM context.
00275  * @param path    The directory to open.
00276  * @return        A pointer to an internal structure, or NULL on failure.
00277  */
00278 dmlite_dir* dmlite_opendir(dmlite_context* context, const char* path);
00279 
00280 /**
00281  * @brief         Closes a directory and free the internal structures.
00282  * @param context The DM context.
00283  * @param dir     The pointer returned by dmlite_opendir.
00284  * @return        0 on success, error code otherwise.
00285  */
00286 int dmlite_closedir(dmlite_context* context, dmlite_dir* dir);
00287 
00288 /**
00289  * @brief         Reads an entry from a directory.
00290  * @param context The DM context.
00291  * @param dir     The pointer returned by dmlite_opendir.
00292  * @return        A pointer to a struct with the recovered data, or NULL on failure or end of directory. Do NOT free it.
00293   */
00294 struct dirent *dmlite_readdir(dmlite_context* context, dmlite_dir* dir);
00295 
00296 /**
00297  * @brief         Reads an entry from a directory (extended data).
00298  * @param context The DM context.
00299  * @param dir     The pointer returned by dmlite_opendir.
00300  * @return        A pointer to a struct with the recovered data, or NULL on failure or end of directory. Do NOT free it.
00301  */
00302 dmlite_xstat *dmlite_readdirx(dmlite_context* context, dmlite_dir* dir);
00303 
00304 /**
00305  * @brief         Creates a new directory.
00306  * @param context The DM context.
00307  * @param path    The directory for the new path. All the precedent folders must exist.
00308  * @param mode    Permissions to use for the creation.
00309  * @return        0 on success, error code otherwise.
00310  */
00311 int dmlite_mkdir(dmlite_context* context, const char* path, mode_t mode);
00312 
00313 /**
00314  * @brief         Renames a file, directory or symlink.
00315  * @param context The DM context.
00316  * @param oldPath The old name.
00317  * @param newPath The new name.
00318  * @return        0 on success, error code otherwise.
00319  */
00320 int dmlite_rename(dmlite_context* context, const char* oldPath, const char* newPath);
00321 
00322 /**
00323  * @brief         Deletes a directory. It must be empty.
00324  * @param context The DM context.
00325  * @param path    The directory to remove.
00326  * @return        0 on success, error code otherwise.
00327  */
00328 int dmlite_rmdir(dmlite_context* context, const char* path);
00329 
00330 /**
00331  * @brief         Gets a specific replica.
00332  * @param context The DM context.
00333  * @param rfn     The replica file name.
00334  * @param replica A buffer where the retrieved data will be put.
00335  * @return        0 on success, error code otherwise.
00336  */
00337 int dmlite_getreplica(dmlite_context* context, const char* rfn, dmlite_replica* replica);
00338 
00339 /**
00340  * @brief         Updates a replica.
00341  * @param context The DM context.
00342  * @param replica The replica to modify.
00343  * @return        0 on success, error code otherwise.
00344  */
00345 int dmlite_updatereplica(dmlite_context* context, const dmlite_replica* replica);
00346 
00347 #ifdef  __cplusplus
00348 }
00349 #endif
00350 
00351 #endif /* DMLITE_CATALOG_H */

Generated on 3 Mar 2013 for dmlite by  doxygen 1.4.7