Altera_Forum
Honored Contributor
19 years agoDoes read(fileHandle, buf, bytes); work??
Hello,
I have mounted an NFS file system residing in a UNIX box. There, there is a binary file from which I am trying to read 4 bytes from the top (a header). I have included the appropriate header files and it has compiled correctly. It seems that the file open is successful but the read() hangs (nothing happens the processor does not hang but the thread does). This is a simple sample code:#ifndef __NIOS2_SYSTEM_H__# include "nios2_system.h"# endif
# include <unistd.h># include <stdio.h># include <string.h># include <fcntl.h># include <stdlib.h> /* getenv, exit */# include <sys/types.h># include <sys/stat.h>
int main(void)
{
int fileHandle;
void *buf;
int re = 0;
fileHandle = open( "/mnt/nfs/files/file.bin", O_RDWR );
if (fileHandle == -1)
{
printf (" Could not open file\n");
return(-1);
}
buf = malloc(4);
re = read(fileHandle, buf, 4); <---- Hangs here
if (re == -1)
{
printf(" Read Failed\n");
free(buf);
close(fileHandle);
return(-1);
}
printf(" Data = %s\n", buf);
free(buf);
close(fileHandle);
return(0);
} I have mounted the file system as: mount -t nfs 13.1.143.56:/opt/X_FILES /mnt/nfs -n -o nolock and the file has permissions of 777. Am I missing something? (this is a rather simple thing it ought to work!) Thanks, Carlos