]> git.decadent.org.uk Git - nfs-utils.git/blob - support/nfs/getfh.c
Initial revision
[nfs-utils.git] / support / nfs / getfh.c
1 /*
2  * support/nfs/getfh.c
3  *
4  * Get the FH for a given client and directory. This function takes
5  * the NFS protocol version number as an additional argument.
6  *
7  * This function has nothing in common with the SunOS getfh function,
8  * which is a front-end to the RPC mount call.
9  *
10  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
11  */
12
13 #include "config.h"
14
15 #include <string.h>
16 #include <sys/types.h>
17 #include <errno.h>
18 #include "nfslib.h"
19
20 struct knfs_fh *
21 getfh_old (struct sockaddr *addr, dev_t dev, ino_t ino)
22 {
23         static union nfsctl_res res;
24         struct nfsctl_arg       arg;
25
26         arg.ca_version = NFSCTL_VERSION;
27         arg.ca_getfh.gf_version = 2;    /* obsolete */
28         arg.ca_getfh.gf_dev = dev;
29         arg.ca_getfh.gf_ino = ino;
30         memcpy(&arg.ca_getfh.gf_addr, addr, sizeof(struct sockaddr_in));
31
32         if (nfsctl(NFSCTL_GETFH, &arg, &res) < 0)
33                 return NULL;
34
35         return &res.cr_getfh;
36 }
37
38 struct knfs_fh *
39 getfh(struct sockaddr *addr, const char *path)
40 {
41         static union nfsctl_res res;
42         struct nfsctl_arg       arg;
43
44         arg.ca_version = NFSCTL_VERSION;
45         arg.ca_getfd.gd_version = 2;    /* obsolete */
46         strncpy(arg.ca_getfd.gd_path, path,
47                 sizeof(arg.ca_getfd.gd_path) - 1);
48         arg.ca_getfd.gd_path[sizeof (arg.ca_getfd.gd_path) - 1] = '\0';
49         memcpy(&arg.ca_getfd.gd_addr, addr, sizeof(struct sockaddr_in));
50
51         if (nfsctl(NFSCTL_GETFD, &arg, &res) < 0)
52                 return NULL;
53
54         return &res.cr_getfh;
55 }