Skip to content

Commit

Permalink
Fixed bug when adding many files into a folder, added more checks whe…
Browse files Browse the repository at this point in the history
…n writing to floppy images,
  • Loading branch information
ggnkua committed Nov 15, 2023
1 parent a7c5e4e commit c0ccccc
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
9 changes: 6 additions & 3 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,10 @@ int DFS_HostWriteSector(uint8_t *buffer, uint32_t sector, uint32_t count)
// It's cached in ram, so let's not hit the disk
if (disk_image.mode != DISKMODE_HARD_DISK)
{
if (sector > disk_image.file_size/512)
{
return -1;
}
memcpy(&disk_image.buffer[sector * SECTOR_SIZE], buffer, SECTOR_SIZE);
return 0;
}
Expand Down Expand Up @@ -909,9 +913,8 @@ uint32_t scan_files(char* path, VOLINFO *vi, char *partition_prefix)
if (strcmp((char *)lastEntry->de.name, ".. \x10") == 0) continue;
if (strlen(lastEntry->de.name) > 12)
{
// Invalid filename, abort
ret = DFS_ERRMISC;
break;
// Invalid filename, mark it as illegal
strcpy(lastEntry->de.name, "ILLEGAL");
}
dir_to_canonical(filename_canonical, lastEntry->de.name);
if (lastEntry->de.attr & ATTR_VOLUME_ID) {
Expand Down
39 changes: 14 additions & 25 deletions dosfs-1.03/dosfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,26 +898,19 @@ uint32_t DFS_GetFreeDirEnt(PVOLINFO volinfo, uint8_t *path, PDIRINFO di, PDIRENT
di->currententry = 1; // since the code coming after this expects to subtract 1

// Mark newly allocated cluster as end of chain
// ggn: For GEMDOS the end-of-chain marker is fff/ffff/fffffff
switch(volinfo->filesystem) {
case FAT12: tempclus = 0xff8; break;
case FAT16: tempclus = 0xfff8; break;
case FAT32: tempclus = 0x0ffffff8; break;
case FAT12: tempclus = 0xfff; break;
case FAT16: tempclus = 0xffff; break;
case FAT32: tempclus = 0x0fffffff; break;
default: return DFS_ERRMISC;
}
// ggn: If we were asked to create a folder, the end-of-chain marker is fff/ffff/fffffff
if (mode & DFS_FOLDER)
{
tempclus |= 7;
// ggn: ?
//tempclus = 0;
di->currententry = 0;
}
// ggn: If we reached this far then we should exit instead of looping
// TODO: get rid of the do{} block?
//tempclus = 0;
di->currententry = 0;
DFS_SetFAT(volinfo, di->scratch, &i, di->currentcluster, tempclus);
if (mode & DFS_FOLDER)
{
return DFS_OK;
}

return DFS_OK;
}
} while (!tempclus);

Expand Down Expand Up @@ -1111,17 +1104,13 @@ uint32_t DFS_OpenFile(PVOLINFO volinfo, uint8_t *path, uint8_t mode, uint8_t *sc
return DFS_ERRMISC;

// Mark newly allocated cluster as end of chain
// ggn: For GEMDOS the end-of-chain marker is fff/ffff/fffffff
switch(volinfo->filesystem) {
case FAT12: cluster = 0xff8; break;
case FAT16: cluster = 0xfff8; break;
case FAT32: cluster = 0x0ffffff8; break;
case FAT12: cluster = 0xfff; break;
case FAT16: cluster = 0xffff; break;
case FAT32: cluster = 0x0fffffff; break;
default: return DFS_ERRMISC;
}
// ggn: If we were asked to create a folder, the end-of-chain marker is fff/ffff/fffffff
if (mode & DFS_FOLDER)
{
cluster |= 7;
}
temp = 0;
DFS_SetFAT(volinfo, scratch, &temp, fileinfo->cluster, cluster);

Expand Down Expand Up @@ -1501,7 +1490,7 @@ uint32_t DFS_WriteFile(PFILEINFO fileinfo, uint8_t *scratch, uint8_t *buffer, ui
// Mark newly allocated cluster as end of chain
switch(fileinfo->volinfo->filesystem) {
case FAT12: tempclus = 0xfff; break; // ggn: Changed this from ff8 for debugging (matching GEMDOS' behaviour)
case FAT16: tempclus = 0xfff8; break;
case FAT16: tempclus = 0xffff; break;
case FAT32: tempclus = 0x0ffffff8; break;
default: return DFS_ERRMISC;
}
Expand Down
Binary file modified install/jacknife.wcx
Binary file not shown.
Binary file modified install/jacknife.wcx64
Binary file not shown.
Binary file modified install/jacknife.zip
Binary file not shown.
Binary file modified install/jacknife_ctrlpagedownonly.zip
Binary file not shown.
1 change: 1 addition & 0 deletions install/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Progress bar info during operations |✓|✓ |&c

### What's missing, but planned (in order of severity/implementation likelihood)

- Writing outside the partitions (i.e. the folder where "0", "1" etc folders exist) causes a crash
- Extended (XGM) partition support
- `.ini` file with various settings (specify if creating a HD disk image is allowed, customisable hard disk image extension, etc)
- Writing .DIM images (only opening and extracting is possible at the moment)
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Progress bar info during operations |✓|✓ |&c

### What's missing, but planned (in order of severity/implementation likelihood)

- Writing outside the partitions (i.e. the folder where "0", "1" etc folders exist) causes a crash
- Extended (XGM) partition support
- `.ini` file with various settings (specify if creating a HD disk image is allowed, customisable hard disk image extension, etc)
- Writing .DIM images (only opening and extracting is possible at the moment)
Expand Down

0 comments on commit c0ccccc

Please sign in to comment.