mirror of
https://github.com/ipxe/ipxe
synced 2025-12-16 17:41:18 +03:00
[xfer] Add xfer_check_order() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -359,3 +359,34 @@ int xfer_seek ( struct interface *intf, off_t offset ) {
|
|||||||
|
|
||||||
return xfer_deliver ( intf, iobuf, &meta );
|
return xfer_deliver ( intf, iobuf, &meta );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that data is delivered strictly in order
|
||||||
|
*
|
||||||
|
* @v meta Data transfer metadata
|
||||||
|
* @v pos Current position
|
||||||
|
* @v len Length of data
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int xfer_check_order ( struct xfer_metadata *meta, size_t *pos, size_t len ) {
|
||||||
|
size_t new_pos;
|
||||||
|
|
||||||
|
/* Allow out-of-order zero-length packets (as used by xfer_seek()) */
|
||||||
|
if ( len == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Calculate position of this delivery */
|
||||||
|
new_pos = *pos;
|
||||||
|
if ( meta->flags & XFER_FL_ABS_OFFSET )
|
||||||
|
new_pos = 0;
|
||||||
|
new_pos += meta->offset;
|
||||||
|
|
||||||
|
/* Fail if delivery position is not equal to current position */
|
||||||
|
if ( new_pos != *pos )
|
||||||
|
return -EPROTO;
|
||||||
|
|
||||||
|
/* Update current position */
|
||||||
|
*pos += len;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,5 +103,7 @@ extern int xfer_vprintf ( struct interface *intf,
|
|||||||
extern int __attribute__ (( format ( printf, 2, 3 ) ))
|
extern int __attribute__ (( format ( printf, 2, 3 ) ))
|
||||||
xfer_printf ( struct interface *intf, const char *format, ... );
|
xfer_printf ( struct interface *intf, const char *format, ... );
|
||||||
extern int xfer_seek ( struct interface *intf, off_t offset );
|
extern int xfer_seek ( struct interface *intf, off_t offset );
|
||||||
|
extern int xfer_check_order ( struct xfer_metadata *meta, size_t *pos,
|
||||||
|
size_t len );
|
||||||
|
|
||||||
#endif /* _IPXE_XFER_H */
|
#endif /* _IPXE_XFER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user