mirror of https://github.com/ipxe/ipxe.git
				
				
				
			[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>pull/1/head
							parent
							
								
									b0eacbd421
								
							
						
					
					
						commit
						364b92521a
					
				| 
						 | 
				
			
			@ -85,7 +85,7 @@ static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp,
 | 
			
		|||
	int rc = 0;
 | 
			
		||||
 | 
			
		||||
	/* Calculate new buffer position */
 | 
			
		||||
	if ( meta->whence != SEEK_CUR )
 | 
			
		||||
	if ( meta->flags & XFER_FL_ABS_OFFSET )
 | 
			
		||||
		pxe_tftp->offset = 0;
 | 
			
		||||
	pxe_tftp->offset += meta->offset;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -160,7 +160,7 @@ static int downloader_xfer_deliver ( struct downloader *downloader,
 | 
			
		|||
	int rc;
 | 
			
		||||
 | 
			
		||||
	/* Calculate new buffer position */
 | 
			
		||||
	if ( meta->whence != SEEK_CUR )
 | 
			
		||||
	if ( meta->flags & XFER_FL_ABS_OFFSET )
 | 
			
		||||
		downloader->pos = 0;
 | 
			
		||||
	downloader->pos += meta->offset;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -105,7 +105,7 @@ static int posix_file_xfer_deliver ( struct posix_file *file,
 | 
			
		|||
				     struct xfer_metadata *meta ) {
 | 
			
		||||
 | 
			
		||||
	/* Keep track of file position solely for the filesize */
 | 
			
		||||
	if ( meta->whence != SEEK_CUR )
 | 
			
		||||
	if ( meta->flags & XFER_FL_ABS_OFFSET )
 | 
			
		||||
		file->pos = 0;
 | 
			
		||||
	file->pos += meta->offset;
 | 
			
		||||
	if ( file->filesize < file->pos )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -276,18 +276,17 @@ int xfer_printf ( struct interface *intf, const char *format, ... ) {
 | 
			
		|||
 *
 | 
			
		||||
 * @v intf		Data transfer interface
 | 
			
		||||
 * @v offset		Offset to new position
 | 
			
		||||
 * @v whence		Basis for new position
 | 
			
		||||
 * @ret rc		Return status code
 | 
			
		||||
 */
 | 
			
		||||
int xfer_seek ( struct interface *intf, off_t offset, int whence ) {
 | 
			
		||||
int xfer_seek ( struct interface *intf, off_t offset ) {
 | 
			
		||||
	struct io_buffer *iobuf;
 | 
			
		||||
	struct xfer_metadata meta = {
 | 
			
		||||
		.flags = XFER_FL_ABS_OFFSET,
 | 
			
		||||
		.offset = offset,
 | 
			
		||||
		.whence = whence,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek %s+%ld\n",
 | 
			
		||||
	       INTF_DBG ( intf ), whence_text ( whence ), offset );
 | 
			
		||||
	DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek to %ld\n",
 | 
			
		||||
	       INTF_DBG ( intf ), offset );
 | 
			
		||||
 | 
			
		||||
	/* Allocate and send a zero-length data buffer */
 | 
			
		||||
	iobuf = xfer_alloc_iob ( intf, 0 );
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,21 +18,23 @@ struct io_buffer;
 | 
			
		|||
struct sockaddr;
 | 
			
		||||
struct net_device;
 | 
			
		||||
 | 
			
		||||
/** Basis positions for seek() events */
 | 
			
		||||
enum seek_whence {
 | 
			
		||||
	SEEK_CUR = 0,
 | 
			
		||||
	SEEK_SET,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/** Data transfer metadata */
 | 
			
		||||
struct xfer_metadata {
 | 
			
		||||
	/** Position of data within stream */
 | 
			
		||||
	off_t offset;
 | 
			
		||||
	/** Basis for data position
 | 
			
		||||
	/** Flags
 | 
			
		||||
	 *
 | 
			
		||||
	 * Must be one of @c SEEK_CUR or @c SEEK_SET.
 | 
			
		||||
	 * This is the bitwise OR of zero or more @c XFER_FL_XXX
 | 
			
		||||
	 * constants.
 | 
			
		||||
	 */
 | 
			
		||||
	int whence;
 | 
			
		||||
	unsigned int flags;
 | 
			
		||||
	/** Offset of data within stream
 | 
			
		||||
	 *
 | 
			
		||||
	 * This is an absolute offset if the @c XFER_FL_ABS_OFFSET
 | 
			
		||||
	 * flag is set, otherwise a relative offset.  (A freshly
 | 
			
		||||
	 * zeroed @c xfer_metadata structure therefore represents a
 | 
			
		||||
	 * relative offset of zero, i.e. no offset from the current
 | 
			
		||||
	 * position.)
 | 
			
		||||
	 */
 | 
			
		||||
	off_t offset;
 | 
			
		||||
	/** Source socket address, or NULL */
 | 
			
		||||
	struct sockaddr *src;
 | 
			
		||||
	/** Destination socket address, or NULL */
 | 
			
		||||
| 
						 | 
				
			
			@ -41,19 +43,8 @@ struct xfer_metadata {
 | 
			
		|||
	struct net_device *netdev;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Describe seek basis
 | 
			
		||||
 *
 | 
			
		||||
 * @v whence		Basis for new position
 | 
			
		||||
 */
 | 
			
		||||
static inline __attribute__ (( always_inline )) const char *
 | 
			
		||||
whence_text ( int whence ) {
 | 
			
		||||
	switch ( whence ) {
 | 
			
		||||
	case SEEK_CUR:	return "CUR";
 | 
			
		||||
	case SEEK_SET:	return "SET";
 | 
			
		||||
	default:	return "INVALID";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
/** Offset is absolute */
 | 
			
		||||
#define XFER_FL_ABS_OFFSET 0x0001
 | 
			
		||||
 | 
			
		||||
/* Data transfer interface operations */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +80,6 @@ extern int xfer_vprintf ( struct interface *intf,
 | 
			
		|||
			  const char *format, va_list args );
 | 
			
		||||
extern int __attribute__ (( format ( printf, 2, 3 ) ))
 | 
			
		||||
xfer_printf ( struct interface *intf, const char *format, ... );
 | 
			
		||||
extern int xfer_seek ( struct interface *intf, off_t offset, int whence );
 | 
			
		||||
extern int xfer_seek ( struct interface *intf, off_t offset );
 | 
			
		||||
 | 
			
		||||
#endif /* _IPXE_XFER_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -223,8 +223,8 @@ static int http_rx_content_length ( struct http_request *http,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	/* Use seek() to notify recipient of filesize */
 | 
			
		||||
	xfer_seek ( &http->xfer, http->content_length, SEEK_SET );
 | 
			
		||||
	xfer_seek ( &http->xfer, 0, SEEK_SET );
 | 
			
		||||
	xfer_seek ( &http->xfer, http->content_length );
 | 
			
		||||
	xfer_seek ( &http->xfer, 0 );
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -462,7 +462,7 @@ static int slam_pull_header ( struct slam_request *slam,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	/* Notify recipient of file size */
 | 
			
		||||
	xfer_seek ( &slam->xfer, slam->total_bytes, SEEK_SET );
 | 
			
		||||
	xfer_seek ( &slam->xfer, slam->total_bytes );
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -526,7 +526,7 @@ static int slam_mc_socket_deliver ( struct slam_request *slam,
 | 
			
		|||
 | 
			
		||||
	/* Pass to recipient */
 | 
			
		||||
	memset ( &meta, 0, sizeof ( meta ) );
 | 
			
		||||
	meta.whence = SEEK_SET;
 | 
			
		||||
	meta.flags = XFER_FL_ABS_OFFSET;
 | 
			
		||||
	meta.offset = ( packet * slam->block_size );
 | 
			
		||||
	if ( ( rc = xfer_deliver ( &slam->xfer, iobuf, &meta ) ) != 0 )
 | 
			
		||||
		goto err;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -269,8 +269,8 @@ static int tftp_presize ( struct tftp_request *tftp, size_t filesize ) {
 | 
			
		|||
	tftp->filesize = filesize;
 | 
			
		||||
 | 
			
		||||
	/* Notify recipient of file size */
 | 
			
		||||
	xfer_seek ( &tftp->xfer, filesize, SEEK_SET );
 | 
			
		||||
	xfer_seek ( &tftp->xfer, 0, SEEK_SET );
 | 
			
		||||
	xfer_seek ( &tftp->xfer, filesize );
 | 
			
		||||
	xfer_seek ( &tftp->xfer, 0 );
 | 
			
		||||
 | 
			
		||||
	/* Calculate expected number of blocks.  Note that files whose
 | 
			
		||||
	 * length is an exact multiple of the blocksize will have a
 | 
			
		||||
| 
						 | 
				
			
			@ -854,7 +854,7 @@ static int tftp_rx_data ( struct tftp_request *tftp,
 | 
			
		|||
 | 
			
		||||
	/* Deliver data */
 | 
			
		||||
	memset ( &meta, 0, sizeof ( meta ) );
 | 
			
		||||
	meta.whence = SEEK_SET;
 | 
			
		||||
	meta.flags = XFER_FL_ABS_OFFSET;
 | 
			
		||||
	meta.offset = offset;
 | 
			
		||||
	if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
 | 
			
		||||
				   &meta ) ) != 0 ) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue