34 FILE *fp = fopen(
"/proc/self/mountinfo",
"r");
37 error(
_(
"cannot open file '%s': %s"),
"/proc/self/mountinfo", strerror(errno));
46 char *mntpoint = NULL;
47 char *mntopts1 = NULL;
50 char *mntopts2 = NULL;
54 while((readsize = getline(&line, &s, fp)) != -1)
56 if(line[readsize - 1] ==
'\n')
57 line[--readsize] =
'\0';
63 root = malloc(readsize);
70 if(sscanf(line,
"%d %d %d:%d %[^%#= ] %[^%#= ] %[^ ]%*[^-]- %[^%#= ] %[^%#= ] %s", &
mntid, &
parentid, &
major, &
minor,
root,
mntpoint,
mntopts1,
fstype,
mntsrc,
mntopts2) == 10)
72 *collection = (
struct mnt_info **)realloc(*collection, (n + 1) *
sizeof(
struct mnt_info *));
73 ptr = *collection + n;
77 (*ptr)->major =
major;
78 (*ptr)->minor =
minor;
79 (*ptr)->root = strdup(
root);
82 (*ptr)->fstype = strdup(
fstype);
83 (*ptr)->mntsrc = strdup(
mntsrc);
103 debug(
_(
"wrong call to function %s"),
"check_device(const char*, const char*)");
104 debug(
_(
"One of the parameters has a zero length"));
108 struct stat sb_file, sb_dev;
110 debug(
_(
"Check if file '%s' is on device '%s'."), file, dev);
111 if(stat(file, &sb_file) == 0)
113 if(stat(dev, &sb_dev) == 0)
115 if(S_ISBLK(sb_dev.st_mode) && sb_file.st_dev == sb_dev.st_rdev)
117 debug(
_(
"file '%s' is on device '%s'"), file, dev);
124 output(LOG_WARNING,
_(
"cannot stat file: %s"), file);
128 int minor_file = minor(sb_file.st_dev);
129 int major_file = major(sb_file.st_dev);
137 if(mntinfo[n]->
major == major_file && mntinfo[n]->
minor == minor_file && strcmp(mntinfo[n]->
mntsrc, dev) == 0)
139 debug(
_(
"file '%s' is on device '%s'"), file, dev);
144 output(LOG_NOTICE,
_(
"file '%s' is not device '%s'"), file, dev);
#define str_len(s)
Shorthand for counting '\0' terminating strings. See _len for more info.
int check_device(const char *file, const char *dev)
int readmountinfo(struct mnt_info ***collection)