All of lore.kernel.org
 help / color / mirror / Atom feed
* NFS and C Language
@ 2005-12-09 11:12 RLN
  2005-12-09 11:31 ` Vincent Roqueta
  0 siblings, 1 reply; 4+ messages in thread
From: RLN @ 2005-12-09 11:12 UTC (permalink / raw)
  To: nfs

Hi!


I want to write simple C language program to read and write a file in =
NFS file system.

Please give a link or advice to write a program using C language.

Also help for which calls I have to use.




Send instant messages to your online friends http://in.messenger.yahoo.com 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFS and C Language
  2005-12-09 11:12 NFS and C Language RLN
@ 2005-12-09 11:31 ` Vincent Roqueta
  2005-12-09 14:10   ` Peter Staubach
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Roqueta @ 2005-12-09 11:31 UTC (permalink / raw)
  To: nfs; +Cc: RLN

Le Vendredi 09 D=E9cembre 2005 12:12, RLN a =E9crit=A0:
> Hi!
>
>
> I want to write simple C language program to read and write a file in NFS
> file system.
>
> Please give a link or advice to write a program using C language.
>
> Also help for which calls I have to use.
You access NFS as other file systems...
Generic C howto about files manipulations works for NFS.

Vincent


_______________________
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main(int argc, char **argv){
    char path[]=3D"/path/to/the/testfile";
    char string[]=3D"hello world!";
    int fd;

    fd=3Dopen(path,O_WRONLY|O_CREAT);
    if(fd<0){
        perror("Open");
        return 0;
    }
    write(fd, string,strlen(string));
    return 0;
}



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFS and C Language
  2005-12-09 11:31 ` Vincent Roqueta
@ 2005-12-09 14:10   ` Peter Staubach
  2005-12-09 14:24     ` Vincent Roqueta
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Staubach @ 2005-12-09 14:10 UTC (permalink / raw)
  To: Vincent Roqueta; +Cc: nfs, RLN

Vincent Roqueta wrote:

>Le Vendredi 09 D=E9cembre 2005 12:12, RLN a =E9crit :
> =20
>
>>Hi!
>>
>>
>>I want to write simple C language program to read and write a file in N=
FS
>>file system.
>>
>>Please give a link or advice to write a program using C language.
>>
>>Also help for which calls I have to use.
>>   =20
>>
>You access NFS as other file systems...
>Generic C howto about files manipulations works for NFS.
>
>Vincent
>
>
>_______________________
>#include <stdio.h>
>#include <string.h>
>#include <sys/types.h>
>#include <sys/stat.h>
>#include <fcntl.h>
>
>
>int main(int argc, char **argv){
>    char path[]=3D"/path/to/the/testfile";
>    char string[]=3D"hello world!";
>    int fd;
>
>    fd=3Dopen(path,O_WRONLY|O_CREAT);
>    if(fd<0){
>        perror("Open");
>        return 0;
>    }
>    write(fd, string,strlen(string));
>    return 0;
>}
>

Actually, this little program may or may not work on an NFS mounted file
system.  It contains a bug in that the open(2) system call takes three
arguments and the third, the mode, is used when O_CREAT is specified and
the file does not already exist.  If the random bits, which the kernel
uses because the mode was not actually specified, are wrong, like for
example require mandatory locking, then the write(2) call may fail.
Also, the write(2) call returns whether or not it succeeded and how much
data was written.  The close(2) call, which was not explicitly coded,
but should have been, is also used to return whether any error occurred
while trying to write data to the NFS server.

    Thanx...

       ps


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: NFS and C Language
  2005-12-09 14:10   ` Peter Staubach
@ 2005-12-09 14:24     ` Vincent Roqueta
  0 siblings, 0 replies; 4+ messages in thread
From: Vincent Roqueta @ 2005-12-09 14:24 UTC (permalink / raw)
  To: nfs

Le Vendredi 09 D=E9cembre 2005 15:10, Peter Staubach a =E9crit=A0:
> Vincent Roqueta wrote:
> >Le Vendredi 09 D=E9cembre 2005 12:12, RLN a =E9crit :
> >>Hi!
> >>
> >>
> >>I want to write simple C language program to read and write a file in N=
=46S
> >>file system.
> >>
> >>Please give a link or advice to write a program using C language.
> >>
> >>Also help for which calls I have to use.
> >
> >You access NFS as other file systems...
> >Generic C howto about files manipulations works for NFS.
> >
> >Vincent
> >
> >
> >_______________________
> >#include <stdio.h>
> >#include <string.h>
> >#include <sys/types.h>
> >#include <sys/stat.h>
> >#include <fcntl.h>
> >
> >
> >int main(int argc, char **argv){
> >    char path[]=3D"/path/to/the/testfile";
> >    char string[]=3D"hello world!";
> >    int fd;
> >
> >    fd=3Dopen(path,O_WRONLY|O_CREAT);
> >    if(fd<0){
> >        perror("Open");
> >        return 0;
> >    }
> >    write(fd, string,strlen(string));
> >    return 0;
> >}
>
> Actually, this little program may or may not work on an NFS mounted file
> system.  It contains a bug in that the open(2) system call takes three
> arguments and the third, the mode, is used when O_CREAT is specified and
> the file does not already exist.  If the random bits, which the kernel
> uses because the mode was not actually specified, are wrong, like for
> example require mandatory locking, then the write(2) call may fail.
> Also, the write(2) call returns whether or not it succeeded and how much
> data was written.  The close(2) call, which was not explicitly coded,
> but should have been, is also used to return whether any error occurred
> while trying to write data to the NFS server.
Right...
You can add I return 0 even if the program fails...

I have taken a little less than 3 minutes to write this little example :)
I hope C howto examples will be better :)

Vincent


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-12-09 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-09 11:12 NFS and C Language RLN
2005-12-09 11:31 ` Vincent Roqueta
2005-12-09 14:10   ` Peter Staubach
2005-12-09 14:24     ` Vincent Roqueta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.