summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2005-07-19 11:14:12 -0400
committerKay Sievers <kay.sievers@suse.de>2005-07-19 11:14:12 -0400
commitbf375e3af65f0e9728516a3627613fb95288c1d1 (patch)
tree04747054c3d536c87374a3ee0bfc9e564135128b
parent6a5aac78f4d04490fc1d0178b1d7c0cb415c2944 (diff)
create_floppy_devices: add tool to create floppy nodes based on sysfs info
-rw-r--r--extras/floppy/Makefile52
-rw-r--r--extras/floppy/create_floppy_devices.c136
-rwxr-xr-xtest/simple-build-check.sh1
3 files changed, 189 insertions, 0 deletions
diff --git a/extras/floppy/Makefile b/extras/floppy/Makefile
new file mode 100644
index 0000000000..2601eeeb55
--- /dev/null
+++ b/extras/floppy/Makefile
@@ -0,0 +1,52 @@
+# Makefile for create_floppy_devices
+#
+# Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+#
+# 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; version 2 of the License.
+#
+
+PROG = create_floppy_devices
+
+all: $(PROG)
+
+prefix =
+exec_prefix = ${prefix}
+etcdir = ${prefix}/etc
+sbindir = ${exec_prefix}/sbin
+usrbindir = ${exec_prefix}/usr/bin
+usrsbindir = ${exec_prefix}/usr/sbin
+mandir = ${prefix}/usr/share/man
+devddir = ${etcdir}/dev.d/default
+configdir = ${etcdir}/udev/
+initdir = ${etcdir}/init.d/
+srcdir = .
+
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALL_SCRIPT = ${INSTALL_PROGRAM}
+
+CFLAGS+=-D_FILE_OFFSET_BITS=64
+
+OBJS = $(PROG).o ../../udev.a
+
+$(OBJS): $(HEADERS)
+
+.c.o:
+ $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
+
+$(PROG): $(OBJS) $(HEADERS)
+ $(QUIET) $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIB_OBJS)
+
+clean:
+ rm -f $(PROG) $(OBJS)
+
+spotless: clean
+
+install: all
+ $(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(sbindir)/$(PROG)
+
+uninstall:
+ - rm $(DESTDIR)$(sbindir)/$(PROG)
diff --git a/extras/floppy/create_floppy_devices.c b/extras/floppy/create_floppy_devices.c
new file mode 100644
index 0000000000..f4003c2ce2
--- /dev/null
+++ b/extras/floppy/create_floppy_devices.c
@@ -0,0 +1,136 @@
+/*
+ * create_floppy_devices
+ *
+ * Create all possible floppy device based on the CMOS type.
+ * Based upon code from drivers/block/floppy.c
+ *
+ * Copyright(C) 2005, SUSE Linux Products GmbH
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Hannes Reinecke <hare@suse.de>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+static char *table[] = {
+ "", "d360", "h1200", "u360", "u720", "h360", "h720",
+ "u1440", "u2880", "CompaQ", "h1440", "u1680", "h410",
+ "u820", "h1476", "u1722", "h420", "u830", "h1494", "u1743",
+ "h880", "u1040", "u1120", "h1600", "u1760", "u1920",
+ "u3200", "u3520", "u3840", "u1840", "u800", "u1600",
+ NULL
+};
+
+static int t360[] = { 1 };
+static int t1200[] = { 2, 5, 6, 10, 12, 14, 16, 18, 20, 23 };
+static int t3in[] = { 8, 9, 26, 27, 28, 7, 11, 15, 19, 24, 25, 29, 31, 3, 4, 13, 17, 21, 22, 30 };
+
+static int *table_sup[] = { NULL, t360, t1200, t3in + 5 + 8, t3in + 5, t3in, t3in };
+
+int main(int argc, char **argv)
+{
+ char *dev;
+ char node[64];
+ int type = 0, i, fdnum, c;
+ int major = 2, minor;
+ int mode = 0;
+ int create_nodes = 0;
+ int print_nodes = 0;
+ int unlink_nodes = 0;
+ int is_err = 0;
+
+ while ((c = getopt(argc, argv, "cdm:M:t:u")) != -1) {
+ switch (c) {
+ case 'c':
+ create_nodes = 1;
+ unlink_nodes = 0;
+ break;
+ case 'd':
+ print_nodes = 1;
+ break;
+ case 'M':
+ mode = strtol(optarg, NULL, 10);
+ break;
+ case 'm':
+ major = strtol(optarg, NULL, 10);
+ break;
+ case 't':
+ type = strtol(optarg, NULL, 10);
+ break;
+ case 'u':
+ unlink_nodes = 1;
+ create_nodes = 0;
+ break;
+ default:
+ is_err++;
+ break;
+ }
+ }
+
+ if (is_err || optind >= argc) {
+ fprintf(stderr,"Usage: %s [-d|-c|-u|-m <major>|-t <type>] <device>\n",
+ argv[0]);
+ return 1;
+ }
+
+ dev = argv[optind];
+ if (dev[strlen(dev) - 3] != 'f' || dev[strlen(dev) -2 ] != 'd') {
+ fprintf(stderr,"Device '%s' is not a floppy device\n", dev);
+ return 1;
+ }
+
+ fdnum = strtol(dev + 2, NULL, 10);
+ if (fdnum < 0 || fdnum > 7) {
+ fprintf(stderr,"Floppy device number %d out of range (0-7)\n", fdnum);
+ return 1;
+ }
+ if (fdnum > 3)
+ fdnum += 128;
+
+ if (major < 1) {
+ fprintf(stderr,"Invalid major number %d\n", major);
+ return 1;
+ }
+
+ if (type < 0 || type > (int) sizeof(table)) {
+ fprintf(stderr,"Invalid CMOS type %d\n", type);
+ return 1;
+ }
+
+ if (type == 0)
+ return 0;
+
+ i = 0;
+ while (table_sup[type][i]) {
+ sprintf(node,"%s%s",dev,table[table_sup[type][i]]);
+ minor = (table_sup[type][i] << 2) + fdnum;
+ if (print_nodes)
+ printf("%s b %d %d %d\n", node, mode, major, minor);
+ if (create_nodes)
+ mknod(node, S_IFBLK | mode, makedev(major,minor));
+ i++;
+ }
+
+ return 0;
+}
+
diff --git a/test/simple-build-check.sh b/test/simple-build-check.sh
index 7e9a940f85..742b28ec1c 100755
--- a/test/simple-build-check.sh
+++ b/test/simple-build-check.sh
@@ -7,6 +7,7 @@ EXTRAS="\
extras/volume_id \
extras/usb_id \
extras/dasd_id \
+ extras/floppy \
extras/run_directory"
[ -z "$KERNEL_DIR" ] && KERNEL_DIR=/lib/modules/`uname -r`/build