CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface.cc
Go to the documentation of this file.
1 
4 #include "interface.h"
5 
6 #include <dirent.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <utime.h>
13 
14 #include <cstring>
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 #include "crypto/hash.h"
20 #include "garbage_collector.h"
21 #include "helpers.h"
22 #include "libcvmfs.h"
24 #include "shrinkwrap/util.h"
25 #include "util/logging.h"
26 #include "util/posix.h"
27 #include "util/smalloc.h"
28 #include "util/string.h"
29 #include "xattr.h"
30 
32  std::string path;
33  FILE *fd;
34  struct utimbuf mtimes;
36 };
37 
38 /*
39  * BASIC FS OPERATIONS
40  */
41 void posix_list_dir(struct fs_traversal_context *ctx, const char *dir,
42  char ***buf, size_t *len);
43 
45  const char *path, struct cvmfs_attr *stat_result, bool get_hash);
46 
48  const char *path, const struct cvmfs_attr *stat_info);
49 
51  const struct cvmfs_attr *stat);
52 
54  const char *ident);
55 
57  const char *path);
58 
60  const char *path);
61 
63  const char *path, const char *identifier);
64 
65 int posix_do_mkdir(struct fs_traversal_context *ctx, const char *path,
66  const struct cvmfs_attr *stat_info);
67 
68 int posix_do_symlink(struct fs_traversal_context *ctx, const char *src,
69  const char *dest, const struct cvmfs_attr *stat_info);
70 
72  const struct cvmfs_attr *stat_info);
73 
75  const struct cvmfs_attr *stat_info);
76 
77 /*
78  * FILE OPERATIONS
79  */
80 
82  const char *identifier);
83 
84 int posix_do_fopen(void *file_ctx, fs_open_type op_mode);
85 
86 int posix_do_fclose(void *file_ctx);
87 
88 int posix_do_fread(void *file_ctx, char *buff, size_t len, size_t *read_len);
89 
90 int posix_do_fwrite(void *file_ctx, const char *buff, size_t len);
91 
92 void posix_do_ffree(void *file_ctx);
93 
94 /*
95  * GARBAGE COLLECTION
96  */
97 
99 
100 
101 /*
102  * ARCHIVE PROVENANCE INFORMATION
103  */
105  std::string config_name,
106  std::string prov_name
107 );
108 
110  struct fs_traversal_context *ctx,
111  const char *info_file
112 );
113 
115  struct fs_traversal_context *src,
116  struct fs_traversal_context *dest);
117 
118 /*
119  * INITIALIZATION
120  */
121 
123  const char *repo,
124  const char *base,
125  const char *data,
126  const char *config,
127  int num_threads);
128 
130 
132  struct fs_traversal *result = new struct fs_traversal;
133  result->initialize = posix_initialize;
134  result->finalize = posix_finalize;
136  result->list_dir = posix_list_dir;
137  result->get_stat = posix_get_stat;
139  result->set_meta = posix_set_meta;
140  result->has_file = posix_has_file;
142  result->do_link = posix_do_link;
143  result->do_unlink = posix_do_unlink;
144  result->do_mkdir = posix_do_mkdir;
145  result->do_rmdir = posix_do_rmdir;
146  result->touch = posix_touch;
147  result->get_handle = posix_get_handle;
148  result->do_symlink = posix_do_symlink;
150 
151  result->do_fopen = posix_do_fopen;
152  result->do_fclose = posix_do_fclose;
153  result->do_fread = posix_do_fread;
154  result->do_fwrite = posix_do_fwrite;
155  result->do_ffree = posix_do_ffree;
156 
157  return result;
158 }
159 
160 // Utility function
162  const char *path) {
163  std::string complete_path = BuildPath(ctx, path);
164  std::string dirname = GetParentPath(complete_path);
165  if (!DirectoryExists(dirname)) {
166  // Directory doesn't exist
167  errno = ENOENT;
168  return -1;
169  }
170  if (FileExists(complete_path) || SymlinkExists(complete_path)) {
171  // Unlink file if existing
172  int res = posix_do_unlink(ctx, path);
173  if (res != 0) return -1;
174  }
175  if (DirectoryExists(complete_path)) {
176  struct dirent *de;
177  DIR *dr = opendir(complete_path.c_str());
178  while ((de = readdir(dr)) != NULL) {
179  if (strcmp(de->d_name, ".") != 0
180  && strcmp(de->d_name, "..") != 0) {
181  std::string cur_path = std::string(path) + "/" + de->d_name;
182  if (posix_cleanup_path(ctx, cur_path.c_str()) != 0) {
183  return -1;
184  }
185  }
186  }
187  int res = closedir(dr);
188  res |= posix_do_rmdir(ctx, path);
189  if (res != 0) return -1;
190  }
191  return 0;
192 }
193 
199  const char *dir,
200  char ***buf,
201  size_t *len) {
202  struct dirent *de;
203  *len = 0;
204  size_t buflen = 5;
205  *buf = reinterpret_cast<char **>(smalloc(sizeof(char *) * buflen));
206 
207  DIR *dr = opendir(BuildPath(ctx, dir).c_str());
208 
209  // NULL terminate the list;
210  AppendStringToList(NULL, buf, len, &buflen);
211 
212  if (dr == NULL) {
213  return;
214  }
215 
216  while ((de = readdir(dr)) != NULL) {
217  if (strcmp(de->d_name, ".") != 0
218  && strcmp(de->d_name, "..") != 0
219  && strcmp(de->d_name, WARNING_FILE_NAME) != 0) {
220  AppendStringToList(de->d_name, buf, len, &buflen);
221  }
222  }
223 
224  closedir(dr);
225  return;
226 }
227 
229  const char *path,
230  struct cvmfs_attr *stat_result,
231  bool get_hash)
232 {
233  std::string complete_path = BuildPath(ctx, path);
234  struct stat buf;
235  int res = lstat(complete_path.c_str(), &buf);
236  if (res == -1) {
237  return -1;
238  }
239  stat_result->st_dev = buf.st_dev;
240  stat_result->st_ino = buf.st_ino;
241  stat_result->st_mode = buf.st_mode;
242  stat_result->st_nlink = buf.st_nlink;
243  stat_result->st_uid = buf.st_uid;
244  stat_result->st_gid = buf.st_gid;
245  stat_result->st_rdev = buf.st_rdev;
246  stat_result->st_size = buf.st_size;
247  stat_result->mtime = buf.st_mtime;
248 
249  if (get_hash && S_ISREG(buf.st_mode)) {
250  // We cannot reliably figure out the hash
251  // because we don't know the hash algorithm
252  return -1;
253  } else {
254  // We usually do not calculate the checksum for posix files since it's a
255  // destination file system.
256  stat_result->cvm_checksum = NULL;
257  }
258 
259  if (S_ISLNK(buf.st_mode)) {
260  char slnk[PATH_MAX+1];
261  const ssize_t length =
262  readlink(complete_path.c_str(), slnk, PATH_MAX);
263  if (length < 0) {
264  return -1;
265  }
266  slnk[length] = '\0';
267  stat_result->cvm_symlink = strdup(slnk);
268  } else {
269  stat_result->cvm_symlink = NULL;
270  }
271  std::string parent_path = GetParentPath(path);
272  std::string file_name = GetFileName(path);
273  stat_result->cvm_parent = strdup(parent_path.c_str());
274  stat_result->cvm_name = strdup(file_name.c_str());
275 
276  stat_result->cvm_xattrs = XattrList::CreateFromFile(complete_path);
277  if (stat_result->cvm_xattrs == NULL) return -1;
278 
279  return 0;
280 }
281 
283  const char *path, const struct cvmfs_attr *stat_info) {
284  std::string complete_path = BuildPath(ctx, path);
285  return PosixSetMeta(complete_path.c_str(), stat_info,
286  !S_ISLNK(stat_info->st_mode));
287 }
288 
290  const struct cvmfs_attr *stat) {
291  shash::Any content_hash =
293  shash::Any meta_hash = HashMeta(stat);
294  std::string path = ("/"
295  + content_hash.MakePathExplicit(kDirLevels, kDigitsPerDirLevel, '.')
296  + meta_hash.ToString());
297  char *res = strdup(path.c_str());
298  return res;
299 }
300 
302  const char *ident) {
303  return FileExists(BuildHiddenPath(ctx, ident));
304 }
305 
307  const char *path) {
308  std::string complete_path = BuildPath(ctx, path);
309  std::string parent_path = GetParentPath(complete_path);
310  const char *complete_path_char = complete_path.c_str();
311  struct stat buf;
312  int res2 = lstat(complete_path_char, &buf);
313  if (res2 == -1 && errno == ENOENT) return -1;
314  assert(res2 == 0);
315  struct utimbuf mtimes;
316  if (!BackupMtimes(parent_path, &mtimes)) return -1;
317  // Unlinking
318  int res1 = unlink(complete_path_char);
319  res1 |= utime(parent_path.c_str(), &mtimes);
320  if (res1 == -1) return -1;
321  // GC Flagging
322  if (S_ISREG(buf.st_mode) && buf.st_nlink == 2) {
323  struct fs_traversal_posix_context *pos_ctx
324  = reinterpret_cast<struct fs_traversal_posix_context*>(ctx->ctx);
325  pos_ctx->gc_flagged[buf.st_ino] = true;
326  }
327  return 0;
328 }
329 
331  const char *path) {
332  std::string complete_path = BuildPath(ctx, path);
333  std::string parent_path = GetParentPath(complete_path);
334  struct utimbuf mtimes;
335  if (!BackupMtimes(parent_path, &mtimes)) return -1;
336  int res = rmdir(complete_path.c_str());
337  res |= utime(parent_path.c_str(), &mtimes);
338  if (res != 0) return -1;
339  return 0;
340 }
341 
343  const char *path,
344  const char *identifier) {
345  std::string complete_path = BuildPath(ctx, path);
346  std::string parent_path = GetParentPath(complete_path);
347  std::string hidden_datapath = BuildHiddenPath(ctx, identifier);
348  const char *hidden_datapath_char = hidden_datapath.c_str();
349  if (!FileExists(hidden_datapath)) {
350  // Hash file doesn't exist
351  errno = ENOENT;
352  return -1;
353  }
354  struct utimbuf mtimes_parent;
355  if (!BackupMtimes(parent_path, &mtimes_parent)) return -1;
356 
357  struct utimbuf mtimes_link;
358  if (!BackupMtimes(hidden_datapath, &mtimes_link)) return -1;
359 
360  if (posix_cleanup_path(ctx, path) != 0) {
361  return -1;
362  }
363  // GC Unflagging
364  struct stat buf;
365  int res2 = lstat(hidden_datapath_char, &buf);
366  assert(res2 == 0);
367  int res1 = link(hidden_datapath_char, complete_path.c_str());
368  res1 |= utime(parent_path.c_str(), &mtimes_parent);
369  res1 |= utime(hidden_datapath.c_str(), &mtimes_link);
370  if (res1 != 0) {
372  "Failed to create link : %s->%s : %d : %s\n",
373  hidden_datapath_char, complete_path.c_str(), errno, strerror(errno));
374  return -1;
375  }
376  if (S_ISREG(buf.st_mode) && buf.st_nlink == 2) {
377  struct fs_traversal_posix_context *pos_ctx
378  = reinterpret_cast<struct fs_traversal_posix_context*>(ctx->ctx);
379  if (pos_ctx->gc_flagged.count(buf.st_ino) > 0) {
380  pos_ctx->gc_flagged[buf.st_ino] = false;
381  }
382  }
383  return 0;
384 }
385 
387  const char *path,
388  const struct cvmfs_attr *stat_info) {
389  std::string complete_path = BuildPath(ctx, path);
390  std::string parent_path = GetParentPath(complete_path);
391  std::string dirname = GetParentPath(complete_path);
392  struct utimbuf mtimes;
393  if (!BackupMtimes(parent_path, &mtimes)) return -1;
394  if (posix_cleanup_path(ctx, path) != 0) {
395  return -1;
396  }
397  int res = mkdir(complete_path.c_str(), stat_info->st_mode);
398  res |= utime(parent_path.c_str(), &mtimes);
399  if (res != 0) return -1;
400  return PosixSetMeta(complete_path.c_str(), stat_info);
401 }
402 
404  const char *src,
405  const char *dest,
406  const struct cvmfs_attr *stat_info) {
407  std::string complete_src_path = BuildPath(ctx, src);
408  std::string parent_path = GetParentPath(complete_src_path);
409  std::string complete_dest_path = dest;
410  struct utimbuf mtimes;
411  if (!BackupMtimes(parent_path, &mtimes)) return -1;
412  if (posix_cleanup_path(ctx, src) != 0) {
413  return -1;
414  }
415  int res = symlink(complete_dest_path.c_str(), complete_src_path.c_str());
416  res |= utime(parent_path.c_str(), &mtimes);
417  if (res != 0) return -1;
418  return PosixSetMeta(complete_src_path.c_str(), stat_info, false);
419 }
420 
422  const struct cvmfs_attr *stat_info) {
423  // NOTE(steuber): creat is only atomic on non-NFS paths!
424  char *identifier = posix_get_identifier(ctx, stat_info);
425  if (posix_has_file(ctx, identifier)) {
426  free(identifier);
427  errno = EEXIST;
428  return -1;
429  }
430  std::string hidden_datapath = BuildHiddenPath(ctx, identifier);
431  free(identifier);
432  int res1 = creat(hidden_datapath.c_str(), stat_info->st_mode);
433  if (res1 < 0) return -1;
434  int res2 = close(res1);
435  if (res2 < 0) return -1;
436  int res3 = PosixSetMeta(hidden_datapath.c_str(), stat_info);
437  if (res3 < 0) return -1;
438  return 0;
439 }
440 
442  const struct cvmfs_attr *stat_info) {
443  errno = 0;
444  std::string complete_path = BuildPath(ctx,
445  (std::string(stat_info->cvm_parent)+"/"+stat_info->cvm_name).c_str());
446  struct stat display_path_stat;
447  int res1 = lstat(complete_path.c_str(), &display_path_stat);
448  if (res1 == -1) {
449  // If visible path doesn't exist => error
450  return false;
451  }
452  char *identifier = posix_get_identifier(ctx, stat_info);
453  if (!posix_has_file(ctx, identifier)) {
454  free(identifier);
455  return false;
456  }
457  std::string hidden_datapath = BuildHiddenPath(ctx, identifier);
458  free(identifier);
459  struct stat hidden_path_stat;
460  int res2 = stat(hidden_datapath.c_str(), &hidden_path_stat);
461  if (res2 == -1) {
462  // If hidden path doesn't exist although apparently existing => error
463  return false;
464  }
465  return display_path_stat.st_ino == hidden_path_stat.st_ino;
466 }
467 
469  const char *identifier) {
470  struct posix_file_handle *file_ctx = new struct posix_file_handle;
471  file_ctx->path = BuildHiddenPath(ctx, identifier);
472 
473  return file_ctx;
474 }
475 
477  struct stat info;
478  int retval = stat(handle->path.c_str(), &info);
479  if (retval != 0) return false;
480  handle->original_mode = info.st_mode;
481  retval = chmod(handle->path.c_str(), info.st_mode | S_IWUSR | S_IWUSR);
482  return retval == 0;
483 }
484 
485 int posix_do_fopen(void *file_ctx, fs_open_type op_mode) {
486  struct posix_file_handle *handle =
487  reinterpret_cast<posix_file_handle *>(file_ctx);
488  const char *mode = "r";
489  if (op_mode == fs_open_write) {
490  mode = "w";
491  } else if (op_mode == fs_open_append) {
492  mode = "a";
493  }
494  if (!BackupMtimes(handle->path, &(handle->mtimes))) return -1;
495  handle->original_mode = 0;
496 
497  FILE *fd = fopen(handle->path.c_str(), mode);
498  if (fd == NULL) {
499  if (errno == EACCES) {
500  EnableWriteAccess(handle);
501  fd = fopen(handle->path.c_str(), mode);
502  if (fd == NULL)
503  return -1;
504  } else {
505  return -1;
506  }
507  }
508  handle->fd = fd;
509  return 0;
510 }
511 
512 int posix_do_fclose(void *file_ctx) {
513  struct posix_file_handle *handle =
514  reinterpret_cast<posix_file_handle *>(file_ctx);
515  int res = 0;
516  if (handle->original_mode != 0) {
517  res = fchmod(fileno(handle->fd), handle->original_mode);
518  }
519  res |= fclose(handle->fd);
520  handle->fd = NULL;
521  if (res != 0) {
522  // Opportunistic approach to reset time stamp
523  utime(handle->path.c_str(), &(handle->mtimes));
524  return -1;
525  }
526  res = utime(handle->path.c_str(), &(handle->mtimes));
527  if (res != 0) return -1;
528  return 0;
529 }
530 
531 int posix_do_fread(void *file_ctx, char *buff, size_t len, size_t *read_len) {
532  struct posix_file_handle *handle =
533  reinterpret_cast<posix_file_handle *>(file_ctx);
534  *read_len = fread(buff, sizeof(char), len, handle->fd);
535  if (*read_len < len && ferror(handle->fd) != 0) {
536  clearerr(handle->fd);
537  return -1;
538  }
539  return 0;
540 }
541 
542 int posix_do_fwrite(void *file_ctx, const char *buff, size_t len) {
543  struct posix_file_handle *handle =
544  reinterpret_cast<posix_file_handle *>(file_ctx);
545  size_t written_len = fwrite(buff, sizeof(char), len, handle->fd);
546  if (written_len != len) {
547  clearerr(handle->fd);
548  return -1;
549  }
550  return 0;
551 }
552 
553 void posix_do_ffree(void *file_ctx) {
554  struct posix_file_handle *handle =
555  reinterpret_cast<posix_file_handle *>(file_ctx);
556  if (handle->fd != NULL) {
557  posix_do_fclose(file_ctx);
558  }
559  delete handle;
560 }
561 
563  return RunGarbageCollection(ctx);
564 }
565 
567  std::string config_name,
568  std::string prov_name
569 ) {
570  FILE *prov = fopen(prov_name.c_str(), "w");
571  if (prov == NULL) {
573  "Archive config: failed to open : %s : %d : %s\n",
574  prov_name.c_str(), errno, strerror(errno));
575  return false;
576  }
577 
578  std::vector<std::string> config_files = SplitString(config_name, ':');
579  for (unsigned i = 0; i < config_files.size(); ++i) {
580  FILE *config = fopen(config_files[i].c_str(), "r");
581  if (config == NULL) {
583  "Archive config: failed to open : %s : %d : %s\n",
584  config_name.c_str(), errno, strerror(errno));
585  fclose(prov);
586  return false;
587  }
588 
589  while (1) {
590  char buffer[COPY_BUFFER_SIZE];
591 
592  size_t nbytes = 0;
593  nbytes = fread(&buffer, sizeof(char), sizeof(buffer), config);
594  if (nbytes < sizeof(buffer) && ferror(config) != 0) {
596  "Archive config: read failed : %d %s\n", errno, strerror(errno));
597  fclose(config);
598  fclose(prov);
599  return false;
600  }
601 
602  size_t written_len = fwrite(buffer, sizeof(char), nbytes, prov);
603  if (written_len != nbytes) {
605  "Archive config: write failed : %d %s\n",
606  errno, strerror(errno));
607  fclose(config);
608  fclose(prov);
609  return false;
610  }
611 
612  if (nbytes < COPY_BUFFER_SIZE)
613  break;
614  }
615  }
616 
617  return true;
618 }
619 
621  struct fs_traversal_context *ctx,
622  const char *info_file
623 ) {
624  FILE *f = fopen(info_file, "w");
625  if (f != NULL) {
626  fwrite("repo : ", sizeof(char), 7, f);
627  fwrite(ctx->repo, sizeof(char), strlen(ctx->repo), f);
628  fwrite("\nversion : ", sizeof(char), 11, f);
629  fwrite(ctx->lib_version, sizeof(char), strlen(ctx->lib_version), f);
630  fwrite("\nbase : ", sizeof(char), 8, f);
631  if (ctx->base)
632  fwrite(ctx->base, sizeof(char), strlen(ctx->base), f);
633  fwrite("\ncache : ", sizeof(char), 9, f);
634  if (ctx->data)
635  fwrite(ctx->data, sizeof(char), strlen(ctx->data), f);
636  fwrite("\nconfig : ", sizeof(char), 10, f);
637  if (ctx->config)
638  fwrite(ctx->config, sizeof(char), strlen(ctx->config), f);
639  fclose(f);
640  }
641 }
642 
644  struct fs_traversal_context *src,
645  struct fs_traversal_context *dest)
646 {
647  std::string prov_dir;
648  prov_dir.append(dest->base);
649  prov_dir.append(".provenance/");
650  prov_dir.append(dest->repo);
651  prov_dir.append("/");
652 
653  if (!DirectoryExists(prov_dir.c_str())) {
654  if (!MkdirDeep(prov_dir.c_str(), 0755, true)) {
656  "Failed to create repository directory '%s'", prov_dir.c_str());
657  }
658  }
659 
660  std::string src_info = prov_dir;
661  src_info.append("src.info");
662  posix_write_provenance_info(src, src_info.c_str());
663 
664  if (src->config) {
665  std::string src_config = prov_dir + "src.config";
666  if (!posix_archive_config(src->config, src_config)) {
668  "Failed to archive source config '%s'", src->config);
669  }
670  }
671 
672  std::string dest_info = prov_dir;
673  dest_info.append("dest.info");
674  posix_write_provenance_info(dest, dest_info.c_str());
675 
676  if (dest->config) {
677  std::string dest_config = prov_dir + "dest.config";
678  if (!posix_archive_config(dest->config, dest_config)) {
680  "Failed to archive destination config '%s'", dest->config);
681  }
682  }
683 }
684 
686  const char *repo,
687  const char *base,
688  const char *data,
689  const char *config,
690  int num_threads) {
691  fs_traversal_context *result = new struct fs_traversal_context;
692  result->version = 1;
693  result->lib_version = strdup("1.0");
694  struct fs_traversal_posix_context *posix_ctx
695  = new struct fs_traversal_posix_context;
696  posix_ctx->num_threads = num_threads;
697  result->ctx = posix_ctx;
698 
699  // Retrieve base directory for traversal
700  if (!base) {
701  result->base = strdup("/tmp/cvmfs/");
702  } else {
703  if (base[strlen(base)-1] != '/') {
704  size_t len = 2 + strlen(base);
705  char *base_dir = reinterpret_cast<char *>(smalloc(len*sizeof(char)));
706  snprintf(base_dir, len, "%s/", base);
707  result->base = strdup(base_dir);
708  free(base_dir);
709  } else {
710  result->base = strdup(base);
711  }
712  }
713 
714  // Retrieve repository (inside base directory) for traversal
715  if (!repo) {
717  "Repository name must be specified");
718  return NULL;
719  }
720  result->repo = strdup(repo);
721 
722  // Retrieve data directory (for hidden dedup directory)
723  if (!data) {
724  size_t len = 6 + strlen(result->base);
725  char *def_data = reinterpret_cast<char *>(smalloc(len*sizeof(char)));
726  snprintf(def_data, len, "%s.data", result->base);
727  result->data = strdup(def_data);
728  free(def_data);
729  } else {
730  result->data = strdup(data);
731  }
732 
733  if (config && strlen(config) > 0) {
735  "Configuration file is not supported in POSIX interface '%s'", config);
736  return NULL;
737  }
738  result->config = NULL;
739 
740  // Build directory if not there yet
741  std::string req_dirs = BuildPath(result, "");
742  if (!DirectoryExists(req_dirs.c_str())) {
743  if (!MkdirDeep(req_dirs.c_str(), 0755, true)) {
745  "Failed to create repository directory '%s'", req_dirs.c_str());
746  return NULL;
747  }
748  }
749 
750  // Initializes Data Directory, Garbage Collection and Warning file
751  InitialFsOperations(result);
752  return result;
753 }
754 
757  free(ctx->repo);
758  free(ctx->base);
759  free(ctx->data);
760  free(ctx->config);
761  free(ctx->lib_version);
762  struct fs_traversal_posix_context *posix_ctx
763  = reinterpret_cast<struct fs_traversal_posix_context*>(ctx->ctx);
764  delete posix_ctx;
765  delete ctx;
766 }
nlink_t st_nlink
Definition: libcvmfs.h:159
std::map< ino_t, bool > gc_flagged
Definition: helpers.h:26
char * cvm_symlink
Definition: libcvmfs.h:172
struct cvmcache_context * ctx
char * cvm_name
Definition: libcvmfs.h:174
int(* do_fopen)(void *file_ctx, fs_open_type op_mode)
NameString GetFileName(const PathString &path)
Definition: shortstring.cc:29
int posix_garbage_collector(struct fs_traversal_context *ctx)
Definition: interface.cc:562
int posix_do_fopen(void *file_ctx, fs_open_type op_mode)
Definition: interface.cc:485
int posix_get_stat(struct fs_traversal_context *ctx, const char *path, struct cvmfs_attr *stat_result, bool get_hash)
Definition: interface.cc:228
std::string ToString(const bool with_suffix=false) const
Definition: hash.h:249
int(* set_meta)(struct fs_traversal_context *ctx, const char *path, const struct cvmfs_attr *stat)
bool(* is_hash_consistent)(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat)
void InitialFsOperations(struct fs_traversal_context *ctx)
Definition: helpers.cc:39
void posix_finalize(struct fs_traversal_context *ctx)
Definition: interface.cc:755
void posix_do_ffree(void *file_ctx)
Definition: interface.cc:553
bool posix_has_file(struct fs_traversal_context *ctx, const char *ident)
Definition: interface.cc:301
dev_t st_dev
Definition: libcvmfs.h:156
struct fs_traversal * posix_get_interface()
Definition: interface.cc:131
int posix_do_rmdir(struct fs_traversal_context *ctx, const char *path)
Definition: interface.cc:330
int posix_cleanup_path(struct fs_traversal_context *ctx, const char *path)
Definition: interface.cc:161
int posix_do_fread(void *file_ctx, char *buff, size_t len, size_t *read_len)
Definition: interface.cc:531
int PosixSetMeta(const char *path, const struct cvmfs_attr *stat_info, bool set_permissions)
Definition: helpers.cc:79
void FinalizeFsOperations(struct fs_traversal_context *ctx)
Definition: helpers.cc:45
int posix_do_fwrite(void *file_ctx, const char *buff, size_t len)
Definition: interface.cc:542
assert((mem||(size==0))&&"Out Of Memory")
int posix_set_meta(struct fs_traversal_context *ctx, const char *path, const struct cvmfs_attr *stat_info)
Definition: interface.cc:282
char * cvm_parent
Definition: libcvmfs.h:173
int(* do_unlink)(struct fs_traversal_context *ctx, const char *path)
int(* garbage_collector)(struct fs_traversal_context *ctx)
int(* do_rmdir)(struct fs_traversal_context *ctx, const char *path)
void *(* get_handle)(struct fs_traversal_context *ctx, const char *identifier)
#define WARNING_FILE_NAME
Definition: helpers.h:15
bool posix_archive_config(std::string config_name, std::string prov_name)
Definition: interface.cc:566
char * cvm_checksum
Definition: libcvmfs.h:171
bool SymlinkExists(const std::string &path)
Definition: posix.cc:834
void(* do_ffree)(void *file_ctx)
int posix_do_unlink(struct fs_traversal_context *ctx, const char *path)
Definition: interface.cc:306
bool FileExists(const std::string &path)
Definition: posix.cc:802
int posix_do_mkdir(struct fs_traversal_context *ctx, const char *path, const struct cvmfs_attr *stat_info)
Definition: interface.cc:386
int(* touch)(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat)
void posix_list_dir(struct fs_traversal_context *ctx, const char *dir, char ***buf, size_t *len)
Definition: interface.cc:198
void * cvm_xattrs
Definition: libcvmfs.h:175
bool EnableWriteAccess(posix_file_handle *handle)
Definition: interface.cc:476
int(* do_symlink)(struct fs_traversal_context *ctx, const char *src, const char *dest, const struct cvmfs_attr *stat_info)
void(* finalize)(struct fs_traversal_context *ctx)
vector< string > SplitString(const string &str, char delim)
Definition: string.cc:290
int(* do_link)(struct fs_traversal_context *ctx, const char *path, const char *identifier)
int RunGarbageCollection(struct fs_traversal_context *ctx)
const unsigned kDigitsPerDirLevel
Definition: helpers.h:22
struct fs_traversal_context *(* initialize)(const char *repo, const char *base, const char *data, const char *config, int num_threads)
time_t mtime
Definition: libcvmfs.h:164
gid_t st_gid
Definition: libcvmfs.h:161
void(* list_dir)(struct fs_traversal_context *ctx, const char *dir, char ***buf, size_t *len)
void(* archive_provenance)(struct fs_traversal_context *src, struct fs_traversal_context *dest)
std::string BuildPath(struct fs_traversal_context *ctx, const char *dir)
Definition: helpers.cc:61
off_t st_size
Definition: libcvmfs.h:163
bool MkdirDeep(const std::string &path, const mode_t mode, bool verify_writable)
Definition: posix.cc:857
bool(* has_file)(struct fs_traversal_context *ctx, const char *identifier)
const unsigned kDirLevels
Definition: helpers.h:21
std::string path
Definition: interface.cc:32
#define COPY_BUFFER_SIZE
int posix_touch(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat_info)
Definition: interface.cc:421
bool BackupMtimes(std::string path, struct utimbuf *mtimes)
Definition: helpers.cc:116
shash::Any HashMeta(const struct cvmfs_attr *stat_info)
Definition: util.cc:16
void posix_write_provenance_info(struct fs_traversal_context *ctx, const char *info_file)
Definition: interface.cc:620
bool DirectoryExists(const std::string &path)
Definition: posix.cc:824
int posix_do_fclose(void *file_ctx)
Definition: interface.cc:512
std::string BuildHiddenPath(struct fs_traversal_context *ctx, const char *ident)
Definition: helpers.cc:72
int(* do_fclose)(void *file_ctx)
int posix_do_link(struct fs_traversal_context *ctx, const char *path, const char *identifier)
Definition: interface.cc:342
int(* get_stat)(struct fs_traversal_context *ctx, const char *path, struct cvmfs_attr *stat, bool get_hash)
std::string MakePathExplicit(const unsigned dir_levels, const unsigned digits_per_level, const Suffix hash_suffix=kSuffixNone) const
Definition: hash.h:351
int(* do_fwrite)(void *file_ctx, const char *buff, size_t len)
ino_t st_ino
Definition: libcvmfs.h:157
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:15
void * posix_get_handle(struct fs_traversal_context *ctx, const char *identifier)
Definition: interface.cc:468
int(* do_fread)(void *file_ctx, char *buff, size_t len, size_t *read_len)
Any MkFromHexPtr(const HexPtr hex, const char suffix)
Definition: hash.cc:83
static XattrList * CreateFromFile(const std::string &path)
Definition: xattr.cc:30
uid_t st_uid
Definition: libcvmfs.h:160
bool posix_is_hash_consistent(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat_info)
Definition: interface.cc:441
int(* do_mkdir)(struct fs_traversal_context *ctx, const char *path, const struct cvmfs_attr *stat)
dev_t st_rdev
Definition: libcvmfs.h:162
char *(* get_identifier)(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat)
char * posix_get_identifier(struct fs_traversal_context *ctx, const struct cvmfs_attr *stat)
Definition: interface.cc:289
int posix_do_symlink(struct fs_traversal_context *ctx, const char *src, const char *dest, const struct cvmfs_attr *stat_info)
Definition: interface.cc:403
struct utimbuf mtimes
Definition: interface.cc:34
struct fs_traversal_context * posix_initialize(const char *repo, const char *base, const char *data, const char *config, int num_threads)
Definition: interface.cc:685
void AppendStringToList(char const *str, char ***buf, size_t *listlen, size_t *buflen)
Definition: util.cc:64
void posix_archive_provenance(struct fs_traversal_context *src, struct fs_traversal_context *dest)
Definition: interface.cc:643
mode_t st_mode
Definition: libcvmfs.h:158
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528