GCC Code Coverage Report


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