|
Packit |
8480eb |
/* ----------------------------------------------------------------------- *
|
|
Packit |
8480eb |
*
|
|
Packit |
8480eb |
* mount_ext2.c - module for Linux automountd to mount ext2 filesystems
|
|
Packit |
8480eb |
* after running fsck on them.
|
|
Packit |
8480eb |
*
|
|
Packit |
8480eb |
* Copyright 1998 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; incorporated herein by reference.
|
|
Packit |
8480eb |
*
|
|
Packit |
8480eb |
* ----------------------------------------------------------------------- */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#include <stdio.h>
|
|
Packit |
8480eb |
#include <malloc.h>
|
|
Packit |
8480eb |
#include <string.h>
|
|
Packit |
8480eb |
#include <stdlib.h>
|
|
Packit |
8480eb |
#include <sys/param.h>
|
|
Packit |
8480eb |
#include <sys/types.h>
|
|
Packit |
8480eb |
#include <sys/stat.h>
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define MODULE_MOUNT
|
|
Packit |
8480eb |
#include "automount.h"
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define MODPREFIX "mount(ext2): "
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int mount_init(void **context)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
return 0;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int mount_reinit(void **context)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
return 0;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int mount_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, void *context)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
char fullpath[PATH_MAX];
|
|
Packit |
8480eb |
char buf[MAX_ERR_BUF];
|
|
Packit |
8480eb |
const char *p, *p1;
|
|
Packit |
8480eb |
int err, ro = 0;
|
|
Packit |
8480eb |
const char *fsck_prog;
|
|
Packit |
8480eb |
int len, status, existed = 1;
|
|
Packit Service |
1592bd |
void (*mountlog)(unsigned int, const char*, ...) = &log_debug;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (ap->flags & MOUNT_FLAG_REMOUNT)
|
|
Packit |
8480eb |
return 0;
|
|
Packit |
8480eb |
|
|
Packit Service |
1592bd |
if (defaults_get_mount_verbose())
|
|
Packit Service |
1592bd |
mountlog = &log_info;
|
|
Packit Service |
1592bd |
|
|
Packit |
8480eb |
/* Root offset of multi-mount */
|
|
Packit |
8480eb |
len = strlen(root);
|
|
Packit |
8480eb |
if (root[len - 1] == '/') {
|
|
Packit |
8480eb |
len = snprintf(fullpath, len, "%s", root);
|
|
Packit |
8480eb |
} else if (*name == '/') {
|
|
Packit |
8480eb |
/*
|
|
Packit |
8480eb |
* Direct or offset mount, name is absolute path so
|
|
Packit |
8480eb |
* don't use root (but with move mount changes root
|
|
Packit |
8480eb |
* is now the same as name).
|
|
Packit |
8480eb |
*/
|
|
Packit |
8480eb |
len = sprintf(fullpath, "%s", root);
|
|
Packit |
8480eb |
} else {
|
|
Packit |
8480eb |
len = sprintf(fullpath, "%s/%s", root, name);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
fullpath[len] = '\0';
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);
|
|
Packit |
8480eb |
|
|
Packit Service |
a565d0 |
status = mkdir_path(fullpath, mp_mode);
|
|
Packit |
8480eb |
if (status && errno != EEXIST) {
|
|
Packit |
8480eb |
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
Packit |
8480eb |
error(ap->logopt,
|
|
Packit |
8480eb |
MODPREFIX "mkdir_path %s failed: %s", fullpath, estr);
|
|
Packit |
8480eb |
return 1;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (!status)
|
|
Packit |
8480eb |
existed = 0;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (options && options[0]) {
|
|
Packit |
8480eb |
for (p = options; (p1 = strchr(p, ',')); p = p1)
|
|
Packit |
8480eb |
if (!_strncmp("ro", p, p1 - p) && ++p1 - p == sizeof("ro"))
|
|
Packit |
8480eb |
ro = 1;
|
|
Packit |
8480eb |
if (!strcmp(p, "ro"))
|
|
Packit |
8480eb |
ro = 1;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
fsck_prog = PATH_E2FSCK;
|
|
Packit |
8480eb |
#ifdef HAVE_E3FSCK
|
|
Packit |
8480eb |
if (!strcmp(fstype,"ext3"))
|
|
Packit |
8480eb |
fsck_prog = PATH_E3FSCK;
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
#ifdef HAVE_E4FSCK
|
|
Packit |
8480eb |
if (!strcmp(fstype,"ext4"))
|
|
Packit |
8480eb |
fsck_prog = PATH_E4FSCK;
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
if (ro) {
|
|
Packit |
8480eb |
debug(ap->logopt,
|
|
Packit |
8480eb |
MODPREFIX "calling %s -n %s", fsck_prog, what);
|
|
Packit |
8480eb |
err = spawnl(ap->logopt, fsck_prog, fsck_prog, "-n", what, NULL);
|
|
Packit |
8480eb |
} else {
|
|
Packit |
8480eb |
debug(ap->logopt,
|
|
Packit |
8480eb |
MODPREFIX "calling %s -p %s", fsck_prog, what);
|
|
Packit |
8480eb |
err = spawnl(ap->logopt, fsck_prog, fsck_prog, "-p", what, NULL);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/*
|
|
Packit |
8480eb |
* spawnl returns the error code, left shifted by 8 bits. We are
|
|
Packit |
8480eb |
* interested in the following error bits from the fsck program:
|
|
Packit |
8480eb |
* 2 - File system errors corrected, system should be rebooted
|
|
Packit |
8480eb |
* 4 - File system errors left uncorrected
|
|
Packit |
8480eb |
*/
|
|
Packit |
8480eb |
if ((err >> 8) & 6) {
|
|
Packit |
8480eb |
error(ap->logopt,
|
|
Packit |
8480eb |
MODPREFIX "%s: filesystem needs repair, won't mount",
|
|
Packit |
8480eb |
what);
|
|
Packit |
8480eb |
return 1;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (options) {
|
|
Packit Service |
1592bd |
mountlog(ap->logopt, MODPREFIX
|
|
Packit Service |
1592bd |
"calling mount -t %s -o %s %s %s",
|
|
Packit Service |
1592bd |
fstype, options, what, fullpath);
|
|
Packit |
8480eb |
err = spawn_mount(ap->logopt, "-t", fstype,
|
|
Packit |
8480eb |
"-o", options, what, fullpath, NULL);
|
|
Packit |
8480eb |
} else {
|
|
Packit Service |
1592bd |
mountlog(ap->logopt,
|
|
Packit Service |
1592bd |
MODPREFIX "calling mount -t %s %s %s",
|
|
Packit Service |
1592bd |
fstype, what, fullpath);
|
|
Packit |
8480eb |
err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (err) {
|
|
Packit |
8480eb |
info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
|
|
Packit |
8480eb |
what, fstype, fullpath);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if (ap->type != LKP_INDIRECT)
|
|
Packit |
8480eb |
return 1;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
if ((!(ap->flags & MOUNT_FLAG_GHOST) && name_len) || !existed)
|
|
Packit |
8480eb |
rmdir_path(ap, fullpath, ap->dev);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
return 1;
|
|
Packit |
8480eb |
} else {
|
|
Packit |
8480eb |
debug(ap->logopt,
|
|
Packit |
8480eb |
MODPREFIX "mounted %s type %s on %s",
|
|
Packit |
8480eb |
what, fstype, fullpath);
|
|
Packit |
8480eb |
return 0;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int mount_done(void *context)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
return 0;
|
|
Packit |
8480eb |
}
|