浏览代码

Obsolete code removal

tags/v0.9.3
Michael Brown 17 年前
父节点
当前提交
7df3d4a177
共有 4 个文件被更改,包括 0 次插入576 次删除
  1. 0
    265
      src/core/buffer.c
  2. 0
    106
      src/include/gpxe/buffer.h
  3. 0
    172
      src/include/tftp.h
  4. 0
    33
      src/include/tftpcore.h

+ 0
- 265
src/core/buffer.c 查看文件

@@ -1,265 +0,0 @@
1
-/*
2
- * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2 of the
7
- * License, or any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-#include <stddef.h>
20
-#include <string.h>
21
-#include <errno.h>
22
-#include <assert.h>
23
-#include <gpxe/uaccess.h>
24
-#include <gpxe/buffer.h>
25
-
26
-/** @file
27
- *
28
- * Buffer internals.
29
- *
30
- * A buffer consists of a single, contiguous area of memory, some of
31
- * which is "filled" and the remainder of which is "free".  The
32
- * "filled" and "free" spaces are not necessarily contiguous.
33
- *
34
- * At the start of a buffer's life, it consists of a single free
35
- * space.  As data is added to the buffer via fill_buffer(), this free
36
- * space decreases and can become fragmented.
37
- *
38
- * Each free block within a buffer (except the last) starts with a @c
39
- * struct @c buffer_free_block.  This describes the size of the free
40
- * block, and the offset to the next free block.
41
- *
42
- * We cannot simply start every free block (including the last) with a
43
- * descriptor, because it is conceivable that we will, at some point,
44
- * encounter a situation in which the final free block of a buffer is
45
- * too small to contain a descriptor.  Consider a protocol with a
46
- * blocksize of 512 downloading a 1025-byte file into a 1025-byte
47
- * buffer.  Suppose that the first two blocks are received; we have
48
- * now filled 1024 of the 1025 bytes in the buffer, and our only free
49
- * block consists of the 1025th byte.
50
- * 
51
- * Note that the rather convoluted way of manipulating the buffer
52
- * descriptors (using copy_{to,from}_user rather than straightforward
53
- * pointers) is needed to cope with operation as a PXE stack, when we
54
- * may be running in real mode or 16-bit protected mode, and therefore
55
- * cannot directly access arbitrary areas of memory using simple
56
- * pointers.
57
- *
58
- */
59
-
60
-/**
61
- * A free block descriptor
62
- *
63
- * This is the data structure that is found at the start of a free
64
- * block within a data buffer.
65
- */
66
-struct buffer_free_block {
67
-	/** Starting offset of the free block */
68
-	size_t start;
69
-	/** Ending offset of the free block */
70
-	size_t end;
71
-	/** Offset of next free block */
72
-	size_t next;
73
-};
74
-
75
-/**
76
- * Get next free block within the buffer
77
- *
78
- * @v buffer		Data buffer
79
- * @v block		Previous free block descriptor
80
- * @ret block		Next free block descriptor
81
- * @ret rc		Return status code
82
- *
83
- * Set @c block->next=buffer->fill before first call to
84
- * get_next_free_block().
85
- */
86
-static int get_next_free_block ( struct buffer *buffer,
87
-				 struct buffer_free_block *block ) {
88
-
89
-	/* Check for end of buffer */
90
-	if ( block->next >= buffer->len )
91
-		return -ENOENT;
92
-
93
-	/* Move to next block */
94
-	block->start = block->next;
95
-	if ( block->start >= buffer->free ) {
96
-		/* Final block; no in-band descriptor */
97
-		block->next = block->end = buffer->len;
98
-	} else {
99
-		/* Retrieve block descriptor */
100
-		copy_from_user ( block, buffer->addr, block->start,
101
-				 sizeof ( *block ) );
102
-	}
103
-
104
-	return 0;
105
-}
106
-
107
-/**
108
- * Write free block descriptor back to buffer
109
- *
110
- * @v buffer		Data buffer
111
- * @v block		Free block descriptor
112
- */
113
-static void store_free_block ( struct buffer *buffer,
114
-			       struct buffer_free_block *block ) {
115
-	size_t free_block_size = ( block->end - block->start );
116
-
117
-	assert ( free_block_size >= sizeof ( *block ) );
118
-	copy_to_user ( buffer->addr, block->start, block, sizeof ( *block ) );
119
-}
120
-
121
-/**
122
- * Write data into a buffer
123
- *
124
- * @v buffer		Data buffer
125
- * @v data		Data to be written
126
- * @v offset		Offset within the buffer at which to write the data
127
- * @v len		Length of data to be written
128
- * @ret rc		Return status code
129
- *
130
- * Writes a block of data into the buffer.  The block need not be
131
- * aligned to any particular boundary, or be of any particular size,
132
- * and it may overlap blocks already in the buffer (i.e. duplicate
133
- * calls to fill_buffer() are explicitly permitted).
134
- *
135
- * @c buffer->fill will be updated to indicate the fill level of the
136
- * buffer, i.e. the offset to the first gap within the buffer.  If the
137
- * filesize is known (e.g. as with the SLAM protocol), you can test
138
- * for end-of-file by checking for @c buffer->fill==filesize.  If the
139
- * filesize is not known, but there is a well-defined end-of-file test
140
- * (e.g. as with the TFTP protocol), you can read @c buffer->fill to
141
- * determine the final filesize.  If blocks are known to be delivered
142
- * in a strictly sequential order with no packet loss or duplication,
143
- * then you can pass in @c offset==buffer->fill.
144
- *
145
- * @b NOTE: It is the caller's responsibility to ensure that the
146
- * boundaries between data blocks are more than @c sizeof(struct @c
147
- * buffer_free_block) apart.  If this condition is not satisfied, data
148
- * corruption will occur.
149
- *
150
- * In practice this is not a problem.  Callers of fill_buffer() will
151
- * be download protocols such as TFTP, and very few protocols have a
152
- * block size smaller than @c sizeof(struct @c buffer_free_block).
153
- *
154
- */
155
-int fill_buffer ( struct buffer *buffer, const void *data,
156
-		  size_t offset, size_t len ) {
157
-	struct buffer_free_block block, before, after;
158
-	size_t data_start = offset;
159
-	size_t data_end = ( data_start + len );
160
-	int rc;
161
-
162
-	DBGC2 ( buffer, "BUFFER %p [%lx,%lx) filling portion [%lx,%lx)\n",
163
-		buffer, user_to_phys ( buffer->addr, 0 ),
164
-		user_to_phys ( buffer->addr, buffer->len ),
165
-		user_to_phys ( buffer->addr, data_start ),
166
-		user_to_phys ( buffer->addr, data_end ) );
167
-
168
-	/* Check that block fits within buffer, expand if necessary */
169
-	if ( data_end > buffer->len ) {
170
-		if ( ( rc = expand_buffer ( buffer, data_end ) ) != 0 )
171
-			return rc;
172
-		assert ( buffer->len >= data_end );
173
-	}
174
-
175
-	/* Find 'before' and 'after' blocks, if any */
176
-	before.start = before.end = 0;
177
-	after.start = after.end = buffer->len;
178
-	block.next = buffer->fill;
179
-	while ( get_next_free_block ( buffer, &block ) == 0 ) {
180
-		if ( ( block.start < data_start ) &&
181
-		     ( block.start >= before.start ) )
182
-			memcpy ( &before, &block, sizeof ( before ) );
183
-		if ( ( block.end > data_end ) &&
184
-		     ( block.end <= after.end ) )
185
-			memcpy ( &after, &block, sizeof ( after ) );
186
-	}
187
-
188
-	/* Truncate 'before' and 'after' blocks around data. */
189
-	if ( data_start < before.end )
190
-		before.end = data_start;
191
-	if ( data_end > after.start )
192
-		after.start = data_end;
193
-
194
-	/* Link 'after' block to 'before' block */
195
-	before.next = after.start;
196
-
197
-	DBGC2 ( buffer, "BUFFER %p split before [%lx,%lx) after [%lx,%lx)\n",
198
-		buffer, user_to_phys ( buffer->addr, before.start ),
199
-		user_to_phys ( buffer->addr, before.end ),
200
-		user_to_phys ( buffer->addr, after.start ),
201
-		user_to_phys ( buffer->addr, after.end ) );
202
-
203
-	/* Write back 'before' block, if any */
204
-	if ( before.end == 0 ) {
205
-		/* No 'before' block: update buffer->fill */
206
-		buffer->fill = after.start;
207
-		DBGC2 ( buffer, "BUFFER %p full up to %lx\n", buffer,
208
-			user_to_phys ( buffer->addr, buffer->fill ) );
209
-	} else {
210
-		/* Write back 'before' block */
211
-		store_free_block ( buffer, &before );
212
-	}
213
-
214
-	/* Write back 'after' block */
215
-	if ( after.end == buffer->len ) {
216
-		/* 'After' block is the final block: update buffer->free */
217
-		buffer->free = after.start;
218
-		DBGC2 ( buffer, "BUFFER %p free from %lx onwards\n", buffer,
219
-			user_to_phys ( buffer->addr, buffer->free ) );
220
-	} else {
221
-		/* Write back 'after' block */
222
-		store_free_block ( buffer, &after );
223
-	}
224
-
225
-	/* Copy data into buffer */
226
-	copy_to_user ( buffer->addr, data_start, data, len );
227
-
228
-	return 0;
229
-}
230
-
231
-/** Expand data buffer
232
- *
233
- * @v buffer		Data buffer
234
- * @v new_len		New length
235
- * @ret rc		Return status code
236
- *
237
- * Expand the data buffer to accommodate more data.  Some buffers may
238
- * not support being expanded.
239
- */
240
-int expand_buffer ( struct buffer *buffer, size_t new_len ) {
241
-	int rc;
242
-
243
-	if ( new_len <= buffer->len )
244
-		return 0;
245
-
246
-	DBGC ( buffer, "BUFFER %p attempting to expand from length %zx to "
247
-	       "length %zx\n", buffer, buffer->len, new_len );
248
-
249
-	if ( ! buffer->expand ) {
250
-		DBGC ( buffer, "BUFFER %p is not expandable\n", buffer );
251
-		return -ENOBUFS;
252
-	}
253
-
254
-	if ( ( rc = buffer->expand ( buffer, new_len ) ) != 0 ) {
255
-		DBGC ( buffer, "BUFFER %p could not expand: %s\n",
256
-		       buffer, strerror ( rc ) );
257
-		return rc;
258
-	}
259
-
260
-	DBGC ( buffer, "BUFFER %p expanded to [%lx,%lx)\n", buffer,
261
-	       user_to_phys ( buffer->addr, 0 ),
262
-	       user_to_phys ( buffer->addr, buffer->len ) );
263
-
264
-	return 0;
265
-}

+ 0
- 106
src/include/gpxe/buffer.h 查看文件

@@ -1,106 +0,0 @@
1
-#ifndef _GPXE_BUFFER_H
2
-#define _GPXE_BUFFER_H
3
-
4
-#include <stdint.h>
5
-#include <errno.h>
6
-#include <gpxe/uaccess.h>
7
-
8
-/** @file
9
- *
10
- * Buffers for loading files.
11
- *
12
- * This file provides routines for filling a buffer with data received
13
- * piecemeal, where the size of the data is not necessarily known in
14
- * advance.
15
- *
16
- * Some protocols do not provide a mechanism for us to know the size
17
- * of the file before we happen to receive a particular block
18
- * (e.g. the final block in an MTFTP transfer).  In addition, some
19
- * protocols (e.g. the multicast protocols) can, in theory, provide
20
- * the data in any order.
21
- *
22
- * Example usage:
23
- *
24
- * @code
25
- *
26
- *   struct buffer my_buffer;
27
- *   void *data;
28
- *   off_t offset;
29
- *   size_t len;
30
- *   
31
- *   // We have an area of memory [buf_start,buf_start+len) into which to
32
- *   // load a file, where buf_start is a userptr_t.
33
- *   memset ( &buffer, 0, sizeof ( buffer ) );
34
- *   buffer->start = buf_start;
35
- *   buffer->len = len;
36
- *   ...
37
- *   while ( get_file_block ( ... ) ) {
38
- *     // Downloaded block is stored in [data,data+len), and represents 
39
- *     // the portion of the file at offsets [offset,offset+len)
40
- *     if ( fill_buffer ( &buffer, data, offset, len ) != 0 ) {
41
- *       // An error occurred
42
- *     }
43
- *     ...
44
- *   }
45
- *   ...
46
- *   // The whole file is now present at [buf_start,buf_start+filesize),
47
- *   // where buf_start is a userptr_t.  The struct buffer can simply
48
- *   // be discarded.
49
- *
50
- * @endcode
51
- *
52
- */
53
-
54
-/**
55
- * A data buffer
56
- *
57
- * A buffer looks something like this:
58
- *
59
- * @code
60
- *
61
- *     XXXXXXXXXXXXXXXXX.........XXX..........XXXXXXX........XXXXXX.........
62
- *
63
- *     ^
64
- *     |
65
- *   start
66
- *
67
- *     <----- fill ---->
68
- *
69
- *     <------------------------ free ---------------------------->
70
- *
71
- *     <------------------------------ len -------------------------------->
72
- *
73
- * @endcode
74
- *
75
- * #start and #len denote the real boundaries of the buffer.  #fill
76
- * denotes the offset to the first free block in the buffer.  (If the
77
- * buffer is full, #fill, #free and #len will all be equal.)
78
- *
79
- */
80
-struct buffer {
81
-	/** Start of buffer */
82
-	userptr_t addr;
83
-	/** Total length of buffer */
84
-	size_t len;
85
-	/** Offset to first free block within buffer */
86
-	size_t fill;
87
-	/** Offset to last free block within buffer */
88
-	size_t free;
89
-	/** Expand data buffer
90
-	 *
91
-	 * @v buffer		Data buffer
92
-	 * @v new_len		New length
93
-	 * @ret rc		Return status code
94
-	 *
95
-	 * Expand the data buffer to accommodate more data.  This
96
-	 * method is optional; if it is @c NULL then the buffer will
97
-	 * not be expandable.
98
-	 */
99
-	int ( * expand ) ( struct buffer *buffer, size_t new_len );
100
-};
101
-
102
-extern int fill_buffer ( struct buffer *buffer, const void *data,
103
-			 size_t offset, size_t len );
104
-extern int expand_buffer ( struct buffer *buffer, size_t new_len );
105
-
106
-#endif /* _GPXE_BUFFER_H */

+ 0
- 172
src/include/tftp.h 查看文件

@@ -1,172 +0,0 @@
1
-#ifndef	TFTP_H
2
-#define	TFTP_H
3
-
4
-/** @file */
5
-
6
-#include <gpxe/in.h>
7
-#include <gpxe/buffer.h>
8
-#include "nic.h"
9
-#include "ip.h"
10
-#include "udp.h"
11
-
12
-#define TFTP_PORT	69		/**< Default TFTP server port */
13
-#define	TFTP_DEFAULT_BLKSIZE	512
14
-#define	TFTP_MAX_BLKSIZE		1432 /* 512 */
15
-
16
-#define TFTP_RRQ	1
17
-#define TFTP_WRQ	2
18
-#define TFTP_DATA	3
19
-#define TFTP_ACK	4
20
-#define TFTP_ERROR	5
21
-#define TFTP_OACK	6
22
-
23
-#define TFTP_ERR_FILE_NOT_FOUND	1 /**< File not found */
24
-#define TFTP_ERR_ACCESS_DENIED	2 /**< Access violation */
25
-#define TFTP_ERR_DISK_FULL	3 /**< Disk full or allocation exceeded */
26
-#define TFTP_ERR_ILLEGAL_OP	4 /**< Illegal TFTP operation */
27
-#define TFTP_ERR_UNKNOWN_TID	5 /**< Unknown transfer ID */
28
-#define TFTP_ERR_FILE_EXISTS	6 /**< File already exists */
29
-#define TFTP_ERR_UNKNOWN_USER	7 /**< No such user */
30
-#define TFTP_ERR_BAD_OPTS	8 /**< Option negotiation failed */
31
-
32
-/** A TFTP request (RRQ) packet */
33
-struct tftp_rrq {
34
-	struct iphdr ip;
35
-	struct udphdr udp;
36
-	uint16_t opcode;
37
-	char data[TFTP_DEFAULT_BLKSIZE];
38
-} PACKED;
39
-
40
-/** A TFTP data (DATA) packet */
41
-struct tftp_data {
42
-	struct iphdr ip;
43
-	struct udphdr udp;
44
-	uint16_t opcode;
45
-	uint16_t block;
46
-	uint8_t data[TFTP_MAX_BLKSIZE];
47
-} PACKED;
48
- 
49
-/** A TFTP acknowledgement (ACK) packet */
50
-struct tftp_ack {
51
-	struct iphdr ip;
52
-	struct udphdr udp;
53
-	uint16_t opcode;
54
-	uint16_t block;
55
-} PACKED;
56
-
57
-/** A TFTP error (ERROR) packet */
58
-struct tftp_error {
59
-	struct iphdr ip;
60
-	struct udphdr udp;
61
-	uint16_t opcode;
62
-	uint16_t errcode;
63
-	char errmsg[TFTP_DEFAULT_BLKSIZE];
64
-} PACKED;
65
-
66
-/** A TFTP options acknowledgement (OACK) packet */
67
-struct tftp_oack {
68
-	struct iphdr ip;
69
-	struct udphdr udp;
70
-	uint16_t opcode;
71
-	uint8_t data[TFTP_DEFAULT_BLKSIZE];
72
-} PACKED;
73
-
74
-/** The common header of all TFTP packets */
75
-struct tftp_common {
76
-	struct iphdr ip;
77
-	struct udphdr udp;
78
-	uint16_t opcode;
79
-} PACKED;
80
-
81
-/** A union encapsulating all TFTP packet types */
82
-union tftp_any {
83
-	struct tftp_common	common;
84
-	struct tftp_rrq		rrq;
85
-	struct tftp_data	data;
86
-	struct tftp_ack		ack;
87
-	struct tftp_error	error;
88
-	struct tftp_oack	oack;
89
-};	
90
-
91
-/**
92
- * TFTP state
93
- *
94
- * This data structure holds the state for an ongoing TFTP transfer.
95
- */
96
-struct tftp_state {
97
-	/** TFTP server address
98
-	 *
99
-	 * This is the IP address and UDP port from which data packets
100
-	 * will be sent, and to which ACK packets should be sent.
101
-	 */
102
-	struct sockaddr_in server;
103
-	/** TFTP client port
104
-	 *
105
-	 * This is the UDP port from which the open request will be
106
-	 * sent, and to which any unicast data packets will be sent.
107
-	 */
108
-	uint16_t lport;
109
-	/** TFTP multicast address
110
-	 *
111
-	 * This is the IP address and UDP port to which multicast data
112
-	 * packets, if any, will be sent.
113
-	 */
114
-	struct sockaddr_in multicast;
115
-	/** Master client
116
-	 *
117
-	 * This will be true if the client is the master client for a
118
-	 * multicast protocol (i.e. MTFTP or TFTM).  (It will always
119
-	 * be true for a non-multicast protocol, i.e. plain old TFTP).
120
-	 */
121
-	int master;
122
-	/** Data block size
123
-	 *
124
-	 * This is the "blksize" option negotiated with the TFTP
125
-	 * server.  (If the TFTP server does not support TFTP options,
126
-	 * this will default to 512).
127
-	 */
128
-	unsigned int blksize;
129
-	/** File size
130
-	 *
131
-	 * This is the value returned in the "tsize" option from the
132
-	 * TFTP server.  If the TFTP server does not support the
133
-	 * "tsize" option, this value will be zero.
134
-	 */
135
-	off_t tsize;
136
-	/** Last received block
137
-	 *
138
-	 * The block number of the most recent block received from the
139
-	 * TFTP server.  Note that the first data block is block 1; a
140
-	 * value of 0 indicates that no data blocks have yet been
141
-	 * received.
142
-	 *
143
-	 * For multicast TFTP protocols, where the blocks may not be
144
-	 * received in strict order, the meaning of this field changes
145
-	 * slightly, to "first missing block minus one".  For example,
146
-	 * suppose that we have received blocks 1, 2, 4 and 5; this
147
-	 * field would then have the value 2, since the first missing
148
-	 * block is block 3.  If the blocks do arrive in strict order,
149
-	 * this definition is exactly equivalent to "most recently
150
-	 * received block".
151
-	 */
152
-	unsigned int block;
153
-};
154
-
155
-
156
-
157
-struct tftpreq_info_t {
158
-	struct sockaddr_in *server;
159
-	const char *name;
160
-	unsigned short blksize;
161
-} PACKED;
162
-
163
-struct tftpblk_info_t {
164
-	char *data;
165
-	unsigned int block;
166
-	unsigned int len;
167
-	int eof;
168
-} PACKED;
169
-
170
-#define TFTP_MIN_PACKET	(sizeof(struct iphdr) + sizeof(struct udphdr) + 4)
171
-
172
-#endif	/* TFTP_H */

+ 0
- 33
src/include/tftpcore.h 查看文件

@@ -1,33 +0,0 @@
1
-#ifndef TFTPCORE_H
2
-#define TFTPCORE_H
3
-
4
-/** @file
5
- *
6
- * TFTP core functions
7
- *
8
- * This file provides functions that are common to the TFTP (rfc1350),
9
- * TFTM (rfc2090) and MTFTP (PXE) protocols.
10
- *
11
- */
12
-
13
-#include "tftp.h"
14
-
15
-extern int tftp_open ( struct tftp_state *state, const char *filename,
16
-		       union tftp_any **reply, int multicast );
17
-
18
-extern int tftp_process_opts ( struct tftp_state *state,
19
-			       struct tftp_oack *oack );
20
-
21
-extern int tftp_ack_nowait ( struct tftp_state *state );
22
-
23
-extern int tftp_get ( struct tftp_state *state, long timeout,
24
-		      union tftp_any **reply );
25
-
26
-extern int tftp_ack ( struct tftp_state *state, union tftp_any **reply );
27
-
28
-extern int tftp_error ( struct tftp_state *state, int errcode,
29
-			const char *errmsg );
30
-
31
-extern void tftp_set_errno ( struct tftp_error *error );
32
-
33
-#endif /* TFTPCORE_H */

正在加载...
取消
保存