Commit f9869942 authored by Pavel Emelyanov's avatar Pavel Emelyanov

proc: Move proc string parse into separate fn

We'll have to parse it all and the format is not scanf
friendly, so it's simpler to have it in a separate fn.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5e593e9b
......@@ -470,6 +470,21 @@ err_parse:
return 0;
}
static int parse_mountinfo_ent(char *str, struct proc_mountinfo *new)
{
unsigned int kmaj, kmin;
int ret;
ret = sscanf(str, "%i %i %u:%u %63s %63s",
&new->mnt_id, &new->parent_mnt_id,
&kmaj, &kmin, new->root, new->mountpoint);
if (ret != 6)
return -1;
new->s_dev = MKKDEV(kmaj, kmin);
return 0;
}
struct proc_mountinfo *parse_mountinfo(pid_t pid)
{
struct proc_mountinfo *list = NULL;
......@@ -485,22 +500,18 @@ struct proc_mountinfo *parse_mountinfo(pid_t pid)
while (fgets(str, sizeof(str), f)) {
struct proc_mountinfo *new;
unsigned int kmaj, kmin;
int ret;
new = xmalloc(sizeof(*new));
if (!new)
goto err;
ret = sscanf(str, "%i %i %u:%u %63s %63s",
&new->mnt_id, &new->parent_mnt_id,
&kmaj, &kmin, new->root, new->mountpoint);
if (ret != 6) {
ret = parse_mountinfo_ent(str, new);
if (ret < 0) {
pr_err("Bad format in %d mountinfo\n", pid);
goto err;
}
new->s_dev = MKKDEV(kmaj, kmin);
new->next = list;
list = new;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment