1
#ident "$Id: mount_ext2.c,v 1.18 2005/01/10 13:28:29 raven Exp $"
2
/* ----------------------------------------------------------------------- *
4
* mount_ext2.c - module for Linux automountd to mount ext2 filesystems
5
* after running fsck on them.
7
* Copyright 1998 Transmeta Corporation - All Rights Reserved
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
12
* USA; either version 2 of the License, or (at your option) any later
13
* version; incorporated herein by reference.
15
* ----------------------------------------------------------------------- */
25
#include <sys/param.h>
26
#include <sys/types.h>
30
#include "automount.h"
32
#define MODPREFIX "mount(ext2): "
34
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
36
int mount_init(void **context)
41
int mount_mount(const char *root, const char *name, int name_len,
42
const char *what, const char *fstype, const char *options, void *context)
47
const char *fsck_prog;
48
int status, existed = 1;
50
fullpath = alloca(strlen(root) + name_len + 2);
52
error(MODPREFIX "alloca: %m");
57
sprintf(fullpath, "%s/%s", root, name);
59
sprintf(fullpath, "%s", root);
61
debug(MODPREFIX "calling mkdir_path %s", fullpath);
63
status = mkdir_path(fullpath, 0555);
64
if (status && errno != EEXIST) {
65
error(MODPREFIX "mkdir_path %s failed: %m", fullpath);
72
if (is_mounted(_PATH_MOUNTED, fullpath)) {
74
"warning: %s is already mounted", fullpath);
78
if (options && options[0]) {
79
for (p = options; (p1 = strchr(p, ',')); p = p1)
80
if (!strncmp(p, "ro", p1 - p) && ++p1 - p == sizeof("ro"))
87
if (!strcmp(fstype,"ext3") || !strcmp(fstype,"auto"))
88
fsck_prog = PATH_E3FSCK;
90
fsck_prog = PATH_E2FSCK;
92
fsck_prog = PATH_E2FSCK;
95
debug(MODPREFIX "calling %s -n %s", fsck_prog, what);
96
err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-n", what, NULL);
98
debug(MODPREFIX "calling %s -p %s", fsck_prog, what);
99
err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-p", what, NULL);
103
error(MODPREFIX "%s: filesystem needs repair, won't mount",
109
debug(MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
110
fstype, options, what, fullpath);
111
err = spawnll(LOG_NOTICE,
112
PATH_MOUNT, PATH_MOUNT, "-t", fstype,
113
SLOPPYOPT "-o", options, what, fullpath, NULL);
115
debug(MODPREFIX "calling mount -t %s %s %s",
116
fstype, what, fullpath);
117
err = spawnll(LOG_NOTICE,
118
PATH_MOUNT, PATH_MOUNT, "-t", fstype,
119
what, fullpath, NULL);
123
if ((!ap.ghost && name_len) || !existed)
125
error(MODPREFIX "failed to mount %s (type %s) on %s",
126
what, fstype, fullpath);
129
debug(MODPREFIX "mounted %s type %s on %s",
130
what, fstype, fullpath);
135
int mount_done(void *context)