- f->netbuf_size = f->netbuf_maxsize;
-
- DBG_PRT((L"\nbefore netbuf:0x%lx netbuf_size=%ld\n", f->netbuf, f->netbuf_size));
-
- /*
- * For EFI versions older than 14.61:
- * it seems like there is an EFI bug (or undocumented behavior) when the buffer size
- * is too small AND the blocksize parameter is NULL, i.e., used the largest possible.
- * In this case, Mtftp() never returns EFI_BUFFER_TOO_SMALL but EFI_TIMEOUT instead.
- * This is true for 1.02 and also 1.10 it seems. Here we set it to the minimal value (512).
- *
- * Also it seems like on a READ_FILE which returns EFI_BUFFER_TOO_SMALL, the buffersize
- * is NOT updated to reflect the required size for the next attempt.
- *
- * For EFI versions 14.61 and higher:
- * In case the buffer is too small AND the TFTP server reports the file size (see RFC 2349),
- * the f->netbuf_size will report the exact size for the buffer.
+ if (retries == 2) {
+ netfs_fd_free(nfs, f);
+ VERB_PRT(2, Print(L"Failed: %r\n", status));
+ return status;
+ }
+
+/*
+ * netboot bugfix SF tracker 2874380
+ * EFI 1.10 spec
+ * For read operations, the return data will be placed in the buffer specified by BufferPtr. If
+ * BufferSize is too small to contain the entire downloaded file, then
+ * EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero or the size of
+ * the requested file (the size of the requested file is only returned if the TFTP server supports TFTP
+ * options). If BufferSize is large enough for the read operation, then BufferSize will be set to
+ * the size of the downloaded file, and EFI_SUCCESS will be returned. Applications using the
+ * PxeBc.Mtftp() services should use the get-file-size operations to determine the size of the
+ * downloaded file prior to using the read-file operations—especially when downloading large
+ * (greater than 64 MB) files—instead of making two calls to the read-file operation. Following this
+ * recommendation will save time if the file is larger than expected and the TFTP server does not
+ * support TFTP option extensions. Without TFTP option extension support, the client has to
+ * download the entire file, counting and discarding the received packets, to determine the file size.
+ * ...
+ * For TFTP “get file size” operations, the size of the requested file or directory is returned in
+ * BufferSize, and EFI_SUCCESS will be returned. If the TFTP server does not support options,
+ * the file will be downloaded into a bit bucket and the length of the downloaded file will be returned.
+ */
+ status = uefi_call_wrapper(nfs->pxe->Mtftp, 10,
+ nfs->pxe,
+ EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
+ f->netbuf,
+ FALSE,
+ &(f->netbuf_size), // PXE writes size of file from server here
+ &blocksize,
+ &nfs->srv_ip,
+ ascii_name,
+ NULL,
+ FALSE);
+ /*
+ * If options are not supported by this tftp server, according to the spec the file will be
+ * downloaded into a bit bucket, the size calculated by efi fw and returned in the status
+ * field of this call. YUK!!... in this case we will default to currently allocated max
+ * if thats still not big enough it will be caught and increased following the read file attempt
+ * then retried.
+ * XXX need to research how this is handled or changed in the latest UEFI spec.