+// IsMounted - Returns true if the mount point is mounted /*{{{*/
+// ---------------------------------------------------------------------
+/* This is a simple algorithm that should always work, we stat the mount point
+ and the '..' file in the mount point and see if they are on the same device.
+ By definition if they are the same then it is not mounted. This should
+ account for symlinked mount points as well. */
+bool IsMounted(string &Path)
+{
+ if (Path.empty() == true)
+ return false;
+
+ // Need that trailing slash for directories
+ if (Path[Path.length() - 1] != '/')
+ Path += '/';
+
+ /* First we check if the path is actualy mounted, we do this by
+ stating the path and the previous directory (carefull of links!)
+ and comparing their device fields. */
+ struct stat Buf,Buf2;
+ if (stat(Path.c_str(),&Buf) != 0 ||
+ stat((Path + "../").c_str(),&Buf2) != 0)
+ return _error->Errno("stat",_("Unable to stat the mount point %s"),Path.c_str());
+
+ if (Buf.st_dev == Buf2.st_dev)
+ return false;
+ return true;
+}
+ /*}}}*/