Lines Matching defs:fs
18 #include "fs.h"
87 "/sys/fs/bpf",
91 struct fs {
103 static void fs__init_once(struct fs *fs);
104 static const char *fs__mountpoint(const struct fs *fs);
105 static const char *fs__mount(struct fs *fs);
108 static struct fs fs__##lower_name = { \
117 struct fs *fs = &fs__##lower_name; \
119 fs__init_once(fs); \
125 struct fs *fs = &fs__##lower_name; \
128 return fs__mountpoint(fs); \
134 struct fs *fs = &fs__##lower_name; \
139 return fs__mount(fs); \
154 static bool fs__read_mounts(struct fs *fs)
167 if (strcmp(type, fs->name) == 0) {
168 fs->path = strdup(path);
170 return fs->path != NULL;
177 static int fs__valid_mount(const char *fs, long magic)
181 if (statfs(fs, &st_fs) < 0)
189 static bool fs__check_mounts(struct fs *fs)
193 ptr = fs->mounts;
195 if (fs__valid_mount(*ptr, fs->magic) == 0) {
196 fs->path = strdup(*ptr);
197 if (!fs->path)
217 * Check for "NAME_PATH" environment variable to override fs location (for
221 static bool fs__env_override(struct fs *fs)
224 size_t name_len = strlen(fs->name);
228 memcpy(upper_name, fs->name, name_len);
236 fs->path = strdup(override_path);
237 if (!fs->path)
242 static void fs__init_once(struct fs *fs)
244 if (!fs__env_override(fs) &&
245 !fs__check_mounts(fs) &&
246 !fs__read_mounts(fs)) {
247 assert(!fs->path);
249 assert(fs->path);
253 static const char *fs__mountpoint(const struct fs *fs)
255 return fs->path;
258 static const char *mount_overload(struct fs *fs)
260 size_t name_len = strlen(fs->name);
264 snprintf(upper_name, name_len, "PERF_%s_ENVIRONMENT", fs->name);
267 return getenv(upper_name) ?: *fs->mounts;
270 static const char *fs__mount(struct fs *fs)
274 pthread_mutex_lock(&fs->mount_mutex);
277 mountpoint = fs__mountpoint(fs);
281 mountpoint = mount_overload(fs);
283 if (mount(NULL, mountpoint, fs->name, 0, NULL) == 0 &&
284 fs__valid_mount(mountpoint, fs->magic) == 0) {
285 fs->path = strdup(mountpoint);
286 mountpoint = fs->path;
289 pthread_mutex_unlock(&fs->mount_mutex);