From: Arvin Schnell Date: Thu, 4 Aug 2011 16:10:53 +0000 (+0200) Subject: - detect filesystem during setup X-Git-Tag: v0.1.3~315 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e672cbf57632031c7ca141436c0cd654f55642e;p=thirdparty%2Fsnapper.git - detect filesystem during setup --- diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index ee5b3883..4929565a 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "config.h" @@ -614,13 +615,61 @@ namespace snapper } + static bool + is_subpath(const string& a, const string& b) + { + if (b == "/") + return true; + + size_t len = b.length(); + + if (len > a.length()) + return false; + + return (len == a.length() || a[len] == '/') && a.compare(0, len, b) == 0; + } + + bool Snapper::detectFstype(const string& subvolume, string& fstype) { - // TODO + y2mil("subvolume:" << subvolume); - fstype = "btrfs"; - return true; + if (!boost::starts_with(subvolume, "/") || !checkDir(subvolume)) + return false; + + FILE* f = setmntent("/etc/mtab", "r"); + if (!f) + { + y2err("setmntent failed"); + return false; + } + + fstype.clear(); + + string best_match; + + struct mntent* m; + while ((m = getmntent(f))) + { + if (strcmp(m->mnt_type, "rootfs") == 0) + continue; + + if (strlen(m->mnt_dir) > best_match.length() && is_subpath(subvolume, m->mnt_dir)) + { + best_match = m->mnt_dir; + fstype = m->mnt_type; + } + } + + endmntent(f); + + if (fstype == "ext4dev") + fstype = "ext4"; + + y2mil("fstype:" << fstype); + + return !best_match.empty(); } }