Browse Source

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

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
0fe74493f4
6 changed files with 37 additions and 50 deletions
  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 View File

162
 MAIN - Kick off routine
162
 MAIN - Kick off routine
163
 **************************************************************************/
163
 **************************************************************************/
164
 int main ( void ) {
164
 int main ( void ) {
165
+	struct buffer buffer;
165
 	int skip = 0;
166
 	int skip = 0;
166
 
167
 
167
 	/* Print out configuration */
168
 	/* Print out configuration */
213
 			continue;
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 View File

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
 	struct protocol *proto;
289
 	struct protocol *proto;
294
 	struct sockaddr_in server;
290
 	struct sockaddr_in server;
295
 	char *filename;
291
 	char *filename;
303
 	}
299
 	}
304
 	
300
 	
305
 	/* Call protocol's method to download the file */
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
 /**************************************************************************
308
 /**************************************************************************
313
 LOAD - Try to get booted
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
 	char	*kernel;
312
 	char	*kernel;
320
 
313
 
321
 	/* Now use TFTP to load file */
314
 	/* Now use TFTP to load file */
327
 #endif
320
 #endif
328
 		: KERNEL_BUF;
321
 		: KERNEL_BUF;
329
 	if ( kernel ) {
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
 	} else {	
324
 	} else {	
333
 		printf("No filename\n");
325
 		printf("No filename\n");
334
 	}
326
 	}
335
-	interruptible_sleep(2);		/* lay off the server for a while */
336
 	return 0;
327
 	return 0;
337
 }
328
 }
338
 
329
 

+ 4
- 9
src/include/dev.h View File

3
 
3
 
4
 #include "stdint.h"
4
 #include "stdint.h"
5
 #include "string.h"
5
 #include "string.h"
6
+#include "buffer.h"
6
 #include "dhcp.h" /* for dhcp_dev_id */
7
 #include "dhcp.h" /* for dhcp_dev_id */
7
 #include "tables.h"
8
 #include "tables.h"
8
 
9
 
182
 	struct type_dev *type_dev; /* single instance */
183
 	struct type_dev *type_dev; /* single instance */
183
 	char * ( * describe_device ) ( struct type_dev *type_dev );
184
 	char * ( * describe_device ) ( struct type_dev *type_dev );
184
 	int ( * configure ) ( struct type_dev *type_dev );
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
 #define __type_driver __attribute__ (( used, __table_section(type_driver,01) ))
189
 #define __type_driver __attribute__ (( used, __table_section(type_driver,01) ))
277
 	return dev->type_driver->configure ( dev->type_dev );
275
 	return dev->type_driver->configure ( dev->type_dev );
278
 }
276
 }
279
 /* Boot from a device */
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
 #endif /* DEV_H */
282
 #endif /* DEV_H */

+ 3
- 7
src/include/proto.h View File

2
 #define PROTO_H
2
 #define PROTO_H
3
 
3
 
4
 #include "tables.h"
4
 #include "tables.h"
5
+#include "buffer.h"
5
 #include "in.h"
6
 #include "in.h"
6
 
7
 
7
 struct protocol {
8
 struct protocol {
8
 	char *name;
9
 	char *name;
9
 	in_port_t default_port;
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 View File

2
 #define	TFTP_H
2
 #define	TFTP_H
3
 
3
 
4
 #include "in.h"
4
 #include "in.h"
5
+#include "buffer.h"
5
 #include "nic.h"
6
 #include "nic.h"
6
 
7
 
7
 #define TFTP_PORT	69
8
 #define TFTP_PORT	69
83
  */
84
  */
84
 extern int tftp_block ( struct tftpreq_info_t *request,
85
 extern int tftp_block ( struct tftpreq_info_t *request,
85
 			struct tftpblk_info_t *block );
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
 #endif	/* TFTP_H */
90
 #endif	/* TFTP_H */

+ 12
- 12
src/proto/tftp.c View File

144
  * Download a file via TFTP
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
 	struct tftpreq_info_t request_data = {
149
 	struct tftpreq_info_t request_data = {
154
 		.server = server,
150
 		.server = server,
155
 		.name = file,
151
 		.name = file,
157
 	};
153
 	};
158
 	struct tftpreq_info_t *request = &request_data;
154
 	struct tftpreq_info_t *request = &request_data;
159
 	struct tftpblk_info_t block;
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
 		request = NULL; /* Send request only once */
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
 struct protocol tftp_protocol __default_protocol = {
170
 struct protocol tftp_protocol __default_protocol = {

Loading…
Cancel
Save