Temporarily, I am writing files to SD card. Perhaps this is the source of the issue?
My client software receives real-time streamed data via tcpip and writes this data to files based on data size. The file naming convection is basically a '0' padded integer, e.g. 000001.tmp, 000002.tmp, etc.
Once a file is completed (writing done), the file is closed and then renamed using the rename function. I am closely checking both the returned values from file closing (fclose) and file renaming and both are returning the correct values (0== success).
Code:
// close file function
BOOL closeDataFile()
{
int ret;
if( pFile != NULL )
{
ret=fclose(pFile);
if(ret==0)
{
pFile = NULL;
return TRUE;
}
else return FALSE;
}
return TRUE;
}
// rename file function
BOOL renameTempFile()
{
...
ret = rename(old_fnp, new_fnp);
if( ret != 0 )
{
printf("ERROR: Failed to Rename Data File %s",old_fnp);
perror( old_fnp );
return FALSE;
}
return TRUE;
}
The issue I am having is that occasionally the old file (in the renaming function) remains in the directory list after the renaming function has successfully completed. The matching newly renamed file is there also. The old files remaining in the folder are not valid files and cannot be manually deleted. On rebooting the RPi these old files are cleared in the reboot process. One further note is that the free space on the SD card is not an issue as I only write a few MBs before stopping the program while I have multi GBs free.
I have not found others reporting this issue and would like to know if someone has any ideals.
Thanks
Jim