Skip to content

Commit

Permalink
Modified HD disk detection, enabled opening of read-only files
Browse files Browse the repository at this point in the history
  • Loading branch information
ggnkua committed Oct 9, 2023
1 parent 96ffc57 commit a7c5e4e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/leenueks_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: rmac-build-alpine
name: jacknife-build-alpine
on:
workflow_dispatch:
push:
Expand Down
18 changes: 15 additions & 3 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ BOOL guess_size(int size)
int start_sectors = 11;
// If our image is greater than 1mb, then it's a HD image. Not the best way to detect
// HD disks in general, but it should hold
if (size > 1024 * 1024)
if (size > 83 * 11 * 512 * 2)
{
start_sectors = 21;
}
Expand Down Expand Up @@ -463,9 +463,19 @@ unsigned char *expand_dim(BOOL fastcopy_header)
*/
uint32_t DFS_HostAttach(tArchive *arch)
{
disk_image.image_opened_read_only = FALSE;
disk_image.file_handle = fopen(arch->archname, "r+b");
if (disk_image.file_handle == NULL)
return J_FILE_NOT_FOUND;
{
// Maybe the image is write protected, try to open read only
disk_image.file_handle = fopen(arch->archname, "rb");
if (disk_image.file_handle == NULL)
{
return J_FILE_NOT_FOUND;
}
disk_image.image_opened_read_only = TRUE;
}


fseek(disk_image.file_handle, 0, SEEK_END);
disk_image.file_size = _ftelli64(disk_image.file_handle);
Expand Down Expand Up @@ -627,6 +637,8 @@ uint32_t DFS_ReadSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_t
*/
int DFS_HostWriteSector(uint8_t *buffer, uint32_t sector, uint32_t count)
{
if (disk_image.image_opened_read_only) return -1;

if (disk_image.disk_geometry_does_not_match_bpb)
{
// Wonky disk image detected, let's recalculate the requested sector
Expand Down Expand Up @@ -981,7 +993,7 @@ uint32_t OpenImage(tOpenArchiveData *wcx_archive, tArchive *arch)
// Obtain pointer to first partition on first (only) unit
if (disk_image.mode == DISKMODE_HARD_DISK)
{
disk_image.image_sectors = disk_image.file_size / 512;
disk_image.image_sectors = (int)disk_image.file_size / 512;

PART_INFO *p = disk_image.partition_info;
VOLINFO *a = arch->vi;
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 jacknife.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct DISK_IMAGE_INFO_
int image_sectors; // Derived value from image
int image_sides; // Derived value from image
int image_tracks; // Derived value from image
BOOL image_opened_read_only;
PART_INFO partition_info[MAX_PARTITIONS];
} DISK_IMAGE_INFO;

Expand Down

0 comments on commit a7c5e4e

Please sign in to comment.