"Invalid argument" error while mounting NFS partition
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"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>
#include <errno.h>
#include <sys/mount.h>
int main ()
{
int retval;
retval = mount ((const char *) "127.0.0.1:/home/test", (const char *) "/tmp/test", "nfs", MS_RDONLY, "");
if (retval != 0) {
printf(" Mount system call failed and return value is %d\n", errno) ;
perror("mount");
} else {
printf(" Mount system call successfull \n");
}
return 0;
}
I am getting the following error:
Quote:
Mount system call failed and return value is 22
mount: Invalid argument
I have made appropriate changes in the /etc/exports file and restarted the NFS server. The NFS mount command works from the terminal but not from the above program.
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!
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.
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
mount(const char *type, const char *dir, int flags, void *data);
I usually check for Linux specific man pages; don't know why I relied on my BSD system yesterday for documentation.
Your fifth argument should not be a string, it should be pointer to a struct nfs_mount_data.
man 2 mount:
Quote:
The data argument is interpreted by the different file systems. Typically it is a string of comma-separated options understood by this file system. See mount(8) for details of the options available for each filesystem type.
man 8 mount
Quote:
Mount options for nfs Instead of a textual option string, parsed by the kernel, the nfs file system expects a binary argument of type struct nfs_mount_data. The program mount itself parses the following options of the form 'tag=value', and puts them in the structure mentioned: rsize=n, wsize=n, timeo=n, retrans=n, acregmin=n, acregmax=n, acdirmin=n, acdirmax=n, actimeo=n, retry=n, port=n, mountport=n, mounthost=name, mountprog=n, mountvers=n, nfsprog=n, nfsvers=n, namlen=n. The option addr=n is accepted but ignored. Also the following Boolean options, possibly preceded by no are recognized: bg, fg, soft, hard, intr, posix, cto, ac, tcp, udp, lock. For details, see nfs(5).
Thanks for the reply Mr. C.
I tried to declare struct nfs_mount_data in my program, but it gives the following error:
Quote:
error: storage size of ‘nfs_mount_data’ isn’t known
So, i guess my program is not able to get the struct declaration of nfs_mount_data.
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:
In file included from /usr/include/linux/nfs_mount.h:11,
from mount_test.c:7:
/usr/include/linux/in.h:182: error: expected specifier-qualifier-list before ‘sa_family_t’
This error comes as nfs_mount.h includes linux/in.h and that file is giving an error.
if (retval != 0) {
printf(" Mount system call failed and return value is %d\n", errno);
perror("mount");
} else {
printf(" Mount system call successfull \n");
}
return 0;
}
Now, do i need to fill everything in the nfs_mount_data structure? This link might be of some help:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.