-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 288662 b: refs/heads/master c: e90fda0 h: refs/heads/master v: v3
- Loading branch information
Jiri Olsa
authored and
Arnaldo Carvalho de Melo
committed
Feb 14, 2012
1 parent
5413efc
commit d5e90cc
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 2837609fefbfe8f1248bfce09d9f0b44d5eb713d | ||
refs/heads/master: e90fda0635401225ca7c2343bea2f6d279347d10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
#include "util.h" | ||
#include "sysfs.h" | ||
|
||
static const char * const sysfs_known_mountpoints[] = { | ||
"/sys", | ||
0, | ||
}; | ||
|
||
static int sysfs_found; | ||
char sysfs_mountpoint[PATH_MAX]; | ||
|
||
static int sysfs_valid_mountpoint(const char *sysfs) | ||
{ | ||
struct statfs st_fs; | ||
|
||
if (statfs(sysfs, &st_fs) < 0) | ||
return -ENOENT; | ||
else if (st_fs.f_type != (long) SYSFS_MAGIC) | ||
return -ENOENT; | ||
|
||
return 0; | ||
} | ||
|
||
const char *sysfs_find_mountpoint(void) | ||
{ | ||
const char * const *ptr; | ||
char type[100]; | ||
FILE *fp; | ||
|
||
if (sysfs_found) | ||
return (const char *) sysfs_mountpoint; | ||
|
||
ptr = sysfs_known_mountpoints; | ||
while (*ptr) { | ||
if (sysfs_valid_mountpoint(*ptr) == 0) { | ||
sysfs_found = 1; | ||
strcpy(sysfs_mountpoint, *ptr); | ||
return sysfs_mountpoint; | ||
} | ||
ptr++; | ||
} | ||
|
||
/* give up and parse /proc/mounts */ | ||
fp = fopen("/proc/mounts", "r"); | ||
if (fp == NULL) | ||
return NULL; | ||
|
||
while (!sysfs_found && | ||
fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", | ||
sysfs_mountpoint, type) == 2) { | ||
|
||
if (strcmp(type, "sysfs") == 0) | ||
sysfs_found = 1; | ||
} | ||
|
||
fclose(fp); | ||
|
||
return sysfs_found ? sysfs_mountpoint : NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef __SYSFS_H__ | ||
#define __SYSFS_H__ | ||
|
||
const char *sysfs_find_mountpoint(void); | ||
|
||
#endif /* __DEBUGFS_H__ */ |