]> git.decadent.org.uk Git - nfs-utils.git/blob - support/nfs/getfh.c
Cleanup xlog logging code to be safe and usable for all
[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 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <string.h>
18 #include <sys/types.h>
19 #include <errno.h>
20 #include "nfslib.h"
21
22 struct nfs_fh_len *
23 getfh_old (struct sockaddr *addr, dev_t dev, ino_t ino)
24 {
25         union nfsctl_res        res;
26         struct nfsctl_arg       arg;
27         static struct nfs_fh_len rfh;
28
29         arg.ca_version = NFSCTL_VERSION;
30         arg.ca_getfh.gf_version = 2;    /* obsolete */
31         arg.ca_getfh.gf_dev = dev;
32         arg.ca_getfh.gf_ino = ino;
33         memcpy(&arg.ca_getfh.gf_addr, addr, sizeof(struct sockaddr_in));
34
35         if (nfsctl(NFSCTL_GETFH, &arg, &res) < 0)
36                 return NULL;
37
38         rfh.fh_size = 32;
39         memcpy(rfh.fh_handle, &res.cr_getfh, 32);
40         return &rfh;
41 }
42
43 struct nfs_fh_len *
44 getfh(struct sockaddr *addr, const char *path)
45 {
46         static union nfsctl_res res;
47         struct nfsctl_arg       arg;
48         static struct nfs_fh_len rfh;
49
50         arg.ca_version = NFSCTL_VERSION;
51         arg.ca_getfd.gd_version = 2;    /* obsolete */
52         strncpy(arg.ca_getfd.gd_path, path,
53                 sizeof(arg.ca_getfd.gd_path) - 1);
54         arg.ca_getfd.gd_path[sizeof (arg.ca_getfd.gd_path) - 1] = '\0';
55         memcpy(&arg.ca_getfd.gd_addr, addr, sizeof(struct sockaddr_in));
56
57         if (nfsctl(NFSCTL_GETFD, &arg, &res) < 0)
58                 return NULL;
59
60         rfh.fh_size = 32;
61         memcpy(rfh.fh_handle, &res.cr_getfh, 32);
62         return &rfh;
63 }
64
65 struct nfs_fh_len *
66 getfh_size(struct sockaddr *addr, const char *path, int size)
67 {
68         static union nfsctl_res res;
69         struct nfsctl_arg       arg;
70
71         arg.ca_version = NFSCTL_VERSION;
72         strncpy(arg.ca_getfs.gd_path, path,
73                 sizeof(arg.ca_getfs.gd_path) - 1);
74         arg.ca_getfs.gd_path[sizeof (arg.ca_getfs.gd_path) - 1] = '\0';
75         memcpy(&arg.ca_getfs.gd_addr, addr, sizeof(struct sockaddr_in));
76         arg.ca_getfs.gd_maxlen = size;
77
78         if (nfsctl(NFSCTL_GETFS, &arg, &res) < 0)
79                 return NULL;
80
81         return &res.cr_getfs;
82 }