[libvirt] [PATCH 1/6] Add virFileIsMountPoint function
Eric Blake
eblake at redhat.com
Wed Oct 9 03:16:20 UTC 2013
On 10/07/2013 07:06 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at 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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131008/8519cc13/attachment-0001.sig>
More information about the libvir-list
mailing list