GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/libcvmfs_int.h
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 4 5 80.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * This is the internal implementation of libcvmfs, not to be exposed to the
5 * code using the library.
6 *
7 * Defines LibGlobals and LibContext classes that wrap around a FileSystem
8 * and a MountPoint. The libcvmfs.cc implementation of the libcvmfs interface
9 * uses LibGlobals for library initialization and deinitialization. It uses
10 * LibContext objects for all the file system heavy lifting.
11 */
12
13 #ifndef CVMFS_LIBCVMFS_INT_H_
14 #define CVMFS_LIBCVMFS_INT_H_
15
16 #include <syslog.h>
17 #include <time.h>
18 #include <unistd.h>
19
20 #include <string>
21 #include <vector>
22
23 #include "backoff.h"
24 #include "catalog_mgr.h"
25 #include "file_chunk.h"
26 #include "interrupt.h"
27 #include "loader.h"
28 #include "lru.h"
29 #include "mountpoint.h"
30 #include "options.h"
31
32
33 class CacheManager;
34 namespace catalog {
35 class ClientCatalogManager;
36 }
37 namespace signature {
38 class SignatureManager;
39 }
40 namespace download {
41 class DownloadManager;
42 }
43 namespace perf {
44 class Statistics;
45 }
46
47 namespace cvmfs {
48 extern pid_t pid_;
49 extern std::string *repository_name_;
50 extern bool foreground_;
51 class Fetcher;
52 }
53
54 struct cvmfs_stat_t;
55
56
57 /**
58 * A singleton managing the cvmfs resources for all attached repositories. A
59 * thin wrapper around the FileSystem object that does most of the heavy work.
60 */
61 class LibGlobals : SingleCopy {
62 public:
63 static loader::Failures Initialize(OptionsManager *options_mgr);
64 static void CleanupInstance();
65 static LibGlobals* GetInstance();
66
67 34 FileSystem *file_system() { return file_system_; }
68 11 void set_options_mgr(OptionsManager *value) { options_mgr_ = value; }
69
70 private:
71 LibGlobals();
72 ~LibGlobals();
73 static LibGlobals *instance_;
74
75 /**
76 * Only non-NULL if cvmfs_init is used for initialization. In this case, the
77 * options manager needs to be cleaned up by cvmfs_fini.
78 */
79 OptionsManager *options_mgr_;
80 FileSystem *file_system_;
81 };
82
83
84 /**
85 * Encapsulates a single attached repository. It uses a MountPoint object for
86 * creating the state of all the necessary manager objects. On top of the
87 * managers it implements file system operations (read, list, ...).
88 */
89 class LibContext : SingleCopy {
90 public:
91 static LibContext *Create(const std::string &fqrn,
92 OptionsManager *options_mgr);
93 ~LibContext();
94
95 void EnableMultiThreaded();
96 int GetAttr(const char *c_path, struct stat *info);
97 int Readlink(const char *path, char *buf, size_t size);
98 int ListDirectory(const char *path,
99 char ***buf,
100 size_t *listlen,
101 size_t *buflen,
102 bool self_reference);
103 int ListDirectoryStat(const char *c_path,
104 cvmfs_stat_t **buf,
105 size_t *listlen,
106 size_t *buflen);
107
108 int Open(const char *c_path);
109 int64_t Pread(int fd, void *buf, uint64_t size, uint64_t off);
110 int Close(int fd);
111
112 int GetExtAttr(const char *c_path, struct cvmfs_attr *info);
113 int GetNestedCatalogAttr(const char *c_path, struct cvmfs_nc_attr *nc_attr);
114 int ListNestedCatalogs(const char *path, char ***buf, size_t *buflen);
115
116 int Remount();
117 uint64_t GetRevision();
118
119 11 MountPoint *mount_point() { return mount_point_; }
120 void set_options_mgr(OptionsManager *value) { options_mgr_ = value; }
121
122 private:
123 /**
124 * File descriptors of chunked files have bit 30 set.
125 */
126 static const int kFdChunked = 1 << 30;
127 /**
128 * use static method Create() for construction
129 */
130 LibContext();
131 24 FileSystem *file_system() { return LibGlobals::GetInstance()->file_system(); }
132
133 void AppendStringToList(char const *str,
134 char ***buf,
135 size_t *listlen,
136 size_t *buflen);
137 void AppendStatToList(const cvmfs_stat_t st,
138 cvmfs_stat_t **buf,
139 size_t *listlen,
140 size_t *buflen);
141 bool GetDirentForPath(const PathString &path,
142 catalog::DirectoryEntry *dirent);
143 void CvmfsAttrFromDirent(const catalog::DirectoryEntry dirent,
144 struct cvmfs_attr *attr);
145
146 /**
147 * Only non-NULL if cvmfs_attache_repo is used for initialization. In this
148 * case, the options manager needs to be cleaned up by cvmfs_fini.
149 */
150 OptionsManager *options_mgr_;
151 MountPoint *mount_point_;
152
153 /**
154 * Used to prevent construction/destruction of an InterruptCue object in every
155 * file system operation.
156 */
157 InterruptCue default_interrupt_cue_;
158 };
159
160 #endif // CVMFS_LIBCVMFS_INT_H_
161