mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 05:21:49 +03:00
[tftp] Temporary fix for conveying TFTP block size to callers
pxe_tftp.c assumes that the first seek on its data-transfer interface represents the block size. Apart from being an ugly hack, this will also screw up file size calculation for files smaller than one block. The proper solution would be to extend the data-transfer interface to support the reporting of stat()-like data. This is not going to happen until the cost of adding interface methods is reduced (a fix I have planned since June 2008). In the meantime, abuse the xfer_window() method to return the block size, since it is not being used for anything else and is vaguely justifiable. Astonishingly, having returned the incorrect TFTP blocksize via PXENV_TFTP_OPEN for almost a year seems not to have affected any of the test cases run during that time; this bug was found only when someone tried running the heavily-patched version of pxegrub found in OpenSolaris.
This commit is contained in:
@@ -113,12 +113,6 @@ static int pxe_tftp_xfer_deliver_iob ( struct xfer_interface *xfer __unused,
|
||||
/* Calculate new buffer position */
|
||||
pxe_tftp.offset += len;
|
||||
|
||||
/* Mildly ugly hack; assume that the first non-zero seek
|
||||
* indicates the block size.
|
||||
*/
|
||||
if ( pxe_tftp.blksize == 0 )
|
||||
pxe_tftp.blksize = pxe_tftp.offset;
|
||||
|
||||
/* Record maximum offset as the file size */
|
||||
if ( pxe_tftp.max_offset < pxe_tftp.offset )
|
||||
pxe_tftp.max_offset = pxe_tftp.offset;
|
||||
@@ -265,10 +259,12 @@ PXENV_EXIT_t pxenv_tftp_open ( struct s_PXENV_TFTP_OPEN *tftp_open ) {
|
||||
|
||||
/* Wait for OACK to arrive so that we have the block size */
|
||||
while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) &&
|
||||
( pxe_tftp.blksize == 0 ) ) {
|
||||
( pxe_tftp.max_offset == 0 ) ) {
|
||||
step();
|
||||
}
|
||||
pxe_tftp.blksize = xfer_window ( &pxe_tftp.xfer );
|
||||
tftp_open->PacketSize = pxe_tftp.blksize;
|
||||
DBG ( " blksize=%d", tftp_open->PacketSize );
|
||||
|
||||
/* EINPROGRESS is normal; we don't wait for the whole transfer */
|
||||
if ( rc == -EINPROGRESS )
|
||||
@@ -571,6 +567,7 @@ PXENV_EXIT_t pxenv_tftp_get_fsize ( struct s_PXENV_TFTP_GET_FSIZE
|
||||
step();
|
||||
}
|
||||
tftp_get_fsize->FileSize = pxe_tftp.max_offset;
|
||||
DBG ( " fsize=%d", tftp_get_fsize->FileSize );
|
||||
|
||||
/* EINPROGRESS is normal; we don't wait for the whole transfer */
|
||||
if ( rc == -EINPROGRESS )
|
||||
|
||||
Reference in New Issue
Block a user