Skip to content

Commit

Permalink
gard: Add iterators
Browse files Browse the repository at this point in the history
Add a `for_each_gard` iterator rather than using do_iterate. Callbacks
are banned under the Genoa convention and we need to apply a
zero-tolerance policy.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Nov 21, 2017
1 parent 1e03838 commit 07d6b1a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions external/gard/gard.c
Expand Up @@ -212,6 +212,37 @@ static int do_iterate(struct gard_ctx *ctx,
return rc;
}

/*
* read the next guard record into the supplied buffer (gard)
*
* returns the record id (nb: 1 based not zero)
*
*/
static int __gard_next(struct gard_ctx *ctx, int pos, struct gard_record *gard, int *rc)
{
uint32_t offset = pos * sizeof_gard(ctx);

if (offset > ctx->gard_data_len) /* too big */
return -1;

/* you lose error handling information, *gruble* */
memset(gard, 0, sizeof(*gard));
*rc = blocklevel_read(ctx->bl, ctx->gard_data_pos + offset,
gard, sizeof(*gard));

if (!is_valid_record(gard))
return -1;

if (*rc)
return -1;

return pos;
}

#define for_each_gard(ctx, pos, gard, rc) \
for (pos = __gard_next(ctx, 0, gard, rc); \
pos >= 0; pos = __gard_next(ctx, ++pos, gard, rc))

static int get_largest_pos_i(struct gard_ctx *ctx, int pos, struct gard_record *gard, void *priv)
{
(void)ctx;
Expand Down

0 comments on commit 07d6b1a

Please sign in to comment.