2005-12-09 11:12:28

by RLN

[permalink] [raw]
Subject: NFS and C Language

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 - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2005-12-09 11:29:02

by Vincent Roqueta

[permalink] [raw]
Subject: Re: NFS and C Language

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 - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-12-09 14:11:00

by Peter Staubach

[permalink] [raw]
Subject: Re: NFS and C Language

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 - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-12-09 14:23:43

by Vincent Roqueta

[permalink] [raw]
Subject: Re: NFS and C Language

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 - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs