dmlite 0.6
catalog.h File Reference

C wrapper for DMLite Catalog API. More...

#include "dmlite.h"
#include "inode.h"
#include "utils.h"
Include dependency graph for catalog.h:

Go to the source code of this file.

Typedefs

typedef struct dmlite_dir dmlite_dir
 

Functions

int dmlite_chdir (dmlite_context *context, const char *path)
 Changes the working dir.
 
char * dmlite_getcwd (dmlite_context *context, char *buffer, size_t size)
 Gets the current working directory.
 
mode_t dmlite_umask (dmlite_context *context, mode_t mask)
 Sets the file mode creation mask.
 
int dmlite_stat (dmlite_context *context, const char *path, struct stat *buf)
 Does a stat of a file or directory.
 
int dmlite_statl (dmlite_context *context, const char *path, struct stat *buf)
 Does a stat of a file, directory, or symbolic link (does not follow).
 
int dmlite_statx (dmlite_context *context, const char *path, dmlite_xstat *buf)
 Does an extended stat of a file, directory or symbolic link.
 
int dmlite_rstatx (dmlite_context *context, const char *rfn, dmlite_xstat *buf)
 Does an extended stat of a logical file using an associated replica filename.
 
int dmlite_access (dmlite_context *context, const char *lfn, int mode)
 Checks wether the process would be allowed to read, write, or check existence.
 
int dmlite_accessr (dmlite_context *context, const char *rfn, int mode)
 Checks wether the process would be allowed to read, write, or check existence.
 
int dmlite_addreplica (dmlite_context *context, const dmlite_replica *replica)
 Adds a new replica to an entry.
 
int dmlite_delreplica (dmlite_context *context, const dmlite_replica *replica)
 Deletes a replica.
 
int dmlite_getreplicas (dmlite_context *context, const char *path, unsigned *nReplicas, dmlite_replica **fileReplicas)
 Gets the replicas of a file.
 
int dmlite_replicas_free (unsigned nReplicas, dmlite_replica *fileReplicas)
 Frees a replica list.
 
int dmlite_symlink (dmlite_context *context, const char *oldPath, const char *newPath)
 Creates a symlink.
 
int dmlite_readlink (dmlite_context *context, const char *path, char *buf, size_t bufsize)
 Reads a symlink.
 
int dmlite_unlink (dmlite_context *context, const char *path)
 Removes a file.
 
int dmlite_create (dmlite_context *context, const char *path, mode_t mode)
 Creates a file in the catalog (no replicas).
 
int dmlite_chmod (dmlite_context *context, const char *path, mode_t mode)
 Changes the mode of a file or directory.
 
int dmlite_chown (dmlite_context *context, const char *path, uid_t newUid, gid_t newGid)
 Changes the owner of a file or directory.
 
int dmlite_lchown (dmlite_context *context, const char *path, uid_t newUid, gid_t newGid)
 Changes the owner of a file, directory or symlink (does not follow).
 
int dmlite_setfsize (dmlite_context *context, const char *path, uint64_t filesize)
 Changes the size of a file in the catalog.
 
int dmlite_setfsizec (dmlite_context *context, const char *path, uint64_t filesize, const char *csumtype, const char *csumvalue)
 Changes the size and checksum of a file in the catalog.
 
int dmlite_getchecksum (dmlite_context *context, const char *path, const char *csumtype, char *csumvalue, const int maxcksumlen, const char *pfn, const int forcerecalc, const int waitsecs)
 Gets the checksum of a file in the catalog.
 
int dmlite_setacl (dmlite_context *context, const char *path, unsigned nEntries, dmlite_aclentry *acl)
 Changes the ACL of a file.
 
int dmlite_utime (dmlite_context *context, const char *path, const struct utimbuf *buf)
 Changes access and/or modification time.
 
int dmlite_getcomment (dmlite_context *context, const char *path, char *comment, size_t bufsize)
 Gets the comment associated with a file.
 
int dmlite_setcomment (dmlite_context *context, const char *path, const char *comment)
 Sets the comment associated with a file.
 
int dmlite_setguid (dmlite_context *context, const char *path, const char *guid)
 Sets the file Grid Unique Identifier.
 
int dmlite_update_xattr (dmlite_context *context, const char *path, const dmlite_any_dict *xattr)
 Updates the file extended attributes.
 
int dmlite_getgrpbynam (dmlite_context *context, const char *groupName, gid_t *gid)
 Gets the id of a group.
 
int dmlite_getusrbynam (dmlite_context *context, const char *userName, uid_t *uid)
 Get the user id.
 
dmlite_dirdmlite_opendir (dmlite_context *context, const char *path)
 Opens a directory to read it later.
 
int dmlite_closedir (dmlite_context *context, dmlite_dir *dir)
 Closes a directory and free the internal structures.
 
struct dirent * dmlite_readdir (dmlite_context *context, dmlite_dir *dir)
 Reads an entry from a directory.
 
dmlite_xstatdmlite_readdirx (dmlite_context *context, dmlite_dir *dir)
 Reads an entry from a directory (extended data).
 
int dmlite_mkdir (dmlite_context *context, const char *path, mode_t mode)
 Creates a new directory.
 
int dmlite_rename (dmlite_context *context, const char *oldPath, const char *newPath)
 Renames a file, directory or symlink.
 
int dmlite_rmdir (dmlite_context *context, const char *path)
 Deletes a directory. It must be empty.
 
int dmlite_getreplica_by_rfn (dmlite_context *context, const char *rfn, dmlite_replica *replica)
 Gets a specific replica.
 
int dmlite_updatereplica (dmlite_context *context, const dmlite_replica *replica)
 Updates a replica.
 

Detailed Description

C wrapper for DMLite Catalog API.

Author
Alejandro Álvarez Ayllon aalva.nosp@m.rez@.nosp@m.cern..nosp@m.ch

Typedef Documentation

◆ dmlite_dir

typedef struct dmlite_dir dmlite_dir

Function Documentation

◆ dmlite_access()

int dmlite_access ( dmlite_context * context,
const char * lfn,
int mode )

Checks wether the process would be allowed to read, write, or check existence.

Parameters
contextThe DM context.
lfnLogical filename.
modeA mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
Returns
0 on success, error code otherwise.

◆ dmlite_accessr()

int dmlite_accessr ( dmlite_context * context,
const char * rfn,
int mode )

Checks wether the process would be allowed to read, write, or check existence.

Parameters
contextThe DM context.
rfnReplica filename.
modeA mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
Returns
0 on success, error code otherwise.

◆ dmlite_addreplica()

int dmlite_addreplica ( dmlite_context * context,
const dmlite_replica * replica )

Adds a new replica to an entry.

Parameters
contextThe DM context.
replicaThe replica to add.
Returns
0 on success, error code otherwise.

◆ dmlite_chdir()

int dmlite_chdir ( dmlite_context * context,
const char * path )

Changes the working dir.

Parameters
contextThe DM context.
pathThe new working dir.
Returns
0 on success, error code otherwise.

◆ dmlite_chmod()

int dmlite_chmod ( dmlite_context * context,
const char * path,
mode_t mode )

Changes the mode of a file or directory.

Parameters
contextThe DM context.
pathThe logical path.
modeThe new mode.
Returns
0 on success, error code otherwise.

◆ dmlite_chown()

int dmlite_chown ( dmlite_context * context,
const char * path,
uid_t newUid,
gid_t newGid )

Changes the owner of a file or directory.

Parameters
contextThe DM context.
pathThe logical path.
newUidThe new owner.
newGidThe new group.
Returns
0 on success, error code otherwise.

◆ dmlite_closedir()

int dmlite_closedir ( dmlite_context * context,
dmlite_dir * dir )

Closes a directory and free the internal structures.

Parameters
contextThe DM context.
dirThe pointer returned by dmlite_opendir.
Returns
0 on success, error code otherwise.

◆ dmlite_create()

int dmlite_create ( dmlite_context * context,
const char * path,
mode_t mode )

Creates a file in the catalog (no replicas).

Parameters
contextThe DM context.
pathThe logical file name.
modeThe creation mode.
Returns
0 on success, error code otherwise.

◆ dmlite_delreplica()

int dmlite_delreplica ( dmlite_context * context,
const dmlite_replica * replica )

Deletes a replica.

Parameters
contextThe DM context.
replicaThe replica to delete.
Returns
0 on success, error code otherwise.

◆ dmlite_getchecksum()

int dmlite_getchecksum ( dmlite_context * context,
const char * path,
const char * csumtype,
char * csumvalue,
const int maxcksumlen,
const char * pfn,
const int forcerecalc,
const int waitsecs )

Gets the checksum of a file in the catalog.

Parameters
contextThe DM context.
pathThe logical path.
csumtypeThe wanted checksum type (CS, AD or MD. We can also pass a long checksum name (e.g. checksum.adler32))
csumvalueThe wanted checksum value will be written into this string. Make sure it has enough space.
maxcksumlenMax allowed length for a checksum, to avoid buffer overflows.
pfnOptional: the corresponding replica for which to calculate a checksum
forcerecalcTrue if nonzero. Force recalculation of the checksum (may take long and return EAGAIN)
waitsecsSeconds to wait for a checksum to be calculated. Returns EAGAIN if timeouts. Set to 0 for blocking behavior.
Returns
0 on success, error code otherwise.

◆ dmlite_getcomment()

int dmlite_getcomment ( dmlite_context * context,
const char * path,
char * comment,
size_t bufsize )

Gets the comment associated with a file.

Parameters
contextThe DM context.
pathThe logical path.
commentWhere to put the retrieved comment. It must be at least of size COMMENT_MAX.
bufsizeSize of the memory zone pointed by comment.
Returns
0 on success, error code otherwise.

◆ dmlite_getcwd()

char * dmlite_getcwd ( dmlite_context * context,
char * buffer,
size_t size )

Gets the current working directory.

Parameters
contextThe DM context.
bufferIf not NULL, the path will be stored here. malloc will be used otherwise.
sizeThe buffer size.
Returns
A pointer to a string with the current working dir.

◆ dmlite_getgrpbynam()

int dmlite_getgrpbynam ( dmlite_context * context,
const char * groupName,
gid_t * gid )

Gets the id of a group.

Parameters
contextThe DM context.
groupNameThe group name.
gidWhere to put the group ID.
Returns
0 on success, error code otherwise.

◆ dmlite_getreplica_by_rfn()

int dmlite_getreplica_by_rfn ( dmlite_context * context,
const char * rfn,
dmlite_replica * replica )

Gets a specific replica.

Parameters
contextThe DM context.
rfnThe replica file name.
replicaA buffer where the retrieved data will be put.
Returns
0 on success, error code otherwise.

◆ dmlite_getreplicas()

int dmlite_getreplicas ( dmlite_context * context,
const char * path,
unsigned * nReplicas,
dmlite_replica ** fileReplicas )

Gets the replicas of a file.

Parameters
contextThe DM context.
pathThe logical file name.
nReplicasThe number of entries will be put here.
fileReplicasAn array with nEntries elements will be stored here. Use dmlite_replicas_free to free it.
Returns
0 on success, error code otherwise.

◆ dmlite_getusrbynam()

int dmlite_getusrbynam ( dmlite_context * context,
const char * userName,
uid_t * uid )

Get the user id.

Parameters
contextThe DM context.
userNameThe user name.
uidWhere to put the user ID.
Returns
0 on success, error code otherwise.

◆ dmlite_lchown()

int dmlite_lchown ( dmlite_context * context,
const char * path,
uid_t newUid,
gid_t newGid )

Changes the owner of a file, directory or symlink (does not follow).

Parameters
contextThe DM context.
pathThe logical path.
newUidThe new owner.
newGidThe new group.
Returns
0 on success, error code otherwise.

◆ dmlite_mkdir()

int dmlite_mkdir ( dmlite_context * context,
const char * path,
mode_t mode )

Creates a new directory.

Parameters
contextThe DM context.
pathThe directory for the new path. All the precedent folders must exist.
modePermissions to use for the creation.
Returns
0 on success, error code otherwise.

◆ dmlite_opendir()

dmlite_dir * dmlite_opendir ( dmlite_context * context,
const char * path )

Opens a directory to read it later.

Parameters
contextThe DM context.
pathThe directory to open.
Returns
A pointer to an internal structure, or NULL on failure.

◆ dmlite_readdir()

struct dirent * dmlite_readdir ( dmlite_context * context,
dmlite_dir * dir )

Reads an entry from a directory.

Parameters
contextThe DM context.
dirThe pointer returned by dmlite_opendir.
Returns
A pointer to a struct with the recovered data. NULL on failure, or end of dir. If an error occurred, dm_errno(context) will be different than 0.
Note
The pointer is internally allocated. Do not free it.

◆ dmlite_readdirx()

dmlite_xstat * dmlite_readdirx ( dmlite_context * context,
dmlite_dir * dir )

Reads an entry from a directory (extended data).

Parameters
contextThe DM context.
dirThe pointer returned by dmlite_opendir.
Returns
A pointer to a struct with the recovered data. NULL on failure, or end of dir. If an error occurred, dm_errno(context) will be different than 0.
Note
The pointer is internally allocated. Do not free it.

◆ dmlite_readlink()

int dmlite_readlink ( dmlite_context * context,
const char * path,
char * buf,
size_t bufsize )

Reads a symlink.

Parameters
contextThe DM context.
pathThe symlink file.
bufWhere to put the symlink target.
bufsizeThe size of the memory pointed by buf.
Returns
0 on success, error code otherwise.

◆ dmlite_rename()

int dmlite_rename ( dmlite_context * context,
const char * oldPath,
const char * newPath )

Renames a file, directory or symlink.

Parameters
contextThe DM context.
oldPathThe old name.
newPathThe new name.
Returns
0 on success, error code otherwise.

◆ dmlite_replicas_free()

int dmlite_replicas_free ( unsigned nReplicas,
dmlite_replica * fileReplicas )

Frees a replica list.

Parameters
nReplicasThe number of replicas contained in the array.
fileReplicasThe array to free.
Returns
0 on success, error code otherwise.

◆ dmlite_rmdir()

int dmlite_rmdir ( dmlite_context * context,
const char * path )

Deletes a directory. It must be empty.

Parameters
contextThe DM context.
pathThe directory to remove.
Returns
0 on success, error code otherwise.

◆ dmlite_rstatx()

int dmlite_rstatx ( dmlite_context * context,
const char * rfn,
dmlite_xstat * buf )

Does an extended stat of a logical file using an associated replica filename.

Parameters
contextThe DM context.
rfnReplica filename.
bufWhere to put the retrieved information.
Returns
0 on success, error code otherwise.

◆ dmlite_setacl()

int dmlite_setacl ( dmlite_context * context,
const char * path,
unsigned nEntries,
dmlite_aclentry * acl )

Changes the ACL of a file.

Parameters
contextThe DM context.
pathThe logical path.
nEntriesThe number of entries in the acl array.
aclAn ACL array.
Returns
0 on success, error code otherwise.

◆ dmlite_setcomment()

int dmlite_setcomment ( dmlite_context * context,
const char * path,
const char * comment )

Sets the comment associated with a file.

Parameters
contextThe DM context.
pathThe logical path.
commentThe comment to associate. '\0' terminated string.
Returns
0 on success, error code otherwise.

◆ dmlite_setfsize()

int dmlite_setfsize ( dmlite_context * context,
const char * path,
uint64_t filesize )

Changes the size of a file in the catalog.

Parameters
contextThe DM context.
pathThe logical path.
filesizeThe new file size.
Returns
0 on success, error code otherwise.

◆ dmlite_setfsizec()

int dmlite_setfsizec ( dmlite_context * context,
const char * path,
uint64_t filesize,
const char * csumtype,
const char * csumvalue )

Changes the size and checksum of a file in the catalog.

Parameters
contextThe DM context.
pathThe logical path.
filesizeThe new file size.
csumtypeThe new checksum type (CS, AD or MD).
csumvalueThe new checksum value.
Returns
0 on success, error code otherwise.

◆ dmlite_setguid()

int dmlite_setguid ( dmlite_context * context,
const char * path,
const char * guid )

Sets the file Grid Unique Identifier.

Parameters
contextThe DM context.
pathThe logical path.
guidThe new GUID.
Returns
0 on success, error code otherwise.

◆ dmlite_stat()

int dmlite_stat ( dmlite_context * context,
const char * path,
struct stat * buf )

Does a stat of a file or directory.

Parameters
contextThe DM context.
pathThe path.
bufWhere to put the retrieved information.
Returns
0 on success, error code otherwise.

◆ dmlite_statl()

int dmlite_statl ( dmlite_context * context,
const char * path,
struct stat * buf )

Does a stat of a file, directory, or symbolic link (does not follow).

Parameters
contextThe DM context.
pathThe path.
bufWhere to put the retrieved information.
Returns
0 on success, error code otherwise.

◆ dmlite_statx()

int dmlite_statx ( dmlite_context * context,
const char * path,
dmlite_xstat * buf )

Does an extended stat of a file, directory or symbolic link.

Parameters
contextThe DM context.
pathThe path.
bufWhere to put the retrieved information.
Returns
0 on success, error code otherwise.

◆ dmlite_symlink()

int dmlite_symlink ( dmlite_context * context,
const char * oldPath,
const char * newPath )

Creates a symlink.

Parameters
contextThe DM context.
oldPathThe old path.
newPathThe new path.
Returns
0 on success, error code otherwise.

◆ dmlite_umask()

mode_t dmlite_umask ( dmlite_context * context,
mode_t mask )

Sets the file mode creation mask.

Parameters
contextThe DM context.
maskThe new mask.
Returns
The previous mask.

◆ dmlite_unlink()

int dmlite_unlink ( dmlite_context * context,
const char * path )

Removes a file.

Parameters
contextThe DM context.
pathThe logical file name.
Returns
0 on success, error code otherwise.

◆ dmlite_update_xattr()

int dmlite_update_xattr ( dmlite_context * context,
const char * path,
const dmlite_any_dict * xattr )

Updates the file extended attributes.

Parameters
contextThe DM context.
pathThe logical path.
xattrThe new set of extended attributes.
Returns
0 on success, error code otherwise.

◆ dmlite_updatereplica()

int dmlite_updatereplica ( dmlite_context * context,
const dmlite_replica * replica )

Updates a replica.

Parameters
contextThe DM context.
replicaThe replica to modify.
Returns
0 on success, error code otherwise.

◆ dmlite_utime()

int dmlite_utime ( dmlite_context * context,
const char * path,
const struct utimbuf * buf )

Changes access and/or modification time.

Parameters
contextThe DM context.
pathThe file path.
bufA struct holding the new times.
Returns
0 on success, error code otherwise.