"Invalid argument" error while mounting NFS partition
I am trying to mount a local folder through NFS on the same machine.
Here's my code: Code:
#include <stdio.h> Quote:
Is it not possible to mount NFS partitions using the mount() API in code? |
well, you know that NFS comes in two parts, nfs-server and nfs-client! you need to have the nfs-client package or nfs-common package installed on your client machine for NFS to work!
In ubuntu install nfs-common and portmap: Code:
|
As i already stated that NFS mount is working on the command prompt. So, my NFS server is up and working. It's only in the program that I am getting this error.
BTW, i am using Fedora Core 9 and Ubuntu 7.10 |
Argument 3 of mount is an int, not a string. It is a mount flag, such as MNT_RDONLY. Hence an invalid argument. See man 2 mount.
|
Quote:
http://linux.die.net/man/2/mount and here's the syntax given in the man page: Quote:
In the man page itself, they have given examples of 3rd argument i.e. "ext2", "nfs", so i used that. There is not much documentation on the internet about mount API. Please help... |
Well, montylee, I'm sure it can't hurt to at least try out Mr. C's suggestion? It might be your solution! especially if your NFS man page is out of date.
|
Oops, darn, looks like a surprising difference in BSD v. Linux:
BSD Code:
int Your fifth argument should not be a string, it should be pointer to a struct nfs_mount_data. man 2 mount: Quote:
Quote:
|
Thanks for the reply Mr. C.
I tried to declare struct nfs_mount_data in my program, but it gives the following error: Quote:
The nfs_mount_data struct is defined in /usr/include/linux/nfs_mount.h. When i include this header in my code, i get the following error: Quote:
Any ideas? |
sa_family_t is a typedef (it is a socket address family type). That is defined in <sys/socket.h>, which you need to include before nfs_mount.h.
|
ok, i pasted the nfs_mount_data struct inside my file itself. But i am still getting invalid argument error. Here's my code:
Quote:
http://www.koders.com/c/fid838F9F103...D0F99DF4D.aspx |
Sure, the data has to be valid! Otherwise it is filled with garbage, and the kernel tries to interpret. It doesn't know what you want in there.
|
I included the <sys/socket.h>, it fixed the sa_family_t error.
Now, even if the data in nfs_mount_data is not valid, why am i getting the same error i.e. "invalid argument". I'll try filling some data in the nfs_mount_data structure. |
I'm running across this same problem: the normal mount command works (/bin/mount), but the C system call doesn't. Did this issue ever get resolved?
|
All times are GMT -5. The time now is 04:45 PM. |