瀏覽代碼

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

returns the allocated buffer.
tags/v0.9.3
Michael Brown 17 年之前
父節點
當前提交
475d6d1f7c
共有 5 個檔案被更改,包括 19 行新增22 行删除
  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 查看文件

@@ -99,9 +99,7 @@ struct image * find_image ( const char *name ) {
99 99
  * image.
100 100
  */
101 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 103
 	image->data = UNULL;
106 104
 	image->len = 0;
107 105
 }

+ 0
- 8
src/include/gpxe/image.h 查看文件

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

+ 5
- 2
src/include/usr/fetch.h 查看文件

@@ -4,10 +4,13 @@
4 4
 /**
5 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 16
 #endif /* _USR_FETCH_H */

+ 12
- 8
src/usr/fetch.c 查看文件

@@ -34,13 +34,18 @@
34 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 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 49
 	struct buffer buffer;
45 50
 	int rc;
46 51
 
@@ -69,10 +74,9 @@ int fetch ( struct image *image, const char *filename ) {
69 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 81
 	return 0;
78 82
 }

+ 1
- 1
src/usr/imgmgmt.c 查看文件

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

Loading…
取消
儲存