FAT.LIB and FILE SYSTEM

Hi,

I m trying to write a fat file in the serial flash of the RCM3700 but I ve somes problem when I get the created file with a FTP Server I don’t see the expected file I see a file with weird characters and parts of the things I ve written In. I ve heard that it could be due to FAT.LIB because of the recovery code.

Does someone knows how to solve this problem ?
I think that I should write my own fat file system or built my own fat.lib
what do you think about that ?
Does someone knows how to do that ?

Thanks a lot for help,

JUJU :wink: :smiley:

Which code are you having this problem with? The FAT filesystem, if properly interfaced, has no problems with FTP. I have used it and we have many customers who use the FAT library with FTP. Please send more details of the problem and the code your running, or call technical support and they can get you on track with this.

For the FTP Server I use Updpages.c and to create the file I run the following code (I use DC 9.52):

/*****************************************************************************

Description :

This prog write a fat file named “Fichier2.txt” in the serial flash the expected file is :

"DESCRIPTIF

10.12.30 20:20 Jean-Louis

"

but I obtain :

"DESCRIPTIF

10.12.30 20:20
an-Louis

"

******************************************************************************/

#class auto

// This macro causes the FAT library to wait for everything to complete
// before returning to the caller. This makes the application MUCH simpler.

#define FAT_BLOCK

// DEFINITION DES CONSTANTES CHAINES

#define DESC "DESCRIPTIF " //Les chaines font toutes la meme taille pour faciliter la mise en page
#define LI "Lieu "
#define ECH "Echantillons "
#define DIV "Divers "

// Uncomment to turn on Debug options

//#define FAT_DEBUG
//#define NFLASH_DEBUG // only useful for boards with nand flash
//#define SFLASH_DEBUG // only useful for boards with serial flash
//#define FATWTC_DEBUG
//#define PART_DEBUG
//#define ECC_DEBUG

// Call in the FAT filesystem support code.
#use “fat.lib”

//////////////////////VARIABLES GLOBALES///////////////////////////////////////

FATfile my_file;//variable correspondant au fichier.
int rc; // Return code store.

long position; //Variable de posionnement dans le fichier utilis�e dans chaque elle est remise � jour apr�s chaque ecriture dans le fichier

char buffer[700];
char date[30];
char heure[8] ;
char login[15] ;

char clock[100];

fat_part *first_part;

///////////////////////////FIN DES VARIABLES GLOBALES//////////////////////////

/* FONCTIONS PROTOTYPES */

void Ecrire_Chaine_Ds_Fichier(char*); //Write a string in the file

/Fin des prototypes/

/////////////////////////////PROGRAMME PRINCIPAL////////////////////////////////

void main(void)
{
char buf[255];
char chaine[7];
int i;

long prealloc;


brdInit();

strcpy(clock,"10.12.30 20:20"); //CLOCK

strcpy(login,"Jean-Louis"); //LOGIN

rc = fat_AutoMount(FDDF_USE_DEFAULT);

// Scan the populated mounted partitions list to find the first mounted
// partition.  The number of configured fat devices, as well as the mounted
// partition list, are provided for us in FAT_CONFIG.LIB.
first_part = NULL;
for (i = 0; i < num_fat_devices * FAT_MAX_PARTITIONS; ++i) {
	if ((first_part = fat_part_mounted[i]) != NULL) {
		// found a mounted partition, so use it
		break;
	}
}

// Check if a mounted partition was found
if (first_part == NULL) {
	// No mounted partition found, ensure rc is set to a FAT error code.
	rc = (rc < 0) ? rc : -ENOPART;
} else {
	// It is possible that a non-fatal error was encountered and reported,
	// even though fat_AutoMount() succeeded in mounting at least one
	// FAT partition.
	printf("fat_AutoMount() succeeded with return code %d.

", rc);
// We found a partition to work with, so ignore other error (if any).
rc = 0;
}

// FAT return codes always follow the convention that a negative value
// indicates an error.
if (rc < 0) {
// An error occurred. Here, we print out the numeric code. You can
// look in lib\filesystem\errno.lib to see what type of error it
// really is. Note that the values in errno.lib are the absolute
// value of the return code.
if (rc == -EUNFORMAT)
printf("Device not Formatted, Please run Fmt_Device.c
");
else
printf("fat_AutoMount() failed with return code %d.
", rc);
exit(1);
}

prealloc = 0;//TAILLE_MAX_DU_FICHIER;

        // Open (and maybe create) it...

// costate Co_Ouvrir_Fichier init_on

// {
printf(“Opening File …”);

   rc = fat_Open(

                   first_part,	// First partition pointer from fat_AutoMount()
                   "try7.txt",	// Name of file.  Always an absolute path name.
                   FAT_FILE,		// Type of object, i.e. a file.
                   FAT_CREATE,	// Create the file if it does not exist.
                   &amp;my_file,		// Fill in this structure with file details
                   &amp;prealloc		// Number of bytes to allocate.

                               );

     	if (rc &lt; 0) {
                        	printf("fat_Open() failed with return code %d

", rc);
exit(1);
}
else
{
printf("File_Open() succeeded ");

           }

// }

position=0;

//while(1)
while(position < 20000L)
{

	 fat_Seek(&amp;my_file,position,SEEK_SET);

	  Ecrire_Chaine_Ds_Fichier(DESC);

  	fat_Seek(&amp;my_file,position,SEEK_SET);

 	 Ecrire_Chaine_Ds_Fichier("

");

  	fat_Seek(&amp;my_file,position,SEEK_SET);

 	 Ecrire_Chaine_Ds_Fichier(clock);

 	 fat_Seek(&amp;my_file,position,SEEK_SET);

   Ecrire_Chaine_Ds_Fichier(login);

   fat_Seek(&amp;my_file,position,SEEK_SET);

  	Ecrire_Chaine_Ds_Fichier("

");

// fat_Seek(&my_file,position,SEEK_SET);

}
fat_Close(&my_file);

rc = fat_Open(
first_part, // First partition pointer from fat_AutoMount()
“try7.txt”, // Name of file. Always an absolute path name.
FAT_FILE, // Type of object, i.e. a file.
0, // 0 means the file must exist.
&my_file, // Fill in this structure with file details
NULL // This will not be used, you can pass NULL.
);

if (rc &lt; 0) {
printf("fat_Open() (for read) failed with return code %d

", rc);
exit(1);
}

position=0;


while(position &lt; 20000L)
{


	 fat_Seek(&amp;my_file,position,SEEK_SET);

    rc = fat_Read(&amp;my_file, buf, sizeof(buf));

if (rc &lt; 0)
  {
	printf("fat_Read() failed with return code %d

", rc);
}
else
{
// Read OK. Print out the buffer contents.
printf(“Read %d bytes:
“, rc);
printf(”%*.*s”, rc, rc, buf); // Print a string which is not NULL
position += (long) sizeof(buf);
}

}
rc = fat_UnmountDevice(first_part->dev);
if (rc < 0)
printf("Unmount Error %ls
",error_message(rc));

  while(1);

}

//=====================================>

void Ecrire_Chaine_Ds_Fichier(char *mot)

{

rc = fat_Write(
&my_file, // File, as set by fat_Open()
mot, // Some data to write.
strlen(mot) // Number of characters to write et accessoirement longueur de la chaine “mot”.
);

position += (long) strlen(mot);

fat_Seek(&my_file,position,SEEK_SET);

  rc = fat_Write(
              &amp;my_file,				// File, as set by fat_Open()
              "

", // Some data to write.
2 // Number of characters to write et accessoirement longueur de la chaine “mot”.
);

    fat_Seek(&amp;my_file,position,SEEK_SET);

if (rc < 0) {

           printf("fat_Write() failed with return code %d

", rc);
exit(1);

           }

           printf("

POSITION : %d
",position);

        }

Problem Solved !

It was just because of the version the DC 9.52 seems to run badly with the fat instead of the DC 9.62 !

JUJU ; - )