2 /* TODO merge/factor into tools/lib/lk/debugfs.c */
7 static const char * const sysfs__fs_known_mountpoints[] = {
14 const char * const *mounts;
15 char path[PATH_MAX + 1];
24 static struct fs fs__entries[] = {
27 .mounts = sysfs__fs_known_mountpoints,
32 static bool fs__read_mounts(struct fs *fs)
38 fp = fopen("/proc/mounts", "r");
43 fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
44 fs->path, type) == 2) {
46 if (strcmp(type, fs->name) == 0)
51 return fs->found = found;
54 static int fs__valid_mount(const char *fs, long magic)
58 if (statfs(fs, &st_fs) < 0)
60 else if (st_fs.f_type != magic)
66 static bool fs__check_mounts(struct fs *fs)
68 const char * const *ptr;
72 if (fs__valid_mount(*ptr, fs->magic) == 0) {
74 strcpy(fs->path, *ptr);
83 static const char *fs__get_mountpoint(struct fs *fs)
85 if (fs__check_mounts(fs))
88 return fs__read_mounts(fs) ? fs->path : NULL;
91 static const char *fs__find_mountpoint(int idx)
93 struct fs *fs = &fs__entries[idx];
96 return (const char *)fs->path;
98 return fs__get_mountpoint(fs);
101 #define FIND_MOUNTPOINT(name, idx) \
102 const char *name##_find_mountpoint(void) \
104 return fs__find_mountpoint(idx); \
107 FIND_MOUNTPOINT(sysfs, FS__SYSFS);