From d2a8b8d145435a39b489c51b200d80ab18bda9c7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 10 Jun 2014 13:32:02 +0200 Subject: libblkid: cleanup internal return codes Signed-off-by: Karel Zak --- libblkid/src/partitions/partitions.c | 30 +++++++++++++++++++----------- libblkid/src/superblocks/superblocks.c | 23 +++++++++++------------ libblkid/src/topology/topology.c | 8 ++++---- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index cee963ff6..04c75afa7 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -536,7 +536,7 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id, { const struct blkid_idmag *mag = NULL; blkid_loff_t off; - int rc = BLKID_PROBE_NONE; /* = nothing detected */ + int rc = BLKID_PROBE_NONE; /* default is nothing */ if (pr->size <= 0 || (id->minsz && id->minsz > pr->size)) goto nothing; /* the device is too small */ @@ -567,8 +567,10 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id, DBG(LOWPROBE, ul_debug("%s: <--- (rc = %d)", id->name, rc)); } -nothing: return rc; + +nothing: + return BLKID_PROBE_NONE; } /* @@ -581,11 +583,12 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) if (!pr || chn->idx < -1) return -EINVAL; - if (pr->flags & BLKID_FL_NOSCAN_DEV) - goto done; /* nothing */ blkid_probe_chain_reset_vals(pr, chn); + if (pr->flags & BLKID_FL_NOSCAN_DEV) + return BLKID_PROBE_NONE; + if (chn->binary) partitions_init_data(chn); @@ -627,7 +630,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) DBG(LOWPROBE, ul_debug("<-- leaving probing loop (type=%s) [PARTS idx=%d]", name, chn->idx)); - rc = 0; + rc = BLKID_PROBE_OK; break; } @@ -653,7 +656,6 @@ details_only: rc = xrc; } -done: DBG(LOWPROBE, ul_debug("partitions probe done [rc=%d]", rc)); return rc; } @@ -723,7 +725,6 @@ int blkid_partitions_do_subprobe(blkid_probe pr, blkid_partition parent, static int blkid_partitions_probe_partition(blkid_probe pr) { - int rc = BLKID_PROBE_NONE; blkid_probe disk_pr = NULL; blkid_partlist ls; blkid_partition par; @@ -748,7 +749,9 @@ static int blkid_partitions_probe_partition(blkid_probe pr) goto nothing; par = blkid_partlist_devno_to_partition(ls, devno); - if (par) { + if (!par) + goto nothing; + else { const char *v; blkid_parttable tab = blkid_partition_get_table(par); dev_t disk = blkid_probe_get_devno(disk_pr); @@ -794,10 +797,15 @@ static int blkid_partitions_probe_partition(blkid_probe pr) blkid_probe_sprintf_value(pr, "PART_ENTRY_DISK", "%u:%u", major(disk), minor(disk)); } - rc = BLKID_PROBE_OK; + + DBG(LOWPROBE, ul_debug("parts: end probing for partition entry [success]")); + return BLKID_PROBE_OK; + nothing: - DBG(LOWPROBE, ul_debug("parts: end probing for partition entry [rc=%d]", rc)); - return rc; + DBG(LOWPROBE, ul_debug("parts: end probing for partition entry [nothing]")); + return BLKID_PROBE_NONE; + + } /* diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index bfe37b85d..80bd6e596 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -340,19 +340,20 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn) if (!pr || chn->idx < -1) return -EINVAL; - if (pr->flags & BLKID_FL_NOSCAN_DEV) - goto nothing; blkid_probe_chain_reset_vals(pr, chn); - DBG(LOWPROBE, ul_debug("--> starting probing loop [SUBLKS idx=%d]", - chn->idx)); + if (pr->flags & BLKID_FL_NOSCAN_DEV) + return BLKID_PROBE_NONE; if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode))) /* Ignore very very small block devices or regular files (e.g. * extended partitions). Note that size of the UBI char devices * is 1 byte */ - goto nothing; + return BLKID_PROBE_NONE; + + DBG(LOWPROBE, ul_debug("--> starting probing loop [SUBLKS idx=%d]", + chn->idx)); i = chn->idx < 0 ? 0 : chn->idx + 1U; @@ -422,7 +423,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn) (unsigned char *) mag->magic); if (rc) { blkid_probe_chain_reset_vals(pr, chn); - DBG(LOWPROBE, ul_debug("failed to set result -- ingnore")); + DBG(LOWPROBE, ul_debug("failed to set result -- ignore")); continue; } @@ -431,7 +432,6 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn) return BLKID_PROBE_OK; } -nothing: DBG(LOWPROBE, ul_debug("<-- leaving probing loop (failed=%d) [SUBLKS idx=%d]", rc, chn->idx)); return rc; @@ -459,13 +459,12 @@ static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn) int rc; if (pr->flags & BLKID_FL_NOSCAN_DEV) - return 1; /* nothing */ + return BLKID_PROBE_NONE; while ((rc = superblocks_probe(pr, chn)) == 0) { if (blkid_probe_is_tiny(pr) && !count) - /* floppy or so -- returns the first result. */ - return 0; + return BLKID_PROBE_OK; /* floppy or so -- returns the first result. */ count++; @@ -494,7 +493,7 @@ static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn) return -2; /* error, ambivalent result (more FS) */ } if (!count) - return 1; /* nothing detected */ + return BLKID_PROBE_NONE; if (idx != -1) { /* restore the first result */ @@ -511,7 +510,7 @@ static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn) if (chn->idx >= 0 && idinfos[chn->idx]->usage & BLKID_USAGE_RAID) pr->prob_flags |= BLKID_PROBE_FL_IGNORE_PT; - return 0; + return BLKID_PROBE_OK; } int blkid_probe_set_version(blkid_probe pr, const char *version) diff --git a/libblkid/src/topology/topology.c b/libblkid/src/topology/topology.c index a6a7a3bd5..93fa3802e 100644 --- a/libblkid/src/topology/topology.c +++ b/libblkid/src/topology/topology.c @@ -150,7 +150,7 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn) return -1; if (!S_ISBLK(pr->mode)) - return -1; /* nothing, works with block devices only */ + return -EINVAL; /* nothing, works with block devices only */ if (chn->binary) { DBG(LOWPROBE, ul_debug("initialize topology binary data")); @@ -163,7 +163,7 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn) chn->data = calloc(1, sizeof(struct blkid_struct_topology)); if (!chn->data) - return -1; + return -ENOMEM; } } @@ -193,12 +193,12 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn) DBG(LOWPROBE, ul_debug("<-- leaving probing loop (type=%s) [TOPOLOGY idx=%d]", id->name, chn->idx)); - return 0; + return BLKID_PROBE_OK; } DBG(LOWPROBE, ul_debug("<-- leaving probing loop (failed) [TOPOLOGY idx=%d]", chn->idx)); - return 1; + return BLKID_PROBE_NONE; } static void topology_free(blkid_probe pr __attribute__((__unused__)), -- cgit v1.2.3-55-g7522