76,9 → 76,9 |
// extern signed int Fat16_Deinit(void); |
// extern signed char* FAT16_GetVolumeLabel(void); |
// |
// extern File_t * fopen_(const unsigned char *filename, const signed char mode); |
// extern File_t * fopen_( unsigned char *filename, signed char mode); |
// extern signed int fclose_(File_t *file); |
// extern unsigned char fexist_(signed char * const filename); |
// extern unsigned char fexist_(signed char * filename); |
// extern signed int fflush_(File_t *file); |
// extern signed int fseek_(File_t *file, signed long offset, signed int origin); |
// extern signed int fgetc_(File_t *file); |
85,16 → 85,16 |
// extern signed int fputc_(unsigned char c, File_t *file); |
// extern unsigned long fread_(void *buffer, unsigned long size, unsigned long count, File_t *file); |
// extern unsigned long fwrite_(void *buffer, unsigned long size, unsigned long count, File_t *file); |
// extern signed int fputs_(const unsigned char *string, File_t *File); |
// extern signed int fputs_( unsigned char *string, File_t *File); |
// extern unsigned char * fgets_(unsigned char *string, signed int length, File_t *file); |
// extern unsigned char feof_(File_t * const file); |
// extern unsigned char fdelete_(signed char* const filepath); |
// extern unsigned char feof_(File_t * file); |
// extern unsigned char fdelete_(signed char* filepath); |
// |
// extern signed char *getcwd_(void); |
// extern unsigned char chdir_(signed char* const dirpath); |
// extern unsigned char mkdir_(signed char* const dirpath); |
// extern unsigned char rmdir_(signed char* const dirpath); |
// extern unsigned char findfirst_(const signed char* name, unsigned char attribmask, Find_t *); |
// extern unsigned char chdir_(signed char* dirpath); |
// extern unsigned char mkdir_(signed char* dirpath); |
// extern unsigned char rmdir_(signed char* dirpath); |
// extern unsigned char findfirst_( signed char* name, unsigned char attribmask, Find_t *); |
// extern unsigned char findnext_(Find_t *); |
//........................................................................................................................................ |
// ext. functions: extern SD_Result_t SDC_Init(void;) |
482,7 → 482,7 |
} |
|
/****************************************************************************************************************************************/ |
/* Function: signed char* SeperateFormatedDirName(const signed char*, signed char*); */ |
/* Function: signed char* SeperateFormatedDirName( signed char*, signed char*); */ |
/* */ |
/* Description: This function seperates the first dirname from filepath and brings them */ |
/* into the needed format ('test.txt' -> 'TEST TXT') */ |
490,7 → 490,7 |
/* */ |
/* Returnvalue: Return NULL on error or pointer to subpath */ |
/****************************************************************************************************************************************/ |
signed char* SeperateFormatedDirName(const signed char *filepath, signed char *dirname) |
signed char* SeperateFormatedDirName( signed char *filepath, signed char *dirname) |
{ |
signed char* subpath = NULL; |
unsigned char readpointer = 0; |
903,7 → 903,7 |
unsigned int cluster; |
unsigned long fat_byte_offset, sector, byte; |
Fat16Entry_t * fat; |
unsigned char buffer[BYTES_PER_SECTOR]; |
static unsigned char buffer[BYTES_PER_SECTOR]; |
unsigned long sector_in_buffer = 0; |
unsigned char repeat = 0; |
|
947,7 → 947,7 |
// if new sector is not the sector in buffer or the last cluster in the chain was traced |
if((sector != sector_in_buffer) || !repeat) |
{ // write sector in buffer |
if(SD_SUCCESS != SDC_PutSector(sector_in_buffer,buffer)) |
if(SD_SUCCESS != SDC_PutSector(sector_in_buffer, buffer)) |
{ |
Fat16_Deinit(); |
return(0); |
1082,13 → 1082,13 |
|
// no search area defined? |
if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
{ |
{ |
return(direntry_exist); |
} |
//is search area the root? |
else if(Partition.FirstRootDirSector == file->FirstSectorOfFirstCluster) |
{ |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
file->DirectorySector = SECTOR_UNDEFINED; // if we have to search within the root, there is no corresponding directory entry available |
} |
// is search area within the data cluster range? |
1099,7 → 1099,7 |
//there must be a corresponding directory entry |
if(file->DirectorySector == SECTOR_UNDEFINED) |
{ |
return (direntry_exist); |
return (direntry_exist); |
} |
else // check directory entry |
{ |
1107,7 → 1107,7 |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
{ |
Fat16_Deinit(); |
return (direntry_exist); |
return (direntry_exist); |
} |
dir = (DirEntry_t *)file->Cache; // set pointer to directory |
switch((unsigned char )dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1128,13 → 1128,13 |
// check that search area matches directory entry |
if(file->FirstSectorOfFirstCluster != Fat16ClusterToSector(dir[file->DirectoryIndex].StartCluster)) |
{ |
return (direntry_exist); |
return (direntry_exist); |
} |
|
|
} */ |
} |
else return (direntry_exist); // bad sector range for search area |
|
|
// update current file data area position to start of first cluster |
file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
file->SectorOfCurrCluster = 0; |
1197,7 → 1197,7 |
|
|
/****************************************************************************************************************************************/ |
/* Function: CreateDirectoryEntry(signed char *, unsigned int, File_t *) */ |
/* Function: CreateDirectoryEntry(signed char *, unsigned int, File_t *) */ |
/* */ |
/* Description: This function looks for the next free position in the directory and creates an entry. */ |
/* The type of an directory entry is specified by the file attribute. */ |
1221,13 → 1221,13 |
|
// no creation area defined? |
if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
{ |
{ |
return(retvalue); |
} |
//is creation area the root? |
else if(Partition.FirstRootDirSector == file->FirstSectorOfFirstCluster) |
{ |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
file->DirectorySector = SECTOR_UNDEFINED; // if we have to search within the root, there is no corresponding directory entry available |
} |
// is creation area within the data cluster range? |
1237,7 → 1237,7 |
// there must be a corresponding directory entry |
if(file->DirectorySector == SECTOR_UNDEFINED) |
{ |
return (retvalue); |
return (retvalue); |
} |
else // check directory entry |
{ |
1245,7 → 1245,7 |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache)) // read in the sector. |
{ |
Fat16_Deinit(); |
return (retvalue); |
return (retvalue); |
} |
dir = (DirEntry_t *)file->Cache; // set pointer to directory |
switch((unsigned char )dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1266,7 → 1266,7 |
// check that search area matches directory entry |
if(file->FirstSectorOfFirstCluster != Fat16ClusterToSector(dir[file->DirectoryIndex].StartCluster)) |
{ |
return (retvalue); |
return (retvalue); |
} |
} |
} |
1398,7 → 1398,7 |
// valid directory sector? |
if((Partition.FirstRootDirSector <= file->DirectorySector) && (file->DirectorySector < Partition.LastDataSector)) |
{ |
// try to read the sector containing the directory entry of the file to be deleted |
// try to read the sector containing the directory entry of the file to be deleted |
if(SD_SUCCESS != SDC_GetSector((unsigned long) file->DirectorySector,file->Cache)) return(retval); |
// get access to the elements of the directoryentry |
DirectoryEntry = (DirEntry_t *)file->Cache; |
1406,7 → 1406,7 |
DirectoryEntry[file->DirectoryIndex].Name[0] = SLOT_DELETED; |
DirectoryEntry[file->DirectoryIndex].Attribute = 0; |
DirectoryEntry[file->DirectoryIndex].Size = 0; |
// the file has been deleted from the directory, save the modified sector back to the filesystem |
// the file has been deleted from the directory, save the modified sector back to the filesystem |
if(SD_SUCCESS == SDC_PutSector((unsigned long) file->DirectorySector,file->Cache)) retval = 1; |
} |
return(retval); |
1413,7 → 1413,7 |
} |
|
/********************************************************************************************************************************************/ |
/* Function: FileExist(const signed char* filename, unsigned char attribfilter, unsigned char attribmask, File_t *file); */ |
/* Function: FileExist( signed char* filename, unsigned char attribfilter, unsigned char attribmask, File_t *file); */ |
/* */ |
/* Description: This function looks for the specified file including its subdirectories. */ |
/* If the file is found the Filepointer properties are updated. */ |
1420,7 → 1420,7 |
/* */ |
/* Returnvalue: 1 if file is found else 0. */ |
/********************************************************************************************************************************************/ |
unsigned char FileExist(const signed char* filename, const unsigned char attribfilter, const unsigned char attribmask, File_t *file) |
unsigned char FileExist( signed char* filename, unsigned char attribfilter, unsigned char attribmask, File_t *file) |
{ |
signed char* path = 0; |
signed char* subpath = 0; |
1435,7 → 1435,7 |
file->DirectoryIndex = 0; // start search at first dir entry of cluster |
if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
{ |
file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
} |
else // if a path begins not with a '/' the search starts relative to the CWD |
{ |
1481,7 → 1481,7 |
|
|
/********************************************************************************************************************************************/ |
/* Function: FileCreate(const signed char* filename, unsigned char attrib, File_t *file); */ |
/* Function: FileCreate( signed char* filename, unsigned char attrib, File_t *file); */ |
/* */ |
/* Description: This function looks for the specified file including its subdirectories beginning */ |
/* in the rootdirectory of the partition. If the file is found the Filepointer properties are */ |
1489,7 → 1489,7 |
/* */ |
/* Returnvalue: 1 if file was created else 0. */ |
/********************************************************************************************************************************************/ |
unsigned char FileCreate(const signed char* filename, const unsigned char attrib, File_t *file) |
unsigned char FileCreate( signed char* filename, unsigned char attrib, File_t *file) |
{ |
signed char *path = 0; |
signed char *subpath = 0; |
1506,7 → 1506,7 |
|
if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
{ |
file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
} |
else // if a path begins not with a '/' the search starts relative to the CWD |
{ |
1518,6 → 1518,7 |
while((*path != 0) && !file_created) |
{ // separate dirname and subpath from filepath string |
subpath = SeperateFormatedDirName(path, dirname); |
|
if(subpath != NULL) |
{ |
if(*subpath == 0) |
1580,7 → 1581,7 |
/* */ |
/* Returnvalue: The filepointer to the file or 0 if faild. */ |
/********************************************************************************************************************************************/ |
File_t * fopen_(signed char* const filename, const signed char mode) |
File_t * fopen_(signed char* filename, signed char mode) |
{ |
File_t *file = 0; |
signed char *cptr; |
1596,8 → 1597,11 |
file->Mode = mode; // mode of fileoperation (read,write) |
file->Attribute = 0; // the attribute of the file opened. |
|
printf("\r\nFilename: %s", filename); |
// bring the path into the correct syntax |
Slashing_Path(filename); |
printf("\r\nFilename: %s", filename); |
|
cptr = filename; |
|
// check if a real file (no directory) to the given filename exist |
1866,7 → 1870,7 |
} |
|
/********************************************************************************************************************************************/ |
/* Function: fputc_( const signed char c, File *file); */ |
/* Function: fputc_( signed char c, File *file); */ |
/* */ |
/* Description: This function writes a byte to the specified file and takes care of writing the necessary FAT- Entries. */ |
/* next sector of the cluster is read. If the last sector of the cluster read the next cluster will be searched in FAT. */ |
1873,7 → 1877,7 |
/* */ |
/* Returnvalue: The function returns the character written to the stream or EOF on error. */ |
/********************************************************************************************************************************************/ |
signed int fputc_(const signed char c, File_t *file) |
signed int fputc_( signed char c, File_t *file) |
{ |
unsigned long curr_sector = 0; |
|
2032,13 → 2036,13 |
|
|
/****************************************************************************************************************************************/ |
/* Function: fputs_(const signed char *string, File_t *File); */ |
/* Function: fputs_( signed char *string, File_t *File); */ |
/* */ |
/* Description: This function writes a string to the specified file. */ |
/* */ |
/* Returnvalue: The function returns a no negative value or EOF on error. */ |
/****************************************************************************************************************************************/ |
signed int fputs_(signed char * const string, File_t * const file) |
signed int fputs_(signed char * string, File_t * file) |
{ |
unsigned char i=0; |
signed int c = 0; |
2060,7 → 2064,7 |
/* */ |
/* Returnvalue: A pointer to the string read from the file or 0 on error. */ |
/****************************************************************************************************************************************/ |
signed char * fgets_(signed char * const string, signed int const length, File_t * const file) |
signed char * fgets_(signed char * string, signed int length, File_t * file) |
{ |
signed char *pbuff; |
signed int c = 0, bytecount; |
2111,13 → 2115,13 |
|
|
/****************************************************************************************************************************************/ |
/* Function: fexist_(const unsigned char *); */ |
/* Function: fexist_( unsigned char *); */ |
/* */ |
/* Description: This function checks if a file already exist. */ |
/* */ |
/* Returnvalue: 1 if the file exist else 0. */ |
/****************************************************************************************************************************************/ |
unsigned char fexist_(signed char * const filename) |
unsigned char fexist_(signed char * filename) |
{ |
unsigned char exist = 0; |
File_t *file = 0; |
2156,7 → 2160,7 |
/* Returnvalue: 1 : specified file deleted succesfully 0: specified file not found */ |
/********************************************************************************************************************************************/ |
|
unsigned char fdelete_(signed char* const filepath) |
unsigned char fdelete_(signed char* filepath) |
{ |
unsigned char retvalue = 0; |
File_t file; |
2177,7 → 2181,7 |
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)) |
{ |
2189,7 → 2193,7 |
{ |
// and try delete the directory entry of the file |
retvalue = DeleteDirectoryEntry(&file); |
} |
} |
} |
} |
return(retvalue); |
2438,7 → 2442,7 |
/* */ |
/* Returnvalue: (1) if Element was found. (0) if no valid element was found */ |
/********************************************************************************************************************************************/ |
unsigned char findfirst_(const signed char* name, unsigned char attribmask, Find_t *findelement) |
unsigned char findfirst_( signed char* name, unsigned char attribmask, Find_t *findelement) |
{ |
unsigned char itemfound = 0; |
unsigned char index = 0; |
2518,7 → 2522,7 |
|
|
/********************************************************************************************************************************************/ |
/* Function: unsigned char chdir_(signed char* const path); */ |
/* Function: unsigned char chdir_(signed char* path); */ |
/* */ |
/* Description: This function changes the current working directory to the directory specified by the filepath */ |
/* by function findfirst() */ |
2526,7 → 2530,7 |
/* Returnvalue: */ |
/********************************************************************************************************************************************/ |
|
unsigned char chdir_(signed char* const path) |
unsigned char chdir_(signed char* path) |
{ |
unsigned char retvalue = 0; // the value returned by this function |
unsigned long ultemp = 0; // temp. variable |
2553,13 → 2557,13 |
do |
{ |
dirpath = GetSubDirectory(dirpath, dirname); // get the name of the subdirectory we are looking for and the remainig path |
if(dirname[0] == 0) // if no directory name is available |
if(dirname[0] == 0) // if no directory name is available |
{ |
retvalue = 1; // we are done |
break; // break the loop |
} |
} |
// search for the next subdirectory within the path |
if(findfirst_(dirname, ATTR_SUBDIRECTORY, &fe)) |
if(findfirst_(dirname, ATTR_SUBDIRECTORY, &fe)) |
{ |
// we try to change into the directory "..". Now we have to delete the last direntry from the path |
if(strcmp(dirname, "..") == 0) CWDPath_Pop(); |
2572,7 → 2576,7 |
// do we have to change into the rootdirectory? |
if(ultemp) |
{ |
// the first 2 entries are reserved for '.' and '..' |
// 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 |
ultemp *= Partition.SectorsPerCluster; |
2581,7 → 2585,7 |
// the cwd now points to the specified directory |
Partition.CurrentWorkingDirectory = ultemp; |
} |
else // (=0) root directory |
else // (=0) root directory |
{ |
// the cwd now points to the rootdirectory |
Partition.CurrentWorkingDirectory = Partition.FirstRootDirSector; |
2596,7 → 2600,7 |
} |
while(dirpath != NULL); // do this until all subdirectories have been found |
|
// if we could not change to the specified directory we restore the actual path |
// if we could not change to the specified directory we restore the actual path |
if(!retvalue) |
{ |
Partition.CurrentWorkingDirectory = tcwd; |
2615,7 → 2619,7 |
/* Returnvalue: 1 : specified directory deleted succesfully 0: specified directory not found */ |
/********************************************************************************************************************************************/ |
|
unsigned char rmdir_(signed char* const dirpath) |
unsigned char rmdir_(signed char* dirpath) |
{ |
unsigned char retvalue = 0; |
Find_t fe; |
2727,7 → 2731,7 |
/* Returnvalue: 1 : specified directory created succesfully 0: specified dir exist already */ |
/********************************************************************************************************************************************/ |
|
unsigned char mkdir_(signed char* const dirpath) |
unsigned char mkdir_(signed char* dirpath) |
{ |
unsigned char retvalue = 0; |
File_t file; |