Skip to content

Commit 9bdb0ae

Browse files
committed
added some disk_status plumbing so FatFs can get the status from sdmm via an ioctl
1 parent 28f1b80 commit 9bdb0ae

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

include/filesys/block/sdmm.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,13 @@ DRESULT disk_ioctl (
805805
DRESULT res;
806806
BYTE n, csd[16];
807807
DWORD cs;
808-
809-
if (disk_status(drv) & STA_NOINIT) return RES_NOTRDY; /* Check if card is in the socket */
808+
DWORD status = disk_status(drv);
809+
810+
if (ctrl == DISKIO_GET_STATUS) {
811+
*(int *)buff = status;
812+
return 0;
813+
}
814+
if (status & STA_NOINIT) return RES_NOTRDY; /* Check if card is in the socket */
810815

811816
res = RES_ERROR;
812817
switch (ctrl) {
@@ -828,6 +833,7 @@ DRESULT disk_ioctl (
828833

829834
default:
830835
res = RES_PARERR;
836+
break;
831837
}
832838

833839
deselect();

include/filesys/fatfs/diskio.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "diskio.h"
33
#include <stdio.h>
44
#include <sys/vfs.h>
5+
#include <sys/ioctl.h>
56

67
vfs_file_t *fh;
78

@@ -28,9 +29,18 @@ DRESULT disk_deinitialize(BYTE pdrv) {
2829
}
2930

3031
DRESULT disk_status(BYTE pdrv) {
32+
int r;
33+
int val = 0;
3134
if (!fh) {
3235
return RES_NOTRDY;
3336
}
37+
r = fh->ioctl(fh, DISKIO_GET_STATUS, &val);
38+
if (r < 0) {
39+
/* if ioctl not supported, just assume all is well */
40+
return RES_OK;
41+
}
42+
if (val & (STA_NOINIT|STA_NODISK))
43+
return RES_NOTRDY;
3444
return RES_OK;
3545
}
3646

include/sys/ioctl.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
#ifndef _SYS_IOCTL_H
22
#define _SYS_IOCTL_H
33

4+
/* disk control ioctls; must match up with defines
5+
in include/filesys/fatfs/diskio.h
6+
*/
7+
#define DISKIO_CTRL_SYNC 0x0000
8+
#define DISKIO_GET_SECTOR_COUNT 0x0001
9+
#define DISKIO_GET_SECTOR_SIZE 0x0002
10+
#define DISKIO_GET_BLOCK_SIZE 0x0003
11+
#define DISKIO_CTRL_TRIM 0x0004
12+
#define DISKIO_CTRL_FORMAT 0x0005
13+
#define DISKIO_CTRL_POWER_IDLE 0x0006
14+
#define DISKIO_CTRL_POWER_OFF 0x0007
15+
#define DISKIO_CTRL_LOCK 0x0008
16+
#define DISKIO_CTRL_UNLOCK 0x0009
17+
#define DISKIO_CTRL_EJECT 0x000a
18+
#define DISKIO_CTRL_GET_SMART 0x000b
19+
20+
#define DISKIO_GET_STATUS 0x00ff
21+
/* disk status bits */
22+
# define DISKIO_STA_NOINIT 0x01 /* Drive not initialized */
23+
# define DISKIO_STA_NODISK 0x02 /* No medium in the drive */
24+
# define DISKIO_STA_PROTECT 0x04 /* Write protected */
25+
26+
/* tty control */
427
#define TTYIOCTLGETFLAGS 0x0100
528
#define TTYIOCTLSETFLAGS 0x0101
629

730
#define TTY_FLAG_ECHO 0x01
831
#define TTY_FLAG_CRNL 0x02
932

33+
/* flash block control */
1034
#define BLKIOCTLERASE 0x0200
1135

1236
struct _blkio_info {

version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#define VERSION_MAJOR 7
88
#define VERSION_MINOR 6
9-
#define VERSION_REV 11
10-
//#define BETA "-beta"
9+
#define VERSION_REV 12
10+
#define BETA "-beta"
1111

1212
#define VERSIONSTR version_string
1313

0 commit comments

Comments
 (0)