From: Peter Staubach <staubach@redhat.com>
To: Vincent Roqueta <vincent.roqueta@ext.bull.net>
Cc: nfs@lists.sourceforge.net, RLN <e_rln@yahoo.co.in>
Subject: Re: NFS and C Language
Date: Fri, 09 Dec 2005 09:10:48 -0500 [thread overview]
Message-ID: <43999068.3080500@redhat.com> (raw)
In-Reply-To: <200512091231.26341.vincent.roqueta@ext.bull.net>
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
next prev parent reply other threads:[~2005-12-09 14:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-09 11:12 NFS and C Language RLN
2005-12-09 11:31 ` Vincent Roqueta
2005-12-09 14:10 ` Peter Staubach [this message]
2005-12-09 14:24 ` Vincent Roqueta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43999068.3080500@redhat.com \
--to=staubach@redhat.com \
--cc=e_rln@yahoo.co.in \
--cc=nfs@lists.sourceforge.net \
--cc=vincent.roqueta@ext.bull.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.