Lines Matching refs:fs
18 #include "fs.h"
86 "/sys/fs/bpf",
90 struct fs {
102 static void fs__init_once(struct fs *fs);
103 static const char *fs__mountpoint(const struct fs *fs);
104 static const char *fs__mount(struct fs *fs);
107 static struct fs fs__##lower_name = { \
116 struct fs *fs = &fs__##lower_name; \
118 fs__init_once(fs); \
124 struct fs *fs = &fs__##lower_name; \
127 return fs__mountpoint(fs); \
133 struct fs *fs = &fs__##lower_name; \
138 return fs__mount(fs); \
153 static bool fs__read_mounts(struct fs *fs)
166 if (strcmp(type, fs->name) == 0) {
167 fs->path = strdup(path);
169 return fs->path != NULL;
176 static int fs__valid_mount(const char *fs, long magic)
180 if (statfs(fs, &st_fs) < 0)
188 static bool fs__check_mounts(struct fs *fs)
192 ptr = fs->mounts;
194 if (fs__valid_mount(*ptr, fs->magic) == 0) {
195 fs->path = strdup(*ptr);
196 if (!fs->path)
216 * Check for "NAME_PATH" environment variable to override fs location (for
220 static bool fs__env_override(struct fs *fs)
223 size_t name_len = strlen(fs->name);
227 memcpy(upper_name, fs->name, name_len);
235 fs->path = strdup(override_path);
236 if (!fs->path)
241 static void fs__init_once(struct fs *fs)
243 if (!fs__env_override(fs) &&
244 !fs__check_mounts(fs) &&
245 !fs__read_mounts(fs)) {
246 assert(!fs->path);
248 assert(fs->path);
252 static const char *fs__mountpoint(const struct fs *fs)
254 return fs->path;
257 static const char *mount_overload(struct fs *fs)
259 size_t name_len = strlen(fs->name);
263 snprintf(upper_name, name_len, "PERF_%s_ENVIRONMENT", fs->name);
266 return getenv(upper_name) ?: *fs->mounts;
269 static const char *fs__mount(struct fs *fs)
273 pthread_mutex_lock(&fs->mount_mutex);
276 mountpoint = fs__mountpoint(fs);
280 mountpoint = mount_overload(fs);
282 if (mount(NULL, mountpoint, fs->name, 0, NULL) == 0 &&
283 fs__valid_mount(mountpoint, fs->magic) == 0) {
284 fs->path = strdup(mountpoint);
285 mountpoint = fs->path;
288 pthread_mutex_unlock(&fs->mount_mutex);