FORTRAN rewind on NFS filesystems
Toon Moene
toon@moene.indiv.nluug.nl
Thu Feb 3 14:46:00 GMT 2000
Mathias Puetz wrote:
> we are running a Linux cluster with diskless slave nodes
> at our site and have a strange problem related to NFS.
> The problem is more likely to be with Fortran g77 than
> a real NFS problem. However, I'm not sure, the bug might
> as well be some 'feature' of the Linux NFS2 implementation.
> PROGRAM rew
>
> CHARACTER(80) iwrote
>
> OPEN(FILE='testfile',UNIT=10,STATUS='new')
>
> WRITE(10,*) 'Totally Wrong!'
>
> REWIND(10)
>
> WRITE(10,*) 'Right!'
> c
> c comment the above line, and uncomment below and
> c it works on NFS
> c
> c WRITE(10,*) 'Absolutely Right!'
>
> CLOSE(10)
>
> END
>
> -------------------------------------------
> no compiler options in both cases.
> the contents of 'testfile' of the F77 version is
>
> Right!
>
> if run on an ext2 filesystem
>
> and I get the error message
>
> endfile: truncation failed in endfile
> apparent state: unit 10 named testfile
> last format: list io
> lately writing direct formatted external IO
> Aborted (core dumped)
>
> if run on a NFS2 filesystem.
To see if it is a problem with your (mounting of) the NFS2 file system,
try this C equivalent to the Fortran code:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
main()
{
int f = open("testfile",O_RDWR | O_CREAT);
if (f > 0) {
write(f,"Totally wrong !\n", 16);
lseek(f,0,SEEK_SET);
ftruncate(f,0);
write(f,"Right!\n", 8);
close(f);
}
else {
write(0,"Couldn't open file\n",19);
return 1;
}
}
The reason for the ftruncate is the requirement of Fortran that a write
statement on a sequential file always writes the record that's going to
be the last in the file.
So the sequence WRITE/REWIND/WRITE means: write a record, place the
"current record pointer" at the beginning of the file, clear the rest
and write a record (thus establishing a new "end-of-file").
Hope this helps,
--
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://gcc.gnu.org/onlinedocs/g77_news.html
More information about the Gcc-bugs
mailing list