Blame daemon/mount.c

Packit 8480eb
/* ----------------------------------------------------------------------- *
Packit 8480eb
 *   
Packit 8480eb
 *  mount.c - Abstract mount code used by modules for an unexpected
Packit 8480eb
 *            filesystem type
Packit 8480eb
 *
Packit 8480eb
 *   Copyright 1997-2000 Transmeta Corporation - All Rights Reserved
Packit 8480eb
 *
Packit 8480eb
 *   This program is free software; you can redistribute it and/or modify
Packit 8480eb
 *   it under the terms of the GNU General Public License as published by
Packit 8480eb
 *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
Packit 8480eb
 *   USA; either version 2 of the License, or (at your option) any later
Packit 8480eb
 *   version.
Packit 8480eb
 *   
Packit 8480eb
 *   This program is distributed in the hope that it will be useful,
Packit 8480eb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8480eb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8480eb
 *   GNU General Public License for more details.
Packit 8480eb
 *
Packit 8480eb
 * ----------------------------------------------------------------------- */
Packit 8480eb
Packit 8480eb
#include <stdlib.h>
Packit 8480eb
#include <string.h>
Packit 8480eb
#include "automount.h"
Packit 8480eb
Packit 8480eb
#define ERR_PREFIX	"(mount):"
Packit 8480eb
Packit 8480eb
/* These filesystems are known not to work with the "generic" module */
Packit 8480eb
/* Note: starting with Samba 2.0.6, smbfs is handled generically.    */
Packit 8480eb
static char *not_generic[] = { "nfs", "userfs", "afs", "autofs",
Packit 8480eb
			       "changer", "bind", NULL
Packit 8480eb
};
Packit 8480eb
Packit 8480eb
int do_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
Packit 8480eb
	     const char *what, const char *fstype, const char *options)
Packit 8480eb
{
Packit 8480eb
	struct mount_mod *mod;
Packit 8480eb
	const char *modstr;
Packit 8480eb
	size_t root_len = root ? strlen(root) : 0;
Packit 8480eb
	char **ngp;
Packit 8480eb
	int rv;
Packit 8480eb
Packit 8480eb
	/* Initially look for a mount module but don't issue an error on fail */
Packit 8480eb
	mod = open_mount(modstr = fstype, NULL);
Packit 8480eb
	if (!mod) {
Packit 8480eb
		for (ngp = not_generic; *ngp; ngp++) {
Packit 8480eb
			if (!strcmp(fstype, *ngp))
Packit 8480eb
				break;
Packit 8480eb
		}
Packit 8480eb
		/*
Packit 8480eb
		 * If there's not a known mount module use the generic module,
Packit 8480eb
		 * otherwise redo the fs mount module with error reporting
Packit 8480eb
		 */
Packit 8480eb
		if (!*ngp)
Packit 8480eb
			mod = open_mount(modstr = "generic", ERR_PREFIX);
Packit 8480eb
		else
Packit 8480eb
			mod = open_mount(modstr = fstype, ERR_PREFIX);
Packit 8480eb
		if (!mod) {
Packit 8480eb
			error(ap->logopt,
Packit 8480eb
			      "cannot find mount method for filesystem %s",
Packit 8480eb
			      fstype);
Packit 8480eb
			return -1;
Packit 8480eb
		}
Packit 8480eb
	}
Packit 8480eb
Packit 8480eb
	if (*name == '/')
Packit 8480eb
		debug(ap->logopt,
Packit 8480eb
		      "%s %s type %s options %s using module %s",
Packit 8480eb
		      what, name, fstype, options, modstr);
Packit 8480eb
	else if (root_len > 1 && root[root_len - 1] == '/')
Packit 8480eb
		debug(ap->logopt,
Packit 8480eb
		      "%s %s type %s options %s using module %s",
Packit 8480eb
		      what, root, fstype, options, modstr);
Packit 8480eb
	else
Packit 8480eb
		debug(ap->logopt,
Packit 8480eb
		      "%s %s/%s type %s options %s using module %s",
Packit 8480eb
		      what, root, name, fstype, options, modstr);
Packit 8480eb
Packit 8480eb
	rv = mod->mount_mount(ap, root, name, name_len, what, fstype, options, mod->context);
Packit 8480eb
	close_mount(mod);
Packit 8480eb
Packit 8480eb
	return rv;
Packit 8480eb
}