]> err.no Git - util-linux/commitdiff
libblkid: fix blkid_do_probe() to work properly with chains
authorKarel Zak <kzak@redhat.com>
Thu, 1 Oct 2009 22:49:07 +0000 (00:49 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 2 Oct 2009 13:14:50 +0000 (15:14 +0200)
The blkid_do_probe() always switched to the new chain -- that's bad, we
have to try all probing methods in the chain.

Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/probe.c
shlibs/blkid/src/superblocks/superblocks.c
shlibs/blkid/src/topology/topology.c

index 054cc920cd22473c50830d5b611ce785cc5c57d4..078669f48ebf5042b5c94546ebdf769c4c4065cd 100644 (file)
@@ -319,8 +319,9 @@ void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn)
  * blkid_reset_probe:
  * @pr: probe
  *
- * Cleanup probing result. This function does not touch probing filters
- * and keeps assigned device.
+ * Zeroize probing results and resets the current probing (this has impact to
+ * blkid_do_probe() only). This function does not touch probing filters and
+ * keeps assigned device.
  */
 void blkid_reset_probe(blkid_probe pr)
 {
@@ -332,6 +333,8 @@ void blkid_reset_probe(blkid_probe pr)
        blkid_probe_reset_buffer(pr);
        blkid_probe_reset_vals(pr);
 
+       pr->cur_chain = NULL;
+
        for (i = 0; i < BLKID_NCHAINS; i++)
                pr->chains[i].idx = -1;
 }
@@ -537,7 +540,7 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
  * @size: size of probing area (zero means whole device/file)
  *
  * Assigns the device to probe control struct, resets internal buffers and
- * reads 512 bytes from device to the buffers.
+ * resets the current probing.
  *
  * Returns: -1 in case of failure, or 0 on success.
  */
@@ -634,7 +637,8 @@ int blkid_probe_set_dimension(blkid_probe pr,
  * Calls probing functions in all enabled chains. The superblocks chain is
  * enabled by default. The blkid_do_probe() stores result from only one
  * probing function. It's necessary to call this routine in a loop to get
- * resuluts from all probing functions in all chains.
+ * results from all probing functions in all chains. The probing is reseted
+ * by blkid_reset_probe() or by filter functions.
  *
  * This is string-based NAME=value interface only.
  *
@@ -675,25 +679,33 @@ int blkid_do_probe(blkid_probe pr)
                return -1;
 
        do {
-               struct blkid_chain *chn;
+               struct blkid_chain *chn = pr->cur_chain;
 
-               if (!pr->cur_chain)
-                       pr->cur_chain = &pr->chains[0];
-               else {
-                       int idx = pr->cur_chain->driver->id + 1;
+               if (!chn)
+                       chn = pr->cur_chain = &pr->chains[0];
+
+               /* we go to the next chain only when the previous probing
+                * result was nothing (rc == 1) and when the current chain is
+                * disabled or we are at end of the current chain (chain->idx +
+                * 1 == sizeof chain)
+                */
+               else if (rc == 1 && (chn->enabled == FALSE ||
+                                    chn->idx + 1 == chn->driver->nidinfos)) {
+
+                       int idx = chn->driver->id + 1;
 
                        if (idx < BLKID_NCHAINS)
-                               pr->cur_chain = &pr->chains[idx];
+                               chn = pr->cur_chain = &pr->chains[idx];
                        else
                                return 1;       /* all chains already probed */
                }
 
-               chn = pr->cur_chain;
                chn->binary = FALSE;            /* for sure... */
 
-               DBG(DEBUG_LOWPROBE, printf("chain probe %s %s\n",
+               DBG(DEBUG_LOWPROBE, printf("chain probe %s %s (idx=%d)\n",
                                chn->driver->name,
-                               chn->enabled? "ENABLED" : "DISABLED"));
+                               chn->enabled? "ENABLED" : "DISABLED",
+                               chn->idx));
 
                if (!chn->enabled)
                        continue;
index f32873682aaabb68b8968b9dcffaa474db1b4c70..8cd50c9539e954737271845e353649a05522bcb5 100644 (file)
@@ -297,8 +297,6 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
 
        if (!pr || chn->idx < -1)
                return -1;
-       if (chn->idx < -1)
-               return -1;
        blkid_probe_chain_reset_vals(pr, chn);
 
        DBG(DEBUG_LOWPROBE,
index 80499005faccba01b47650b8477daa1ac6d74e0a..072261f395cb301632ccfcfa16d8fda490ee460d 100644 (file)
@@ -133,8 +133,6 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn)
 
        if (!pr || chn->idx < -1)
                return -1;
-       if (chn->idx < -1)
-               return -1;
 
        if (chn->binary) {
                DBG(DEBUG_LOWPROBE, printf("initialize topology binary data\n"));