Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Does 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

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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 ---