Browse Source

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

returns the allocated buffer.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
475d6d1f7c
5 changed files with 19 additions and 22 deletions
  1. 1
    3
      src/core/image.c
  2. 0
    8
      src/include/gpxe/image.h
  3. 5
    2
      src/include/usr/fetch.h
  4. 12
    8
      src/usr/fetch.c
  5. 1
    1
      src/usr/imgmgmt.c

+ 1
- 3
src/core/image.c View File

99
  * image.
99
  * image.
100
  */
100
  */
101
 void free_image ( struct image *image ) {
101
 void free_image ( struct image *image ) {
102
-	if ( image->free )
103
-		image->free ( image->data );
104
-	image->free = NULL;
102
+	efree ( image->data );
105
 	image->data = UNULL;
103
 	image->data = UNULL;
106
 	image->len = 0;
104
 	image->len = 0;
107
 }
105
 }

+ 0
- 8
src/include/gpxe/image.h View File

31
 	userptr_t data;
31
 	userptr_t data;
32
 	/** Length of raw file image */
32
 	/** Length of raw file image */
33
 	size_t len;
33
 	size_t len;
34
-	/**
35
-	 * Free raw file image
36
-	 *
37
-	 * @v data		Raw file image
38
-	 *
39
-	 * Call this method before freeing up the @c struct @c image.
40
-	 */
41
-	void ( * free ) ( userptr_t data );
42
 
34
 
43
 	/** Entry point */
35
 	/** Entry point */
44
 	physaddr_t entry;
36
 	physaddr_t entry;

+ 5
- 2
src/include/usr/fetch.h View File

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

+ 12
- 8
src/usr/fetch.c View File

34
 #include <gpxe/dhcp.h>
34
 #include <gpxe/dhcp.h>
35
 
35
 
36
 /**
36
 /**
37
- * Fetch file as executable/loadable image
37
+ * Fetch file
38
  *
38
  *
39
- * @v image		Executable/loadable image
40
- * @v filename		Filename
39
+ * @v filename		Filename to fetch
40
+ * @ret data		Loaded file
41
+ * @ret len		Length of loaded file
41
  * @ret rc		Return status code
42
  * @ret rc		Return status code
43
+ *
44
+ * Fetch file to an external buffer allocated with emalloc().  The
45
+ * caller is responsible for eventually freeing the buffer with
46
+ * efree().
42
  */
47
  */
43
-int fetch ( struct image *image, const char *filename ) {
48
+int fetch ( const char *filename, userptr_t *data, size_t *len ) {
44
 	struct buffer buffer;
49
 	struct buffer buffer;
45
 	int rc;
50
 	int rc;
46
 
51
 
69
 		return rc;
74
 		return rc;
70
 	}
75
 	}
71
 
76
 
72
-	/* Transfer ownserhip of the data buffer to the image */
73
-	image->data = buffer.addr;
74
-	image->len = buffer.fill;
75
-	image->free = efree;
77
+	/* Fill in buffer address and length */
78
+	*data = buffer.addr;
79
+	*len = buffer.fill;
76
 
80
 
77
 	return 0;
81
 	return 0;
78
 }
82
 }

+ 1
- 1
src/usr/imgmgmt.c View File

54
 		strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
54
 		strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
55
 
55
 
56
 	/* Fetch the file */
56
 	/* Fetch the file */
57
-	if ( ( rc = fetch ( image, filename ) ) != 0 )
57
+	if ( ( rc = fetch ( filename, &image->data, &image->len ) ) != 0 )
58
 		goto err;
58
 		goto err;
59
 
59
 
60
 	/* Register the image */
60
 	/* Register the image */

Loading…
Cancel
Save