fetch() now knows nothing about struct image; it simply loads a file and

returns the allocated buffer.
pull/1/head
Michael Brown 2007-01-12 08:02:27 +00:00
parent 2876197306
commit 475d6d1f7c
5 changed files with 19 additions and 22 deletions

View File

@ -99,9 +99,7 @@ struct image * find_image ( const char *name ) {
* image. * image.
*/ */
void free_image ( struct image *image ) { void free_image ( struct image *image ) {
if ( image->free ) efree ( image->data );
image->free ( image->data );
image->free = NULL;
image->data = UNULL; image->data = UNULL;
image->len = 0; image->len = 0;
} }

View File

@ -31,14 +31,6 @@ struct image {
userptr_t data; userptr_t data;
/** Length of raw file image */ /** Length of raw file image */
size_t len; 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 */ /** Entry point */
physaddr_t entry; physaddr_t entry;

View File

@ -4,10 +4,13 @@
/** /**
* @file * @file
* *
* Fetch file as executable/loadable image * Fetch file
* *
*/ */
extern int fetch ( struct image *image, const char *filename ); #include <stdint.h>
#include <gpxe/uaccess.h>
extern int fetch ( const char *filename, userptr_t *data, size_t *len );
#endif /* _USR_FETCH_H */ #endif /* _USR_FETCH_H */

View File

@ -34,13 +34,18 @@
#include <gpxe/dhcp.h> #include <gpxe/dhcp.h>
/** /**
* Fetch file as executable/loadable image * Fetch file
* *
* @v image Executable/loadable image * @v filename Filename to fetch
* @v filename Filename * @ret data Loaded file
* @ret len Length of loaded file
* @ret rc Return status code * @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; struct buffer buffer;
int rc; int rc;
@ -69,10 +74,9 @@ int fetch ( struct image *image, const char *filename ) {
return rc; return rc;
} }
/* Transfer ownserhip of the data buffer to the image */ /* Fill in buffer address and length */
image->data = buffer.addr; *data = buffer.addr;
image->len = buffer.fill; *len = buffer.fill;
image->free = efree;
return 0; return 0;
} }

View File

@ -54,7 +54,7 @@ int imgfetch ( const char *filename, const char *name,
strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) ); strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
/* Fetch the file */ /* Fetch the file */
if ( ( rc = fetch ( image, filename ) ) != 0 ) if ( ( rc = fetch ( filename, &image->data, &image->len ) ) != 0 )
goto err; goto err;
/* Register the image */ /* Register the image */