Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2421 → Rev 2422

/I2C_Telemetry/trunk/fat16.c
2163,39 → 2163,44
unsigned char fdelete_(signed char* filepath)
{
unsigned char retvalue = 0;
File_t file;
File_t *file;
 
file = LockFilePointer();
 
if(file == NULL) return 0;
 
if(filepath == NULL) return(0);
// correct filepath formatting
Slashing_Path(filepath);
file.FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file.
file.FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment.
file.FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file
file.SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster.
file.ByteOfCurrSector = 0; // The byte location within the current sector.
file.Mode = 0; // Mode of fileoperation (read,write)
file.Size = 0; // The size of the opend file in bytes.
file.Position = 0; // Pointer to a character within the file 0 < fileposition < filesize
file.DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made.
file.DirectoryIndex = 0; // The index to the directoryentry within the specified sector.
file.Attribute = 0; // The attribute of the file opened.
file.SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache.
file.State = FSTATE_USED; // mark it as used
file->FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file.
file->FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment.
file->FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file
file->SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster.
file->ByteOfCurrSector = 0; // The byte location within the current sector.
file->Mode = 0; // Mode of fileoperation (read,write)
file->Size = 0; // The size of the opend file in bytes.
file->Position = 0; // Pointer to a character within the file 0 < fileposition < filesize
file->DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made.
file->DirectoryIndex = 0; // The index to the directoryentry within the specified sector.
file->Attribute = 0; // The attribute of the file opened.
file->SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache.
file->State = FSTATE_USED; // mark it as used
 
// if file is existent
if(FileExist(filepath, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file))
if(FileExist(filepath, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file))
{
// and is not marked as readonly?
if((file.Attribute & ATTR_READONLY) != ATTR_READONLY)
if((file->Attribute & ATTR_READONLY) != ATTR_READONLY)
{
// try to delete the file content from the filesystem
if(DeleteClusterChain(file.FirstSectorOfFirstCluster))
if(DeleteClusterChain(file->FirstSectorOfFirstCluster))
{
// and try delete the directory entry of the file
retvalue = DeleteDirectoryEntry(&file);
retvalue = DeleteDirectoryEntry(file);
}
}
}
UnlockFilePointer(file);
return(retvalue);
}
 
2299,20 → 2304,24
unsigned char writepointer = 0;
unsigned char retvalue = 0;
DirEntry_t *DirectoryEntry;
File_t file;
File_t *file;
 
SD_Result_t res=0;
 
file.FirstSectorOfCurrCluster = findelement->fp.FirstSectorOfCurrCluster;
file.SectorOfCurrCluster = findelement->fp.SectorOfCurrCluster;
file = LockFilePointer();
if(file == NULL) return(retvalue);
 
file->FirstSectorOfCurrCluster = findelement->fp.FirstSectorOfCurrCluster;
file->SectorOfCurrCluster = findelement->fp.SectorOfCurrCluster;
index = findelement->fp.DirectoryIndex;
 
// within the root directory area we can read sectors sequentially until the end of this area
if((Partition.FirstRootDirSector <= file.FirstSectorOfCurrCluster) && (file.FirstSectorOfCurrCluster < Partition.FirstDataSector))
if((Partition.FirstRootDirSector <= file->FirstSectorOfCurrCluster) && (file->FirstSectorOfCurrCluster < Partition.FirstDataSector))
{
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR;
}
// within the data clusters we can read sectors sequentially only within the cluster
else if((Partition.FirstDataSector <= file.FirstSectorOfCurrCluster) && (file.FirstSectorOfCurrCluster <= Partition.LastDataSector))
else if((Partition.FirstDataSector <= file->FirstSectorOfCurrCluster) && (file->FirstSectorOfCurrCluster <= Partition.LastDataSector))
{
max_dir_sector = Partition.SectorsPerCluster; // limit max secters before next cluster
}
2319,7 → 2328,7
 
do
{ // search the next 16 rootentries in this sector of the roordirectory.
res = SDC_GetSector(((unsigned long) file.FirstSectorOfCurrCluster + (unsigned long)file.SectorOfCurrCluster), file.Cache); // Read the Rootdirectory.
res = SDC_GetSector(((unsigned long) file->FirstSectorOfCurrCluster + (unsigned long)file->SectorOfCurrCluster), file->Cache); // Read the Rootdirectory.
if(res != SD_SUCCESS)
{
Fat16_Deinit();
2326,7 → 2335,7
return(0);
}
 
DirectoryEntry = (DirEntry_t *)file.Cache;
DirectoryEntry = (DirEntry_t *)file->Cache;
 
while((!retvalue)&&(index < 16))
{
2368,9 → 2377,9
}
findelement->fp.FirstSectorOfFirstCluster = (unsigned long) DirectoryEntry[index].StartCluster;
findelement->fp.DirectoryIndex = index;
findelement->fp.FirstSectorOfCurrCluster = file.FirstSectorOfCurrCluster;
findelement->fp.DirectorySector = (file.FirstSectorOfCurrCluster + file.SectorOfCurrCluster);
findelement->fp.SectorOfCurrCluster = file.SectorOfCurrCluster;
findelement->fp.FirstSectorOfCurrCluster = file->FirstSectorOfCurrCluster;
findelement->fp.DirectorySector = (file->FirstSectorOfCurrCluster + file->SectorOfCurrCluster);
findelement->fp.SectorOfCurrCluster = file->SectorOfCurrCluster;
findelement->fp.Size = DirectoryEntry[index].Size;
findelement->fp.Attribute = DirectoryEntry[index].Attribute;
retvalue = 1;
2384,11 → 2393,11
/* in the next sector we start looking for the specified entry beginning at index 0 */
index = 0;
/* there are still sectors to be read within the cluster or within the linear addresspace of the rootdirectory */
if(file.SectorOfCurrCluster < max_dir_sector-1) file.SectorOfCurrCluster++;
if(file->SectorOfCurrCluster < max_dir_sector-1) file->SectorOfCurrCluster++;
/* if we are looking for an directoryentry outside the rootdirectory and have reached the end of the cluster we have to get the next one */
else if(Partition.FirstDataSector <= file.FirstSectorOfCurrCluster)
else if(Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)
{
end_of_directory_not_reached = GetNextCluster(&file);
end_of_directory_not_reached = GetNextCluster(file);
}
// within the rootdirectory we abort searching for elements after the maximun number of possible rootentries has beensearched
else
2399,6 → 2408,8
}
while((end_of_directory_not_reached) && (!retvalue) );
 
UnlockFilePointer(file);
 
return(retvalue);
}
 
2734,29 → 2745,33
unsigned char mkdir_(signed char* dirpath)
{
unsigned char retvalue = 0;
File_t file;
File_t *file;
 
file = LockFilePointer();
if(file == NULL) return(0);
 
if(dirpath == NULL) return(0);
// correct filepath formatting
Slashing_Path(dirpath);
file.FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file.
file.FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment.
file.FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file
file.SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster.
file.ByteOfCurrSector = 0; // The byte location within the current sector.
file.Mode = 0; // Mode of fileoperation (read,write)
file.Size = 0; // The size of the opend file in bytes.
file.Position = 0; // Pointer to a character within the file 0 < fileposition < filesize
file.DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made.
file.DirectoryIndex = 0; // The index to the directoryentry within the specified sector.
file.Attribute = 0; // The attribute of the file opened.
file.SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache.
file.State = FSTATE_USED; // mark it as used
file->FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file.
file->FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment.
file->FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file
file->SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster.
file->ByteOfCurrSector = 0; // The byte location within the current sector.
file->Mode = 0; // Mode of fileoperation (read,write)
file->Size = 0; // The size of the opend file in bytes.
file->Position = 0; // Pointer to a character within the file 0 < fileposition < filesize
file->DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made.
file->DirectoryIndex = 0; // The index to the directoryentry within the specified sector.
file->Attribute = 0; // The attribute of the file opened.
file->SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache.
file->State = FSTATE_USED; // mark it as used
// if directory is not existent
if(!FileExist(dirpath, ATTR_SUBDIRECTORY, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file))
if(!FileExist(dirpath, ATTR_SUBDIRECTORY, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file))
{
retvalue = FileCreate(dirpath, ATTR_SUBDIRECTORY, &file);
retvalue = FileCreate(dirpath, ATTR_SUBDIRECTORY, file);
}
UnlockFilePointer(file);
return(retvalue);
}
 
/I2C_Telemetry/trunk/fat16.h
8,7 → 8,7
//
//________________________________________________________________________________________________________________________________________
 
#define FILE_MAX_OPEN 4 // The number of files that can accessed simultaneously.
#define FILE_MAX_OPEN 2 // The number of files that can accessed simultaneously.
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
/I2C_Telemetry/trunk/main.c
117,12 → 117,13
 
void TestFileWrite(void)
{
signed char name[] = "abcdee.txt";
signed char x[] = "/abcdee.txt\0";
File_t* f = 0;
 
 
printf("\r\nStart writing file: % s",name);
printf("\r\n%s",x);
 
/*
f = fopen_(name, 'w');
if(f!= NULL)
{
138,7 → 139,7
else
{
printf("failed");
}
}*/
}