diff options
author | Karel Zak | 2009-09-15 21:27:54 +0200 |
---|---|---|
committer | Karel Zak | 2009-09-16 10:04:26 +0200 |
commit | 9bdf688541df79d2a0885a6d2f7ca4836360efa9 (patch) | |
tree | 7f2de9f968b01431e188fb170fa5d14cb6628175 /shlibs/blkid/src/probe.c | |
parent | libblkid: add chain structs (diff) | |
download | kernel-qcow2-util-linux-9bdf688541df79d2a0885a6d2f7ca4836360efa9.tar.gz kernel-qcow2-util-linux-9bdf688541df79d2a0885a6d2f7ca4836360efa9.tar.xz kernel-qcow2-util-linux-9bdf688541df79d2a0885a6d2f7ca4836360efa9.zip |
libblkid: add functions for chain tags
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/blkid/src/probe.c')
-rw-r--r-- | shlibs/blkid/src/probe.c | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 02fa0a861..b394b1fe7 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -143,6 +143,63 @@ void blkid_free_probe(blkid_probe pr) free(pr); } +/* + * Removes chain values from probing result. + */ +void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn) +{ + int nvals = pr->nvals; + int i, x; + + for (x = 0, i = 0; i < pr->nvals; i++) { + struct blkid_prval *v = &pr->vals[i]; + + if (v->chain != chn && x == i) { + x++; + continue; + } + if (v->chain == chn) { + --nvals; + continue; + } + memcpy(&pr->vals[x++], v, sizeof(struct blkid_prval)); + } + pr->nvals = nvals; +} + +/* + * Copies chain values from probing result to @vals, the max size of @vals is + * @nvals and returns real number of values. + */ +int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn, + struct blkid_prval *vals, int nvals) +{ + int i, x; + + for (x = 0, i = 0; i < pr->nvals && x < nvals; i++) { + struct blkid_prval *v = &pr->vals[i]; + + if (v->chain != chn) + continue; + memcpy(&vals[x++], v, sizeof(struct blkid_prval)); + } + return x; +} + +/* + * Appends values from @vals to the probing result + */ +void blkid_probe_append_vals(blkid_probe pr, struct blkid_prval *vals, int nvals) +{ + int i = 0; + + while (i < nvals && pr->nvals < BLKID_NVALS) { + memcpy(&pr->vals[pr->nvals++], &vals[i++], + sizeof(struct blkid_prval)); + } +} + + static void blkid_probe_reset_vals(blkid_probe pr) { memset(pr->vals, 0, sizeof(pr->vals)); @@ -572,8 +629,7 @@ int blkid_probe_numof_values(blkid_probe pr) return pr->nvals; } - -static struct blkid_prval *blkid_probe_assign_value( +struct blkid_prval *blkid_probe_assign_value( blkid_probe pr, const char *name) { struct blkid_prval *v; @@ -585,9 +641,11 @@ static struct blkid_prval *blkid_probe_assign_value( v = &pr->vals[pr->nvals]; v->name = name; + v->chain = pr->cur_chain; pr->nvals++; - DBG(DEBUG_LOWPROBE, printf("assigning %s\n", name)); + DBG(DEBUG_LOWPROBE, + printf("assigning %s [%s]\n", name, v->chain->driver->name)); return v; } |