904,7 → 904,6 |
return(retvalue); |
} |
|
|
/****************************************************************************************************************************************/ |
/* Function: u16 DeleteClusterChain(File *file); */ |
/* */ |
980,7 → 979,6 |
/* */ |
/* Returnvalue: The function returns the appened cluster number or CLUSTER_UNDEFINED of no cluster was appended. */ |
/****************************************************************************************************************************************/ |
|
u16 AppendCluster(File_t *file) |
{ |
u16 last_cluster, new_cluster = CLUSTER_UNDEFINED; |
987,13 → 985,25 |
u32 fat_byte_offset, sector, byte; |
Fat16Entry_t * fat; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(new_cluster); |
|
new_cluster = FindNextFreeCluster(file); // the next free cluster found on the disk. |
if(new_cluster != CLUSTER_UNDEFINED) |
{ // A free cluster was found and can be added to the end of the file. |
// is there at least one cluster appended to the file? |
if(file->FirstSectorOfLastCluster == CLUSTER_UNDEFINED) |
{ |
fseek_(file, 0, SEEK_END); // jump to the end of the file |
// remember the first sector of the last cluster |
file->FirstSectorOfLastCluster = file->FirstSectorOfCurrCluster; |
last_cluster = SectorToFat16Cluster(file->FirstSectorOfCurrCluster); // determine current file cluster |
} |
else |
{ |
last_cluster = SectorToFat16Cluster(file->FirstSectorOfLastCluster); // determine current file cluster |
} |
|
if(last_cluster != CLUSTER_UNDEFINED) |
{ |
// update FAT entry of last cluster |
1017,6 → 1027,8 |
Fat16_Deinit(); |
return(0); |
} |
// now the new cluster appended to the fat is the last cluster |
file->FirstSectorOfLastCluster = Fat16ClusterToSector(new_cluster); |
} |
else // last cluster of the file is undefined |
{ // then the new cluster must be the first one of the file |
1045,6 → 1057,7 |
} |
// update file info |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(new_cluster); |
file->FirstSectorOfLastCluster = file->FirstSectorOfFirstCluster; |
file->Size = 0; |
file->Position = 0; |
} |