Changeset 154 for uKadecot/trunk/pfatfs
- Timestamp:
- Feb 2, 2016, 9:54:35 PM (8 years ago)
- Location:
- uKadecot/trunk/pfatfs
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uKadecot/trunk/pfatfs/diskio.c
r108 r154 21 21 #define RamDisk ((unsigned char *)0xfff00000) 22 22 #else 23 #include <windows.h>24 #include <tchar.h>25 #include <winioctl.h>26 27 23 unsigned char RamDisk[SZ_RAMDISK * 1024]; 24 extern void win_disk_initialize(void *ramDisk, int size); 28 25 #endif 29 26 … … 34 31 DWORD wip; 35 32 DWORD n_sectors; 36 } STAT;33 } RD_STAT; 37 34 38 35 static volatile 39 STAT Stat[MAX_DRIVES];36 RD_STAT Stat[MAX_DRIVES]; 40 37 41 38 static … … 43 40 44 41 static 45 int get_status(volatile STAT *stat) {42 int get_status(volatile RD_STAT *stat) { 46 43 stat->sz_sector = SS_RAMDISK; 47 44 if(stat->sz_sector < _MIN_SS || stat->sz_sector > _MAX_SS) return 0; … … 54 51 /* Initialize Disk Drive */ 55 52 /*-----------------------------------------------------------------------*/ 56 DSTATUS disk_initialize (void)53 DSTATUS ramdisk_initialize (void) 57 54 { 58 55 DSTATUS sta; 59 56 #ifdef _MSC_VER 60 HANDLE h; 61 DWORD br; 62 63 h = CreateFile(_T("..\\..\\..\\..\\uip\\apps\\webserver\\httpd-fs.bin"), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); 64 if (h != INVALID_HANDLE_VALUE) { 65 ReadFile(h, RamDisk, sizeof(RamDisk), &br, 0); 66 CloseHandle(h); 67 } 57 win_disk_initialize(RamDisk, sizeof(RamDisk)); 68 58 #endif 69 59 get_status(&Stat[0]); … … 77 67 /* Get Disk Status */ 78 68 /*-----------------------------------------------------------------------*/ 79 DSTATUS disk_get_status (void)69 DSTATUS ramdisk_get_status (void) 80 70 { 81 71 return Stat[0].status; … … 85 75 /* Read Partial Sector */ 86 76 /*-----------------------------------------------------------------------*/ 87 DRESULT disk_readp (77 DRESULT ramdisk_readp ( 88 78 BYTE* buff, /* Data read buffer */ 89 79 DWORD sector, /* Sector number (LBA) */ … … 118 108 /* Write Partial Sector */ 119 109 /*-----------------------------------------------------------------------*/ 120 DRESULT disk_writep (110 DRESULT ramdisk_writep ( 121 111 const BYTE* buff, /* Pointer to the write data */ 122 112 DWORD sc /* Sector number (LBA), Number of bytes to send */ -
uKadecot/trunk/pfatfs/diskio.h
r108 r154 19 19 /* Results of Disk Functions */ 20 20 typedef enum { 21 RES_OK = 0, /* 0: Function succeeded */ 22 RES_ERROR, /* 1: Disk error */ 23 RES_NOTRDY, /* 2: Not ready */ 24 RES_PARERR /* 3: Invalid parameter */ 21 RES_OK = 0, /* 0: Successful */ 22 RES_ERROR, /* 1: R/W Error */ 23 RES_WRPRT, /* 2: Write Protected */ 24 RES_NOTRDY, /* 3: Not Ready */ 25 RES_PARERR /* 4: Invalid Parameter */ 25 26 } DRESULT; 26 27 … … 29 30 /* Prototypes for disk control functions */ 30 31 31 DSTATUS disk_initialize (void);32 DSTATUS disk_get_status (void);33 DRESULT disk_readp (BYTE* buff, DWORD sector, UINT offset, UINT count);34 DRESULT disk_writep (const BYTE* buff, DWORD sc);32 DSTATUS ramdisk_initialize (void); 33 DSTATUS ramdisk_get_status (void); 34 DRESULT ramdisk_readp (BYTE* buff, DWORD sector, UINT offset, UINT count); 35 DRESULT ramdisk_writep (const BYTE* buff, DWORD sc); 35 36 36 37 #define STA_NOINIT 0x01 /* Drive not initialized */ 37 38 #define STA_NODISK 0x02 /* No medium in the drive */ 39 #define STA_PROTECT 0x04 /* Write protected */ 38 40 41 /* Generic command (Used by FatFs) */ 42 #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ 43 #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ 44 #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ 45 #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ 46 #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ 47 48 /* MMC/SDC specific command (Not used by FatFs) */ 49 #define MMC_GET_TYPE 50 /* Get card type */ 50 #define MMC_GET_CSD 51 /* Get CSD */ 51 #define MMC_GET_CID 52 /* Get CID */ 52 #define MMC_GET_OCR 53 /* Get OCR */ 53 #define MMC_GET_SDSTAT 54 /* Get SD status */ 54 55 /* MMC card type flags (MMC_GET_TYPE) */ 56 #define CT_MMC 0x01 /* MMC ver 3 */ 57 #define CT_SD1 0x02 /* SD ver 1 */ 58 #define CT_SD2 0x04 /* SD ver 2 */ 59 #define CT_SDC (CT_SD1|CT_SD2) /* SD */ 60 #define CT_BLOCK 0x08 /* Block addressing */ 39 61 40 62 #ifdef __cplusplus -
uKadecot/trunk/pfatfs/pff.c
r108 r154 58 58 #define ABORT(err) {fs->flag = 0; return err;} 59 59 60 #if _USE_LFN61 static WCHAR LfnBuf[_MAX_LFN+1];62 #endif63 64 60 /*--------------------------------------------------------*/ 65 61 /* DBCS code ranges and SBCS extend char conversion table */ … … 509 505 ofs = bc % 512; bc /= 512; 510 506 if (ofs != 511) { 511 if ( disk_readp(buf, fs->fatbase + bc, ofs, 2)) break;507 if (fs->disk_readp(buf, fs->fatbase + bc, ofs, 2)) break; 512 508 } else { 513 if ( disk_readp(buf, fs->fatbase + bc, 511, 1)) break;514 if ( disk_readp(buf+1, fs->fatbase + bc + 1, 0, 1)) break;509 if (fs->disk_readp(buf, fs->fatbase + bc, 511, 1)) break; 510 if (fs->disk_readp(buf+1, fs->fatbase + bc + 1, 0, 1)) break; 515 511 } 516 512 wc = LD_WORD(buf); … … 520 516 #if _FS_FAT16 521 517 case FS_FAT16 : 522 if ( disk_readp(buf, fs->fatbase + clst / 256, ((UINT)clst % 256) * 2, 2)) break;518 if (fs->disk_readp(buf, fs->fatbase + clst / 256, ((UINT)clst % 256) * 2, 2)) break; 523 519 return LD_WORD(buf); 524 520 #endif 525 521 #if _FS_FAT32 526 522 case FS_FAT32 : 527 if ( disk_readp(buf, fs->fatbase + clst / 128, ((UINT)clst % 128) * 4, 4)) break;523 if (fs->disk_readp(buf, fs->fatbase + clst / 128, ((UINT)clst % 128) * 4, 4)) break; 528 524 return LD_DWORD(buf) & 0x0FFFFFFF; 529 525 #endif … … 673 669 BYTE a, ord, sum; 674 670 #endif 671 FATFS *fs = dj->fs; 675 672 676 673 res = dir_rewind(dj); /* Rewind directory object */ … … 681 678 #endif 682 679 do { 683 res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */680 res = fs->disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */ 684 681 ? FR_DISK_ERR : FR_OK; 685 682 if (res != FR_OK) break; … … 735 732 BYTE ord = 0xFF, sum = 0xFF; 736 733 #endif 734 FATFS *fs = dj->fs; 737 735 738 736 res = FR_NO_FILE; 739 737 while (dj->sect) { 740 res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */738 res = fs->disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */ 741 739 ? FR_DISK_ERR : FR_OK; 742 740 if (res != FR_OK) break; … … 1072 1070 ) 1073 1071 { 1074 if ( disk_readp(buf, sect, 510, 2)) /* Read the boot record */1072 if (fs->disk_readp(buf, sect, 510, 2)) /* Read the boot record */ 1075 1073 return 3; 1076 1074 if (LD_WORD(buf) != 0xAA55) /* Check record signature */ 1077 1075 return 2; 1078 1076 1079 if (!_FS_32ONLY && ! disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146) /* Check FAT12/16 */1077 if (!_FS_32ONLY && !fs->disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146) /* Check FAT12/16 */ 1080 1078 return 0; 1081 if (_FS_FAT32 && ! disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146) /* Check FAT32 */1079 if (_FS_FAT32 && !fs->disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146) /* Check FAT32 */ 1082 1080 return 0; 1083 1081 return 1; … … 1106 1104 DWORD bsect, fsize, tsect, mclst; 1107 1105 1108 if ( disk_get_status() & STA_NOINIT) /* Check if the drive is ready or not */1106 if (fs->disk_get_status() & STA_NOINIT) /* Check if the drive is ready or not */ 1109 1107 return FR_NOT_READY; 1110 1108 … … 1114 1112 if (fmt == 1) { /* Not an FAT boot record, it may be FDISK format */ 1115 1113 /* Check a partition listed in top of the partition table */ 1116 if ( disk_readp(buf, bsect, MBR_Table, 16)) { /* 1st partition entry */1114 if (fs->disk_readp(buf, bsect, MBR_Table, 16)) { /* 1st partition entry */ 1117 1115 fmt = 3; 1118 1116 } else { … … 1127 1125 1128 1126 /* Initialize the file system object */ 1129 if ( disk_readp(buf, bsect, 13, sizeof (buf))) return FR_DISK_ERR;1127 if (fs->disk_readp(buf, bsect, 13, sizeof (buf))) return FR_DISK_ERR; 1130 1128 1131 1129 fsize = LD_WORD(buf+BPB_FATSz16-13); /* Number of sectors per FAT */ … … 1187 1185 dj.fn = sp; 1188 1186 #if _USE_LFN 1189 dj.lfn = LfnBuf;1187 dj.lfn = fs->LfnBuf; 1190 1188 #endif 1191 1189 res = follow_path(&dj, dir, path); /* Follow the file path */ … … 1249 1247 rcnt = 512 - (UINT)fs->fptr % 512; /* Get partial sector data from sector buffer */ 1250 1248 if (rcnt > btr) rcnt = btr; 1251 dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (UINT)fs->fptr % 512, rcnt);1249 dr = fs->disk_readp(!buff ? 0 : rbuff, fs->dsect, (UINT)fs->fptr % 512, rcnt); 1252 1250 if (dr) ABORT(FR_DISK_ERR); 1253 1251 fs->fptr += rcnt; rbuff += rcnt; /* Update pointers and counters */ … … 1286 1284 1287 1285 if (!btw) { /* Finalize request */ 1288 if ((fs->flag & FA__WIP) && disk_writep(0, 0)) ABORT(FR_DISK_ERR);1286 if ((fs->flag & FA__WIP) && fs->disk_writep(0, 0)) ABORT(FR_DISK_ERR); 1289 1287 fs->flag &= ~FA__WIP; 1290 1288 return FR_OK; … … 1310 1308 if (!sect) ABORT(FR_DISK_ERR); 1311 1309 fs->dsect = sect + cs; 1312 if ( disk_writep(0, fs->dsect)) ABORT(FR_DISK_ERR); /* Initiate a sector write operation */1310 if (fs->disk_writep(0, fs->dsect)) ABORT(FR_DISK_ERR); /* Initiate a sector write operation */ 1313 1311 fs->flag |= FA__WIP; 1314 1312 } 1315 1313 wcnt = 512 - (UINT)fs->fptr % 512; /* Number of bytes to write to the sector */ 1316 1314 if (wcnt > btw) wcnt = btw; 1317 if ( disk_writep(p, wcnt)) ABORT(FR_DISK_ERR); /* Send data to the sector */1315 if (fs->disk_writep(p, wcnt)) ABORT(FR_DISK_ERR); /* Send data to the sector */ 1318 1316 fs->fptr += wcnt; p += wcnt; /* Update pointers and counters */ 1319 1317 btw -= wcnt; *bw += wcnt; 1320 1318 if ((UINT)fs->fptr % 512 == 0) { 1321 if ( disk_writep(0, 0)) ABORT(FR_DISK_ERR); /* Finalize the currtent secter write operation */1319 if (fs->disk_writep(0, 0)) ABORT(FR_DISK_ERR); /* Finalize the currtent secter write operation */ 1322 1320 fs->flag &= ~FA__WIP; 1323 1321 } … … 1401 1399 dj->fn = sp; 1402 1400 #if _USE_LFN 1403 dj->lfn = LfnBuf;1401 dj->lfn = fs->LfnBuf; 1404 1402 #endif 1405 1403 res = follow_path(dj, dir, path); /* Follow the path to the directory */ -
uKadecot/trunk/pfatfs/pff.h
r108 r154 24 24 #include "integer.h" 25 25 #include "pffconf.h" 26 #include "diskio.h" 26 27 27 28 #if _PFATFS != _PFFCONF … … 39 40 40 41 typedef struct { 42 DSTATUS (* disk_get_status)(void); 43 DRESULT (* disk_readp)(BYTE* buff, DWORD sector, UINT offset, UINT count); 44 DRESULT (* disk_writep)(const BYTE* buff, DWORD sc); 41 45 BYTE fs_type; /* FAT sub type */ 42 46 BYTE flag; /* File status flags */ … … 53 57 CLUST curr_clust; /* File current cluster */ 54 58 DWORD dsect; /* File current data sector */ 59 #if _USE_LFN 60 WCHAR LfnBuf[_MAX_LFN + 1]; 61 #endif 55 62 } FATFS; 56 63 -
uKadecot/trunk/pfatfs/pffconf.h
r108 r154 14 14 #define _USE_LSEEK 1 /* Enable pf_lseek() function */ 15 15 #define _USE_WRITE 1 /* Enable pf_write() function */ 16 #define _USE_IOCTL 1 /* Enable pf_ioctl() function */ 16 17 17 18 #define _FS_FAT12 1 /* Enable FAT12 */
Note:
See TracChangeset
for help on using the changeset viewer.