-2010-05-18 Colin Watson <cjwatson@ubuntu.com>
+2010-06-01 Colin Watson <cjwatson@ubuntu.com>
Add btrfs probing support, currently only in the single-device case.
find_root_device_from_mountinfo (const char *dir)
{
FILE *fp;
- char buf[1024]; /* XXX */
+ char *buf = NULL;
+ size_t len = 0;
char *ret = NULL;
fp = fopen ("/proc/self/mountinfo", "r");
if (! fp)
return NULL; /* fall through to other methods */
- while (fgets (buf, sizeof (buf), fp))
+ while (getline (&buf, &len, fp) > 0)
{
int mnt_id, parent_mnt_id;
unsigned int major, minor;
if (!sep)
continue;
- sep += strlen (" - ");
+ sep += sizeof (" - ") - 1;
if (sscanf (sep, "%s %s", fstype, device) != 2)
continue;
ret = strdup (device);
}
+ free (buf);
fclose (fp);
return ret;
}