Rev 385 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 385 | Rev 387 | ||
---|---|---|---|
Line 902... | Line 902... | ||
902 | retvalue = 0; |
902 | retvalue = 0; |
903 | } |
903 | } |
904 | return(retvalue); |
904 | return(retvalue); |
905 | } |
905 | } |
Line 906... | Line -... | ||
906 | - | ||
907 | 906 | ||
908 | /****************************************************************************************************************************************/ |
907 | /****************************************************************************************************************************************/ |
909 | /* Function: u16 DeleteClusterChain(File *file); */ |
908 | /* Function: u16 DeleteClusterChain(File *file); */ |
910 | /* */ |
909 | /* */ |
911 | /* Description: This function trances along a cluster chain in the fat and frees all clusters visited. */ |
910 | /* Description: This function trances along a cluster chain in the fat and frees all clusters visited. */ |
Line 978... | Line 977... | ||
978 | /* */ |
977 | /* */ |
979 | /* Description: This function looks in the fat to find the next free cluster and appends it to the file. */ |
978 | /* Description: This function looks in the fat to find the next free cluster and appends it to the file. */ |
980 | /* */ |
979 | /* */ |
981 | /* Returnvalue: The function returns the appened cluster number or CLUSTER_UNDEFINED of no cluster was appended. */ |
980 | /* Returnvalue: The function returns the appened cluster number or CLUSTER_UNDEFINED of no cluster was appended. */ |
982 | /****************************************************************************************************************************************/ |
981 | /****************************************************************************************************************************************/ |
983 | - | ||
984 | u16 AppendCluster(File_t *file) |
982 | u16 AppendCluster(File_t *file) |
985 | { |
983 | { |
986 | u16 last_cluster, new_cluster = CLUSTER_UNDEFINED; |
984 | u16 last_cluster, new_cluster = CLUSTER_UNDEFINED; |
987 | u32 fat_byte_offset, sector, byte; |
985 | u32 fat_byte_offset, sector, byte; |
988 | Fat16Entry_t * fat; |
986 | Fat16Entry_t * fat; |
Line -... | Line 987... | ||
- | 987 | ||
989 | 988 | ||
Line 990... | Line 989... | ||
990 | if((!Partition.IsValid) || (file == NULL)) return(new_cluster); |
989 | if((!Partition.IsValid) || (file == NULL)) return(new_cluster); |
991 | 990 | ||
992 | new_cluster = FindNextFreeCluster(file); // the next free cluster found on the disk. |
991 | new_cluster = FindNextFreeCluster(file); // the next free cluster found on the disk. |
- | 992 | if(new_cluster != CLUSTER_UNDEFINED) |
|
- | 993 | { // A free cluster was found and can be added to the end of the file. |
|
- | 994 | // is there at least one cluster appended to the file? |
|
993 | if(new_cluster != CLUSTER_UNDEFINED) |
995 | if(file->FirstSectorOfLastCluster == CLUSTER_UNDEFINED) |
- | 996 | { |
|
- | 997 | fseek_(file, 0, SEEK_END); // jump to the end of the file |
|
994 | { // A free cluster was found and can be added to the end of the file. |
998 | // remember the first sector of the last cluster |
- | 999 | file->FirstSectorOfLastCluster = file->FirstSectorOfCurrCluster; |
|
- | 1000 | last_cluster = SectorToFat16Cluster(file->FirstSectorOfCurrCluster); // determine current file cluster |
|
- | 1001 | } |
|
- | 1002 | else |
|
- | 1003 | { |
|
- | 1004 | last_cluster = SectorToFat16Cluster(file->FirstSectorOfLastCluster); // determine current file cluster |
|
995 | fseek_(file, 0, SEEK_END); // jump to the end of the file |
1005 | } |
996 | last_cluster = SectorToFat16Cluster(file->FirstSectorOfCurrCluster); // determine current file cluster |
1006 | |
997 | if(last_cluster != CLUSTER_UNDEFINED) |
1007 | if(last_cluster != CLUSTER_UNDEFINED) |
998 | { |
1008 | { |
999 | // update FAT entry of last cluster |
1009 | // update FAT entry of last cluster |
Line 1015... | Line 1025... | ||
1015 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // save the modified sector to the FAT. |
1025 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // save the modified sector to the FAT. |
1016 | { |
1026 | { |
1017 | Fat16_Deinit(); |
1027 | Fat16_Deinit(); |
1018 | return(0); |
1028 | return(0); |
1019 | } |
1029 | } |
- | 1030 | // now the new cluster appended to the fat is the last cluster |
|
- | 1031 | file->FirstSectorOfLastCluster = Fat16ClusterToSector(new_cluster); |
|
1020 | } |
1032 | } |
1021 | else // last cluster of the file is undefined |
1033 | else // last cluster of the file is undefined |
1022 | { // then the new cluster must be the first one of the file |
1034 | { // then the new cluster must be the first one of the file |
1023 | // and its cluster number must be set in the direntry |
1035 | // and its cluster number must be set in the direntry |
1024 | DirEntry_t * dir; |
1036 | DirEntry_t * dir; |
Line 1043... | Line 1055... | ||
1043 | Fat16_Deinit(); |
1055 | Fat16_Deinit(); |
1044 | return(CLUSTER_UNDEFINED); |
1056 | return(CLUSTER_UNDEFINED); |
1045 | } |
1057 | } |
1046 | // update file info |
1058 | // update file info |
1047 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(new_cluster); |
1059 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(new_cluster); |
- | 1060 | file->FirstSectorOfLastCluster = file->FirstSectorOfFirstCluster; |
|
1048 | file->Size = 0; |
1061 | file->Size = 0; |
1049 | file->Position = 0; |
1062 | file->Position = 0; |
1050 | } |
1063 | } |
1051 | // update file pointes |
1064 | // update file pointes |
1052 | file->FirstSectorOfCurrCluster = Fat16ClusterToSector(new_cluster); |
1065 | file->FirstSectorOfCurrCluster = Fat16ClusterToSector(new_cluster); |