diff options
author | Ronald G. Minnich <rminnich@gmail.com> | 2018-05-14 13:27:07 -0700 |
---|---|---|
committer | Ronald G. Minnich <rminnich@gmail.com> | 2018-05-14 21:54:15 +0000 |
commit | 60fd684698e7da894d539936307aea94d0c83bd1 (patch) | |
tree | 925751b1250b8485de547bd9864e27aed9d06339 /src/commonlib/cbfs.c | |
parent | 5a1f5400fb93ffc257486318351feff9c3b48d21 (diff) |
cbfs_locate: Optionally return file type
In some cases callers want to know if a file
exists and, if so, what its type is.
Modify cbfs_locate so that if the pointer is non-NULL,
but has the value 0, the type of the file that
matches the name will be returned.
Change-Id: Ic1349d358c3054207ccbccf3825db56784327ad0
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-on: https://review.coreboot.org/26279
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/commonlib/cbfs.c')
-rw-r--r-- | src/commonlib/cbfs.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/commonlib/cbfs.c b/src/commonlib/cbfs.c index 1db8d31acf..e14e6c5e61 100644 --- a/src/commonlib/cbfs.c +++ b/src/commonlib/cbfs.c @@ -212,12 +212,18 @@ int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, if (cbfsf_file_type(fh, &ftype)) break; - if (*type != ftype) { + if (*type != 0 && *type != ftype) { DEBUG(" Unmatched type %x at %zx\n", ftype, rdev_relative_offset(cbfs, &fh->metadata)); continue; } + // *type being 0 means we want to know ftype. + // We could just do a blind assignment but + // if type is pointing to read-only memory + // that might be bad. + if (*type == 0) + *type = ftype; } LOG("Found @ offset %zx size %zx\n", |