7,14 → 7,14 |
// + FOR NON COMMERCIAL USE ONLY |
// + www.MikroKopter.com |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
// + Verkauf von Luftbildaufnahmen, usw. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
25,21 → 25,21 |
// + Benutzung auf eigene Gefahr |
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + mit unserer Zustimmung zulässig |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + this list of conditions and the following disclaimer. |
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
// + from this software without specific prior written permission. |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
// + for non-commercial use (directly or indirectly) |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + with our written permission |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
// |
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
52,7 → 52,7 |
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// + POSSIBILITY OF SUCH DAMAGE. |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include <stdio.h> |
#include "91x_lib.h" |
63,16 → 63,16 |
|
|
//________________________________________________________________________________________________________________________________________ |
// Module name: fat16.c |
// Module name: fat16.c |
// Compiler used: avr-gcc 3.4.5 |
// Last Modifikation: 16.06.2008 |
// Version: 2.00 |
// Authors: Stephan Busker & Gregor Stobrawa |
// Authors: Stephan Busker & Gregor Stobrawa |
// Description: Source files for FAT16 implementation with read and write-access |
// Copyright (C) 2008 Stephan Busker & Gregor Stobrawa |
//........................................................................................................................................ |
// Functions: extern s16 Fat16_Init(void); |
// extern s16 Fat16_Deinit(void); |
// extern s16 Fat16_Deinit(void); |
// extern File_t * fopen_(const u8 *filename, const s8 mode); |
// extern s16 fclose_(File_t *File); |
// extern s16 fflush_(File_t *File); |
79,7 → 79,7 |
// extern s16 fseek_(File_t *File, s32 offset, s16 origin); |
// extern s16 fgetc_(File_t *File); |
// extern s16 fputc_(u8 c, File_t *File); |
// extern u32 fread_(void *buffer, u32 size, u32 count, File_t *File); |
// extern u32 fread_(void *buffer, u32 size, u32 count, File_t *File); |
// extern u32 fwrite_(void *buffer, u32 size, u32 count, File_t *File); |
// extern s16 fputs_(const u8 *string, File_t *File); |
// extern u8 * fgets_(u8 *string, s16 length, File_t *File); |
86,7 → 86,7 |
//........................................................................................................................................ |
// ext. functions: extern SD_Result_t SDC_Init(void;) |
// extern SD_Result_t SDC_Deinit(void); |
// extern SD_Result_t SDC_GetSector (u32,u8 *); |
// extern SD_Result_t SDC_GetSector (u32,u8 *); |
// extern SD_Result_t SDC_PutSector (u32,u8 *); |
//........................................................................................................................................ |
// |
106,8 → 106,8 |
|
/* |
________________________________________________________________________________________________________________________________________ |
|
Structure of an partition entry |
|
Structure of an partition entry |
________________________________________________________________________________________________________________________________________ |
|
Partition Entry is 16 bytes long |
122,13 → 122,13 |
u16 EndCylSec; // End of Partition - Cylinder/Sector |
u32 NoSectorsBeforePartition; // Number of Sectors between the MBR and the First Sector in the Partition |
u32 NoSectorsPartition ; // Number of Sectors in the Partition |
} __attribute__((packed)) PartitionEntry_t; |
} __attribute__((packed)) PartitionEntry_t; |
|
/* |
Coding of Cylinder/Sector words |
|
Cylinder is 10 bits: [7:0] at [15:8] and [9:8] at [7:6] |
Sector is 5 bits: [5:0] at [5:0] |
Sector is 5 bits: [5:0] at [5:0] |
*/ |
|
// Partition Types: |
162,8 → 162,8 |
|
/* |
________________________________________________________________________________________________________________________________________ |
|
Structure of the MasterBootRecord |
|
Structure of the MasterBootRecord |
________________________________________________________________________________________________________________________________________ |
|
Master Boot Record is 512 bytes long |
172,19 → 172,19 |
*/ |
typedef struct |
{ |
u8 ExecutableCode[446]; // 446 bytes for machine start code |
PartitionEntry_t PartitionEntry1; // 16 bytes for partition entry 1 |
PartitionEntry_t PartitionEntry2; // 16 bytes for partition entry 2 |
PartitionEntry_t PartitionEntry3; // 16 bytes for partition entry 3 |
PartitionEntry_t PartitionEntry4; // 16 bytes for partition entry 4 |
u16 ExecutableMarker; // BIOS-Signature (0x55 0xAA) |
} __attribute__((packed)) MBR_Entry_t; |
u8 ExecutableCode[446]; // 446 bytes for machine start code |
PartitionEntry_t PartitionEntry1; // 16 bytes for partition entry 1 |
PartitionEntry_t PartitionEntry2; // 16 bytes for partition entry 2 |
PartitionEntry_t PartitionEntry3; // 16 bytes for partition entry 3 |
PartitionEntry_t PartitionEntry4; // 16 bytes for partition entry 4 |
u16 ExecutableMarker; // BIOS-Signature (0x55 0xAA) |
} __attribute__((packed)) MBR_Entry_t; |
|
|
/* |
________________________________________________________________________________________________________________________________________ |
|
Structure of the VolumeBootRecord |
|
Structure of the VolumeBootRecord |
________________________________________________________________________________________________________________________________________ |
|
The Volume Boot Record is 512 bytes long |
193,12 → 193,12 |
typedef struct |
{ |
u8 JumpCode[3]; // Jump Code + NOP |
s8 OEMName[8]; // OEM Name |
s8 OEMName[8]; // OEM Name |
u16 BytesPerSector; // Bytes Per Sector |
u8 SectorsPerCluster; // Sectors Per Cluster |
u16 ReservedSectors; // Reserved Sectors |
u8 NoFATCopies; // Number of Copies of FAT |
u16 MaxRootEntries; // Maximum Root Directory Entries |
u16 MaxRootEntries; // Maximum Root Directory Entries |
u16 NoSectorsInPartSml32MB; // Number of Sectors in Partition Smaller than 32 MB |
u8 MediaDescriptor; // Media Descriptor (0xF8 for Hard Disks) |
u16 SectorsPerFAT; // Sectors Per FAT |
211,9 → 211,9 |
u32 SerialNo; // Serial Number of the Partition |
s8 VolumeName[11]; // Volume Name of the Partititon |
s8 FATName[8]; // FAT Name (FAT16) |
u8 ExecutableCode[446]; // 446 bytes for machine start code |
u16 ExecutableMarker; // Executable Marker (0x55 0xAA) |
} __attribute__((packed)) VBR_Entry_t; |
u8 ExecutableCode[446]; // 446 bytes for machine start code |
u16 ExecutableMarker; // Executable Marker (0x55 0xAA) |
} __attribute__((packed)) VBR_Entry_t; |
|
|
|
220,7 → 220,7 |
/* |
________________________________________________________________________________________________________________________________________ |
|
Structure of an directory entry |
Structure of an directory entry |
________________________________________________________________________________________________________________________________________ |
|
Directory entry is 32 bytes. |
252,8 → 252,8 |
|
/* |
________________________________________________________________________________________________________________________________________ |
|
Structure of an entry within the fileallocationtable. |
|
Structure of an entry within the fileallocationtable. |
________________________________________________________________________________________________________________________________________ |
*/ |
typedef struct |
272,7 → 272,7 |
#define FAT16_CLUSTER_LAST_MIN 0xFFF8 |
#define FAT16_CLUSTER_LAST_MAX 0xFFFF |
|
/*****************************************************************************************************************************************/ |
/*****************************************************************************************************************************************/ |
/* */ |
/* Global variables needed for read- or write-acces to the FAT16- filesystem. */ |
/* */ |
284,7 → 284,7 |
#define FAT16_BYTES 2 |
#define FAT16_ENTRIES_PER_SECTOR BYTES_PER_SECTOR/FAT16_BYTES |
|
#define FSTATE_UNUSED 0 |
#define FSTATE_UNUSED 0 |
#define FSTATE_USED 1 |
|
typedef struct |
341,9 → 341,9 |
File_t * File = 0; |
for(i = 0; i < FILE_MAX_OPEN; i++) |
{ |
if(FilePointer[i].State == FSTATE_UNUSED) // found an unused one |
if(FilePointer[i].State == FSTATE_UNUSED) // found an unused one |
{ |
File = &FilePointer[i]; // set pointer to that entry |
File = &FilePointer[i]; // set pointer to that entry |
FilePointer[i].State = FSTATE_USED; // mark it as used |
break; |
} |
366,8 → 366,8 |
{ |
if(&FilePointer[cnt] == file) // filepointer to be freed found? |
{ |
file->State = FSTATE_UNUSED; |
file->FirstSectorOfFirstCluster = 0; // Sectorpointer to the first sector of the first datacluster of the file. |
file->State = FSTATE_UNUSED; |
file->FirstSectorOfFirstCluster = 0; // Sectorpointer to the first sector of the first datacluster of the file. |
file->FirstSectorOfCurrCluster = 0; |
file->SectorOfCurrCluster = 0; // Pointer to the cluster which is edited at the moment. |
file->SectorOfCurrCluster = 0; // The sector which is edited at the moment (cluster_pointer + sector_index). |
379,7 → 379,7 |
file->DirectorySector = 0; // 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 = NULL; |
file = NULL; |
return(1); |
} |
} |
401,14 → 401,14 |
u8 readpointer = 0; |
u8 writepointer = 0; |
|
// search subpath from beginning of filepath |
// search subpath from beginning of filepath |
subpath = NULL; |
readpointer = 0; |
if(filepath[0] == '/') readpointer = 1; // ignore first '/' |
while(subpath == NULL) // search the filepath until a subpath was found. |
while(subpath == NULL) // search the filepath until a subpath was found. |
{ |
if(((filepath[readpointer] == 0) || (filepath[readpointer] == '/'))) // if '/' found or end of filepath reached |
{ |
if(((filepath[readpointer] == 0) || (filepath[readpointer] == '/'))) // if '/' found or end of filepath reached |
{ |
subpath = (s8*)&filepath[readpointer]; // store the position of the first "/" found after the beginning of the filenpath |
} |
readpointer++; |
431,7 → 431,7 |
readpointer++; // next character in filename |
writepointer = 8; // jump to start of extension |
} |
else return(NULL); // dirbasename to long |
else return(NULL); // dirbasename to long |
} |
else |
{ |
442,12 → 442,12 |
else |
{ |
dirname[writepointer] = filepath[readpointer]; |
} |
} |
readpointer++; |
writepointer++; |
} |
} |
return(subpath); |
return(subpath); |
} |
|
|
462,7 → 462,7 |
u32 Fat16ClusterToSector(u16 cluster) |
{ |
if(!Partition.IsValid) return 0; |
if (cluster < 2) cluster = 2; // the 0. and 1. cluster in the fat are used for the media descriptor |
if (cluster < 2) cluster = 2; // the 0. and 1. cluster in the fat are used for the media descriptor |
return ( (cluster - 2) * Partition.SectorsPerCluster) + Partition.FirstDataSector; // the first data sector is represented by the 2nd cluster |
} |
|
499,7 → 499,7 |
{ |
returnvalue += fclose_(&FilePointer[cnt]); // try to close open file pointers |
} |
|
|
} |
SDC_Deinit(); // uninitialize interface to sd-card |
Partition.IsValid = 0; // mark data in partition structure as invalid |
515,10 → 515,10 |
/* Returnvalue: The function returns "0" if the filesystem is initialized. */ |
/****************************************************************************************************************************************/ |
u8 Fat16_Init(void) |
{ |
{ |
u8 cnt = 0; |
u32 partitionfirstsector; |
VBR_Entry_t *VBR; |
VBR_Entry_t *VBR; |
MBR_Entry_t *MBR; |
File_t *file; |
u8 result = 0; |
529,17 → 529,17 |
// declare the filepointers as unused. |
for(cnt = 0; cnt < FILE_MAX_OPEN; cnt++) |
{ |
FilePointer[cnt].State = FSTATE_UNUSED; |
FilePointer[cnt].State = FSTATE_UNUSED; |
} |
// set current file pinter to first position in list |
file = &FilePointer[0]; |
|
file = &FilePointer[0]; |
|
// try to initialise the sd-card. |
if(SD_SUCCESS != SDC_Init()) |
{ |
if(SD_SUCCESS != SDC_Init()) |
{ |
SerialPutString("SD-Card could not be initialized."); |
result = 1; |
goto end; |
goto end; |
} |
|
// SD-Card is initialized successfully |
547,10 → 547,10 |
{ |
SerialPutString("Error reading the MBR."); |
result = 2; |
goto end; |
goto end; |
} |
MBR = (MBR_Entry_t *)file->Cache; // Enter the MBR using the structure MBR_Entry_t. |
if((MBR->PartitionEntry1.Type == PART_TYPE_FAT16_ST_32_MB) || |
if((MBR->PartitionEntry1.Type == PART_TYPE_FAT16_ST_32_MB) || |
(MBR->PartitionEntry1.Type == PART_TYPE_FAT16_LT_32_MB) || |
(MBR->PartitionEntry1.Type == PART_TYPE_FAT16LBA)) |
{ |
561,20 → 561,20 |
{ |
SerialPutString("Error reading the VBR."); |
result = 3; |
goto end; |
} |
goto end; |
} |
} |
else // maybe the medium has no partition assuming sector 0 is the vbr |
{ |
partitionfirstsector = 0; |
} |
|
|
VBR = (VBR_Entry_t *) file->Cache; // Enter the VBR using the structure VBR_Entry_t. |
if(VBR->BytesPerSector != BYTES_PER_SECTOR) |
{ |
SerialPutString("VBR: Sector size not supported."); |
result = 4; |
goto end; |
goto end; |
} |
Partition.SectorsPerCluster = VBR->SectorsPerCluster; // Number of sectors per cluster. Depends on the memorysize of the sd-card. |
Partition.FatCopies = VBR->NoFATCopies; // Number of fatcopies. |
582,14 → 582,14 |
Partition.SectorsPerFat = VBR->SectorsPerFAT; // The number of sectors per FAT. |
|
/* Calculate the sectorpositon of the FAT, the Rootdirectory and the first Datacluster. */ |
// Calculate the position of the FileAllocationTable: |
// Calculate the position of the FileAllocationTable: |
// Start + # of Reserved Sectors |
Partition.FirstFatSector = (u32)(partitionfirstsector + (u32)(VBR->ReservedSectors)); |
// Calculate the position of the Rootdirectory: |
// Start + # of Reserved Sectors + (# of Sectors Per FAT * # of FAT Copies) |
Partition.FirstFatSector = (u32)(partitionfirstsector + (u32)(VBR->ReservedSectors)); |
// Calculate the position of the Rootdirectory: |
// Start + # of Reserved Sectors + (# of Sectors Per FAT * # of FAT Copies) |
Partition.FirstRootDirSector = Partition.FirstFatSector + (u32)((u32)Partition.SectorsPerFat*(u32)Partition.FatCopies); |
// Calculate the position of the first datacluster: |
// Start + # of Reserved + (# of Sectors Per FAT * # of FAT Copies) + ((Maximum Root Directory Entries * 32) / Bytes per Sector) |
// Start + # of Reserved + (# of Sectors Per FAT * # of FAT Copies) + ((Maximum Root Directory Entries * 32) / Bytes per Sector) |
Partition.FirstDataSector = Partition.FirstRootDirSector + (u32)(Partition.MaxRootEntries>>4); // assuming 512 Byte Per Sector |
// Calculate the last data sector |
if(VBR->NoSectors == 0) |
596,7 → 596,7 |
{ |
SerialPutString("VBR: Bad number of sectors."); |
result = 5; |
goto end; |
goto end; |
} |
Partition.LastDataSector = Partition.FirstDataSector + VBR->NoSectors - 1; |
// check for FAT16 in VBR of first partition |
611,7 → 611,7 |
end: |
if(result != 0) Fat16_Deinit(); |
else SerialPutString("ok"); |
return(result); |
return(result); |
} |
|
|
627,7 → 627,7 |
{ |
u8 retvalue = 1; |
u32 i; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(0); |
|
for(i = 0; i < BYTES_PER_SECTOR; i++) file->Cache[i] = 0; // clear file cache |
636,11 → 636,11 |
file->SectorInCache = file->FirstSectorOfCurrCluster + i; |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) |
{ |
Fat16_Deinit(); |
Fat16_Deinit(); |
retvalue = 0; |
} |
} |
return(retvalue); |
return(retvalue); |
} |
|
/*****************************************************************************************************************************************/ |
655,7 → 655,7 |
u16 cluster = 0; |
u32 fat_byte_offset, sector, byte; |
Fat16Entry_t * fat; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(cluster); |
// if sector is within the data area |
if((Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)&& (file->FirstSectorOfCurrCluster <= Partition.LastDataSector)) |
676,12 → 676,12 |
{ |
Fat16_Deinit(); |
return (cluster); |
} |
} |
} |
} |
// read the next cluster from cache |
fat = (Fat16Entry_t *)(&(file->Cache[byte])); |
cluster = fat->NextCluster; |
// if last cluster fat entry |
// if last cluster fat entry |
if(FAT16_CLUSTER_LAST_MIN <= cluster) |
{ |
cluster = 0; |
692,7 → 692,7 |
file->SectorOfCurrCluster = 0; |
file->ByteOfCurrSector = 0; |
} |
} |
} |
return(cluster); |
} |
|
711,12 → 711,12 |
u16 fat_entry; // index to an fatentry within the actual sector (256 fatentries are possible within one sector). |
u16 free_cluster = 0; // next free cluster number. |
Fat16Entry_t * fat; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(0); |
|
// start searching for an empty cluster at the beginning of the fat. |
fat_sector = 0; |
do |
fat_sector = 0; |
do |
{ |
curr_sector = Partition.FirstFatSector + fat_sector; // calculate sector to read |
file->SectorInCache = curr_sector; // upate the sector number of file cache. |
728,22 → 728,22 |
|
fat = (Fat16Entry_t *)file->Cache; // set fat pointer to file cache |
|
for(fat_entry = 0; fat_entry < FAT16_ENTRIES_PER_SECTOR; fat_entry++) // look for an free cluster at all entries in this sector of the fat. |
for(fat_entry = 0; fat_entry < FAT16_ENTRIES_PER_SECTOR; fat_entry++) // look for an free cluster at all entries in this sector of the fat. |
{ |
if(fat[fat_entry].NextCluster == FAT16_CLUSTER_FREE) // empty cluster found!! |
{ |
fat[fat_entry].NextCluster = FAT16_CLUSTER_LAST_MAX; // mark this fat-entry as used |
{ |
fat[fat_entry].NextCluster = FAT16_CLUSTER_LAST_MAX; // mark this fat-entry as used |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // and save the sector at the sd-card. |
{ |
Fat16_Deinit(); |
return(free_cluster); |
} |
free_cluster = (u16)(fat_sector * FAT16_ENTRIES_PER_SECTOR + (u32)fat_entry); |
free_cluster = (u16)(fat_sector * FAT16_ENTRIES_PER_SECTOR + (u32)fat_entry); |
fat_entry = FAT16_ENTRIES_PER_SECTOR; // terminate the search for a free cluster in this sector. |
} |
} |
fat_sector++; // continue the search in next fat sector |
// repeat until the end of the fat is reached and no free cluster has been found so far |
// repeat until the end of the fat is reached and no free cluster has been found so far |
}while((fat_sector < Partition.SectorsPerFat) && (!free_cluster)); |
return(free_cluster); |
} |
760,12 → 760,12 |
{ |
s32 fposition = 0; |
s16 retvalue = 1; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(0); |
switch(origin) |
{ |
case SEEK_SET: // Fileposition relative to the beginning of the file. |
fposition = 0; |
fposition = 0; |
break; |
case SEEK_END: // Fileposition relative to the end of the file. |
fposition = (s32)file->Size; |
789,8 → 789,8 |
while(file->Position < fposition) // repeat until the current position is less than target |
{ |
file->Position++; // increment file position |
file->ByteOfCurrSector++; // next byte in current sector |
if(file->ByteOfCurrSector >= BYTES_PER_SECTOR) |
file->ByteOfCurrSector++; // next byte in current sector |
if(file->ByteOfCurrSector >= BYTES_PER_SECTOR) |
{ |
file->ByteOfCurrSector = 0; // reading at the beginning of new sector. |
file->SectorOfCurrCluster++; // continue reading in next sector |
798,7 → 798,7 |
{ |
if(GetNextCluster(file)) // Sets the clusterpointer of the file to the next datacluster. |
{ |
file->SectorOfCurrCluster = 0; |
file->SectorOfCurrCluster = 0; |
} |
else // the last cluster was allready reached |
{ |
806,10 → 806,10 |
file->ByteOfCurrSector = BYTES_PER_SECTOR; // set ByteOfCurrSector one byte over sector end |
} |
} |
} |
} |
} |
} |
} |
if(file->Position == fposition) retvalue = 0; |
if(file->Position == fposition) retvalue = 0; |
return(retvalue); |
} |
|
822,7 → 822,7 |
/****************************************************************************************************************************************/ |
u8 DeleteClusterChain(u16 StartCluster) |
{ |
u16 cluster; |
u16 cluster; |
u32 fat_byte_offset, sector, byte; |
Fat16Entry_t * fat; |
u8 buffer[BYTES_PER_SECTOR]; |
838,7 → 838,7 |
sector = Partition.FirstFatSector + ( fat_byte_offset / BYTES_PER_SECTOR); |
// calculate byte offset of the current cluster within that fat sector |
byte = fat_byte_offset % BYTES_PER_SECTOR; |
do |
do |
{ |
if(sector != sector_in_buffer) |
{ |
845,7 → 845,7 |
// read this sector to buffer |
sector_in_buffer = sector; |
if(SD_SUCCESS != SDC_GetSector(sector_in_buffer, buffer)) return 0; // read sector from sd-card |
} |
} |
// read the next cluster from cache |
fat = (Fat16Entry_t *)(&(buffer[byte])); |
cluster = fat->NextCluster; |
862,7 → 862,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)) return 0; |
if(SD_SUCCESS != SDC_PutSector(sector_in_buffer,buffer)) return 0; |
} |
} |
while(repeat); |
880,17 → 880,17 |
/****************************************************************************************************************************************/ |
u16 AppendCluster(File_t *file) |
{ |
u16 last_cluster, new_cluster = 0; |
u16 last_cluster, new_cluster = 0; |
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) |
{ // A free cluster was found and can be added to the end of the file. |
{ // A free cluster was found and can be added to the end of the file. |
fseek_(file, 0, SEEK_END); // jump to the end of the file |
last_cluster = SectorToFat16Cluster(file->FirstSectorOfCurrCluster); // determine current file cluster |
last_cluster = SectorToFat16Cluster(file->FirstSectorOfCurrCluster); // determine current file cluster |
fat_byte_offset = ((u32)last_cluster)<<1; |
sector = Partition.FirstFatSector + ( fat_byte_offset / BYTES_PER_SECTOR); |
byte = fat_byte_offset % BYTES_PER_SECTOR; |
902,8 → 902,8 |
{ |
Fat16_Deinit(); |
return(0); |
} |
} |
} |
} |
fat = (Fat16Entry_t *)(&(file->Cache[byte])); |
fat->NextCluster = new_cluster; // append the free cluster to the end of the file in the FAT. |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // save the modified sector to the FAT. |
936,12 → 936,12 |
DirEntry_t * dir; |
|
// if incomming pointers are useless return immediatly |
if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return(direntry_exist); |
if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return(direntry_exist); |
|
// dir entries can be searched only in filesclusters that have |
// a corresponding dir entry with adir-flag set in its attribute |
// dir entries can be searched only in filesclusters that have |
// a corresponding dir entry with adir-flag set in its attribute |
// or direct within the root directory area |
|
|
file->FirstSectorOfFirstCluster = 0; |
// no current directory exist therefore assume searching in the root |
if(file->DirectorySector == 0) |
954,7 → 954,7 |
{ |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
} |
// within the data clusters we can read sectors sequentially only within the cluster |
// within the data clusters we can read sectors sequentially only within the cluster |
else if((Partition.FirstDataSector <= file->DirectorySector) && (file->DirectorySector <= Partition.LastDataSector)) |
{ |
max_dir_sector = Partition.SectorsPerCluster; // limit max secters before next cluster |
979,7 → 979,7 |
// therefore no file or subdirectory can be created |
return (direntry_exist); |
break; |
default: // and is a real directory |
default: // and is a real directory |
if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
{ // current file is not a directory therefore no file or subdirectory can be created here |
return (direntry_exist); |
990,21 → 990,21 |
} |
|
// update current file data area position to start of first cluster |
file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
file->SectorOfCurrCluster = 0; |
file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
file->SectorOfCurrCluster = 0; |
file->ByteOfCurrSector = 0; |
|
do // loop over all data clusters of the current directory entry |
{ |
{ |
dir_sector = 0; // reset sector counter within a new cluster |
do // loop over all sectors of a cluster or all sectors of the root directory |
{ |
{ |
curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
file->SectorInCache = curr_sector; // upate the sector number of file cache. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read the sector |
{ |
Fat16_Deinit(); |
return(direntry_exist); |
return(direntry_exist); |
} |
dir = (DirEntry_t *)file->Cache; // set pointer to directory |
// search all directory entries within that sector |
1025,15 → 1025,15 |
if (i < 10) break; // names does not match |
// if dirname and attribute have matched |
file->Attribute = dir[dir_entry].Attribute; // store attribute of found dir entry |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dir[dir_entry].StartCluster); // set sector of first data cluster |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dir[dir_entry].StartCluster); // set sector of first data cluster |
file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
file->SectorOfCurrCluster = 0; |
file->ByteOfCurrSector = 0; |
file->DirectorySector = curr_sector; // current sector |
file->DirectoryIndex = dir_entry; // current direntry in current sector |
file->Size = dir[dir_entry].Size; |
direntry_exist = 1; // mark as found |
dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
file->Size = dir[dir_entry].Size; |
direntry_exist = 1; // mark as found |
dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
} // end of first byte of name check |
} |
dir_sector++; // search next sector |
1041,7 → 1041,7 |
}while((dir_sector < max_dir_sector) && (!direntry_exist)); |
|
// if we are seaching in the data area and the file not found in this cluster so take next cluster. |
if(!direntry_exist && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
if(!direntry_exist && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
{ |
end_of_directory_not_reached = GetNextCluster(file); // updates File->FirstSectorOfCurrCluster |
} |
1065,15 → 1065,15 |
u16 subdircluster, dircluster = 0; |
u16 end_of_directory_not_reached = 0; |
u8 i = 0; |
u8 retvalue = 0; |
u8 retvalue = 0; |
DirEntry_t *dir; |
|
if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return (retvalue); |
// It is not checked here that the dir entry that should be created is already existent! |
|
// Dir entries can be created only in file-clusters that have |
|
// Dir entries can be created only in file-clusters that have |
// the dir-flag set in its attribute or within the root directory |
|
|
file->FirstSectorOfFirstCluster = 0; |
// no current directory exist therefore assume creating in the root |
if(file->DirectorySector == 0) |
1087,22 → 1087,22 |
{ |
max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
} |
// within the data clusters we can read sectors sequentially only within the cluster |
// within the data clusters we can read sectors sequentially only within the cluster |
else if((Partition.FirstDataSector <= file->DirectorySector) && (file->DirectorySector <= Partition.LastDataSector)) |
{ |
max_dir_sector = Partition.SectorsPerCluster; |
} |
else return (retvalue); // bad sector range for directory sector of the file |
else return (retvalue); // bad sector range for directory sector of the file |
// if search area is not defined yet |
if(file->FirstSectorOfFirstCluster == 0) |
{ |
// check if the directory entry of current file is existent and has the dir-flag set |
file->SectorInCache = file->DirectorySector; // update the sector number of file cache. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
{ |
Fat16_Deinit(); |
return(retvalue); |
} |
} |
dir = (DirEntry_t *)file->Cache; // set pointer to directory |
switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
{ |
1110,7 → 1110,7 |
case SLOT_DELETED: |
return (retvalue); |
break; |
default: // and is a real directory |
default: // and is a real directory |
if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
{ // current file is not a directory therefore no file or subdirectory can be created here |
return (retvalue); |
1118,9 → 1118,9 |
break; |
} |
dircluster = dir[file->DirectoryIndex].StartCluster; |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dircluster); |
file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dircluster); |
} |
|
|
subdircluster = FindNextFreeCluster(file); // get the next free cluster on the disk and mark it as used. |
if(subdircluster) |
{ |
1127,23 → 1127,23 |
file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
file->SectorOfCurrCluster = 0; |
do // loop over all clusters of current directory |
{ |
{ |
dir_sector = 0; // reset sector counter within a new cluster |
do // loop over all sectors of a cluster or all sectors of the root directory |
{ |
curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
file->SectorInCache = curr_sector; // upate the sector number of file cache. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
{ |
Fat16_Deinit(); |
return(retvalue); |
} |
} |
dir = (DirEntry_t *)file->Cache; // set pointer to directory |
// search all directory entries of a sector |
for(dir_entry = 0; dir_entry < DIRENTRIES_PER_SECTOR; dir_entry++) |
{ // check if current direntry is available |
if(((u8)dir[dir_entry].Name[0] == SLOT_EMPTY) || ((u8)dir[dir_entry].Name[0] == SLOT_DELETED)) |
{ // a free direntry was found |
{ // a free direntry was found |
for(i = 0; i < 11; i++) dir[dir_entry].Name[i] = dirname[i]; // Set dir name |
dir[dir_entry].Attribute = attrib; // Set the attribute of the new directoryentry. |
dir[dir_entry].StartCluster = subdircluster; // copy the location of the first datacluster to the directoryentry. |
1162,15 → 1162,15 |
file->Size = 0; // new file has no size |
file->DirectorySector = curr_sector; |
file->DirectoryIndex = dir_entry; |
if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) // if a new directory was created then initilize the data area |
{ |
if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) // if a new directory was created then initilize the data area |
{ |
ClearCurrCluster(file); // fill cluster with zeros |
file->SectorInCache = file->FirstSectorOfFirstCluster; |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
{ |
Fat16_Deinit(); |
return(retvalue); |
} |
} |
dir = (DirEntry_t *)file->Cache; |
// create direntry "." to current dir |
dir[0].Name[0] = 0x2E; |
1187,22 → 1187,22 |
dir[1].StartCluster = dircluster; |
dir[1].DateTime = 0; |
dir[1].Size = 0; |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// read in the sector. |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// read in the sector. |
{ |
Fat16_Deinit(); |
return(retvalue); |
} |
} |
} |
} |
retvalue = 1; |
dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
} |
} |
} |
dir_sector++; // search next sector |
// stop if we reached the end of the cluster or the end of the root dir |
}while((dir_sector < max_dir_sector) && (!retvalue)); |
|
|
// if we are seaching in the data area and the file not found in this cluster so take next cluster. |
if(!retvalue && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
if(!retvalue && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
{ |
end_of_directory_not_reached = GetNextCluster(file); // updates File->FirstSectorOfCurrCluster |
} |
1237,14 → 1237,14 |
// trace along the filepath |
path = (s8*)filename; // start a the beginning of the filename string |
file->DirectorySector = 0; // start at RootDirectory with file search |
file->DirectoryIndex = 0; |
file->DirectoryIndex = 0; |
// as long as the file was not found and the remaining path is not empty |
while((*path != 0) && !file_exist) |
{ // separate dirname and subpath from filepath string |
subpath = SeperateDirName(path, dirname); |
if(subpath != NULL) |
{ |
if(*subpath == 0) |
{ |
if(*subpath == 0) |
{ // empty subpath indicates last element of dir chain |
af = attribfilter; |
am = attribmask; |
1258,8 → 1258,8 |
{ |
return (file_exist); // subdirectory does not exist |
} |
else |
{ |
else |
{ |
if (*subpath == 0) |
{ |
file_exist = 1; // last element of path chain was found with the given attribute filter |
1282,7 → 1282,7 |
/* */ |
/* 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 */ |
/* updated. If file or its subdirectories are not found they will be created */ |
/* updated. If file or its subdirectories are not found they will be created */ |
/* */ |
/* Returnvalue: 1 if file was created else 0. */ |
/********************************************************************************************************************************************/ |
1306,7 → 1306,7 |
subpath = SeperateDirName(path, dirname); |
if(subpath != NULL) |
{ |
if(*subpath == 0) |
if(*subpath == 0) |
{ // empty subpath indicates last element of dir chain |
af = ATTR_NONE; |
am = ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL; // any file that is no subdir or volume label |
1321,8 → 1321,8 |
if(*subpath == 0) af = attrib; // if last element in dir chain take the given attribute |
if(!CreateDirectoryEntry(dirname, af, file)) |
{ // could not be created |
return(file_created); |
} |
return(file_created); |
} |
else if (*subpath == 0) file_created = 1; // last element of path chain was created |
} |
} |
1346,9 → 1346,9 |
/* Returnvalue: The filepointer to the file or 0 if faild. */ |
/********************************************************************************************************************************************/ |
File_t * fopen_(const s8 *filename, const s8 mode) |
{ |
{ |
File_t *file = 0; |
|
|
if((!Partition.IsValid) || (filename == 0)) return(file); |
|
// Look for an unused filepointer in the file pointer list? |
1358,7 → 1358,7 |
|
// now we have found a free filepointer and claimed it |
// so let initiate its property values |
file->FirstSectorOfFirstCluster = 0; // Sectorpointer to the first sector of the first datacluster of the file. |
file->FirstSectorOfFirstCluster = 0; // Sectorpointer to the first sector of the first datacluster of the file. |
file->FirstSectorOfCurrCluster = 0; // Pointer to the cluster which is edited at the moment. |
file->SectorOfCurrCluster = 0; // The sector which is edited at the moment (cluster_pointer + sector_index). |
file->ByteOfCurrSector = 0; // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index). |
1371,7 → 1371,7 |
file->Attribute = 0; // the attribute of the file opened. |
|
// check if a real file (no directory) to the given filename exist |
if(FileExist(filename, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file)) |
if(FileExist(filename, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, file)) |
{ // file exist |
switch(mode) // check mode |
{ |
1407,7 → 1407,7 |
} |
break; |
case 'r': // if mode is: read from file |
// goto end of file |
// goto end of file |
fseek_(file, 0, SEEK_SET); |
break; |
default: // other modes are not supported |
1415,7 → 1415,7 |
file = NULL; |
break; |
} |
return(file); |
return(file); |
} |
else // file does not exist |
{ |
1434,9 → 1434,9 |
default: // of unsupported mode |
fclose_(file); |
file = NULL; |
break; |
break; |
} |
return(file); |
return(file); |
} |
// we should never come to this point |
fclose_(file); |
1453,29 → 1453,29 |
/****************************************************************************************************************************************************/ |
s16 fflush_(File_t *file) |
{ |
DirEntry_t *dir; |
|
DirEntry_t *dir; |
|
if((file == NULL) || (!Partition.IsValid)) return (EOF); |
|
|
switch(file->Mode) |
{ |
case 'a': |
case 'w': |
if(file->ByteOfCurrSector > 0) // has data been added to the file? |
if(file->ByteOfCurrSector > 0) // has data been added to the file? |
{ |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// save the data still in the buffer |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// save the data still in the buffer |
{ |
Fat16_Deinit(); |
return(EOF); |
} |
Fat16_Deinit(); |
return(EOF); |
} |
} |
file->SectorInCache = file->DirectorySector; |
if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache)) // read the directory entry for this file. |
{ |
Fat16_Deinit(); |
return(EOF); |
return(EOF); |
} |
|
|
dir = (DirEntry_t *)file->Cache; |
dir[file->DirectoryIndex].Size = file->Size; // update file size |
dir[file->DirectoryIndex].DateTime = FileDateTime(&SystemTime); // update date time |
1521,17 → 1521,17 |
/* Returnvalue: The function returns the character read from the specified memorylocation as u8 casted to s16 or EOF. */ |
/********************************************************************************************************************************************/ |
s16 fgetc_(File_t *file) |
{ |
{ |
s16 c = EOF; |
u32 curr_sector; |
|
|
if( (!Partition.IsValid) || (file == NULL)) return(c); |
// if the end of the file is not reached, get the next character. |
if((0 < file->Size) && ((file->Position+1) < file->Size) ) |
if((0 < file->Size) && ((file->Position+1) < file->Size) ) |
{ |
curr_sector = file->FirstSectorOfCurrCluster; // calculate the sector of the next character to be read. |
curr_sector += file->SectorOfCurrCluster; |
|
curr_sector += file->SectorOfCurrCluster; |
|
if(file->SectorInCache != curr_sector) |
{ |
file->SectorInCache = curr_sector; |
1539,11 → 1539,11 |
{ |
Fat16_Deinit(); |
return(c); |
} |
} |
} |
} |
c = (s16) file->Cache[file->ByteOfCurrSector]; |
file->Position++; // increment file position |
file->ByteOfCurrSector++; // goto next byte in sector |
file->ByteOfCurrSector++; // goto next byte in sector |
if(file->ByteOfCurrSector >= BYTES_PER_SECTOR) // if end of sector |
{ |
file->ByteOfCurrSector = 0; // reset byte location |
1550,7 → 1550,7 |
file->SectorOfCurrCluster++; // next sector |
if(file->SectorOfCurrCluster >= Partition.SectorsPerCluster) // if end of cluster is reached, the next datacluster has to be searched in the FAT. |
{ |
|
|
if(GetNextCluster(file)) // Sets the clusterpointer of the file to the next datacluster. |
{ |
file->SectorOfCurrCluster = 0; // start reading new cluster at first sector of the cluster. |
1575,13 → 1575,13 |
/* Returnvalue: The function returns the character written to the stream or EOF on error. */ |
/********************************************************************************************************************************************/ |
s16 fputc_(const s8 c, File_t *file) |
{ |
{ |
u32 curr_sector = 0; |
|
|
if((!Partition.IsValid) || (file == NULL)) return(EOF); |
|
// If file position equals to file size, then the end of file has reached. |
// In this chase it has to be checked that the ByteOfCurrSector is BYTES_PER_SECTOR |
// In this chase it has to be checked that the ByteOfCurrSector is BYTES_PER_SECTOR |
// and a new cluster should be appended. |
if((file->Position >= file->Size) && (file->ByteOfCurrSector >= BYTES_PER_SECTOR)) |
{ |
1597,13 → 1597,13 |
{ |
Fat16_Deinit(); |
return(EOF); |
} |
} |
} |
|
file->Cache[file->ByteOfCurrSector] = (u8)c; // write databyte into the buffer. The byte will be written to the device at once |
if(file->Size == file->Position) file->Size++; // a character has been written to the file so the size is incremented only when the character has been added at the end of the file. |
file->Position++; // the actual positon within the file. |
file->ByteOfCurrSector++; // goto next byte in sector |
file->ByteOfCurrSector++; // goto next byte in sector |
if(file->ByteOfCurrSector >= BYTES_PER_SECTOR) // if the end of this sector is reached yet |
{ // save the sector to the sd-card |
if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) |
1627,7 → 1627,7 |
else // next cluster |
{ |
file->SectorOfCurrCluster = 0; // start reading new cluster at first sector of the cluster. |
} |
} |
} |
} |
return(0); |
1648,12 → 1648,12 |
u32 object_size = 0; // count the number of bytes read from the actual object. |
u8 *pbuff = 0; // a pointer to the actual bufferposition. |
u8 success = 1; // no error occured during read operation to the file. |
s16 c; |
s16 c; |
|
if((!Partition.IsValid) || (file == NULL) || (buffer == NULL)) return(0); |
|
pbuff = (u8 *) buffer; // cast the void pointer to an u8 * |
|
|
while((object_cnt < count) && success) |
{ |
object_size = size; |
1668,11 → 1668,11 |
} |
else // error or end of file reached |
{ |
success = 0; |
success = 0; |
} |
} |
if(success) object_cnt++; |
} |
} |
return(object_cnt); // return the number of objects succesfully read from the file |
} |
|
1691,12 → 1691,12 |
u32 object_size = 0; // count the number of bytes written from the actual object. |
u8 *pbuff = 0; // a pointer to the actual bufferposition. |
u8 success = 1; // no error occured during write operation to the file. |
s16 c; |
s16 c; |
|
if((!Partition.IsValid) || (file == NULL) || (buffer == NULL)) return(0); |
|
pbuff = (u8 *) buffer; // cast the void pointer to an u8 * |
|
|
while((object_cnt < count) && success) |
{ |
object_size = size; |
1714,10 → 1714,10 |
} |
} |
if(success) object_cnt++; |
} |
|
} |
|
return(object_cnt); // return the number of objects succesfully written to the file |
} |
} |
|
|
/****************************************************************************************************************************************/ |
1731,7 → 1731,7 |
{ |
u8 i=0; |
s16 c = 0; |
|
|
if((!Partition.IsValid) || (file == NULL) || (string == NULL)) return(0); |
|
while((string[i] != 0)&& (c != EOF)) |
1753,10 → 1753,10 |
{ |
u8 *pbuff; |
s16 c = 0; |
|
|
if((!Partition.IsValid) || (file == NULL) || (string == NULL) || (length = 0)) return (0); |
pbuff = string; |
while(length > 1) // read the count-1 characters from the file to the string. |
while(length > 1) // read the length-1 characters from the file to the string. |
{ |
c = fgetc_(file); // read a character from the opened file. |
switch(c) |
1765,13 → 1765,13 |
c = 0; // set string terminator |
length = 1; // stop loop |
break; |
|
|
case EOF: |
c = 0; // set string terminator |
length = 1; // stop loop |
break; |
break; |
} |
*pbuff = (u8)c; // copy byte to string |
*pbuff = (s8)c; // copy byte to string |
length--; |
pbuff++; |
} |
1803,14 → 1803,14 |
/* Returnvalue: 0 if the end of the file was not reached otherwise 1. */ |
/****************************************************************************************************************************************/ |
u8 feof_(File_t *file) |
{ |
{ |
if(((file->Position)+1) < (file->Size)) |
{ |
return(0); |
} |
else |
else |
{ |
return(1); |
return(1); |
} |
} |
|