cbfs: add cbfs_read()
Allow for reading from cbfs media without having a handle to a non-CBFS_DEFAULT_MEDIA cbfs_media. In conjunction with cbfs_locate_file() one can locate and cbfs_read() a file without bringing the entire file through a potentially temporary buffer (non-memory-mappable cbfs media platforms). BUG=chrome-os-partner:29922 BRANCH=None TEST=Built. Change-Id: Ib5d965334bce1267650fc23c9e9f496675cf8450 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/205991 Reviewed-by: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
parent
56c958facd
commit
85200f2886
2 changed files with 20 additions and 0 deletions
|
|
@ -233,6 +233,10 @@ struct cbfs_media {
|
|||
ssize_t cbfs_locate_file(struct cbfs_media *media, struct cbfs_file *file,
|
||||
const char *name);
|
||||
|
||||
/* Read count bytes at offset into dest. Return number of bytes read. */
|
||||
size_t cbfs_read(struct cbfs_media *media, void *dest, size_t offset,
|
||||
size_t count);
|
||||
|
||||
/* returns pointer to a file entry inside CBFS or NULL */
|
||||
struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name);
|
||||
|
||||
|
|
|
|||
|
|
@ -192,6 +192,22 @@ ssize_t cbfs_locate_file(struct cbfs_media *media, struct cbfs_file *file,
|
|||
return -1;
|
||||
}
|
||||
|
||||
size_t cbfs_read(struct cbfs_media *media, void *dest, size_t offset,
|
||||
size_t count)
|
||||
{
|
||||
struct cbfs_media default_media;
|
||||
size_t nread;
|
||||
|
||||
if (init_media(&media, &default_media))
|
||||
return 0;
|
||||
|
||||
media->open(media);
|
||||
nread = media->read(media, dest, offset, count);
|
||||
media->close(media);
|
||||
|
||||
return nread;
|
||||
}
|
||||
|
||||
struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
|
||||
{
|
||||
struct cbfs_media default_media;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue