Commit b5803455 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mount: Allocate mountinfo strings dynamically

On the restore path this structure will be used and it
will be better to have them char * rather than char[64].

When scanning proc use the %ms specifier for this.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c74fb299
......@@ -89,14 +89,14 @@ struct proc_mountinfo {
int mnt_id;
int parent_mnt_id;
unsigned int s_dev;
char root[64];
char mountpoint[64];
char *root;
char *mountpoint;
unsigned flags;
int master_id;
int shared_id;
char fstype[32];
char source[64];
char options[128];
char *fstype;
char *source;
char *options;
struct proc_mountinfo *next;
};
......
......@@ -589,12 +589,12 @@ static int parse_mountinfo_ent(char *str, struct proc_mountinfo *new)
{
unsigned int kmaj, kmin;
int ret, n;
char opt[64];
char *opt;
ret = sscanf(str, "%i %i %u:%u %63s %63s %63s %n",
ret = sscanf(str, "%i %i %u:%u %ms %ms %ms %n",
&new->mnt_id, &new->parent_mnt_id,
&kmaj, &kmin, new->root, new->mountpoint,
opt, &n);
&kmaj, &kmin, &new->root, &new->mountpoint,
&opt, &n);
if (ret != 7)
return -1;
......@@ -603,18 +603,26 @@ static int parse_mountinfo_ent(char *str, struct proc_mountinfo *new)
if (parse_mnt_flags(opt, &new->flags))
return -1;
free(opt); /* after %ms scanf */
str += n;
if (parse_mnt_opt(str, new, &n))
return -1;
str += n;
ret = sscanf(str, "%31s %53s %63s", new->fstype, new->source, opt);
ret = sscanf(str, "%ms %ms %ms", &new->fstype, &new->source, &opt);
if (ret != 3)
return -1;
new->options = xmalloc(strlen(opt));
if (!new->options)
return -1;
if (parse_sb_opt(opt, &new->flags, new->options))
return -1;
free(opt);
return 0;
}
......
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