--- nfsmount-citi.c Mon Aug 28 17:22:37 2006 +++ nfsmount.c Mon Aug 28 18:20:50 2006 @@ -113,6 +113,39 @@ int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int); +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; +} + /* Convert RPC errors into strings */ void rpc_strerror(void) { @@ -548,6 +581,9 @@ 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, @@ -605,6 +641,8 @@ mnt_pmap->pm_vers = val; 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; @@ -695,6 +733,8 @@ *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) @@ -960,6 +1000,17 @@ /* 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 @@ -1021,6 +1072,7 @@ goto fail; } + gothandle: if (nfs_pmap->pm_vers == 2) { if (mntres.nfsv2.fhs_status != 0) { fprintf(stderr, @@ -1084,6 +1136,11 @@ (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 }