From 475d6d1f7c7f169a89ea363ad819b0dd2975ae10 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 12 Jan 2007 08:02:27 +0000 Subject: [PATCH] fetch() now knows nothing about struct image; it simply loads a file and returns the allocated buffer. --- src/core/image.c | 4 +--- src/include/gpxe/image.h | 8 -------- src/include/usr/fetch.h | 7 +++++-- src/usr/fetch.c | 20 ++++++++++++-------- src/usr/imgmgmt.c | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/core/image.c b/src/core/image.c index 51998982..ce69c8a3 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -99,9 +99,7 @@ struct image * find_image ( const char *name ) { * image. */ void free_image ( struct image *image ) { - if ( image->free ) - image->free ( image->data ); - image->free = NULL; + efree ( image->data ); image->data = UNULL; image->len = 0; } diff --git a/src/include/gpxe/image.h b/src/include/gpxe/image.h index 7f11e6a0..5367735c 100644 --- a/src/include/gpxe/image.h +++ b/src/include/gpxe/image.h @@ -31,14 +31,6 @@ struct image { userptr_t data; /** Length of raw file image */ size_t len; - /** - * Free raw file image - * - * @v data Raw file image - * - * Call this method before freeing up the @c struct @c image. - */ - void ( * free ) ( userptr_t data ); /** Entry point */ physaddr_t entry; diff --git a/src/include/usr/fetch.h b/src/include/usr/fetch.h index e7c035be..372f6f8c 100644 --- a/src/include/usr/fetch.h +++ b/src/include/usr/fetch.h @@ -4,10 +4,13 @@ /** * @file * - * Fetch file as executable/loadable image + * Fetch file * */ -extern int fetch ( struct image *image, const char *filename ); +#include +#include + +extern int fetch ( const char *filename, userptr_t *data, size_t *len ); #endif /* _USR_FETCH_H */ diff --git a/src/usr/fetch.c b/src/usr/fetch.c index 00173184..fe5ae59f 100644 --- a/src/usr/fetch.c +++ b/src/usr/fetch.c @@ -34,13 +34,18 @@ #include /** - * Fetch file as executable/loadable image + * Fetch file * - * @v image Executable/loadable image - * @v filename Filename + * @v filename Filename to fetch + * @ret data Loaded file + * @ret len Length of loaded file * @ret rc Return status code + * + * Fetch file to an external buffer allocated with emalloc(). The + * caller is responsible for eventually freeing the buffer with + * efree(). */ -int fetch ( struct image *image, const char *filename ) { +int fetch ( const char *filename, userptr_t *data, size_t *len ) { struct buffer buffer; int rc; @@ -69,10 +74,9 @@ int fetch ( struct image *image, const char *filename ) { return rc; } - /* Transfer ownserhip of the data buffer to the image */ - image->data = buffer.addr; - image->len = buffer.fill; - image->free = efree; + /* Fill in buffer address and length */ + *data = buffer.addr; + *len = buffer.fill; return 0; } diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index 2c949ae2..6a2599d5 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -54,7 +54,7 @@ int imgfetch ( const char *filename, const char *name, strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) ); /* Fetch the file */ - if ( ( rc = fetch ( image, filename ) ) != 0 ) + if ( ( rc = fetch ( filename, &image->data, &image->len ) ) != 0 ) goto err; /* Register the image */