From daebb8f83a8c48771933c98a4ae25c7008362180 Mon Sep 17 00:00:00 2001 From: Jim Rees Date: Thu, 5 Apr 2012 22:53:49 -0400 Subject: [PATCH] add "gethandle" and "handle=" options Signed-off-by: Jim Rees --- utils/mount/nfsmount.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c index 930622d..4891424 100644 --- a/utils/mount/nfsmount.c +++ b/utils/mount/nfsmount.c @@ -103,6 +103,39 @@ extern char *progname; extern int verbose; extern int sloppy; +char * +fhtoa(u_char *fh, int fhn) +{ + int i; + char *s; + + s = (char *) malloc(fhn * 2 + 2); + s[0] = '\0'; + for (i = 0; i < fhn; i++) + sprintf(&s[i * 2], "%02.2x", (int) fh[i]); + return s; +} + +u_char * +atofh(char *a, int *fhnp) +{ + int b, fhn = 0; + u_char *fh; + + fh = (u_char *) malloc(strlen(a) / 2 + 1); + while (1) { + if (sscanf(&a[fhn * 2], "%2x", &b) != 1) + break; + fh[fhn++] = b; + } + *fhnp = fhn; + if (fhn <= 0) { + free(fh); + return NULL; + } + return fh; +} + static inline enum clnt_stat nfs3_mount(CLIENT *clnt, mnt3arg_t *mnt3arg, mnt3res_t *mnt3res) { @@ -161,6 +194,9 @@ nfs_call_mount(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server, return 0; } +u_char *handle; +int gethandle, handlelen; + static int parse_options(char *old_opts, struct nfs_mount_data *data, int *bg, int *retry, clnt_addr_t *mnt_server, @@ -237,6 +273,8 @@ parse_options(char *old_opts, struct nfs_mount_data *data, mounthost=xstrndup(opteq+1, strcspn(opteq+1," \t\n\r,")); else if (!strcmp(opt, "nfsprog")) nfs_pmap->pm_prog = val; + else if (!strcmp(opt, "handle")) + handle = atofh(opteq+1, &handlelen); else if (!strcmp(opt, "nfsvers") || !strcmp(opt, "vers")) { nfs_pmap->pm_vers = val; @@ -341,6 +379,8 @@ parse_options(char *old_opts, struct nfs_mount_data *data, *bg = val; else if (!strcmp(opt, "fg")) *bg = !val; + else if (!strcmp(opt, "gethandle")) + gethandle = val; else if (!strcmp(opt, "soft")) { data->flags &= ~NFS_MOUNT_SOFT; if (val) @@ -630,6 +670,17 @@ nfsmount(const char *spec, const char *node, int flags, /* create mount deamon client */ + if (handle != NULL) { + if (nfs_pmap->pm_vers < 3) + nfs_pmap->pm_vers = 3; + if (nfs_pmap->pm_port == 0) + nfs_pmap->pm_port = NFS_PORT; + memset(&mntres, 0, sizeof(mntres)); + mntres.nfsv3.mountres3_u.mountinfo.fhandle.fhandle3_val = handle; + mntres.nfsv3.mountres3_u.mountinfo.fhandle.fhandle3_len = handlelen; + goto gothandle; + } + /* * The following loop implements the mount retries. On the first * call, "running_bg" is 0. When the mount times out, and the @@ -709,6 +760,7 @@ nfsmount(const char *spec, const char *node, int flags, rpc_mount_errors(*nfs_server.hostname, 1, bg); } + gothandle: if (mnt_pmap->pm_vers <= 2) { if (mntres.nfsv2.fhs_status != 0) { nfs_error(_("%s: %s:%s failed, reason given by server: %s"), @@ -780,6 +832,11 @@ noauth_flavors: (char *) fhandle->fhandle3_val, fhandle->fhandle3_len); + if (gethandle) { + printf("%s\n", + fhtoa((u_char *) fhandle->fhandle3_val, fhandle->fhandle3_len)); + goto fail; + } data.flags |= NFS_MOUNT_VER3; #endif } -- 1.7.5.4