4 * Get the FH for a given client and directory. This function takes
5 * the NFS protocol version number as an additional argument.
7 * This function has nothing in common with the SunOS getfh function,
8 * which is a front-end to the RPC mount call.
10 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
18 #include <sys/types.h>
23 * getfh_old - ask the kernel for an NFSv2 file handle via nfsctl()
24 * @sin: pointer to IPv4 address of a client
25 * @dev: device number of device where requested object resides
26 * @ino: inode number of requested object
28 * Returns a pointer to an NFSv2 file handle, or NULL if some error
29 * occurred. errno is set to reflect the specifics of the error.
32 getfh_old(const struct sockaddr_in *sin, const dev_t dev, const ino_t ino)
35 struct nfsctl_arg arg;
36 static struct nfs_fh_len rfh;
38 if (sin->sin_family != AF_INET) {
43 memset(&arg, 0, sizeof(arg));
44 memset(&res, 0, sizeof(res));
46 arg.ca_version = NFSCTL_VERSION;
47 arg.ca_getfh.gf_version = 2; /* obsolete */
48 arg.ca_getfh.gf_dev = dev;
49 arg.ca_getfh.gf_ino = ino;
50 memcpy(&arg.ca_getfh.gf_addr, sin, sizeof(*sin));
52 if (nfsctl(NFSCTL_GETFH, &arg, &res) < 0)
55 memset(&rfh, 0, sizeof(rfh));
57 memcpy(rfh.fh_handle, &res.cr_getfh, 32);
62 * getfh - ask the kernel for an NFSv2 file handle via nfsctl()
63 * @sin: pointer to IPv4 address of a client
64 * @path: pointer to a '\0'-terminated ASCII string containing an pathname
66 * Returns a pointer to an NFSv2 file handle, or NULL if some error
67 * occurred. errno is set to reflect the specifics of the error.
70 getfh(const struct sockaddr_in *sin, const char *path)
72 static union nfsctl_res res;
73 struct nfsctl_arg arg;
74 static struct nfs_fh_len rfh;
76 if (sin->sin_family != AF_INET) {
81 memset(&arg, 0, sizeof(arg));
82 memset(&res, 0, sizeof(res));
84 arg.ca_version = NFSCTL_VERSION;
85 arg.ca_getfd.gd_version = 2; /* obsolete */
86 strncpy(arg.ca_getfd.gd_path, path,
87 sizeof(arg.ca_getfd.gd_path) - 1);
88 arg.ca_getfd.gd_path[sizeof (arg.ca_getfd.gd_path) - 1] = '\0';
89 memcpy(&arg.ca_getfd.gd_addr, sin, sizeof(*sin));
91 if (nfsctl(NFSCTL_GETFD, &arg, &res) < 0)
94 memset(&rfh, 0, sizeof(rfh));
96 memcpy(rfh.fh_handle, &res.cr_getfh, 32);
101 * getfh_size - ask the kernel for a file handle via nfsctl()
102 * @sin: pointer to IPv4 address of a client
103 * @path: pointer to a '\0'-terminated ASCII string containing an pathname
104 * @size: maximum size, in bytes, of the returned file handle
106 * Returns a pointer to an NFSv3 file handle, or NULL if some error
107 * occurred. errno is set to reflect the specifics of the error.
110 getfh_size(const struct sockaddr_in *sin, const char *path, const int size)
112 static union nfsctl_res res;
113 struct nfsctl_arg arg;
115 if (sin->sin_family != AF_INET) {
116 errno = EAFNOSUPPORT;
120 memset(&arg, 0, sizeof(arg));
121 memset(&res, 0, sizeof(res));
123 arg.ca_version = NFSCTL_VERSION;
124 strncpy(arg.ca_getfs.gd_path, path,
125 sizeof(arg.ca_getfs.gd_path) - 1);
126 arg.ca_getfs.gd_path[sizeof (arg.ca_getfs.gd_path) - 1] = '\0';
127 memcpy(&arg.ca_getfs.gd_addr, sin, sizeof(*sin));
128 arg.ca_getfs.gd_maxlen = size;
130 if (nfsctl(NFSCTL_GETFS, &arg, &res) < 0)
133 return &res.cr_getfs;