comp.os.minix
read error/quirk with minix 2.0.2

The code below generates an EBADFS error (9 - file descripter not valid for
reading) at the read instruction. Anyone know what is neccessary to enable
reading a file that has just been writen?

Hul

----------------------------------------------------
extern int creat();
extern int write();
extern int read();
extern long lseek();
extern int errno;

main()
{
char sp[550];
char c;
int x, y, pmode, tst1;
long xl;
c = 0x30;
pmode = 0666;
tst1 = creat("tst1", pmode);
if(tst1 <= 0)
{
write(1, "error 1", 7);
return;
}
x = write(tst1, &sp[0], 80);
if(x != 80)
{
write(1, "error 2", 7);
return;
}
xl = lseek(tst1, (long) 0, (int) 0);
if(xl != 0)
{
write(1, "error 3", 7);
return;
}
x = read(tst1, &sp[0], 30);
if(x <= 0)
{
write(1, "error 4 = ", 10);
c = c + errno;
write(1, &c, 1);
return;
}
close(tst1);
return;
}