
On 10/07/2013 07:06 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Add a function for efficiently checking if a path is a filesystem mount point.
NB will not work for bind mounts, only true filesystem mounts.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> ---
+ * + * Note that this will not detect bind mounts of dirs/files, + * only true filesystem mounts. + */ +int virFileIsMountPoint(const char *file) +{ + char *parent = NULL; + char *tmp; + int ret = -1; + struct stat sb1, sb2; + + if (VIR_STRDUP_QUIET(parent, file) < 0) + goto cleanup; + + if (!(tmp = strrchr(parent, '/'))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find '/' in '%s'"), + file); + goto cleanup; + } + + *tmp = '\0';
Might be simpler to use gnulib's mdir_name(), which mallocs the result for you and is also ported to work on mingw in spite of their drive letter style paths.
+ + VIR_DEBUG("Comparing '%s' to '%s'", file, parent); + + if (stat(file, &sb1) < 0) {
Is stat() right, or should you be using lstat()? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org