1 /* TODO merge/factor in debugfs.c here */
12 static const char * const sysfs__fs_known_mountpoints[] = {
17 static const char * const procfs__known_mountpoints[] = {
24 const char * const *mounts;
25 char path[PATH_MAX + 1];
35 static struct fs fs__entries[] = {
38 .mounts = sysfs__fs_known_mountpoints,
43 .mounts = procfs__known_mountpoints,
44 .magic = PROC_SUPER_MAGIC,
48 static bool fs__read_mounts(struct fs *fs)
54 fp = fopen("/proc/mounts", "r");
59 fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
60 fs->path, type) == 2) {
62 if (strcmp(type, fs->name) == 0)
67 return fs->found = found;
70 static int fs__valid_mount(const char *fs, long magic)
74 if (statfs(fs, &st_fs) < 0)
76 else if (st_fs.f_type != magic)
82 static bool fs__check_mounts(struct fs *fs)
84 const char * const *ptr;
88 if (fs__valid_mount(*ptr, fs->magic) == 0) {
90 strcpy(fs->path, *ptr);
99 static const char *fs__get_mountpoint(struct fs *fs)
101 if (fs__check_mounts(fs))
104 return fs__read_mounts(fs) ? fs->path : NULL;
107 static const char *fs__mountpoint(int idx)
109 struct fs *fs = &fs__entries[idx];
112 return (const char *)fs->path;
114 return fs__get_mountpoint(fs);
117 #define FS__MOUNTPOINT(name, idx) \
118 const char *name##__mountpoint(void) \
120 return fs__mountpoint(idx); \
123 FS__MOUNTPOINT(sysfs, FS__SYSFS);
124 FS__MOUNTPOINT(procfs, FS__PROCFS);