#define DEBUG_OPTIONS (1 << 3)
#define DEBUG_LOCKS (1 << 4)
#define DEBUG_TAB (1 << 5)
+#define DEBUG_MTAB (1 << 6)
+#define DEBUG_UTILS (1 << 7)
#define DEBUG_ALL 0xFFFF
#ifdef CONFIG_LIBMOUNT_DEBUG
extern int mnt_has_regular_mtab(void);
extern char *mnt_get_mountpoint(const char *path);
-extern char *mnt_get_fs_root(const char *path);
+extern char *mnt_get_fs_root(const char *path, const char *mountpoint);
/*
* Generic iterator
if (!mnt)
return NULL;
if (*mnt == '/' && *(mnt + 1) == '\0')
- return mnt; /* root fs */
+ goto done;
if (stat(mnt, &st))
goto err;
dir = st.st_dev;
if (dir != base) {
*(p - 1) = '/';
- return mnt;
+ goto done;
}
base = dir;
} while (mnt && *(mnt + 1) != '\0');
memcpy(mnt, "/", 2);
- return mnt; /* root fs */
+done:
+ DBG(DEBUG_UTILS, fprintf(stderr,
+ "libmount: utils: fs-root for %s is %s\n", path, mnt));
+ return mnt;
err:
free(mnt);
return NULL;
}
-char *mnt_get_fs_root(const char *path)
+char *mnt_get_fs_root(const char *path, const char *mnt)
{
- char *mnt = mnt_get_mountpoint(path);
+ char *m = (char *) mnt;
const char *p;
size_t sz;
- if (!mnt)
+ if (!m)
+ m = mnt_get_mountpoint(path);
+ if (!m)
return NULL;
- sz = strlen(mnt);
+ sz = strlen(m);
p = sz > 1 ? path + sz : path;
- free(mnt);
+ if (m != mnt)
+ free(m);
return *p ? strdup(p) : strdup("/");
}