mount_nfs.c revision b9238976491622ad75a67ab0c12edf99e36212b9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* mount_nfs.c - procedural interface to the NFS mount operation
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define NFSCLIENT
#include <memory.h>
#include <netconfig.h>
#include <netdb.h>
#include <netdir.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include <rpc/clnt_soc.h>
#include <rpc/pmap_prot.h>
#include <errno.h>
#include <deflt.h>
static void free_knconf(struct knetconfig *k);
extern void set_nfsv4_ephemeral_mount_to(void);
#define TIME_MAX 16
extern int Debug;
extern void errprintf(char *, char *, ...);
void netbuf_free(struct netbuf *);
void free_knconf(struct knetconfig *);
/*
* mount_nfs - mount a file system using NFS
*
* Returns: 0 if OK, 1 if error.
* The "error" string returns the error message.
*/
int
{
struct sockaddr_in sin;
char host[256];
char *path;
char opts[32];
int s = -1;
int printed1 = 0;
int printed2 = 0;
int flags;
char *fstype;
int *auths;
int count;
if (Debug)
return (1);
}
*path = '\0';
*path++ = ':';
if (*path == '\0') {
/*
* handle the special case of importing a root file system
*/
}
if (Debug) {
}
/*
* Get server's address
*/
return (1);
}
if (Debug) {
else
"h_addrtype AF_INET\n\th_adth_length %u\n\t",
else
else
}
return (1);
}
if (Debug)
printf("pingnfs: succeeds.\n");
if (Debug)
"udp");
clnt_spcreateerror("mount server not responding"));
return (1);
}
if (Debug)
if (bindudp_resvport(client) < 0) {
"Couldn't bind to reserved port");
if (Debug)
printf("could not bind to reserved port\n");
return (1);
}
"Couldn't create authsys structure");
if (Debug)
printf("could not create authsys structure\n");
return (1);
}
/*
* #ifdef NOWAY
* if (Debug)
* printf("authsys_create_default called for mountproc\n");
* client->cl_auth = authsys_create_default();
* #endif
*/
/* set mount args */
/* Get fhandle of remote path from server's mountd */
switch (vers) {
case MOUNTVERS:
case MOUNTVERS_POSIX:
if (rpc_stat != RPC_SUCCESS) {
/*
* Given the way "clnt_sperror" works, the "%s"
* following the "not responding" is correct.
*/
return (1);
}
"rexd mount: not in EXPORT list for %s\n",
fsname);
} else {
}
return (1);
}
break;
case MOUNTVERS3:
xdr_dirpath, (char *)&path,
if (rpc_stat != RPC_SUCCESS) {
/*
* Given the way "clnt_sperror" works, the "%s"
* following the "not responding" is correct.
*/
return (1);
}
"rexd mount: not in EXPORT list for %s\n",
fsname);
} else {
}
return (1);
}
auths =
count =
if (count > 0) {
}
break;
default:
vers);
return (1);
}
/*
* remote mount the fhandle on the local path.
*/
return (1);
}
return (1);
}
if (Debug)
/*
* And make sure that we have the ephemeral mount_to
* set for this zone.
*/
/* Provide the mounted resource name when mounting. */
return (1);
}
if (Debug)
/*
* stat the new mount and get its dev
*/
return (1);
}
if (Debug)
/*
*/
return (0);
}
#define UNMOUNTTRIES 6
/*
* umount_nfs - unmount a file system when finished
*/
int
{
char *p;
char *hostname;
int s = -1;
int count = 0;
if (Debug)
/*
* Give the filesystem time to become un-busy when unmounting.
* If child aborted and is takes a core dump, we may receive the
* SIGCHLD before the core dump is completed.
*/
return (1);
}
if (++count > UNMOUNTTRIES)
return (1);
sleep(10);
}
if (Debug)
return (1);
*p++ = 0;
== NULL) {
clnt_spcreateerror("Warning on umount create:");
return (1);
}
if (bindudp_resvport(client) < 0) {
"Could not bind to reserved port\n");
return (1);
}
/*
* #ifdef NOWAWY
* client->cl_auth = authunix_create_default();
* #endif
*/
if (rpc_stat != RPC_SUCCESS) {
return (1);
}
return (0);
}
static struct mnttab *
{
void freemnttab();
goto alloc_failed;
goto alloc_failed;
goto alloc_failed;
goto alloc_failed;
goto alloc_failed;
goto alloc_failed;
return (new);
return (NULL);
}
/*
* Free a single mnttab structure
*/
static void
{
if (mnt) {
if (mnt->mnt_special)
if (mnt->mnt_mountp)
if (mnt->mnt_fstype)
if (mnt->mnt_mntopts)
}
}
/* the following structure is used to build a list of */
struct mntlist {
};
/*
* Free a list of mnttab structures
*/
static void
{
while (mntl) {
}
}
/*
* connect to the give host and look for the exported file system
* that matches.
* Returns: pointer to string containing the part of the pathname
* within the exported directory.
* Returns NULL on errors.
*/
char *
{
int err;
int bestlen = 0;
printf("parsefs of %s entered with errno %d %s\n",
return (NULL);
}
*dir++ = '\0';
if (Debug)
if (err == (int)RPC_TIMEDOUT)
fullname);
else
printf("parsefs: mount call to %s returned %d %s\n",
}
return (NULL);
}
if (Debug)
printf("parsefs: mount call to %s returned %d %s\n",
}
if (Debug)
printf("parsefs: checking export list:\n");
if (Debug)
}
if (bestlen == 0) {
return (NULL);
}
else {
}
*--dir = ':';
return (subdir);
}
/*
* Get the network address for the service identified by "prog"
* and "vers" on "hostname". The netconfig address is returned
* in the value of "nconfp".
* If the hostname is the same as the last call, then the same
* transport is used as last time (same netconfig entry).
*/
static struct netbuf *
{
struct netconfig *getnetconfig();
struct netconfig *getnetconfigent();
int fd = -1;
if (nc)
nc = setnetconfig();
goto done;
/*
* If the port number is specified then UDP is needed.
* Otherwise any connectionless transport will do.
*/
break;
}
}
goto done;
}
if (fd < 0)
goto done;
goto done;
goto retry;
}
/*
* Make a copy of the netbuf to return
*/
goto done;
}
goto done;
}
done:
if (tbind)
if (fd >= 0)
return (nb);
}
static struct knetconfig *
{
struct knetconfig *k;
return (NULL);
}
k = (struct knetconfig *)malloc(sizeof (*k));
if (k == NULL)
goto nomem;
if (k->knc_protofmly == NULL)
goto nomem;
goto nomem;
return (k);
free_knconf(k);
return (NULL);
}
static void
free_knconf(struct knetconfig *k)
{
if (k == NULL)
return;
if (k->knc_protofmly)
free(k->knc_protofmly);
if (k->knc_proto)
free(k);
}
static void
{
return;
}
static enum clnt_stat
{
return (RPC_SUCCESS);
return (RPC_TIMEDOUT);
if (Debug)
/* ping the NFS nullproc on the server */
NFS_VERSMAX, "udp");
if (Debug)
printf("clnt_create failed\n");
} else {
}
if (clnt_stat == RPC_SUCCESS) {
} else {
}
if (Debug)
"OK" : "NO RESPONSE");
return (clnt_stat);
}
{
int clfd;
int rv;
/* check for superuser as reserved ports are for superuser only */
if (geteuid()) {
return (-1);
}
"Could not get file dscriptor for client handle\n");
return (-1);
}
if (Debug)
return (-1);
}
}
return (-1);
}
if (Debug) {
printf("getnetconfigent success\n");
}
(char *)NULL)) == -1) {
if (Debug) {
}
return (-1);
}
if (Debug)
return (0);
}