Browse Source

[xfer] Generalise metadata "whence" field to "flags" field

iPXE has never supported SEEK_END; the usage of "whence" offers only
the options of SEEK_SET and SEEK_CUR and so is effectively a boolean
flag.  Further flags will be required to support additional metadata
required by the Fibre Channel network model, so repurpose the "whence"
field as a generic "flags" field.

xfer_seek() has always been used with SEEK_SET, so remove the "whence"
field altogether from its argument list.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
364b92521a

+ 1
- 1
src/arch/i386/interface/pxe/pxe_tftp.c View File

@@ -85,7 +85,7 @@ static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp,
85 85
 	int rc = 0;
86 86
 
87 87
 	/* Calculate new buffer position */
88
-	if ( meta->whence != SEEK_CUR )
88
+	if ( meta->flags & XFER_FL_ABS_OFFSET )
89 89
 		pxe_tftp->offset = 0;
90 90
 	pxe_tftp->offset += meta->offset;
91 91
 

+ 1
- 1
src/core/downloader.c View File

@@ -160,7 +160,7 @@ static int downloader_xfer_deliver ( struct downloader *downloader,
160 160
 	int rc;
161 161
 
162 162
 	/* Calculate new buffer position */
163
-	if ( meta->whence != SEEK_CUR )
163
+	if ( meta->flags & XFER_FL_ABS_OFFSET )
164 164
 		downloader->pos = 0;
165 165
 	downloader->pos += meta->offset;
166 166
 

+ 1
- 1
src/core/posix_io.c View File

@@ -105,7 +105,7 @@ static int posix_file_xfer_deliver ( struct posix_file *file,
105 105
 				     struct xfer_metadata *meta ) {
106 106
 
107 107
 	/* Keep track of file position solely for the filesize */
108
-	if ( meta->whence != SEEK_CUR )
108
+	if ( meta->flags & XFER_FL_ABS_OFFSET )
109 109
 		file->pos = 0;
110 110
 	file->pos += meta->offset;
111 111
 	if ( file->filesize < file->pos )

+ 4
- 5
src/core/xfer.c View File

@@ -276,18 +276,17 @@ int xfer_printf ( struct interface *intf, const char *format, ... ) {
276 276
  *
277 277
  * @v intf		Data transfer interface
278 278
  * @v offset		Offset to new position
279
- * @v whence		Basis for new position
280 279
  * @ret rc		Return status code
281 280
  */
282
-int xfer_seek ( struct interface *intf, off_t offset, int whence ) {
281
+int xfer_seek ( struct interface *intf, off_t offset ) {
283 282
 	struct io_buffer *iobuf;
284 283
 	struct xfer_metadata meta = {
284
+		.flags = XFER_FL_ABS_OFFSET,
285 285
 		.offset = offset,
286
-		.whence = whence,
287 286
 	};
288 287
 
289
-	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek %s+%ld\n",
290
-	       INTF_DBG ( intf ), whence_text ( whence ), offset );
288
+	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek to %ld\n",
289
+	       INTF_DBG ( intf ), offset );
291 290
 
292 291
 	/* Allocate and send a zero-length data buffer */
293 292
 	iobuf = xfer_alloc_iob ( intf, 0 );

+ 16
- 25
src/include/ipxe/xfer.h View File

@@ -18,21 +18,23 @@ struct io_buffer;
18 18
 struct sockaddr;
19 19
 struct net_device;
20 20
 
21
-/** Basis positions for seek() events */
22
-enum seek_whence {
23
-	SEEK_CUR = 0,
24
-	SEEK_SET,
25
-};
26
-
27 21
 /** Data transfer metadata */
28 22
 struct xfer_metadata {
29
-	/** Position of data within stream */
30
-	off_t offset;
31
-	/** Basis for data position
23
+	/** Flags
24
+	 *
25
+	 * This is the bitwise OR of zero or more @c XFER_FL_XXX
26
+	 * constants.
27
+	 */
28
+	unsigned int flags;
29
+	/** Offset of data within stream
32 30
 	 *
33
-	 * Must be one of @c SEEK_CUR or @c SEEK_SET.
31
+	 * This is an absolute offset if the @c XFER_FL_ABS_OFFSET
32
+	 * flag is set, otherwise a relative offset.  (A freshly
33
+	 * zeroed @c xfer_metadata structure therefore represents a
34
+	 * relative offset of zero, i.e. no offset from the current
35
+	 * position.)
34 36
 	 */
35
-	int whence;
37
+	off_t offset;
36 38
 	/** Source socket address, or NULL */
37 39
 	struct sockaddr *src;
38 40
 	/** Destination socket address, or NULL */
@@ -41,19 +43,8 @@ struct xfer_metadata {
41 43
 	struct net_device *netdev;
42 44
 };
43 45
 
44
-/**
45
- * Describe seek basis
46
- *
47
- * @v whence		Basis for new position
48
- */
49
-static inline __attribute__ (( always_inline )) const char *
50
-whence_text ( int whence ) {
51
-	switch ( whence ) {
52
-	case SEEK_CUR:	return "CUR";
53
-	case SEEK_SET:	return "SET";
54
-	default:	return "INVALID";
55
-	}
56
-}
46
+/** Offset is absolute */
47
+#define XFER_FL_ABS_OFFSET 0x0001
57 48
 
58 49
 /* Data transfer interface operations */
59 50
 
@@ -89,6 +80,6 @@ extern int xfer_vprintf ( struct interface *intf,
89 80
 			  const char *format, va_list args );
90 81
 extern int __attribute__ (( format ( printf, 2, 3 ) ))
91 82
 xfer_printf ( struct interface *intf, const char *format, ... );
92
-extern int xfer_seek ( struct interface *intf, off_t offset, int whence );
83
+extern int xfer_seek ( struct interface *intf, off_t offset );
93 84
 
94 85
 #endif /* _IPXE_XFER_H */

+ 2
- 2
src/net/tcp/http.c View File

@@ -223,8 +223,8 @@ static int http_rx_content_length ( struct http_request *http,
223 223
 	}
224 224
 
225 225
 	/* Use seek() to notify recipient of filesize */
226
-	xfer_seek ( &http->xfer, http->content_length, SEEK_SET );
227
-	xfer_seek ( &http->xfer, 0, SEEK_SET );
226
+	xfer_seek ( &http->xfer, http->content_length );
227
+	xfer_seek ( &http->xfer, 0 );
228 228
 
229 229
 	return 0;
230 230
 }

+ 2
- 2
src/net/udp/slam.c View File

@@ -462,7 +462,7 @@ static int slam_pull_header ( struct slam_request *slam,
462 462
 	}
463 463
 
464 464
 	/* Notify recipient of file size */
465
-	xfer_seek ( &slam->xfer, slam->total_bytes, SEEK_SET );
465
+	xfer_seek ( &slam->xfer, slam->total_bytes );
466 466
 
467 467
 	return 0;
468 468
 }
@@ -526,7 +526,7 @@ static int slam_mc_socket_deliver ( struct slam_request *slam,
526 526
 
527 527
 	/* Pass to recipient */
528 528
 	memset ( &meta, 0, sizeof ( meta ) );
529
-	meta.whence = SEEK_SET;
529
+	meta.flags = XFER_FL_ABS_OFFSET;
530 530
 	meta.offset = ( packet * slam->block_size );
531 531
 	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
532 532
 		goto err;

+ 3
- 3
src/net/udp/tftp.c View File

@@ -269,8 +269,8 @@ static int tftp_presize ( struct tftp_request *tftp, size_t filesize ) {
269 269
 	tftp->filesize = filesize;
270 270
 
271 271
 	/* Notify recipient of file size */
272
-	xfer_seek ( &tftp->xfer, filesize, SEEK_SET );
273
-	xfer_seek ( &tftp->xfer, 0, SEEK_SET );
272
+	xfer_seek ( &tftp->xfer, filesize );
273
+	xfer_seek ( &tftp->xfer, 0 );
274 274
 
275 275
 	/* Calculate expected number of blocks.  Note that files whose
276 276
 	 * length is an exact multiple of the blocksize will have a
@@ -854,7 +854,7 @@ static int tftp_rx_data ( struct tftp_request *tftp,
854 854
 
855 855
 	/* Deliver data */
856 856
 	memset ( &meta, 0, sizeof ( meta ) );
857
-	meta.whence = SEEK_SET;
857
+	meta.flags = XFER_FL_ABS_OFFSET;
858 858
 	meta.offset = offset;
859 859
 	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
860 860
 				   &meta ) ) != 0 ) {

Loading…
Cancel
Save