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
 	int rc = 0;
85
 	int rc = 0;
86
 
86
 
87
 	/* Calculate new buffer position */
87
 	/* Calculate new buffer position */
88
-	if ( meta->whence != SEEK_CUR )
88
+	if ( meta->flags & XFER_FL_ABS_OFFSET )
89
 		pxe_tftp->offset = 0;
89
 		pxe_tftp->offset = 0;
90
 	pxe_tftp->offset += meta->offset;
90
 	pxe_tftp->offset += meta->offset;
91
 
91
 

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

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

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

105
 				     struct xfer_metadata *meta ) {
105
 				     struct xfer_metadata *meta ) {
106
 
106
 
107
 	/* Keep track of file position solely for the filesize */
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
 		file->pos = 0;
109
 		file->pos = 0;
110
 	file->pos += meta->offset;
110
 	file->pos += meta->offset;
111
 	if ( file->filesize < file->pos )
111
 	if ( file->filesize < file->pos )

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

276
  *
276
  *
277
  * @v intf		Data transfer interface
277
  * @v intf		Data transfer interface
278
  * @v offset		Offset to new position
278
  * @v offset		Offset to new position
279
- * @v whence		Basis for new position
280
  * @ret rc		Return status code
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
 	struct io_buffer *iobuf;
282
 	struct io_buffer *iobuf;
284
 	struct xfer_metadata meta = {
283
 	struct xfer_metadata meta = {
284
+		.flags = XFER_FL_ABS_OFFSET,
285
 		.offset = offset,
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
 	/* Allocate and send a zero-length data buffer */
291
 	/* Allocate and send a zero-length data buffer */
293
 	iobuf = xfer_alloc_iob ( intf, 0 );
292
 	iobuf = xfer_alloc_iob ( intf, 0 );

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

18
 struct sockaddr;
18
 struct sockaddr;
19
 struct net_device;
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
 /** Data transfer metadata */
21
 /** Data transfer metadata */
28
 struct xfer_metadata {
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
 	/** Source socket address, or NULL */
38
 	/** Source socket address, or NULL */
37
 	struct sockaddr *src;
39
 	struct sockaddr *src;
38
 	/** Destination socket address, or NULL */
40
 	/** Destination socket address, or NULL */
41
 	struct net_device *netdev;
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
 /* Data transfer interface operations */
49
 /* Data transfer interface operations */
59
 
50
 
89
 			  const char *format, va_list args );
80
 			  const char *format, va_list args );
90
 extern int __attribute__ (( format ( printf, 2, 3 ) ))
81
 extern int __attribute__ (( format ( printf, 2, 3 ) ))
91
 xfer_printf ( struct interface *intf, const char *format, ... );
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
 #endif /* _IPXE_XFER_H */
85
 #endif /* _IPXE_XFER_H */

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

223
 	}
223
 	}
224
 
224
 
225
 	/* Use seek() to notify recipient of filesize */
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
 	return 0;
229
 	return 0;
230
 }
230
 }

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

462
 	}
462
 	}
463
 
463
 
464
 	/* Notify recipient of file size */
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
 	return 0;
467
 	return 0;
468
 }
468
 }
526
 
526
 
527
 	/* Pass to recipient */
527
 	/* Pass to recipient */
528
 	memset ( &meta, 0, sizeof ( meta ) );
528
 	memset ( &meta, 0, sizeof ( meta ) );
529
-	meta.whence = SEEK_SET;
529
+	meta.flags = XFER_FL_ABS_OFFSET;
530
 	meta.offset = ( packet * slam->block_size );
530
 	meta.offset = ( packet * slam->block_size );
531
 	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
531
 	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
532
 		goto err;
532
 		goto err;

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

269
 	tftp->filesize = filesize;
269
 	tftp->filesize = filesize;
270
 
270
 
271
 	/* Notify recipient of file size */
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
 	/* Calculate expected number of blocks.  Note that files whose
275
 	/* Calculate expected number of blocks.  Note that files whose
276
 	 * length is an exact multiple of the blocksize will have a
276
 	 * length is an exact multiple of the blocksize will have a
854
 
854
 
855
 	/* Deliver data */
855
 	/* Deliver data */
856
 	memset ( &meta, 0, sizeof ( meta ) );
856
 	memset ( &meta, 0, sizeof ( meta ) );
857
-	meta.whence = SEEK_SET;
857
+	meta.flags = XFER_FL_ABS_OFFSET;
858
 	meta.offset = offset;
858
 	meta.offset = offset;
859
 	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
859
 	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
860
 				   &meta ) ) != 0 ) {
860
 				   &meta ) ) != 0 ) {

Loading…
Cancel
Save