CernVM-FS
2.12.0
|
#include "libcvmfs.h"
#include <errno.h>
#include <inttypes.h>
#include <stddef.h>
#include <sys/stat.h>
#include <cassert>
#include <cstdlib>
#include <string>
#include "libcvmfs_int.h"
#include "statistics.h"
#include "util/logging.h"
#include "util/posix.h"
#include "util/smalloc.h"
#include "xattr.h"
Go to the source code of this file.
Macros | |
#define | _FILE_OFFSET_BITS 64 |
#define | __STDC_FORMAT_MACROS |
Functions | |
struct cvmfs_attr * | cvmfs_attr_init () |
void | cvmfs_attr_free (struct cvmfs_attr *attr) |
struct cvmfs_nc_attr * | cvmfs_nc_attr_init () |
void | cvmfs_nc_attr_free (struct cvmfs_nc_attr *nc_attr) |
static int | expand_path (const int depth, LibContext *ctx, char const *path, string *expanded_path) |
static int | expand_ppath (LibContext *ctx, const char *path, string *expanded_path) |
int | cvmfs_open (LibContext *ctx, const char *path) |
ssize_t | cvmfs_pread (LibContext *ctx, int fd, void *buf, size_t size, off_t off) |
int | cvmfs_close (LibContext *ctx, int fd) |
int | cvmfs_readlink (LibContext *ctx, const char *path, char *buf, size_t size) |
int | cvmfs_stat (LibContext *ctx, const char *path, struct stat *st) |
int | cvmfs_lstat (LibContext *ctx, const char *path, struct stat *st) |
int | cvmfs_stat_attr (LibContext *ctx, const char *path, struct cvmfs_attr *attr) |
int | cvmfs_listdir (LibContext *ctx, const char *path, char ***buf, size_t *buflen) |
int | cvmfs_listdir_contents (LibContext *ctx, const char *path, char ***buf, size_t *listlen, size_t *buflen) |
int | cvmfs_listdir_stat (LibContext *ctx, const char *path, struct cvmfs_stat_t **buf, size_t *listlen, size_t *buflen) |
int | cvmfs_stat_nc (LibContext *ctx, const char *path, struct cvmfs_nc_attr *nc_attr) |
int | cvmfs_list_nc (LibContext *ctx, const char *path, char ***buf, size_t *buflen) |
void | cvmfs_list_free (char **buf) |
void | cvmfs_enable_threaded (LibContext *ctx) |
cvmfs_errors | cvmfs_attach_repo_v2 (const char *fqrn, SimpleOptionsParser *opts, LibContext **ctx) |
void | cvmfs_adopt_options (cvmfs_context *ctx, SimpleOptionsParser *opts) |
void | cvmfs_detach_repo (LibContext *ctx) |
cvmfs_errors | cvmfs_init_v2 (SimpleOptionsParser *opts) |
void | cvmfs_fini () |
static void | libcvmfs_log_fn (const LogSource, const int, const char *msg) |
void | cvmfs_set_log_fn (void(*log_fn)(const char *msg)) |
char * | cvmfs_statistics_format (cvmfs_context *ctx) |
int | cvmfs_remount (LibContext *ctx) |
uint64_t | cvmfs_get_revision (LibContext *ctx) |
Variables | |
static void(* | ext_log_fn )(const char *msg) = NULL |
#define __STDC_FORMAT_MACROS |
Definition at line 11 of file libcvmfs.cc.
#define _FILE_OFFSET_BITS 64 |
This file is part of the CernVM File System.
libcvmfs provides an API for the CernVM-FS client. This is an alternative to FUSE for reading a remote CernVM-FS repository.
Definition at line 8 of file libcvmfs.cc.
void cvmfs_adopt_options | ( | cvmfs_context * | ctx, |
SimpleOptionsParser * | opts | ||
) |
Definition at line 509 of file libcvmfs.cc.
Referenced by libcvmfs_initialize().
cvmfs_errors cvmfs_attach_repo_v2 | ( | const char * | fqrn, |
SimpleOptionsParser * | opts, | ||
LibContext ** | ctx | ||
) |
Definition at line 489 of file libcvmfs.cc.
Referenced by libcvmfs_initialize().
void cvmfs_attr_free | ( | struct cvmfs_attr * | attr | ) |
Destroy the cvmfs_attr struct and frees the checksum, symlink, name, and xattrs.
Definition at line 53 of file libcvmfs.cc.
Referenced by libcvmfs_has_file(), shrinkwrap::Sync(), and shrinkwrap::updateStat().
struct cvmfs_attr* cvmfs_attr_init | ( | ) |
Create the cvmfs_attr struct which contains the same information as a stat, but also has pointers to the hash, symlink, and name.
Definition at line 39 of file libcvmfs.cc.
Referenced by libcvmfs_has_file(), shrinkwrap::Sync(), and shrinkwrap::updateStat().
int cvmfs_close | ( | cvmfs_context * | ctx, |
int | fd | ||
) |
Close a file previously opened with cvmfs_open().
[in] | fd,file | descriptor to close |
Definition at line 261 of file libcvmfs.cc.
Referenced by libcvmfs_do_fclose().
void cvmfs_detach_repo | ( | cvmfs_context * | ctx | ) |
Uninitialize a cvmfs remote repository and release all resources for it. Works with both cvmfs_attach_repo() and cvmfs_attach_repo_v2().
Definition at line 514 of file libcvmfs.cc.
Referenced by libcvmfs_finalize().
void cvmfs_enable_threaded | ( | LibContext * | ctx | ) |
Definition at line 483 of file libcvmfs.cc.
Referenced by libcvmfs_initialize().
void cvmfs_fini | ( | ) |
Shut down the CVMFS library and release all resources. The cvmfs_option_map object passed to cvmfs_init_v2 must be deleted afterwards by a call to cvmfs_options_fini().
Definition at line 531 of file libcvmfs.cc.
Referenced by libcvmfs_finalize().
uint64_t cvmfs_get_revision | ( | cvmfs_context * | ctx | ) |
Return the root file catalog revision
Definition at line 575 of file libcvmfs.cc.
cvmfs_errors cvmfs_init_v2 | ( | SimpleOptionsParser * | opts | ) |
Definition at line 519 of file libcvmfs.cc.
Referenced by libcvmfs_initialize().
void cvmfs_list_free | ( | char ** | buf | ) |
Free the items contained in list and then the list.
[in] | buf,pointer | to the list that was allocated. |
Definition at line 469 of file libcvmfs.cc.
Referenced by shrinkwrap::Sync().
int cvmfs_list_nc | ( | cvmfs_context * | ctx, |
const char * | path, | ||
char *** | buf, | ||
size_t * | buflen | ||
) |
Get list of nested catalog at path. The list contents includes the empty string for the base and each nested catalog needed to reach this location. It also contains the list of nested catalogs reachable directly from the nested catalog serving this location. If this is a transition point, the nested catalog at this location is used.
On return, the array will contain a NULL-terminated list of strings. The caller must free the strings and the array containing them. The array (*buf) may be NULL when this function is called.
[in] | path,path | of nested catalog (e.g. /dir, not /cvmfs/repo/dir) |
[out] | buf,pointer | to dynamically allocated NULL-terminated array of strings |
[in] | buflen,pointer | to variable containing size of array |
Definition at line 446 of file libcvmfs.cc.
int cvmfs_listdir | ( | cvmfs_context * | ctx, |
const char * | path, | ||
char *** | buf, | ||
size_t * | buflen | ||
) |
Get list of directory contents. The directory contents includes "." and "..".
On return, the array will contain a NULL-terminated list of strings. The caller must free the strings and the array containing them. The array (*buf) may be NULL when this function is called.
[in] | path,path | of directory (e.g. /dir, not /cvmfs/repo/dir) |
[out] | buf,pointer | to dynamically allocated NULL-terminated array of strings |
[in] | buflen,pointer | to variable containing size of array |
Definition at line 353 of file libcvmfs.cc.
int cvmfs_listdir_contents | ( | cvmfs_context * | ctx, |
const char * | path, | ||
char *** | buf, | ||
size_t * | listlen, | ||
size_t * | buflen | ||
) |
Get list of directory contents. The list does not include "." or "..".
On return, the array will contain a NULL-terminated list of strings. The caller must free the strings and the array containing them. The array (*buf) may be NULL when this function is called.
[in] | path,path | of directory (e.g. /dir, not /cvmfs/repo/dir) |
[out] | buf,pointer | to dynamically allocated NULL-terminated array of strings |
[in] | buflen,pointer | to variable containing size of array |
Definition at line 376 of file libcvmfs.cc.
Referenced by libcvmfs_list_dir().
int cvmfs_listdir_stat | ( | cvmfs_context * | ctx, |
const char * | path, | ||
struct cvmfs_stat_t ** | buf, | ||
size_t * | listlen, | ||
size_t * | buflen | ||
) |
Get list of directory contents' stat info. The list does not include "." or "..".
On return,
buf | will contain list of cvmfs_stat_t objects. The caller must free the cvmfs_stat_t::name and the array containing cvmfs_stat_t objects (*buf). The array (*buf) may be NULL when this function is called. | |
[in] | path,path | of directory (e.g. /dir, not /cvmfs/repo/dir) |
[out] | buf,pointer | to dynamically allocated array of cvmfs_stat_t |
[in] | buflen,pointer | to variable containing size of |
buf | ||
in/out] | listlen, pointer to number of entries in | |
buf. | Set | |
listlen | to 0 before to fill | |
buf | from index 0. |
Definition at line 399 of file libcvmfs.cc.
int cvmfs_lstat | ( | cvmfs_context * | ctx, |
const char * | path, | ||
struct stat * | st | ||
) |
Get information about a file. If the file is a symlink, return info about the link, not the file it points to.
[in] | path,path | of file (e.g. /dir/file, not /cvmfs/repo/dir/file) |
[out] | st,stat | buffer in which to write the result |
Definition at line 313 of file libcvmfs.cc.
void cvmfs_nc_attr_free | ( | struct cvmfs_nc_attr * | nc_attr | ) |
Frees the cvmfs_nc_attr struct passed, including freeing the mountpoint and hash.
[in] | nc_attr,pointer | the cvmfs_nc_attr to be destroyed |
Definition at line 73 of file libcvmfs.cc.
Referenced by libcvmfs_list_dir().
struct cvmfs_nc_attr* cvmfs_nc_attr_init | ( | ) |
Creates an empty cvmfs_nc_attr struct and returns the pointer to the user.
Definition at line 66 of file libcvmfs.cc.
Referenced by libcvmfs_list_dir().
int cvmfs_open | ( | cvmfs_context * | ctx, |
const char * | path | ||
) |
Open a file in the cvmfs cache.
[in] | path,path | to open (e.g. /dir/file, not /cvmfs/repo/dir/file) |
Definition at line 227 of file libcvmfs.cc.
ssize_t cvmfs_pread | ( | cvmfs_context * | ctx, |
int | fd, | ||
void * | buf, | ||
size_t | size, | ||
off_t | off | ||
) |
Read from a file descriptor returned by cvmfs_open(). File descriptors that have bit 30 set indicate chunked files.
Definition at line 245 of file libcvmfs.cc.
Referenced by libcvmfs_do_fread().
int cvmfs_readlink | ( | cvmfs_context * | ctx, |
const char * | path, | ||
char * | buf, | ||
size_t | size | ||
) |
Read a symlink from the catalog. Environment variables in the symlink that are of the form are expanded according to the process' environment variables. If the provided buffer is not long enough for the null-terminated value of the symlink, -1 is returned and errno is set to ERANGE.
[in] | path,path | of symlink (e.g. /dir/file, not /cvmfs/repo/dir/file) |
[out] | buf,buffer | in which to write the null-terminated value of the symlink |
[in] | size,size | of buffer |
Definition at line 272 of file libcvmfs.cc.
int cvmfs_remount | ( | cvmfs_context * | ctx | ) |
Load a new catalog if there is one.
Definition at line 569 of file libcvmfs.cc.
void cvmfs_set_log_fn | ( | void(*)(const char *msg) | log_fn | ) |
Send syslog and debug messages to log_fn instead. This may (and probably should) be called before any other routine. Setting this to NULL restores the default logging behavior.
Definition at line 550 of file libcvmfs.cc.
Referenced by libcvmfs_initialize().
int cvmfs_stat | ( | cvmfs_context * | ctx, |
const char * | path, | ||
struct stat * | st | ||
) |
Get information about a file. If the file is a symlink, return info about the file it points to, not the symlink itself.
[in] | path,path | of file (e.g. /dir/file, not /cvmfs/repo/dir/file) |
[out] | st,stat | buffer in which to write the result |
Definition at line 295 of file libcvmfs.cc.
int cvmfs_stat_attr | ( | cvmfs_context * | ctx, |
const char * | path, | ||
struct cvmfs_attr * | attr | ||
) |
Get the extended CVMFS information about a file. If the file is a symlink, return info about the link, not the file it points to.
[in] | path,path | of file (e.g. /dir/file, not /cvmfs/repo/dir/file) |
[out] | attr,cvmfs_attr | struct in which to write the result |
Definition at line 331 of file libcvmfs.cc.
Referenced by libcvmfs_get_stat(), and libcvmfs_has_file().
int cvmfs_stat_nc | ( | cvmfs_context * | ctx, |
const char * | path, | ||
struct cvmfs_nc_attr * | ncst | ||
) |
Get the CVMFS information about a nested catalog. The information returned pertains to the catalog that serves this path, if this path is a transition point, then the information is about this transition point.
[in] | path,path | of nested catalog (e.g. /dir, not /cvmfs/repo/dir) |
[out] | ncst,cvmfs_nc_attr | buffer in which to write the result |
Definition at line 424 of file libcvmfs.cc.
Referenced by libcvmfs_list_dir().
char* cvmfs_statistics_format | ( | cvmfs_context * | ctx | ) |
Get runtime statistics formatted as a string. The raw counters are also available via cvmfs_talk
when using the FUSE module. cvmfs_statistics()
allocates a new string, which the caller must free. Returns NULL if insufficient memory was available.
Definition at line 561 of file libcvmfs.cc.
|
static |
Expand symlinks in all levels of a path. Also, expand ".." and ".". This also has the side-effect of ensuring that cvmfs_getattr() is called on all parent paths, which is needed to ensure proper loading of nested catalogs before the child is accessed.
Definition at line 89 of file libcvmfs.cc.
Referenced by cvmfs_list_nc(), cvmfs_listdir(), cvmfs_listdir_contents(), cvmfs_listdir_stat(), cvmfs_open(), cvmfs_stat(), cvmfs_stat_nc(), and expand_ppath().
|
static |
Like expand_path(), but do not expand the final element of the path.
Definition at line 203 of file libcvmfs.cc.
Referenced by cvmfs_lstat(), cvmfs_readlink(), and cvmfs_stat_attr().
|
static |
Definition at line 539 of file libcvmfs.cc.
Referenced by cvmfs_set_log_fn().
|
static |
Definition at line 536 of file libcvmfs.cc.
Referenced by cvmfs_set_log_fn(), and libcvmfs_log_fn().