2 /* TODO merge/factor into tools/lib/lk/debugfs.c */
7 static const char * const sysfs__fs_known_mountpoints[] = {
12 static const char * const procfs__known_mountpoints[] = {
19 const char * const *mounts;
20 char path[PATH_MAX + 1];
30 static struct fs fs__entries[] = {
33 .mounts = sysfs__fs_known_mountpoints,
38 .mounts = procfs__known_mountpoints,
39 .magic = PROC_SUPER_MAGIC,
43 static bool fs__read_mounts(struct fs *fs)
49 fp = fopen("/proc/mounts", "r");
54 fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
55 fs->path, type) == 2) {
57 if (strcmp(type, fs->name) == 0)
62 return fs->found = found;
65 static int fs__valid_mount(const char *fs, long magic)
69 if (statfs(fs, &st_fs) < 0)
71 else if (st_fs.f_type != magic)
77 static bool fs__check_mounts(struct fs *fs)
79 const char * const *ptr;
83 if (fs__valid_mount(*ptr, fs->magic) == 0) {
85 strcpy(fs->path, *ptr);
94 static const char *fs__get_mountpoint(struct fs *fs)
96 if (fs__check_mounts(fs))
99 return fs__read_mounts(fs) ? fs->path : NULL;
102 static const char *fs__mountpoint(int idx)
104 struct fs *fs = &fs__entries[idx];
107 return (const char *)fs->path;
109 return fs__get_mountpoint(fs);
112 #define FS__MOUNTPOINT(name, idx) \
113 const char *name##__mountpoint(void) \
115 return fs__mountpoint(idx); \
118 FS__MOUNTPOINT(sysfs, FS__SYSFS);
119 FS__MOUNTPOINT(procfs, FS__PROCFS);