Skip to content

Commit 79469bd

Browse files
committed
src: Replace disk_initialize and disk_status with ioctl commands.
1 parent eedb8d7 commit 79469bd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/diskio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ typedef enum {
3131
/* Prototypes for disk control functions */
3232

3333

34-
DSTATUS disk_initialize (void *drv);
35-
DSTATUS disk_status (void *drv);
3634
DRESULT disk_read (void *drv, BYTE* buff, DWORD sector, UINT count);
3735
DRESULT disk_write (void *drv, const BYTE* buff, DWORD sector, UINT count);
3836
DRESULT disk_ioctl (void *drv, BYTE cmd, void* buff);
@@ -53,6 +51,8 @@ DRESULT disk_ioctl (void *drv, BYTE cmd, void* buff);
5351
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
5452
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
5553
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
54+
#define IOCTL_INIT 5
55+
#define IOCTL_STATUS 6
5656

5757
/* Generic command (Not used by FatFs) */
5858
#define CTRL_POWER 5 /* Get/Set power status */

src/ff.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
22282228
*rfs = fs; /* Return pointer to the file system object */
22292229

22302230
if (fs->fs_type) { /* If the volume has been mounted */
2231-
stat = disk_status(fs->drv);
2231+
disk_ioctl(fs->drv, IOCTL_STATUS, &stat);
22322232
if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */
22332233
if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check write protection if needed */
22342234
return FR_WRITE_PROTECTED;
@@ -2240,7 +2240,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
22402240
/* Following code attempts to mount the volume. (analyze BPB and initialize the fs object) */
22412241

22422242
fs->fs_type = 0; /* Clear the file system object */
2243-
stat = disk_initialize(fs->drv); /* Initialize the physical drive */
2243+
disk_ioctl(fs->drv, IOCTL_INIT, &stat); /* Initialize the physical drive */
22442244
if (stat & STA_NOINIT) /* Check if the initialization succeeded */
22452245
return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */
22462246
if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */
@@ -2372,10 +2372,15 @@ FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */
23722372
void* obj /* Pointer to the object FIL/DIR to check validity */
23732373
)
23742374
{
2375+
DSTATUS stat;
23752376
FIL *fil = (FIL*)obj; /* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
23762377

23772378

2378-
if (!fil || !fil->fs || !fil->fs->fs_type || fil->fs->id != fil->id || (disk_status(fil->fs->drv) & STA_NOINIT))
2379+
if (!fil || !fil->fs || !fil->fs->fs_type || fil->fs->id != fil->id)
2380+
return FR_INVALID_OBJECT;
2381+
2382+
disk_ioctl(fil->fs->drv, IOCTL_STATUS, &stat);
2383+
if (stat & STA_NOINIT)
23792384
return FR_INVALID_OBJECT;
23802385

23812386
ENTER_FF(fil->fs); /* Lock file system */
@@ -4091,7 +4096,7 @@ FRESULT f_mkfs (
40914096
part = LD2PT(vol); /* Partition (0:auto detect, 1-4:get from partition table)*/
40924097

40934098
/* Get disk statics */
4094-
stat = disk_initialize(pdrv);
4099+
disk_ioctl(pdrv, IOCTL_INIT, &stat);
40954100
if (stat & STA_NOINIT) return FR_NOT_READY;
40964101
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
40974102
#if _MAX_SS != _MIN_SS /* Get disk sector size */
@@ -4317,7 +4322,7 @@ FRESULT f_fdisk (
43174322
DWORD sz_disk, sz_part, s_part;
43184323

43194324

4320-
stat = disk_initialize(pdrv);
4325+
disk_ioctl(pdrv, IOCTL_INIT, &stat);
43214326
if (stat & STA_NOINIT) return FR_NOT_READY;
43224327
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
43234328
if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR;

0 commit comments

Comments
 (0)