Rev 211 | Rev 219 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 211 | Rev 218 | ||
---|---|---|---|
Line 487... | Line 487... | ||
487 | /* Returnvalue: The sector number with the data area of the given cluster */ |
487 | /* Returnvalue: The sector number with the data area of the given cluster */ |
488 | /****************************************************************************************************************************************/ |
488 | /****************************************************************************************************************************************/ |
489 | u32 Fat16ClusterToSector(u16 cluster) |
489 | u32 Fat16ClusterToSector(u16 cluster) |
490 | { |
490 | { |
491 | if(!Partition.IsValid) return SECTOR_UNDEFINED; |
491 | if(!Partition.IsValid) return SECTOR_UNDEFINED; |
492 | if (cluster < 2) |
492 | if ((cluster < 2) || (cluster == CLUSTER_UNDEFINED)) |
493 | { |
493 | { |
494 | return SECTOR_UNDEFINED; |
494 | return SECTOR_UNDEFINED; |
495 | } |
495 | } |
496 | else |
496 | else |
497 | { |
497 | { |
Line 1202... | Line 1202... | ||
1202 | { |
1202 | { |
1203 | Fat16_Deinit(); |
1203 | Fat16_Deinit(); |
1204 | return(retvalue); |
1204 | return(retvalue); |
1205 | } |
1205 | } |
1206 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1206 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1207 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1207 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1208 | { |
1208 | { |
1209 | case SLOT_EMPTY: |
1209 | case SLOT_EMPTY: |
1210 | case SLOT_DELETED: |
1210 | case SLOT_DELETED: |
1211 | return (retvalue); |
1211 | return (retvalue); |
1212 | break; |
1212 | break; |
Line 1219... | Line 1219... | ||
1219 | } |
1219 | } |
1220 | dircluster = dir[file->DirectoryIndex].StartCluster; |
1220 | dircluster = dir[file->DirectoryIndex].StartCluster; |
1221 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dircluster); |
1221 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dircluster); |
1222 | } |
1222 | } |
Line -... | Line 1223... | ||
- | 1223 | ||
- | 1224 | // if the new direntry is a subdirectory |
|
- | 1225 | if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) |
|
- | 1226 | { // get a free clutser for its content |
|
- | 1227 | subdircluster = FindNextFreeCluster(file); // get the next free cluster on the disk and mark it as used. |
|
- | 1228 | } |
|
- | 1229 | else // a normal file |
|
- | 1230 | { // has no data cluster after creation |
|
- | 1231 | subdircluster = CLUSTER_UNDEFINED; |
|
- | 1232 | } |
|
1223 | 1233 | ||
1224 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
1234 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
1225 | file->SectorOfCurrCluster = 0; |
1235 | file->SectorOfCurrCluster = 0; |
1226 | do // loop over all clusters of current directory |
1236 | do // loop over all clusters of current directory |
1227 | { |
1237 | { |
Line 1251... | Line 1261... | ||
1251 | dir[dir_entry].LastAccessDate = dir[dir_entry].CreationDate; |
1261 | dir[dir_entry].LastAccessDate = dir[dir_entry].CreationDate; |
1252 | dir[dir_entry].Res2[0] = 0; |
1262 | dir[dir_entry].Res2[0] = 0; |
1253 | dir[dir_entry].Res2[1] = 0; |
1263 | dir[dir_entry].Res2[1] = 0; |
1254 | dir[dir_entry].ModTime = dir[dir_entry].CreationTime; |
1264 | dir[dir_entry].ModTime = dir[dir_entry].CreationTime; |
1255 | dir[dir_entry].ModDate = dir[dir_entry].CreationDate; |
1265 | dir[dir_entry].ModDate = dir[dir_entry].CreationDate; |
1256 | // if the new direntry is a subdirectory |
- | |
1257 | if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) |
- | |
1258 | { // get a free clutser for its content |
- | |
1259 | subdircluster = FindNextFreeCluster(file); // get the next free cluster on the disk and mark it as used. |
- | |
1260 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(subdircluster); // Calculate absolute sectorposition of first datacluster. |
- | |
1261 | } |
- | |
1262 | else // normal file |
- | |
1263 | { // has no data cluster after creation |
- | |
1264 | subdircluster = CLUSTER_UNDEFINED; |
- | |
1265 | file->FirstSectorOfFirstCluster = SECTOR_UNDEFINED; |
- | |
1266 | } |
- | |
1267 | // Set the attribute of the new directoryentry. |
1266 | // Set the attribute of the new directoryentry. |
1268 | dir[dir_entry].StartCluster = subdircluster; // copy the location of the first datacluster to the directoryentry. |
1267 | dir[dir_entry].StartCluster = subdircluster; // copy the location of the first datacluster to the directoryentry. |
1269 | dir[dir_entry].Size = 0; // the new createted file has no content yet. |
1268 | dir[dir_entry].Size = 0; // the new createted file has no content yet. |
1270 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // write back to card |
1269 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // write back to card |
1271 | { |
1270 | { |
1272 | Fat16_Deinit(); |
1271 | Fat16_Deinit(); |
1273 | return(retvalue); |
1272 | return(retvalue); |
1274 | } |
1273 | } |
- | 1274 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(subdircluster); // Calculate absolute sectorposition of first datacluster. |
|
1275 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; // Start reading the file with the first sector of the first datacluster. |
1275 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; // Start reading the file with the first sector of the first datacluster. |
1276 | file->SectorOfCurrCluster = 0; // reset sector of cureen cluster |
1276 | file->SectorOfCurrCluster = 0; // reset sector of cureen cluster |
1277 | file->ByteOfCurrSector = 0; // reset the byte location within the current sector |
1277 | file->ByteOfCurrSector = 0; // reset the byte location within the current sector |
1278 | file->Attribute = attrib; // set file attribute to dir attribute |
1278 | file->Attribute = attrib; // set file attribute to dir attribute |
1279 | file->Size = 0; // new file has no size |
1279 | file->Size = 0; // new file has no size |
Line 1564... | Line 1564... | ||
1564 | fclose_(file); |
1564 | fclose_(file); |
1565 | file = NULL; |
1565 | file = NULL; |
1566 | } |
1566 | } |
1567 | break; |
1567 | break; |
1568 | case 'r': // else opened for 'r' |
1568 | case 'r': // else opened for 'r' |
1569 | default: // of unsupported mode |
1569 | default: // if unsupported mode |
1570 | fclose_(file); |
1570 | fclose_(file); |
1571 | file = NULL; |
1571 | file = NULL; |
1572 | break; |
1572 | break; |
1573 | } |
1573 | } |
1574 | return(file); |
1574 | return(file); |
Line 2027... | Line 2027... | ||
2027 | for(i = 0; i<11;i++) Partition.VolumeLabel[i] = dir[dir_entry].Name[i]; |
2027 | for(i = 0; i<11;i++) Partition.VolumeLabel[i] = dir[dir_entry].Name[i]; |
2028 | Partition.VolumeLabel[11] = '\0'; // terminate string |
2028 | Partition.VolumeLabel[11] = '\0'; // terminate string |
2029 | file->Attribute = dir[dir_entry].Attribute; // store attribute of found dir entry |
2029 | file->Attribute = dir[dir_entry].Attribute; // store attribute of found dir entry |
2030 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dir[dir_entry].StartCluster); // set sector of first data cluster |
2030 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dir[dir_entry].StartCluster); // set sector of first data cluster |
2031 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
2031 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
2032 | file->SectorOfCurrCluster = 0; |
2032 | file->SectorOfCurrCluster = 0 file->ByteOfCurrSector = 0; |
2033 | file->ByteOfCurrSector = 0; |
- | |
2034 | file->DirectorySector = curr_sector; // current sector |
2033 | file->DirectorySector = curr_sector; // current sector |
2035 | file->DirectoryIndex = dir_entry; // current direntry in current sector |
2034 | file->DirectoryIndex = dir_entry; // current direntry in current sector |
2036 | file->Size = dir[dir_entry].Size; |
2035 | file->Size = dir[dir_entry].Size; |
2037 | dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
2036 | dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
2038 | pVolumeLabel = Partition.VolumeLabel; |
2037 | pVolumeLabel = Partition.VolumeLabel; |