~ubuntu-branches/debian/wheezy/autofs/wheezy

« back to all changes in this revision

Viewing changes to modules/mount_ext2.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2008-03-08 01:36:09 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080308013609-cvs4f2ecoyoism02
Tags: 4.1.4+debian-2.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Add -DLDAP_DEPRECATED to CFLAGS, to fix compatibility with OpenLDAP
  2.4 on 64-bit architectures.  Closes: #463419.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ident "$Id: mount_ext2.c,v 1.18 2005/01/10 13:28:29 raven Exp $"
 
2
/* ----------------------------------------------------------------------- *
 
3
 *   
 
4
 *  mount_ext2.c - module for Linux automountd to mount ext2 filesystems
 
5
 *                 after running fsck on them.
 
6
 *
 
7
 *   Copyright 1998 Transmeta Corporation - All Rights Reserved
 
8
 *
 
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.
 
14
 *
 
15
 * ----------------------------------------------------------------------- */
 
16
 
 
17
#include <stdio.h>
 
18
#include <malloc.h>
 
19
#include <errno.h>
 
20
#include <fcntl.h>
 
21
#include <unistd.h>
 
22
#include <syslog.h>
 
23
#include <string.h>
 
24
#include <stdlib.h>
 
25
#include <sys/param.h>
 
26
#include <sys/types.h>
 
27
#include <sys/stat.h>
 
28
 
 
29
#define MODULE_MOUNT
 
30
#include "automount.h"
 
31
 
 
32
#define MODPREFIX "mount(ext2): "
 
33
 
 
34
int mount_version = AUTOFS_MOUNT_VERSION;       /* Required by protocol */
 
35
 
 
36
int mount_init(void **context)
 
37
{
 
38
        return 0;
 
39
}
 
40
 
 
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)
 
43
{
 
44
        char *fullpath;
 
45
        const char *p, *p1;
 
46
        int err, ro = 0;
 
47
        const char *fsck_prog;
 
48
        int status, existed = 1;
 
49
 
 
50
        fullpath = alloca(strlen(root) + name_len + 2);
 
51
        if (!fullpath) {
 
52
                error(MODPREFIX "alloca: %m");
 
53
                return 1;
 
54
        }
 
55
 
 
56
        if (name_len)
 
57
                sprintf(fullpath, "%s/%s", root, name);
 
58
        else
 
59
                sprintf(fullpath, "%s", root);
 
60
 
 
61
        debug(MODPREFIX "calling mkdir_path %s", fullpath);
 
62
 
 
63
        status = mkdir_path(fullpath, 0555);
 
64
        if (status && errno != EEXIST) {
 
65
                error(MODPREFIX "mkdir_path %s failed: %m", fullpath);
 
66
                return 1;
 
67
        }
 
68
 
 
69
        if (!status)
 
70
                existed = 0;
 
71
 
 
72
        if (is_mounted(_PATH_MOUNTED, fullpath)) {
 
73
                error(MODPREFIX 
 
74
                  "warning: %s is already mounted", fullpath);
 
75
                return 0;
 
76
        }
 
77
 
 
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"))
 
81
                                ro = 1;
 
82
                if (!strcmp(p, "ro"))
 
83
                        ro = 1;
 
84
        }
 
85
 
 
86
#ifdef HAVE_E3FSCK
 
87
        if (!strcmp(fstype,"ext3") || !strcmp(fstype,"auto"))
 
88
                fsck_prog = PATH_E3FSCK;
 
89
        else
 
90
                fsck_prog = PATH_E2FSCK;
 
91
#else
 
92
        fsck_prog = PATH_E2FSCK;
 
93
#endif
 
94
        if (ro) {
 
95
                debug(MODPREFIX "calling %s -n %s", fsck_prog, what);
 
96
                err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-n", what, NULL);
 
97
        } else {
 
98
                debug(MODPREFIX "calling %s -p %s", fsck_prog, what);
 
99
                err = spawnl(LOG_DEBUG, fsck_prog, fsck_prog, "-p", what, NULL);
 
100
        }
 
101
 
 
102
        if (err & ~6) {
 
103
                error(MODPREFIX "%s: filesystem needs repair, won't mount",
 
104
                      what);
 
105
                return 1;
 
106
        }
 
107
 
 
108
        if (options) {
 
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);
 
114
        } else {
 
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);
 
120
        }
 
121
 
 
122
        if (err) {
 
123
                if ((!ap.ghost && name_len) || !existed)
 
124
                        rmdir_path(name);
 
125
                error(MODPREFIX "failed to mount %s (type %s) on %s",
 
126
                      what, fstype, fullpath);
 
127
                return 1;
 
128
        } else {
 
129
                debug(MODPREFIX "mounted %s type %s on %s",
 
130
                      what, fstype, fullpath);
 
131
                return 0;
 
132
        }
 
133
}
 
134
 
 
135
int mount_done(void *context)
 
136
{
 
137
        return 0;
 
138
}