summaryrefslogtreecommitdiffstats
path: root/libblkid/src/probe.c
diff options
context:
space:
mode:
authorManuel Bentele2019-08-21 14:58:42 +0200
committerManuel Bentele2019-08-21 14:58:42 +0200
commit0692b963aa3cb846d8abab5ef5247c4dbb3fec96 (patch)
treef13776d25da3e1adc1445aef22e7566ac98cbe84 /libblkid/src/probe.c
parentlosetup: added file format option to the man page (diff)
parentpartx: document -d vs. --nr and fix test (diff)
downloadkernel-qcow2-util-linux-kernel-qcow2.tar.gz
kernel-qcow2-util-linux-kernel-qcow2.tar.xz
kernel-qcow2-util-linux-kernel-qcow2.zip
lib/losetup: merge remote-tracking branch 'util-linux/master'kernel-qcow2
Signed-off-by: Manuel Bentele <development@manuel-bentele.de>
Diffstat (limited to 'libblkid/src/probe.c')
-rw-r--r--libblkid/src/probe.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 1ace06a68..ae1fc06d6 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -846,10 +846,15 @@ failed:
* @off: begin of probing area
* @size: size of probing area (zero means whole device/file)
*
- * Assigns the device to probe control struct, resets internal buffers and
- * resets the current probing.
+ * Assigns the device to probe control struct, resets internal buffers, resets
+ * the current probing, and close previously associated device (if open by
+ * libblkid).
*
- * Returns: -1 in case of failure, or 0 on success.
+ * If @fd is < 0 than only resets the prober and returns 1. Note that
+ * blkid_reset_probe() keeps the device associated with the prober, but
+ * blkid_probe_set_device() does complete reset.
+ *
+ * Returns: -1 in case of failure, 0 on success and 1 on reset.
*/
int blkid_probe_set_device(blkid_probe pr, int fd,
blkid_loff_t off, blkid_loff_t size)
@@ -864,6 +869,11 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
if ((pr->flags & BLKID_FL_PRIVATE_FD) && pr->fd >= 0)
close(pr->fd);
+ if (pr->disk_probe) {
+ blkid_free_probe(pr->disk_probe);
+ pr->disk_probe = NULL;
+ }
+
pr->flags &= ~BLKID_FL_PRIVATE_FD;
pr->flags &= ~BLKID_FL_TINY_DEV;
pr->flags &= ~BLKID_FL_CDROM_DEV;
@@ -879,6 +889,9 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
pr->wipe_size = 0;
pr->wipe_chain = NULL;
+ if (fd < 0)
+ return 1;
+
#if defined(POSIX_FADV_RANDOM) && defined(HAVE_POSIX_FADVISE)
/* Disable read-ahead */
posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);