CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
libcvmfs.cc File Reference
#include "cvmfs_config.h"
#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 "logging.h"
#include "smalloc.h"
#include "statistics.h"
#include "util/posix.h"
#include "xattr.h"
Include dependency graph for libcvmfs.cc:

Go to the source code of this file.

Macros

#define _FILE_OFFSET_BITS   64
 
#define __STDC_FORMAT_MACROS
 

Functions

struct cvmfs_attrcvmfs_attr_init ()
 
void cvmfs_attr_free (struct cvmfs_attr *attr)
 
struct cvmfs_nc_attrcvmfs_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
 

Macro Definition Documentation

#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.

Function Documentation

void cvmfs_adopt_options ( cvmfs_context ctx,
SimpleOptionsParser opts 
)

Definition at line 509 of file libcvmfs.cc.

Referenced by cvmfs_test_attach(), and libcvmfs_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

cvmfs_errors cvmfs_attach_repo_v2 ( const char *  fqrn,
SimpleOptionsParser opts,
LibContext **  ctx 
)

Definition at line 489 of file libcvmfs.cc.

Referenced by cvmfs_test_attach(), and libcvmfs_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

int cvmfs_close ( cvmfs_context ctx,
int  fd 
)

Close a file previously opened with cvmfs_open().

Parameters
[in]fd,filedescriptor to close
Returns
0 on success, -1 on failure (sets errno)

Definition at line 261 of file libcvmfs.cc.

Referenced by cvmfs_test_cat(), and libcvmfs_do_fclose().

Here is the call graph for this function:

Here is the caller graph for this function:

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 cvmfs_test_detach(), and libcvmfs_finalize().

Here is the caller graph for this function:

void cvmfs_enable_threaded ( LibContext ctx)

Definition at line 483 of file libcvmfs.cc.

Referenced by libcvmfs_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

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(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t cvmfs_get_revision ( cvmfs_context ctx)

Return the root file catalog revision

Definition at line 575 of file libcvmfs.cc.

Here is the call graph for this function:

cvmfs_errors cvmfs_init_v2 ( SimpleOptionsParser opts)

Definition at line 519 of file libcvmfs.cc.

Referenced by libcvmfs_initialize(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

void cvmfs_list_free ( char **  buf)

Free the items contained in list and then the list.

Parameters
[in]buf,pointerto the list that was allocated.

Definition at line 469 of file libcvmfs.cc.

Referenced by shrinkwrap::Sync().

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof nested catalog (e.g. /dir, not /cvmfs/repo/dir)
[out]buf,pointerto dynamically allocated NULL-terminated array of strings
[in]buflen,pointerto variable containing size of array
Returns
0 on success, -1 on failure (sets errno)

Definition at line 446 of file libcvmfs.cc.

Here is the call graph for this function:

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.

Parameters
[in]path,pathof directory (e.g. /dir, not /cvmfs/repo/dir)
[out]buf,pointerto dynamically allocated NULL-terminated array of strings
[in]buflen,pointerto variable containing size of array
Returns
0 on success, -1 on failure (sets errno)

Definition at line 353 of file libcvmfs.cc.

Referenced by cvmfs_test_list().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof directory (e.g. /dir, not /cvmfs/repo/dir)
[out]buf,pointerto dynamically allocated NULL-terminated array of strings
[in]buflen,pointerto variable containing size of array
Returns
0 on success, -1 on failure (sets errno)

Definition at line 376 of file libcvmfs.cc.

Referenced by libcvmfs_list_dir().

Here is the call graph for this function:

Here is the caller graph for this function:

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,

Parameters
bufwill 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,pathof directory (e.g. /dir, not /cvmfs/repo/dir)
[out]buf,pointerto dynamically allocated array of cvmfs_stat_t
[in]buflen,pointerto variable containing size of
buf
in/out]listlen, pointer to number of entries in
buf.Set
listlento 0 before to fill
buffrom index 0.
Returns
0 on success, -1 on failure (sets errno)

Definition at line 399 of file libcvmfs.cc.

Here is the call graph for this function:

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.

Parameters
[in]path,pathof file (e.g. /dir/file, not /cvmfs/repo/dir/file)
[out]st,statbuffer in which to write the result
Returns
0 on success, -1 on failure (sets errno)

Definition at line 313 of file libcvmfs.cc.

Here is the call graph for this function:

void cvmfs_nc_attr_free ( struct cvmfs_nc_attr nc_attr)

Frees the cvmfs_nc_attr struct passed, including freeing the mountpoint and hash.

Parameters
[in]nc_attr,pointerthe cvmfs_nc_attr to be destroyed

Definition at line 73 of file libcvmfs.cc.

Referenced by libcvmfs_list_dir().

Here is the caller graph for this function:

struct cvmfs_nc_attr* cvmfs_nc_attr_init ( )

Creates an empty cvmfs_nc_attr struct and returns the pointer to the user.

Returns
pointer to newly created cvmfs_nc_attr struct

Definition at line 66 of file libcvmfs.cc.

Referenced by libcvmfs_list_dir().

Here is the caller graph for this function:

int cvmfs_open ( cvmfs_context ctx,
const char *  path 
)

Open a file in the cvmfs cache.

Parameters
[in]path,pathto open (e.g. /dir/file, not /cvmfs/repo/dir/file)
Returns
read-only file descriptor, -1 on failure (sets errno)

Definition at line 227 of file libcvmfs.cc.

Here is the call graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof symlink (e.g. /dir/file, not /cvmfs/repo/dir/file)
[out]buf,bufferin which to write the null-terminated value of the symlink
[in]size,sizeof buffer
Returns
0 on success, -1 on failure (sets errno)

Definition at line 272 of file libcvmfs.cc.

Here is the call graph for this function:

int cvmfs_remount ( cvmfs_context ctx)

Load a new catalog if there is one.

Returns
0 on success (up to date or new catalog loaded), -1 otherwise

Definition at line 569 of file libcvmfs.cc.

Here is the call graph for this function:

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(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof file (e.g. /dir/file, not /cvmfs/repo/dir/file)
[out]st,statbuffer in which to write the result
Returns
0 on success, -1 on failure (sets errno)

Definition at line 295 of file libcvmfs.cc.

Referenced by cvmfs_test_list().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof file (e.g. /dir/file, not /cvmfs/repo/dir/file)
[out]attr,cvmfs_attrstruct in which to write the result
Returns
0 on success, -1 on failure

Definition at line 331 of file libcvmfs.cc.

Referenced by libcvmfs_get_stat(), and libcvmfs_has_file().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]path,pathof nested catalog (e.g. /dir, not /cvmfs/repo/dir)
[out]ncst,cvmfs_nc_attrbuffer in which to write the result
Returns
0 on success, -1 on failure

Definition at line 424 of file libcvmfs.cc.

Referenced by libcvmfs_list_dir().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the call graph for this function:

static int expand_path ( const int  depth,
LibContext ctx,
char const *  path,
string *  expanded_path 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static int expand_ppath ( LibContext ctx,
const char *  path,
string *  expanded_path 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

static void libcvmfs_log_fn ( const LogSource  ,
const int  ,
const char *  msg 
)
static

Definition at line 539 of file libcvmfs.cc.

Referenced by cvmfs_set_log_fn().

Here is the caller graph for this function:

Variable Documentation

void(* ext_log_fn)(const char *msg) = NULL
static

Definition at line 536 of file libcvmfs.cc.

Referenced by cvmfs_set_log_fn(), and libcvmfs_log_fn().