Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
AC_INIT([hdfmonkey], [0.4], [matt@west.co.tt])
AC_INIT([hdfmonkey], [0.5], [matt@west.co.tt])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CANONICAL_HOST
AC_PROG_CC

case "$host_os" in
mingw32*)
AC_DEFINE([COMPAT_WIN32], 1, [Defined if needs Windows compatibility])
AC_SYS_LARGEFILE
;;
esac

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bin_PROGRAMS = hdfmonkey
hdfmonkey_SOURCES = hdfmonkey.c diskio.c image_file.c ff.c clock.c ccsbcs.c \
hdfmonkey_SOURCES = hdfmonkey.c diskio.c image_file.c ff.c clock.c ffunicode.c \
diskio.h ffconf.h integer.h volume_container.h ff.h image_file.h mbr.h
540 changes: 0 additions & 540 deletions src/ccsbcs.c

This file was deleted.

93 changes: 54 additions & 39 deletions src/diskio.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
/* Low-level disk operations required by the FAT driver */
/* Low-level disk operations required by the FAT driver */

#include <fcntl.h>
#include <config.h>

#include "diskio.h"
#include "ff.h" /* Obtains integer types */
#include "diskio.h" /* Declarations of disk functions */

static volume_container *volume_containers[8];

/* Associate a volume_container structure with a drive number so that it can
be addressed by the FAT driver */
int disk_map(BYTE drive_number, volume_container *vol)
/*-----------------------------------------------------------------------*/
/* Associate a volume_container structure with a drive number so that it */
/* can be addressed by the FAT driver */
/*-----------------------------------------------------------------------*/

DSTATUS disk_map (
BYTE drive_number,
volume_container *vol
)
{
volume_containers[drive_number] = vol;
return 0;
return 0; /* status = success */
}

/*-----------------------------------------------------------------------*/
/* Initialize a Drive */
/* Get Drive Status */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (BYTE drv)
DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
return 0; /* status = success */
}



/*-----------------------------------------------------------------------*/
/* Return Disk Status */
/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/

DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
return 0; /* status = success */
Expand All @@ -38,24 +49,25 @@ DSTATUS disk_status (

/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/

DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
volume_container *vol;
size_t size_requested;
size_t result;
vol = volume_containers[drv];
size_requested = count * vol->bytes_per_sector;
result = vol->read(vol, sector * vol->bytes_per_sector, (void *)buff,
ssize_t result;

vol = volume_containers[pdrv];
size_requested = (size_t)count * vol->bytes_per_sector;

result = vol->read(vol, (size_t)sector * vol->bytes_per_sector, (void *)buff,
size_requested);

if (result == size_requested) {
return RES_OK;
} else {
Expand All @@ -67,53 +79,56 @@ DRESULT disk_read (

/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/

#if FF_FS_READONLY == 0

#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
volume_container *vol;
size_t size_requested;
size_t result;
vol = volume_containers[drv];
size_requested = count * vol->bytes_per_sector;
result = vol->write(vol, sector * vol->bytes_per_sector, (void *)buff,
ssize_t result;

vol = volume_containers[pdrv];
size_requested = (size_t)count * vol->bytes_per_sector;

result = vol->write(vol, (size_t)sector * vol->bytes_per_sector, (void *)buff,
size_requested);

if (result == size_requested) {
return RES_OK;
} else {
return RES_PARERR;
}
}
#endif /* _READONLY */

#endif


/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/

DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
switch (ctrl) {
switch (cmd) {
case CTRL_SYNC:
/* syncing happens automatically on write */
return RES_OK;
case GET_SECTOR_SIZE:
*((WORD *)buff) = volume_containers[drv]->bytes_per_sector;
*((WORD *)buff) = volume_containers[pdrv]->bytes_per_sector;
return RES_OK;
case GET_SECTOR_COUNT:
*((DWORD *)buff) = volume_containers[drv]->sector_count;
*((DWORD *)buff) = volume_containers[pdrv]->sector_count;
return RES_OK;
case GET_BLOCK_SIZE:
*((DWORD *)buff) = 1;
Expand Down
91 changes: 51 additions & 40 deletions src/diskio.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009
/*-----------------------------------------------------------------------/
/ Low level disk interface modlue include file (C)ChaN, 2019 /
/-----------------------------------------------------------------------*/

#ifndef _DISKIO
#ifndef _DISKIO_DEFINED
#define _DISKIO_DEFINED

#define _READONLY 0 /* 1: Read-only mode */
#define _USE_IOCTL 1

#include "integer.h"
#include "volume_container.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Status of Disk Functions */
typedef BYTE DSTATUS;

Expand All @@ -26,17 +27,16 @@ typedef enum {
/*---------------------------------------*/
/* Prototypes for disk control functions */

BOOL assign_drives (int argc, char *argv[]);
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (BYTE, BYTE, void*);

/* Called by the top-level controlling program: associate a volume_container with a drive number */
int disk_map(BYTE drive_number, volume_container *vol);
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);

/* Called by the top-level controlling program:
associate a volume_container with a drive number */
DSTATUS disk_map(BYTE drive_number, volume_container *vol);

/* Disk Status Bits (DSTATUS) */

Expand All @@ -45,27 +45,38 @@ int disk_map(BYTE drive_number, volume_container *vol);
#define STA_PROTECT 0x04 /* Write protected */


/* Command code for disk_ioctrl() */

/* Generic command */
#define CTRL_SYNC 0 /* Mandatory for write functions */
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
#define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
#define CTRL_POWER 4
#define CTRL_LOCK 5
#define CTRL_EJECT 6
/* MMC/SDC command */
#define MMC_GET_TYPE 10
#define MMC_GET_CSD 11
#define MMC_GET_CID 12
#define MMC_GET_OCR 13
#define MMC_GET_SDSTAT 14
/* ATA/CF command */
#define ATA_GET_REV 20
#define ATA_GET_MODEL 21
#define ATA_GET_SN 22


#define _DISKIO
/* Command code for disk_ioctrl fucntion */

/* Generic command (Used by FatFs) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */

/* Generic command (Not used by FatFs) */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
#define CTRL_FORMAT 8 /* Create physical format on the media */

/* MMC/SDC specific ioctl command */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */

/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */

#ifdef __cplusplus
}
#endif

#endif
Loading