2 * create_floppy_devices
4 * Create all possible floppy device based on the CMOS type.
5 * Based upon code from drivers/block/floppy.c
7 * Copyright(C) 2005, SUSE Linux Products GmbH
10 * Hannes Reinecke <hare@suse.de>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation version 2 of the License.
19 #include <sys/types.h>
28 #include "libudev-private.h"
30 static char *table[] = {
31 "", "d360", "h1200", "u360", "u720", "h360", "h720",
32 "u1440", "u2880", "CompaQ", "h1440", "u1680", "h410",
33 "u820", "h1476", "u1722", "h420", "u830", "h1494", "u1743",
34 "h880", "u1040", "u1120", "h1600", "u1760", "u1920",
35 "u3200", "u3520", "u3840", "u1840", "u800", "u1600",
39 static int t360[] = { 1, 0 };
40 static int t1200[] = { 2, 5, 6, 10, 12, 14, 16, 18, 20, 23, 0 };
41 static int t3in[] = { 8, 9, 26, 27, 28, 7, 11, 15, 19, 24, 25, 29, 31, 3, 4, 13, 17, 21, 22, 30, 0 };
42 static int *table_sup[] = { NULL, t360, t1200, t3in+5+8, t3in+5, t3in, t3in };
44 static void log_fn(struct udev *udev, int priority,
45 const char *file, int line, const char *fn,
46 const char *format, va_list args)
48 vsyslog(priority, format, args);
51 int main(int argc, char **argv)
57 int type = 0, i, fdnum, c;
70 udev_log_init("create_floppy_devices");
71 udev_set_log_fn(udev, log_fn);
72 udev_selinux_init(udev);
74 while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
83 uid = util_lookup_user(udev, optarg);
86 gid = util_lookup_group(udev, optarg);
89 mode = strtol(optarg, NULL, 0);
93 major = strtol(optarg, NULL, 0);
96 type = strtol(optarg, NULL, 0);
104 if (is_err || optind >= argc) {
105 printf("Usage: %s [OPTION] device\n"
109 " -t floppy type number\n"
110 " -U device node user ownership\n"
111 " -G device node group owner\n"
112 " -M device node mode\n"
118 devname = strrchr(dev, '/');
120 devname = &devname[1];
123 if (strncmp(devname, "fd", 2) != 0) {
124 fprintf(stderr,"Device '%s' is not a floppy device\n", dev);
128 fdnum = strtol(&devname[2], NULL, 10);
129 if (fdnum < 0 || fdnum > 7) {
130 fprintf(stderr,"Floppy device number %d out of range (0-7)\n", fdnum);
137 fprintf(stderr,"Invalid major number %d\n", major);
141 if (type < 0 || type >= (int) ARRAY_SIZE(table_sup)) {
142 fprintf(stderr,"Invalid CMOS type %d\n", type);
150 while (table_sup[type][i]) {
151 sprintf(node, "%s%s", dev, table[table_sup[type][i]]);
152 minor = (table_sup[type][i] << 2) + fdnum;
154 printf("%s b %.4o %d %d\n", node, mode, major, minor);
157 udev_selinux_setfscreatecon(udev, node, S_IFBLK | mode);
158 mknod(node, S_IFBLK | mode, makedev(major,minor));
159 udev_selinux_resetfscreatecon(udev);
160 chown(node, uid, gid);
161 chmod(node, S_IFBLK | mode);
166 udev_selinux_exit(udev);