Skip to content

Commit

Permalink
Merge pull request #223 from nielsmh/sd-sendfile-fixes
Browse files Browse the repository at this point in the history
Toolbox fixes for file upload
  • Loading branch information
erichelgeson authored Jan 4, 2025
2 parents da7df4b + bc07c93 commit 859407e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/BlueSCSI_Toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ void onGetFile10(char * dir_name) {
void onSendFilePrep(char * dir_name)
{
char file_name[32+1];
memset(file_name, '\0', 32+1);

scsiEnterPhase(DATA_OUT);
for (int i = 0; i < 32+1; ++i)
{
file_name[i] = scsiReadByte();
}
scsiRead(static_cast<uint8_t *>(static_cast<void *>(file_name)), 32+1, NULL);
file_name[32] = '\0';

debuglog("TOOLBOX OPEN FILE FOR WRITE: '", file_name, "'");
SD.chdir(dir_name);
gFile.open(file_name, FILE_WRITE);
SD.chdir("/");
Expand Down Expand Up @@ -296,19 +296,22 @@ void onSendFile10(void)
uint16_t bytes_sent = ((uint16_t)scsiDev.cdb[1] << 8) | scsiDev.cdb[2];
// 512 byte offset of where to put these bytes.
uint32_t offset = ((uint32_t)scsiDev.cdb[3] << 16) | ((uint32_t)scsiDev.cdb[4] << 8) | scsiDev.cdb[5];
uint16_t buf_size = 512;
uint8_t buf[512];
const uint16_t BUFSIZE = 512;
uint8_t buf[BUFSIZE];

// Check if last block of file, and not the only bock in file.
if(bytes_sent < buf_size)
// Do not allow buffer overrun
if (bytes_sent > BUFSIZE)
{
buf_size = bytes_sent;
debuglog("TOOLBOX SEND FILE 10 ILLEGAL DATA SIZE");
gFile.close();
scsiDev.status = CHECK_CONDITION;
scsiDev.target->sense.code = ILLEGAL_REQUEST;
}

scsiEnterPhase(DATA_OUT);
scsiRead(buf, bytes_sent, NULL);
gFile.seekCur(offset * 512);
gFile.write(buf, buf_size);
gFile.write(buf, bytes_sent);
if(gFile.getWriteError())
{
gFile.clearWriteError();
Expand Down

0 comments on commit 859407e

Please sign in to comment.