1
/* ----------------------------------------------------------------------- *
3
* mount_changer.c - module for Linux automountd to mount filesystems
6
* Copyright 1999 Toby Jaffey - All Rights Reserved
7
* CD swapping code from linux kernel in Documentation/cdrom/ide-cd
8
* Based on code originally from Gerhard Zuber <zuber@berlin.snafu.de>.
9
* Changer status information, and rewrite for the new Uniform CDROM driver
10
* interface by Erik Andersen <andersee@debian.org>.
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
15
* USA; either version 2 of the License, or (at your option) any later
16
* version; incorporated herein by reference.
18
* ----------------------------------------------------------------------- */
23
#include <sys/param.h>
24
#include <sys/types.h>
27
#include <sys/ioctl.h>
28
#include <linux/cdrom.h>
31
#include "automount.h"
33
#define MODPREFIX "mount(changer): "
35
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
37
int swapCD(const char *device, const char *slotName);
39
int mount_init(void **context)
44
int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
45
const char *what, const char *fstype, const char *options, void *context)
47
char fullpath[PATH_MAX];
48
char buf[MAX_ERR_BUF];
50
int len, status, existed = 1;
52
if (ap->flags & MOUNT_FLAG_REMOUNT)
57
/* Root offset of multi-mount */
59
if (root[len - 1] == '/') {
60
len = snprintf(fullpath, len, "%s", root);
61
} else if (*name == '/') {
63
* Direct or offset mount, name is absolute path so
64
* don't use root (but with move mount changes root
65
* is now the same as name).
67
len = sprintf(fullpath, "%s", root);
69
len = sprintf(fullpath, "%s/%s", root, name);
73
debug(ap->logopt, MODPREFIX "calling umount %s", what);
75
err = spawn_umount(ap->logopt, what, NULL);
79
"umount of %s failed (all may be unmounted)",
83
debug(ap->logopt, MODPREFIX "calling mkdir_path %s", fullpath);
85
status = mkdir_path(fullpath, 0555);
86
if (status && errno != EEXIST) {
87
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
89
MODPREFIX "mkdir_path %s failed: %s", fullpath, estr);
96
debug(ap->logopt, MODPREFIX "Swapping CD to slot %s", name);
98
err = swapCD(what, name);
101
MODPREFIX "failed to swap CD to slot %s", name);
105
if (options && options[0]) {
107
MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
108
fstype, options, what, fullpath);
110
err = spawn_mount(ap->logopt, "-t", fstype,
111
SLOPPYOPT "-o", options, what, fullpath, NULL);
114
MODPREFIX "calling mount -t %s %s %s",
115
fstype, what, fullpath);
117
err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
121
info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
122
what, fstype, fullpath);
124
if (ap->type != LKP_INDIRECT)
127
if ((!(ap->flags & MOUNT_FLAG_GHOST) && name_len) || !existed)
128
rmdir_path(ap, fullpath, ap->dev);
132
info(ap->logopt, MODPREFIX "mounted %s type %s on %s",
133
what, fstype, fullpath);
138
int mount_done(void *context)
143
int swapCD(const char *device, const char *slotName)
145
int fd; /* file descriptor for CD-ROM device */
146
int status; /* return status for system calls */
148
int total_slots_available;
150
slot = atoi(slotName) - 1;
153
fd = open_fd(device, O_RDONLY | O_NONBLOCK);
155
logerr(MODPREFIX "Opening device %s failed : %s",
156
device, strerror(errno));
160
/* Check CD player status */
161
total_slots_available = ioctl(fd, CDROM_CHANGER_NSLOTS);
162
if (total_slots_available <= 1) {
164
"Device %s is not an ATAPI compliant CD changer.",
171
slot = ioctl(fd, CDROM_SELECT_DISC, slot);
173
logerr(MODPREFIX "CDROM_SELECT_DISC failed");
181
logerr(MODPREFIX "close failed for `%s': %s",
182
device, strerror(errno));