[syslinux] TFTP progress indicator
Geert Stappers
stappers at stappers.nl
Fri Apr 24 02:15:25 PDT 2015
Hello,
This is from http://wormfood.net/pxelinux_tftp_progress_display.patch
--- syslinux-6.03-original/core/fs/pxe/pxe.c 2014-10-07 00:27:44.000000000 +0800
+++ syslinux-6.03/core/fs/pxe/pxe.c 2015-04-16 17:28:49.000000000 +0800
@@ -197,29 +197,47 @@
int blocks, bool *have_more)
{
struct inode *inode = file->inode;
struct pxe_pvt_inode *socket = PVT(inode);
int count = blocks;
int chunk;
int bytes_read = 0;
+ int printed = 0; /* The number of bytes output by the percentage display */
+ int percent;
+ bool verbose = true; /* display progress flag - we need to be passed a flag to tell if we're quiet or not, and set this accordingly */
+ int percentage = -1;
count <<= TFTP_BLOCKSIZE_LG2;
+ if ( blocks < 512 ) /* don't display the progress for small files. */
+ verbose=false; /* This should not be needed, once the verbose flag is properly passed from other parts of the program */
+
+ if (verbose)
+ percent=(count/1000); /* one tenth, of one percent, really */
+
while (count) {
fill_buffer(inode); /* If we have no 'fresh' buffer, get it */
if (!socket->tftp_bytesleft)
break;
chunk = count;
if (chunk > socket->tftp_bytesleft)
chunk = socket->tftp_bytesleft;
socket->tftp_bytesleft -= chunk;
memcpy(buf, socket->tftp_dataptr, chunk);
socket->tftp_dataptr += chunk;
buf += chunk;
bytes_read += chunk;
+ if ( verbose ) {
+ if ( percentage != bytes_read/percent ) { /* only print percentage if it increases */
+ percentage = bytes_read/percent; /* record the current position in the file, as a percentage */
+ while (printed--) /* before we print the new percentage, backspace over what we printed previously. */
+ printf("\b");
+ printed = printf("%3d.%.1d%% ", percentage/10, percentage%10);
+ }
+ }
count -= chunk;
}
if (socket->tftp_bytesleft || (socket->tftp_filepos < inode->size)) {
fill_buffer(inode);
*have_more = 1;
Groeten
Geert Stappers
--
Leven en laten leven
More information about the Syslinux
mailing list