2 * Create all possible floppy device based on the CMOS type.
3 * Based upon code from drivers/block/floppy.c
5 * Copyright(C) 2005, SUSE Linux Products GmbH
7 * Author: Hannes Reinecke <hare@suse.de>
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, either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/types.h>
34 #include "libudev-private.h"
36 static char *table[] = {
37 "", "d360", "h1200", "u360", "u720", "h360", "h720",
38 "u1440", "u2880", "CompaQ", "h1440", "u1680", "h410",
39 "u820", "h1476", "u1722", "h420", "u830", "h1494", "u1743",
40 "h880", "u1040", "u1120", "h1600", "u1760", "u1920",
41 "u3200", "u3520", "u3840", "u1840", "u800", "u1600",
45 static int t360[] = { 1, 0 };
46 static int t1200[] = { 2, 5, 6, 10, 12, 14, 16, 18, 20, 23, 0 };
47 static int t3in[] = { 8, 9, 26, 27, 28, 7, 11, 15, 19, 24, 25, 29, 31, 3, 4, 13, 17, 21, 22, 30, 0 };
48 static int *table_sup[] = { NULL, t360, t1200, t3in+5+8, t3in+5, t3in, t3in };
50 static void log_fn(struct udev *udev, int priority,
51 const char *file, int line, const char *fn,
52 const char *format, va_list args)
54 vsyslog(priority, format, args);
57 int main(int argc, char **argv)
63 int type = 0, i, fdnum, c;
76 udev_log_init("create_floppy_devices");
77 udev_set_log_fn(udev, log_fn);
78 udev_selinux_init(udev);
80 while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
89 uid = util_lookup_user(udev, optarg);
92 gid = util_lookup_group(udev, optarg);
95 mode = strtol(optarg, NULL, 0);
99 major = strtol(optarg, NULL, 0);
102 type = strtol(optarg, NULL, 0);
110 if (is_err || optind >= argc) {
111 printf("Usage: %s [OPTION] device\n"
115 " -t floppy type number\n"
116 " -U device node user ownership\n"
117 " -G device node group owner\n"
118 " -M device node mode\n"
124 devname = strrchr(dev, '/');
126 devname = &devname[1];
129 if (strncmp(devname, "fd", 2) != 0) {
130 fprintf(stderr,"Device '%s' is not a floppy device\n", dev);
134 fdnum = strtol(&devname[2], NULL, 10);
135 if (fdnum < 0 || fdnum > 7) {
136 fprintf(stderr,"Floppy device number %d out of range (0-7)\n", fdnum);
143 fprintf(stderr,"Invalid major number %d\n", major);
147 if (type < 0 || type >= (int) ARRAY_SIZE(table_sup)) {
148 fprintf(stderr,"Invalid CMOS type %d\n", type);
156 while (table_sup[type][i]) {
157 sprintf(node, "%s%s", dev, table[table_sup[type][i]]);
158 minor = (table_sup[type][i] << 2) + fdnum;
160 printf("%s b %.4o %d %d\n", node, mode, major, minor);
163 udev_selinux_setfscreatecon(udev, node, S_IFBLK | mode);
164 mknod(node, S_IFBLK | mode, makedev(major,minor));
165 udev_selinux_resetfscreatecon(udev);
166 chown(node, uid, gid);
167 chmod(node, S_IFBLK | mode);
172 udev_selinux_exit(udev);