Changeset 154 for uKadecot/trunk/pfatfs/pff.c
- Timestamp:
- Feb 2, 2016, 9:54:35 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 */
Note:
See TracChangeset
for help on using the changeset viewer.