[270] | 1 | /*-----------------------------------------------------------------------*/
|
---|
| 2 | /* PFF - Low level disk control module for Win32 (C)ChaN, 2014 */
|
---|
| 3 | /*-----------------------------------------------------------------------*/
|
---|
| 4 |
|
---|
| 5 | #include <string.h>
|
---|
| 6 | #include "ffconf.h"
|
---|
| 7 | #include "diskio.h"
|
---|
| 8 |
|
---|
| 9 | /*--------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | Module Private Functions
|
---|
| 12 |
|
---|
| 13 | ---------------------------------------------------------------------------*/
|
---|
| 14 |
|
---|
| 15 | #define MAX_DRIVES 1 /* Max number of physical drives to be used */
|
---|
| 16 |
|
---|
[279] | 17 | #define RamDisk _binary____webserver_httpd_fs_bin_start
|
---|
| 18 | extern unsigned char RamDisk[];
|
---|
[270] | 19 |
|
---|
| 20 | typedef struct {
|
---|
| 21 | DSTATUS status;
|
---|
| 22 | WORD sz_sector;
|
---|
| 23 | DWORD wofs;
|
---|
| 24 | DWORD wip;
|
---|
| 25 | DWORD n_sectors;
|
---|
| 26 | } RD_STAT;
|
---|
| 27 |
|
---|
| 28 | static volatile
|
---|
| 29 | RD_STAT Stat[MAX_DRIVES];
|
---|
| 30 |
|
---|
| 31 | static
|
---|
| 32 | BYTE Buffer[SS_RAMDISK];
|
---|
| 33 |
|
---|
| 34 | static
|
---|
| 35 | int get_status(volatile RD_STAT *stat) {
|
---|
| 36 | stat->sz_sector = SS_RAMDISK;
|
---|
| 37 | if(stat->sz_sector < _MIN_SS || stat->sz_sector > _MAX_SS) return 0;
|
---|
| 38 | stat->n_sectors = SZ_RAMDISK * 1024 / SS_RAMDISK;
|
---|
| 39 | stat->status = 0;
|
---|
| 40 | return 1;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /*-----------------------------------------------------------------------*/
|
---|
| 44 | /* Initialize Disk Drive */
|
---|
| 45 | /*-----------------------------------------------------------------------*/
|
---|
| 46 | DSTATUS ramdisk_initialize (void)
|
---|
| 47 | {
|
---|
| 48 | DSTATUS sta;
|
---|
| 49 |
|
---|
| 50 | get_status(&Stat[0]);
|
---|
| 51 | sta = Stat[0].status;
|
---|
| 52 | Stat[0].wip = 0;
|
---|
| 53 |
|
---|
| 54 | return sta;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /*-----------------------------------------------------------------------*/
|
---|
| 58 | /* Get Disk Status */
|
---|
| 59 | /*-----------------------------------------------------------------------*/
|
---|
| 60 | DSTATUS ramdisk_get_status (void)
|
---|
| 61 | {
|
---|
| 62 | return Stat[0].status;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /*-----------------------------------------------------------------------*/
|
---|
| 66 | /* Read Partial Sector */
|
---|
| 67 | /*-----------------------------------------------------------------------*/
|
---|
| 68 | DRESULT ramdisk_read (
|
---|
| 69 | BYTE* buff, /* Data read buffer */
|
---|
| 70 | DWORD sector, /* Sector number (LBA) */
|
---|
| 71 | UINT count /* Number of sectors to read (1..128) */
|
---|
| 72 | )
|
---|
| 73 | {
|
---|
| 74 | DRESULT res;
|
---|
| 75 | int dofs;
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | if(Stat[0].status & STA_NOINIT) return RES_NOTRDY;
|
---|
| 79 |
|
---|
| 80 | if(sector >= Stat[0].n_sectors || !count || (sector + count) > Stat[0].n_sectors/* || Stat[0].wip*/) {
|
---|
| 81 | res = RES_PARERR;
|
---|
| 82 | }
|
---|
| 83 | else {
|
---|
| 84 | if(buff) {
|
---|
| 85 | dofs = sector * Stat[0].sz_sector;
|
---|
| 86 | memcpy(buff, &RamDisk[dofs], count * Stat[0].sz_sector);
|
---|
| 87 | res = RES_OK;
|
---|
| 88 | }
|
---|
| 89 | else {
|
---|
| 90 | res = RES_OK;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | return res;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /*-----------------------------------------------------------------------*/
|
---|
| 98 | /* Write Partial Sector */
|
---|
| 99 | /*-----------------------------------------------------------------------*/
|
---|
| 100 | DRESULT ramdisk_write (
|
---|
| 101 | const BYTE* buff, /* Pointer to the write data */
|
---|
| 102 | DWORD sc, /* Sector number (LBA), Number of bytes to send */
|
---|
| 103 | UINT count /* Number of sectors to read (1..128) */
|
---|
| 104 | )
|
---|
| 105 | {
|
---|
| 106 | DRESULT res;
|
---|
| 107 | int dofs;
|
---|
| 108 |
|
---|
| 109 | if(Stat[0].status & STA_NOINIT) return RES_NOTRDY;
|
---|
| 110 |
|
---|
| 111 | if(!buff) {
|
---|
| 112 | if(sc) {
|
---|
| 113 | Stat[0].wip = sc;
|
---|
| 114 | Stat[0].wofs = 0;
|
---|
| 115 | memset(Buffer, 0, sizeof Buffer);
|
---|
| 116 | res = RES_OK;
|
---|
| 117 | }
|
---|
| 118 | else {
|
---|
| 119 | if(Stat[0].wip) {
|
---|
| 120 | dofs = Stat[0].wip * Stat[0].sz_sector;
|
---|
| 121 | memcpy(RamDisk + dofs, Buffer, Stat[0].sz_sector);
|
---|
| 122 | Stat[0].wip = 0;
|
---|
| 123 | res = RES_OK;
|
---|
| 124 | }
|
---|
| 125 | else {
|
---|
| 126 | res = RES_OK;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | else {
|
---|
| 131 | if(Stat[0].wofs + sc > Stat[0].sz_sector) sc = Stat[0].sz_sector - Stat[0].wofs;
|
---|
| 132 | memcpy(&Buffer[Stat[0].wofs], buff, sc);
|
---|
| 133 | Stat[0].wofs += sc;
|
---|
| 134 | res = RES_OK;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | return res;
|
---|
| 138 | }
|
---|