[En-Nut-Discussion] Opening files for append with size > 16KB failes on Nut/OS 4.6.0

Harald Kipp harald.kipp at egnite.de
Sat Aug 23 10:24:20 CEST 2008


Hi Ole,

Ole Reinhardt wrote:
> When opening a file with is slightly larger than 16 KByte with
> 
> fopen("filename", "a+");
> 
> an error EEXISTS (17) is returned. In my case the file has a size of
> 16392 bytes.

The errno code seems to be a leftover from a previous action. No error 
code is set in case of the problem you described.

> Any ideas where to search? Phat implementation or fopen() c runtime
> functions? 

The problem is, that the seek is done _before_ the PHAT file descriptor 
has been properly initialized.

To fix this, the following changes are required in function 
PhatFileOpen(), located in file fs/phatfs.c:

Remove

-----------------------
/*
  * Append to an existing file.
  */
if ((mode & _O_APPEND) != 0 && ffcb->f_dirent.dent_fsize) {
   if (PhatFilePosSet(nfp, ffcb->f_dirent.dent_fsize)) {
     PhatFileClose(ndp);
     PhatFileClose(nfp);
     free(srch);
     return NUTFILE_EOF;
   }
}
-----------------------

and insert

-----------------------
/*
  * Append to an existing file.
  */
if ((mode & _O_APPEND) != 0 && ffcb->f_dirent.dent_fsize) {
   if (PhatFilePosSet(nfp, ffcb->f_dirent.dent_fsize)) {
     PhatFileClose(nfp);
     return NUTFILE_EOF;
   }
}
-----------------------

right after the call to PhatFileClose(ndp) at the end of PhatFileOpen().

As soon as someone confirms, that this fixes the problem, I'll commit it 
to CVS HEAD and the 4.6 branch.

Harald







More information about the En-Nut-Discussion mailing list