62,7 → 62,6 |
#include "uart1.h" |
#include "main.h" |
#include "logging.h" |
#include "debug.h" |
|
|
//________________________________________________________________________________________________________________________________________ |
587,7 → 586,6 |
return(returnvalue); |
} |
|
|
/****************************************************************************************************************************************/ |
/* Function: Fat16_Init(void); */ |
/* */ |
906,6 → 904,7 |
return(retvalue); |
} |
|
|
/****************************************************************************************************************************************/ |
/* Function: u16 DeleteClusterChain(File *file); */ |
/* */ |
981,6 → 980,7 |
/* */ |
/* 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,25 → 987,13 |
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 |
1029,8 → 1017,6 |
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 |
1059,7 → 1045,6 |
} |
// update file info |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(new_cluster); |
file->FirstSectorOfLastCluster = file->FirstSectorOfFirstCluster; |
file->Size = 0; |
file->Position = 0; |
} |
2150,7 → 2135,6 |
u8 retvalue = 0; |
DirEntry_t *DirectoryEntry; |
File_t file; |
SD_Result_t res=0; |
|
file.FirstSectorOfCurrCluster = findelement->fp.FirstSectorOfCurrCluster; |
file.SectorOfCurrCluster = findelement->fp.SectorOfCurrCluster; |
2169,8 → 2153,7 |
|
do |
{ // search the next 16 rootentries in this sector of the roordirectory. |
res = SDC_GetSector(((u32) file.FirstSectorOfCurrCluster + (u32)file.SectorOfCurrCluster), file.Cache); // Read the Rootdirectory. |
if(res != SD_SUCCESS) |
if(SD_SUCCESS != SDC_GetSector(((u32) file.FirstSectorOfCurrCluster + (u32)file.SectorOfCurrCluster), file.Cache)); // Read the Rootdirectory. |
{ |
Fat16_Deinit(); |
return(0); |
2478,6 → 2461,16 |
/* */ |
/* Returnvalue: */ |
/********************************************************************************************************************************************/ |
/* |
#define ATTR_NONE 0x00 // normal file |
#define ATTR_READONLY 0x01 // file is readonly |
#define ATTR_HIDDEN 0x02 // file is hidden |
#define ATTR_SYSTEM 0x04 // file is a system file |
#define ATTR_VOLUMELABEL 0x08 // entry is a volume label |
#define ATTR_LONG_FILENAME 0x0F // this is a long filename entry |
#define ATTR_SUBDIRECTORY 0x10 // entry is a directory name |
#define ATTR_ARCHIVE 0x20 // file is new or modified |
*/ |
|
u8 chdir_(s8 *path) |
{ |
2499,7 → 2492,6 |
if(*cptr == '\\') *cptr = '/'; |
cptr++; |
} |
// Debug("1"); |
/* lets remember the actual path */ |
strcpy(tp, Partition.PathToCwd); |
cwdt = Partition.CurrentWorkingDirectory; |
2513,7 → 2505,6 |
/* if there is no other pathinformation we only switch to the rootdirectory. So theres nothing left todo.*/ |
if(!dircount) return(1); |
} |
// Debug("2"); |
/* now we parse through all the subdirectories within the path */ |
do |
{ |
2532,9 → 2523,6 |
else AppendDirToPath(cache); |
/* The startcluster within an directoryentry specifies the position within the fat where the file or directory starts */ |
ultemp = (u32) fe.fp.FirstSectorOfFirstCluster; |
/* do we have to change into the rootdirectory? */ |
if(ultemp) |
{ |
/* the first 2 entries are reserved for '.' and '..' */ |
ultemp -= 2; |
/* now we have to transform the position within the fat into the corrosponding sectoraddress relative to the beginning of the datasection of the active partition*/ |
2546,17 → 2534,9 |
/* we found the folder specified by the foldername */ |
retvalue = 1; |
} |
else |
{ |
/* the cwd now points to the rootdirectory */ |
Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector; |
/* changed into the rootdirectory succesfully */ |
retvalue = 1; |
} |
} |
} |
while(dircount && retvalue ); /* do this until all subdirectories have been found or a subdirectory is missing */ |
// Debug("3"); |
/* do this until all subdirectories have been found or a subdirectory is missing */ |
while(dircount && retvalue ); |
|
/* if we could not change to the specified directory we restore the actual path */ |
if(!retvalue) |
2566,72 → 2546,3 |
} |
return(retvalue); |
} |
|
|
|
/********************************************************************************************************************************************/ |
/* Function: void DeleteDirectoryEntry(Find *item) */ |
/* Description: This function deletes the directoryentry of the file to be deleted from the filesystem */ |
/* */ |
/* */ |
/* Returnvalue: none */ |
/********************************************************************************************************************************************/ |
|
void DeleteDirectoryEntry(Find_t *fe) |
{ |
DirEntry_t *DirectoryEntry = NULL; |
|
/* read the sector containint the directoryentry of the file to be deleted */ |
SDC_GetSector((u32) fe->fp.DirectorySector,fe->fp.Cache); |
/* get access to the elements of the directoryentry */ |
DirectoryEntry = (DirEntry_t *)fe->fp.Cache; |
/* delete the directoryentry */ |
DirectoryEntry[fe->fp.DirectoryIndex].Attribute = 0; |
DirectoryEntry[fe->fp.DirectoryIndex].Name[0] = 0xE5; |
DirectoryEntry[fe->fp.DirectoryIndex].Size = 0; |
/* the file has been deleted from the directory, save the modified sector back to the filesystem */ |
SDC_PutSector((u32) fe->fp.DirectorySector,fe->fp.Cache); |
} |
|
|
|
/********************************************************************************************************************************************/ |
/* Function: fdelete_(s8* filename); */ |
/* */ |
/* Description: This function deletes the file with the specified filename from the filesystem */ |
/* */ |
/* */ |
/* Returnvalue: 1 : specified file deleted succesfully 0: specified file not found */ |
/********************************************************************************************************************************************/ |
|
u8 fdelete_(s8 *fname) |
{ |
u8 retvalue = 0; |
Find_t fe; |
|
/* search for the specified item */ |
retvalue = (u8) findfirst_(fname, 0xff, &fe); |
/* if the item was found */ |
if(retvalue) |
{ |
/* is the file marked as readonly? */ |
if(0)//(fe.fp.Attribute & ATTR_READONLY) == ATTR_READONLY) |
{ |
return(0); |
} |
/* file is not marked as readonly */ |
else |
{ |
/* delete the file from the filesystem */ |
DeleteClusterChain(fe.fp.FirstSectorOfFirstCluster); |
/* delete the directoryentry of the file */ |
DeleteDirectoryEntry(&fe); |
} |
} |
|
return(retvalue); |
} |
|
|
|
|