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>
This commit is contained in:
Ronald G. Minnich 2018-05-14 13:27:07 -07:00
parent 5a1f5400fb
commit 60fd684698

View file

@ -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",