CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
libcvmfs.h
Go to the documentation of this file.
1 
15 #ifndef CVMFS_LIBCVMFS_H_
16 #define CVMFS_LIBCVMFS_H_
17 
18 #define LIBCVMFS_VERSION 2
19 #define LIBCVMFS_VERSION_MAJOR LIBCVMFS_VERSION
20 #define LIBCVMFS_VERSION_MINOR 10
21 // Revision Changelog
22 // 13: revision introduced
23 // 14: fix expand_path for absolute paths, add mountpoint to cvmfs_context
24 // 15: remove counting of open file descriptors
25 // 16: remove unnecessary free
26 // 17: apply new classes around the cache manager
27 // 18: add cvmfs_pread and support for chunked files
28 // 19: CernVM-FS 2.2.0
29 // 20: fix reading of chunked files
30 // 21: CernVM-FS 2.2.3
31 // 22: CernVM-FS 2.3.0
32 // 23: update initialization code
33 // 24: add LIBCVMFS_ERR_REVISION_BLACKLISTED
34 // 25: CernVM-FS 2.4.0
35 // 26: CernVM-FS 2.5.0
36 // 27: Add cvmfs_options_init_v2
37 // 28: CernVM-FS 2.6.0
38 // 29: CernVM-FS 2.8
39 // * Add cvmfs_options_parse_default
40 // * Add cvmfs_listdir_stat
41 // * Add catalog counters to struct cvmfs_nc_attr
42 // 30: CernVM-FS 2.8
43 // * Implement cvmfs_remount()
44 // * Add cvmfs_get_revision()
45 #define LIBCVMFS_REVISION 30
46 
47 #include <stdint.h>
48 #include <sys/stat.h>
49 #include <unistd.h>
50 
51 // Legacy error codes
52 #define LIBCVMFS_FAIL_OK 0
53 #define LIBCVMFS_FAIL_NOFILES -1
54 #define LIBCVMFS_FAIL_MKCACHE -2
55 #define LIBCVMFS_FAIL_OPENCACHE -3
56 #define LIBCVMFS_FAIL_LOCKFILE -4
57 #define LIBCVMFS_FAIL_INITCACHE -5
58 #define LIBCVMFS_FAIL_INITQUOTA -6
59 #define LIBCVMFS_FAIL_BADOPT -7
60 
61 
62 #ifdef __cplusplus
63 extern "C" {
64 // Map C++ clases to their C interface names
65 typedef class LibContext cvmfs_context;
66 typedef class SimpleOptionsParser cvmfs_option_map;
67 #else
68 typedef struct LibContext cvmfs_context;
69 typedef struct OptionsManager cvmfs_option_map;
70 #endif
71 
76 typedef enum {
81  LIBCVMFS_ERR_MOUNT, // unused in the library
82  LIBCVMFS_ERR_LOADER_TALK, // unused in the library
83  LIBCVMFS_ERR_FUSE_LOOP, // unused in the library
84  LIBCVMFS_ERR_LOAD_LIBRARY, // unused in the library
87  LIBCVMFS_ERR_PEERS, // unused
90  LIBCVMFS_ERR_MONITOR, // unused in the library
91  LIBCVMFS_ERR_TALK, // unused in the library
94  LIBCVMFS_ERR_MAINTENANCE_MODE, // unused in the library
95  LIBCVMFS_ERR_SAVE_STATE, // unused in the library
96  LIBCVMFS_ERR_RESTORE_STATE, // unused in the library
97  LIBCVMFS_ERR_OTHER_MOUNT, // unused in the library
98  LIBCVMFS_ERR_DOUBLE_MOUNT, // unused in the library
103 } cvmfs_errors;
104 
115  char *mountpoint;
116  char *hash;
117  uint64_t size;
118 
119  // Catalog counters
120  uint64_t ctr_regular;
121  uint64_t ctr_symlink;
122  uint64_t ctr_special;
123  uint64_t ctr_dir;
124  uint64_t ctr_nested;
125  uint64_t ctr_chunked;
126  uint64_t ctr_chunks;
127  uint64_t ctr_file_size;
129  uint64_t ctr_xattr;
130  uint64_t ctr_external;
132 };
133 
140 
146 void cvmfs_nc_attr_free(struct cvmfs_nc_attr *nc_attr);
147 
148 struct cvmfs_attr {
149  /* Struct definition information */
150  unsigned version;
151  uint64_t size;
152 
153  /* Contents of stat, mapped from DirectoryEntry */
154  dev_t st_dev;
155  ino_t st_ino;
156  mode_t st_mode;
157  nlink_t st_nlink;
158  uid_t st_uid;
159  gid_t st_gid;
160  dev_t st_rdev;
161  off_t st_size;
162  time_t mtime;
163 
164  /* CVMFS related content */
167  /* This information is allocated and should be freed */
168  // For chunked files without bulk hash: hash of chunk hashes
169  char * cvm_checksum;
170  char * cvm_symlink;
171  char * cvm_parent;
172  char * cvm_name;
173  void * cvm_xattrs;
174 };
175 
176 
180 struct cvmfs_stat_t {
181  // name of the object, owned by the struct (needs to be freed)
182  char * name;
183  struct stat info;
184 };
185 
191 struct cvmfs_attr* cvmfs_attr_init();
192 
198 void cvmfs_attr_free(struct cvmfs_attr *attr);
199 
205 void cvmfs_set_log_fn( void (*log_fn)(const char *msg) );
206 
213 char *cvmfs_statistics_format(cvmfs_context *ctx);
214 
218 cvmfs_option_map *cvmfs_options_init();
223 cvmfs_option_map *cvmfs_options_init_v2(int taint_environ);
224 
225 
226 void cvmfs_enable_threaded(cvmfs_context *ctx);
227 
233 cvmfs_option_map *cvmfs_options_init_legacy(const char *legacy_options);
239 cvmfs_option_map *cvmfs_options_clone(cvmfs_option_map *opts);
246 cvmfs_option_map *cvmfs_options_clone_legacy(cvmfs_option_map *opts,
247  const char *legacy_options);
252 void cvmfs_options_fini(cvmfs_option_map *opts);
257 void cvmfs_options_set(cvmfs_option_map *opts,
258  const char *key, const char *value);
263 int cvmfs_options_parse(cvmfs_option_map *opts, const char *path);
268 void cvmfs_options_parse_default(cvmfs_option_map *opts, const char *fqrn);
273 void cvmfs_options_unset(cvmfs_option_map *opts, const char *key);
278 char *cvmfs_options_get(cvmfs_option_map *opts, const char *key);
283 char *cvmfs_options_dump(cvmfs_option_map *opts);
287 void cvmfs_options_free(char *value);
288 
289 
297 int cvmfs_init(char const *options);
298 
299 
304 cvmfs_errors cvmfs_init_v2(cvmfs_option_map *opts);
305 
306 
312 void cvmfs_fini();
313 
320 cvmfs_context* cvmfs_attach_repo(char const *options);
321 
331 cvmfs_errors cvmfs_attach_repo_v2(const char *fqrn, cvmfs_option_map *opts,
332  cvmfs_context **ctx);
333 
338 void cvmfs_adopt_options(cvmfs_context *ctx, cvmfs_option_map *opts);
339 
340 
345 void cvmfs_detach_repo(cvmfs_context *ctx);
346 
347 
352 int cvmfs_remount(cvmfs_context *ctx);
353 
354 
361 int cvmfs_open(cvmfs_context *ctx, const char *path);
362 
363 
368 ssize_t cvmfs_pread(cvmfs_context *ctx,
369  int fd, void *buf, size_t size, off_t off);
370 
377 int cvmfs_close(cvmfs_context *ctx, int fd);
378 
390 int cvmfs_readlink(cvmfs_context *ctx,
391  const char *path,
392  char *buf,
393  size_t size);
394 
403 int cvmfs_stat(cvmfs_context *ctx, const char *path, struct stat *st);
404 
413 int cvmfs_lstat(cvmfs_context *ctx, const char *path, struct stat *st);
414 
423 int cvmfs_stat_attr(
424  cvmfs_context *ctx,
425  const char *path,
426  struct cvmfs_attr *attr);
427 
442 int cvmfs_listdir(
443  cvmfs_context *ctx,
444  const char *path,
445  char ***buf,
446  size_t *buflen);
447 
462  cvmfs_context *ctx,
463  const char *path,
464  char ***buf,
465  size_t *listlen,
466  size_t *buflen);
467 
485  cvmfs_context *ctx,
486  const char *path,
487  struct cvmfs_stat_t **buf,
488  size_t *listlen,
489  size_t *buflen);
490 
501 int cvmfs_stat_nc(
502  cvmfs_context *ctx,
503  const char *path,
504  struct cvmfs_nc_attr *ncst);
505 
523 int cvmfs_list_nc(
524  cvmfs_context *ctx,
525  const char *path,
526  char ***buf,
527  size_t *buflen);
528 
529 
534 void cvmfs_list_free(char **buf);
535 
539 uint64_t cvmfs_get_revision(cvmfs_context *ctx);
540 
541 #ifdef __cplusplus
542 }
543 #endif
544 
545 #endif // CVMFS_LIBCVMFS_H_
int cvmfs_options_parse(cvmfs_option_map *opts, const char *path)
nlink_t st_nlink
Definition: libcvmfs.h:157
char * cvm_symlink
Definition: libcvmfs.h:170
int cvmfs_list_nc(LibContext *ctx, const char *path, char ***buf, size_t *buflen)
Definition: libcvmfs.cc:446
void cvmfs_options_parse_default(cvmfs_option_map *opts, const char *fqrn)
struct cvmcache_context * ctx
void cvmfs_detach_repo(LibContext *ctx)
Definition: libcvmfs.cc:514
uint64_t ctr_external_file_size
Definition: libcvmfs.h:131
char * cvm_name
Definition: libcvmfs.h:172
char * mountpoint
Definition: libcvmfs.h:115
int cvmfs_listdir_contents(LibContext *ctx, const char *path, char ***buf, size_t *listlen, size_t *buflen)
Definition: libcvmfs.cc:376
void cvmfs_fini()
Definition: libcvmfs.cc:531
void cvmfs_attr_free(struct cvmfs_attr *attr)
Definition: libcvmfs.cc:53
struct cvmfs_nc_attr * cvmfs_nc_attr_init()
Definition: libcvmfs.cc:66
cvmfs_context * cvmfs_attach_repo(char const *options)
cvmfs_errors cvmfs_init_v2(SimpleOptionsParser *opts)
Definition: libcvmfs.cc:519
cvmfs_option_map * cvmfs_options_clone(cvmfs_option_map *opts)
int cvmfs_stat_attr(LibContext *ctx, const char *path, struct cvmfs_attr *attr)
Definition: libcvmfs.cc:331
dev_t st_dev
Definition: libcvmfs.h:154
cvmfs_option_map * cvmfs_options_init()
uint64_t ctr_external
Definition: libcvmfs.h:130
int cvmfs_stat_nc(LibContext *ctx, const char *path, struct cvmfs_nc_attr *nc_attr)
Definition: libcvmfs.cc:424
char * cvm_parent
Definition: libcvmfs.h:171
void cvmfs_options_set(cvmfs_option_map *opts, const char *key, const char *value)
uint64_t ctr_xattr
Definition: libcvmfs.h:129
char * cvmfs_statistics_format(cvmfs_context *ctx)
Definition: libcvmfs.cc:561
static void cvmfs_init(void *userdata, struct fuse_conn_info *conn)
Definition: cvmfs.cc:1536
uint64_t cvmfs_get_revision(LibContext *ctx)
Definition: libcvmfs.cc:575
char * cvm_checksum
Definition: libcvmfs.h:169
char * hash
Definition: libcvmfs.h:116
uint64_t ctr_regular
Definition: libcvmfs.h:120
void cvmfs_list_free(char **buf)
Definition: libcvmfs.cc:469
int cvmfs_listdir_stat(LibContext *ctx, const char *path, struct cvmfs_stat_t **buf, size_t *listlen, size_t *buflen)
Definition: libcvmfs.cc:399
void cvmfs_enable_threaded(LibContext *ctx)
Definition: libcvmfs.cc:483
void cvmfs_options_fini(cvmfs_option_map *opts)
void * cvm_xattrs
Definition: libcvmfs.h:173
int cvmfs_stat(LibContext *ctx, const char *path, struct stat *st)
Definition: libcvmfs.cc:295
cvmfs_errors cvmfs_attach_repo_v2(const char *fqrn, SimpleOptionsParser *opts, LibContext **ctx)
Definition: libcvmfs.cc:489
time_t mtime
Definition: libcvmfs.h:162
gid_t st_gid
Definition: libcvmfs.h:159
char * cvmfs_options_get(cvmfs_option_map *opts, const char *key)
static void cvmfs_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:863
uint64_t ctr_chunked_size
Definition: libcvmfs.h:128
int cvmfs_lstat(LibContext *ctx, const char *path, struct stat *st)
Definition: libcvmfs.cc:313
off_t st_size
Definition: libcvmfs.h:161
int cvm_is_hash_artificial
Definition: libcvmfs.h:166
int cvmfs_listdir(LibContext *ctx, const char *path, char ***buf, size_t *buflen)
Definition: libcvmfs.cc:353
char * name
Definition: libcvmfs.h:182
char * cvmfs_options_dump(cvmfs_option_map *opts)
cvmfs_option_map * cvmfs_options_init_legacy(const char *legacy_options)
void cvmfs_nc_attr_free(struct cvmfs_nc_attr *nc_attr)
Definition: libcvmfs.cc:73
cvmfs_option_map * cvmfs_options_init_v2(int taint_environ)
static void cvmfs_readlink(fuse_req_t req, fuse_ino_t ino)
Definition: cvmfs.cc:595
uint64_t ctr_chunked
Definition: libcvmfs.h:125
void cvmfs_options_free(char *value)
void cvmfs_options_unset(cvmfs_option_map *opts, const char *key)
cvmfs_option_map * cvmfs_options_clone_legacy(cvmfs_option_map *opts, const char *legacy_options)
ssize_t cvmfs_pread(LibContext *ctx, int fd, void *buf, size_t size, off_t off)
Definition: libcvmfs.cc:245
ino_t st_ino
Definition: libcvmfs.h:155
uint64_t ctr_symlink
Definition: libcvmfs.h:121
uint64_t size
Definition: libcvmfs.h:117
uint64_t ctr_chunks
Definition: libcvmfs.h:126
unsigned version
Definition: libcvmfs.h:150
uint64_t ctr_file_size
Definition: libcvmfs.h:127
uint64_t size
Definition: libcvmfs.h:151
uid_t st_uid
Definition: libcvmfs.h:158
uint64_t ctr_dir
Definition: libcvmfs.h:123
struct stat info
Definition: libcvmfs.h:183
dev_t st_rdev
Definition: libcvmfs.h:160
int cvmfs_close(LibContext *ctx, int fd)
Definition: libcvmfs.cc:261
int cvm_nchunks
Definition: libcvmfs.h:165
uint64_t ctr_special
Definition: libcvmfs.h:122
int cvmfs_remount(LibContext *ctx)
Definition: libcvmfs.cc:569
static void size_t size
Definition: smalloc.h:47
struct cvmfs_attr * cvmfs_attr_init()
Definition: libcvmfs.cc:39
void cvmfs_set_log_fn(void(*log_fn)(const char *msg))
Definition: libcvmfs.cc:550
void cvmfs_adopt_options(cvmfs_context *ctx, SimpleOptionsParser *opts)
Definition: libcvmfs.cc:509
mode_t st_mode
Definition: libcvmfs.h:156
cvmfs_errors
Definition: libcvmfs.h:76
uint64_t ctr_nested
Definition: libcvmfs.h:124