aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>1998-04-02 05:01:25 +0000
committerH. Peter Anvin <hpa@zytor.com>1998-04-02 05:01:25 +0000
commite5ba2317f9c9fea3111616496d3ddbcedf39b95e (patch)
treecd9ca33273f014b911c83d61acf733bb0564f7e9 /modules
parente954633943f5975462a138324a7a14b75e5d87f1 (diff)
downloadautofs3-e5ba2317f9c9fea3111616496d3ddbcedf39b95e.tar.gz
autofs3-e5ba2317f9c9fea3111616496d3ddbcedf39b95e.tar.xz
autofs3-e5ba2317f9c9fea3111616496d3ddbcedf39b95e.zip
Starting on the CD-changer module
Diffstat (limited to 'modules')
-rw-r--r--modules/mount_cdchanger.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/modules/mount_cdchanger.c b/modules/mount_cdchanger.c
new file mode 100644
index 0000000..0f4e271
--- /dev/null
+++ b/modules/mount_cdchanger.c
@@ -0,0 +1,107 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * mount_cdchanger.c - Mount different slots in a CD-changer
+ *
+ * Copyright 1998 Transmeta Corporation - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ * USA; either version 2 of the License, or (at your option) any later
+ * version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <malloc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define MODULE_MOUNT
+#include "automount.h"
+
+#define MODPREFIX "mount(cdchanger): "
+int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
+
+#define FSTYPE "iso9660" /* Real filesystem type */
+
+int mount_init(void **context)
+{
+ return 0;
+}
+
+int mount_mount(const char *root, const char *name, int name_len,
+ const char *what, const char *fstype, const char *options,
+ void *context)
+{
+ char *fullpath, *slotstr, *device, *colon;
+ int err;
+
+ fullpath = alloca(strlen(root)+name_len+2);
+ slotstr = alloca(strlen(what)+1);
+ if ( !fullpath || !slotstr ) {
+ syslog(LOG_ERR, MODPREFIX "alloca: %m");
+ return 1;
+ }
+ sprintf(fullpath, "%s/%s", root, name);
+
+ strcpy(slotstr, what);
+ colon = strchr(slotstr, ':');
+ if ( !colon || colon[1] != '/' ) {
+ syslog(LOG_ERR, MODPREFIX "entry %s -> %s not in slot:device format",
+ fullpath, slotstr);
+ return 1;
+ }
+ *colon = '\0';
+ device = colon+1;
+
+
+
+ syslog(LOG_DEBUG, MODPREFIX "calling mkdir %s", fullpath);
+ if ( mkdir(fullpath, 0555) && errno != EEXIST ) {
+ syslog(LOG_NOTICE, MODPREFIX "mkdir %s failed: %m", name);
+ return 1;
+ }
+
+ syslog(LOG_DEBUG, MODPREFIX "calling fsck.ext2 -p %s", what);
+ err = spawnl(LOG_DEBUG, PATH_E2FSCK, PATH_E2FSCK, "-p", what, NULL);
+ if ( err & ~7 ) {
+ syslog(LOG_ERR, MODPREFIX "%s: filesystem needs repair, won't mount",
+ what);
+ return 1;
+ }
+
+ if ( options ) {
+ syslog(LOG_DEBUG, MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
+ fstype, options, what, fullpath);
+ err = spawnl(LOG_NOTICE, PATH_MOUNT, PATH_MOUNT, "-t", fstype,
+ SLOPPYOPT "-o", options, what, fullpath, NULL);
+ } else {
+ syslog(LOG_DEBUG, MODPREFIX "calling mount -t %s %s %s",
+ fstype, what, fullpath);
+ err = spawnl(LOG_NOTICE, PATH_MOUNT, PATH_MOUNT, "-t", fstype,
+ what, fullpath, NULL);
+ }
+ if ( err ) {
+ rmdir(fullpath);
+ syslog(LOG_NOTICE, MODPREFIX "failed to mount %s (type %s) on %s",
+ what, fstype, fullpath);
+ return 1;
+ } else {
+ syslog(LOG_DEBUG, MODPREFIX "mounted %s type %s on %s",
+ what, fstype, fullpath);
+ return 0;
+ }
+}
+
+int mount_done(void *context)
+{
+ return 0;
+}