Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12748 Discussions

Does read(fileHandle, buf, bytes); work??

Altera_Forum
Honored Contributor II
1,149 Views

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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
446 Views

Hello, 

 

I have found the answer. If you care to know, I had to enable: 

 

File Systems -> Network File Systems -> Provide NFSv3 client support  

 

option to make it work. 

 

Cheers, 

 

Carlos 

 

 

 

--- Quote Start ---  

originally posted by carlos@Apr 5 2006, 01:58 PM 

hello, 

 

i have mounted an nfs file system residing in a unix box.  there i 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 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=14071)</div> 

--- Quote End ---  

0 Kudos
Reply