Skip to content

Commit

Permalink
Merge pull request #5 from nielsmh/feature/upload
Browse files Browse the repository at this point in the history
Shared folder upload
  • Loading branch information
nielsmh authored Jan 16, 2025
2 parents 2ea3c01 + ca96e5e commit 9d1c53f
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 26 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Working:
- Changing mounted CD image
- List files on shared directory on SD card
- Download files from shared directory
- Upload files to shared directory

Not working:
- See the "beware" notes in the Usage section below for places where
the device firmware might not behave as expected.

Not started:
- Upload files to shared directory
- Windows versions of the software
(lower priority, since the DOS version works under both Windows 3.x and 9x)

Expand Down Expand Up @@ -203,7 +203,7 @@ file you download._
C:\> scsitb get 0 1 scsitb2.zip
Retrieving file list from device 0:0:0 type 0 (Disk)...
Output filename: scsitb2.zip
Block 5/14 (35%)...
Block 5 / 14 (35%)...
```

_**BEWARE:** If a transfer is aborted before it completes, the hardware device
Expand All @@ -212,6 +212,34 @@ If this happens, it is currently unknown whether it's safe to continue using
the hardware device. Consider switching the computer off and back on to ensure
the device is properly reset and does not have unexpected open files._

### Upload file to shared directory

```
scsitb put <device> <filename>
```

Copies a file from the computer to the shared directory on the SD card.

The destination filename will be the same as the original filename.

_**Note:** Current release versions (as of 2024-12-30) of BlueSCSI and ZuluSCSI
firmware have an issue with at least some SCSI adapters, causing the transfer
to fail._

```
C:\> scsitb put 0 D:\dev\output.log
Verifying destination device 0:0:0 type 0 (Disk)...
Sending: D:\dev\output.log => output.log
Finished sending 118 blocks
C:\> scsitb put 0 D:\dev\output.log
Verifying destination device 0:0:0 type 0 (Disk)...
Destination filename: output.log
The destination already contains a file with this name. Overwrite? (Y/N) y
Sending: D:\dev\output.log => output.log
Block 45 / 120 (37%)...
```

## Development environment

Currently this project is developed with Open Watcom C 1.9,
Expand Down
2 changes: 1 addition & 1 deletion dos/aspiintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct DosScsiCommand : public ScsiCommand {
if (bufsize < 0) abort();

data_buf = new unsigned char[bufsize];
memset(data_buf, 0, bufsize);
_fmemset(data_buf, 0, bufsize);
device = dev;

srb6.SRB_Cmd = SC_EXEC_SCSI_CMD;
Expand Down
115 changes: 107 additions & 8 deletions dos/tbdos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**/

#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <wcvector.h>

#include "../include/aspi.h"
Expand Down Expand Up @@ -390,6 +395,93 @@ static int DoGetSharedDirFile(int argc, const char *argv[])
return 0;
}

static int DoPutSharedDirFile(int argc, const char *argv[])
{
int r = InitSCSI();

(void)argc; // unused parameter

if (r) return r;

const Device *dev = GetDeviceByName(argv[0]);
if (!dev) {
fprintf(stderr, "Device ID not found: %s\n", argv[0]);
return 16;
}

printf("Verifying destination device %s type %d (%s)...\n",
dev->name, dev->devtype, GetDeviceTypeName(dev->devtype));

WCValOrderedVector<ToolboxFileEntry> files;
if (!ToolboxGetSharedDirList(*dev, files)) {
return 17;
}

const char *inpfn = argv[1];
const char *outfn = basename(strdup(inpfn)); // assume DOS will clean up the memory on exit

int infile = _open(inpfn, O_RDONLY | O_BINARY);
if (infile == -1) {
fprintf(stderr, "The source file could not be opened for reading.\n");
return 1;
}
long filesize = _filelength(infile);

for (int i = 0; i < files.entries(); i++) {
if (stricmp(outfn, files[i].name) == 0) {
fprintf(stderr, "Destination filename: %s\n", outfn);
if (!AskForConfirmation("The destination already contains a file with this name. Overwrite?")) {
_close(infile);
return 2;
}
}
}

if (!ToolboxSendFileBegin(*dev, outfn)) {
_close(infile);
return 18;
}

const unsigned short BUFSIZE = 512;
char *buf = new char[BUFSIZE];
unsigned long block_index = 0;
unsigned long num_blocks = ((unsigned long)filesize + (BUFSIZE - 1)) / BUFSIZE;
int error_status = 0;

printf("Sending: %s => %s\n", inpfn, outfn);

while (block_index < num_blocks) {
short data_size = _read(infile, buf, BUFSIZE);
if (data_size > 0) {
if (!ToolboxSendFileBlock(*dev, data_size, block_index, buf)) {
error_status = 18;
break;
}
} else if (data_size < 0) {
fprintf(stderr, "Error reading file, aborting transfer.\n");
error_status = 3;
break;
}
printf(" Block %lu / %lu (%d%%)...\r", block_index+1, num_blocks, (block_index + 1) * 100 / num_blocks);
block_index++;
if (data_size < BUFSIZE) break;
}
printf(" Finished sending %lu blocks \n", num_blocks);
delete[] buf;

if (!error_status && !ToolboxSendFileEnd(*dev)) {
error_status = 19;
}

if (error_status) {
fprintf(stderr, "An error occurred during the transfer, the destination file may have errors.\n");
}

_close(infile);

return error_status;
}


static void PrintBanner(void)
{
Expand Down Expand Up @@ -417,14 +509,13 @@ static void PrintHelp(void)
"Usage: SCSITB <command> [parameters]\n"
"\n"
"Commands:\n"
" info List all available SCSI adapters and devices.\n"
" lsimg <device> List available images for the given device.\n"
" setimg <device> <index>\n"
" Change the mounted image in the given device to the\n"
" image with the given index in the image list.\n"
" lsdir <device> List shared directory for the given decice.\n"
" get <device> <index> [filename]\n"
" Download a file from the shared directory.\n"
" info List all available SCSI adapters and devices.\n"
" lsimg <dev> List available images for the given device.\n"
" setimg <dev> <idx> Change the mounted image in the given device, to\n"
" the image with the given index in the image list.\n"
" lsdir <dev> List shared directory for the given decice.\n"
" get <dev> <idx> [name] Download a file from the shared directory.\n"
" put <dev> <filename> Upload a file to the shared directory.\n"
"\n"
"Please see the documentation for more information about supported\n"
"devices, how to configure your device for compatibility, etc.\n"
Expand Down Expand Up @@ -490,6 +581,14 @@ int main(int argc, const char *argv[])
}
}

if (strcmpi(argv[1], "put") == 0) {
if (argc >= 4) {
return DoPutSharedDirFile(argc - 2, argv + 2);
} else {
missingargs = 2;
}
}

if (missingargs) {
fprintf(stderr, "Missing parameters to command: %s\n\n", argv[1]);
PrintHelp();
Expand Down
3 changes: 3 additions & 0 deletions include/estb.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ bool ToolboxSetImage(const Device &dev, int newimage);
bool ToolboxGetSharedDirList(const Device &dev, WCValOrderedVector<ToolboxFileEntry> &images);
int ToolboxGetFileBlock(const Device &dev, int fileindex, unsigned long blockindex, unsigned char databuf[]);
bool ToolboxListDevices(const Device &dev, ToolboxDeviceList &devlist);
bool ToolboxSendFileBegin(const Device &dev, const char *filename);
bool ToolboxSendFileBlock(const Device &dev, unsigned short data_size, unsigned long block_index, const char *data);
bool ToolboxSendFileEnd(const Device &dev);


#endif /* ESTB_H */
Expand Down
6 changes: 4 additions & 2 deletions include/toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ enum ToolboxDeviceType {
/** TOOLBOX_SEND_FILE_PREP (write, length 10)
* Input:
* CDB 00 = command byte
* Data 00 = 32 byte filename to create
* . |
* Data 00 = 32 byte filename to create,
* . | must be NUL terminated
* . |
* . |
* 31 |
* 32 = additional NUL terminator required
* Output:
* None.
* Notes:
Expand Down Expand Up @@ -177,5 +178,6 @@ enum ToolboxDeviceType {
#define TOOLBOX_COUNT_CDS 0xDA

#define OPEN_RETRO_SCSI_TOO_MANY_FILES 0x0001
#define MAX_FILE_LISTING_FILES 100

#endif /* TOOLBOX_H */
Binary file modified scsitb.exe
Binary file not shown.
Loading

0 comments on commit 9d1c53f

Please sign in to comment.