Przeglądaj źródła

Protocols now load data into a buffer; they don't execute it.

tags/v0.9.3
Michael Brown 19 lat temu
rodzic
commit
0fe74493f4
6 zmienionych plików z 37 dodań i 50 usunięć
  1. 10
    2
      src/core/main.c
  2. 5
    14
      src/core/nic.c
  3. 4
    9
      src/include/dev.h
  4. 3
    7
      src/include/proto.h
  5. 3
    6
      src/include/tftp.h
  6. 12
    12
      src/proto/tftp.c

+ 10
- 2
src/core/main.c Wyświetl plik

@@ -162,6 +162,7 @@ void initialise ( void ) {
162 162
 MAIN - Kick off routine
163 163
 **************************************************************************/
164 164
 int main ( void ) {
165
+	struct buffer buffer;
165 166
 	int skip = 0;
166 167
 
167 168
 	/* Print out configuration */
@@ -213,8 +214,15 @@ int main ( void ) {
213 214
 			continue;
214 215
 		}
215 216
 
216
-		/* Boot from the device */
217
-		load ( &dev, load_block );
217
+		/* Load boot file from the device */
218
+		init_buffer ( &buffer, 0x7c00, 0x100 );
219
+		if ( ! load ( &dev, &buffer ) ) {
220
+			/* Load (e.g. TFTP failed) */
221
+			printf ( "...load failed\n" );
222
+			continue;
223
+		}
224
+
225
+		printf ( "Loaded file of size %d\n", buffer.fill );
218 226
 
219 227
 	}
220 228
 

+ 5
- 14
src/core/nic.c Wyświetl plik

@@ -282,14 +282,10 @@ static int nic_configure ( struct type_dev *type_dev ) {
282 282
 
283 283
 
284 284
 /*
285
- * Download a file from the specified URL and process it with the
286
- * specified function
285
+ * Download a file from the specified URL into the specified buffer
287 286
  *
288 287
  */
289
-int download_url ( char *url,
290
-		   int ( * process ) ( unsigned char *data,
291
-				       unsigned int blocknum,
292
-				       unsigned int len, int eof ) ) {
288
+int download_url ( char *url, struct buffer *buffer ) {
293 289
 	struct protocol *proto;
294 290
 	struct sockaddr_in server;
295 291
 	char *filename;
@@ -303,7 +299,7 @@ int download_url ( char *url,
303 299
 	}
304 300
 	
305 301
 	/* Call protocol's method to download the file */
306
-	return proto->load ( url, &server, filename, process );
302
+	return proto->load ( url, &server, filename, buffer );
307 303
 }
308 304
 
309 305
 
@@ -312,10 +308,7 @@ int download_url ( char *url,
312 308
 /**************************************************************************
313 309
 LOAD - Try to get booted
314 310
 **************************************************************************/
315
-static int nic_load ( struct type_dev *type_dev,
316
-		      int ( * process ) ( unsigned char *data,
317
-					  unsigned int blocknum,
318
-					  unsigned int size, int eof ) ) {
311
+static int nic_load ( struct type_dev *type_dev, struct buffer *buffer ) {
319 312
 	char	*kernel;
320 313
 
321 314
 	/* Now use TFTP to load file */
@@ -327,12 +320,10 @@ static int nic_load ( struct type_dev *type_dev,
327 320
 #endif
328 321
 		: KERNEL_BUF;
329 322
 	if ( kernel ) {
330
-		download_url(kernel,process); /* We don't return except on error */
331
-		printf("Unable to load file.\n");
323
+		return download_url ( kernel, buffer );
332 324
 	} else {	
333 325
 		printf("No filename\n");
334 326
 	}
335
-	interruptible_sleep(2);		/* lay off the server for a while */
336 327
 	return 0;
337 328
 }
338 329
 

+ 4
- 9
src/include/dev.h Wyświetl plik

@@ -3,6 +3,7 @@
3 3
 
4 4
 #include "stdint.h"
5 5
 #include "string.h"
6
+#include "buffer.h"
6 7
 #include "dhcp.h" /* for dhcp_dev_id */
7 8
 #include "tables.h"
8 9
 
@@ -182,10 +183,7 @@ struct type_driver {
182 183
 	struct type_dev *type_dev; /* single instance */
183 184
 	char * ( * describe_device ) ( struct type_dev *type_dev );
184 185
 	int ( * configure ) ( struct type_dev *type_dev );
185
-	int ( * load ) ( struct type_dev *type_dev, 
186
-			 int ( * process ) ( unsigned char *data,
187
-					     unsigned int blocknum,
188
-					     unsigned int len, int eof ) );
186
+	int ( * load ) ( struct type_dev *type_dev, struct buffer *buffer );
189 187
 };
190 188
 
191 189
 #define __type_driver __attribute__ (( used, __table_section(type_driver,01) ))
@@ -277,11 +275,8 @@ static inline int configure ( struct dev *dev ) {
277 275
 	return dev->type_driver->configure ( dev->type_dev );
278 276
 }
279 277
 /* Boot from a device */
280
-static inline int load ( struct dev *dev,
281
-			 int ( * process ) ( unsigned char *data,
282
-					     unsigned int blocknum, 
283
-					     unsigned int len, int eof ) ) {
284
-	return dev->type_driver->load ( dev->type_dev, process );
278
+static inline int load ( struct dev *dev, struct buffer *buffer ) {
279
+	return dev->type_driver->load ( dev->type_dev, buffer );
285 280
 }
286 281
 
287 282
 #endif /* DEV_H */

+ 3
- 7
src/include/proto.h Wyświetl plik

@@ -2,18 +2,14 @@
2 2
 #define PROTO_H
3 3
 
4 4
 #include "tables.h"
5
+#include "buffer.h"
5 6
 #include "in.h"
6 7
 
7 8
 struct protocol {
8 9
 	char *name;
9 10
 	in_port_t default_port;
10
-	int ( * load ) ( char *url,
11
-			 struct sockaddr_in *server,
12
-			 char *file,
13
-			 int ( * process ) ( unsigned char *data,
14
-					     unsigned int blocknum,
15
-					     unsigned int len,
16
-					     int eof ) );
11
+	int ( * load ) ( char *url, struct sockaddr_in *server, char *file,
12
+			 struct buffer *buffer );
17 13
 };
18 14
 
19 15
 /*

+ 3
- 6
src/include/tftp.h Wyświetl plik

@@ -2,6 +2,7 @@
2 2
 #define	TFTP_H
3 3
 
4 4
 #include "in.h"
5
+#include "buffer.h"
5 6
 #include "nic.h"
6 7
 
7 8
 #define TFTP_PORT	69
@@ -83,11 +84,7 @@ struct tftpblk_info_t {
83 84
  */
84 85
 extern int tftp_block ( struct tftpreq_info_t *request,
85 86
 			struct tftpblk_info_t *block );
86
-extern int tftp ( char *url,
87
-		  struct sockaddr_in *server,
88
-		  char *file,
89
-		  int ( * process ) ( unsigned char *data,
90
-				      unsigned int blocknum,
91
-				      unsigned int len, int eof ) );
87
+extern int tftp ( char *url, struct sockaddr_in *server, char *file,
88
+		  struct buffer *buffer );
92 89
 
93 90
 #endif	/* TFTP_H */

+ 12
- 12
src/proto/tftp.c Wyświetl plik

@@ -144,12 +144,8 @@ int tftp_block ( struct tftpreq_info_t *request,
144 144
  * Download a file via TFTP
145 145
  *
146 146
  */
147
-int tftp ( char *url __unused,
148
-	   struct sockaddr_in *server,
149
-	   char *file,
150
-	   int ( * process ) ( unsigned char *data,
151
-			       unsigned int blocknum,
152
-			       unsigned int len, int eof ) ) {
147
+int tftp ( char *url __unused, struct sockaddr_in *server, char *file,
148
+	   struct buffer *buffer ) {
153 149
 	struct tftpreq_info_t request_data = {
154 150
 		.server = server,
155 151
 		.name = file,
@@ -157,14 +153,18 @@ int tftp ( char *url __unused,
157 153
 	};
158 154
 	struct tftpreq_info_t *request = &request_data;
159 155
 	struct tftpblk_info_t block;
160
-	int rc;
156
+	off_t offset = 0;
161 157
 
162
-	while ( tftp_block ( request, &block ) ) {
158
+	do {
159
+		if ( ! tftp_block ( request, &block ) )
160
+			return 0;
161
+		if ( ! fill_buffer ( buffer, block.data, offset, block.len ) )
162
+			return 0;
163
+		offset += block.len;
163 164
 		request = NULL; /* Send request only once */
164
-		rc = process ( block.data, block.block, block.len, block.eof );
165
-		if ( rc <= 0 ) return ( rc );
166
-	}
167
-	return 0;
165
+	} while ( ! block.eof );
166
+
167
+	return 1;
168 168
 }
169 169
 
170 170
 struct protocol tftp_protocol __default_protocol = {

Ładowanie…
Anuluj
Zapisz