From 9fbd73a208c9465b4bf9e2c80c7290b72e62ead1 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Tue, 1 Oct 2013 12:27:35 +0800 Subject: discover: Add device_{request,release}_write Add a pair of functions to the parser API to allow write access to the underlying device. We'll use this in the GRUB2 parser to implement environment persistence. Signed-off-by: Jeremy Kerr --- test/parser/utils.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/parser/utils.c') diff --git a/test/parser/utils.c b/test/parser/utils.c index d1ced73..33efda8 100644 --- a/test/parser/utils.c +++ b/test/parser/utils.c @@ -186,6 +186,36 @@ int parser_request_file(struct discover_context *ctx, return -1; } +int parser_replace_file(struct discover_context *ctx, + struct discover_device *dev, const char *filename, + char *buf, int len) +{ + struct parser_test *test = ctx->test_data; + struct test_file *f, *file; + + list_for_each_entry(&test->files, f, list) { + if (f->dev != dev) + continue; + if (strcmp(f->name, filename)) + continue; + + file = f; + break; + } + + if (!file) { + file = talloc_zero(test, struct test_file); + file->dev = dev; + file->name = filename; + list_add(&test->files, &file->list); + } else { + talloc_free(file->data); + } + + file->data = talloc_memdup(test, buf, len); + file->size = len; + return 0; +} int test_run_parser(struct parser_test *test, const char *parser_name) { struct p_item* i; -- cgit v1.2.1