chiark / gitweb /
rules: implement TAGS== match
[elogind.git] / extras / floppy / create_floppy_devices.c
index 2c7d44b16d01a3d6f118fad26d7e0dd9353bb88a..47724f8b0484f0a4793594f48a07fb6676d0d640 100644 (file)
@@ -1,17 +1,23 @@
 /*
- * 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
  *
- * Author:
- *     Hannes Reinecke <hare@suse.de>
+ * Author: Hannes Reinecke <hare@suse.de>
+ *
+ * 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, either version 2 of the License, or
+ * (at your option) any later version.
  *
- *     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.
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdio.h>
@@ -24,8 +30,8 @@
 #include <pwd.h>
 #include <grp.h>
 
-#include "../../udev/udev.h"
-#include "../../udev/udev_selinux.h"
+#include "libudev.h"
+#include "libudev-private.h"
 
 static char *table[] = {
        "", "d360", "h1200", "u360", "u720", "h360", "h720",
@@ -67,8 +73,9 @@ int main(int argc, char **argv)
        if (udev == NULL)
                goto exit;
 
-       logging_init("create_floppy_devices");
+       udev_log_init("create_floppy_devices");
        udev_set_log_fn(udev, log_fn);
+       udev_selinux_init(udev);
 
        while ((c = getopt(argc, argv, "cudm:U:G:M:t:")) != -1) {
                switch (c) {
@@ -79,10 +86,10 @@ int main(int argc, char **argv)
                        print_nodes = 1;
                        break;
                case 'U':
-                       uid = lookup_user(udev, optarg);
+                       uid = util_lookup_user(udev, optarg);
                        break;
                case 'G':
-                       gid = lookup_group(udev, optarg);
+                       gid = util_lookup_group(udev, optarg);
                        break;
                case 'M':
                        mode = strtol(optarg, NULL, 0);
@@ -130,14 +137,14 @@ int main(int argc, char **argv)
                return 1;
        }
        if (fdnum > 3)
-               fdnum += 128;
+               fdnum += 124;
 
        if (major < 1) {
                fprintf(stderr,"Invalid major number %d\n", major);
                return 1;
        }
 
-       if (type < 0 || type > (int) sizeof(table)) {
+       if (type < 0 || type >= (int) ARRAY_SIZE(table_sup)) {
                fprintf(stderr,"Invalid CMOS type %d\n", type);
                return 1;
        }
@@ -145,27 +152,26 @@ int main(int argc, char **argv)
        if (type == 0)
                return 0;
 
-       selinux_init(udev);
-
        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);
+                       printf("%s b %.4o %d %d\n", node, mode, major, minor);
                if (create_nodes) {
                        unlink(node);
-                       selinux_setfscreatecon(udev, node, NULL, S_IFBLK | mode);
+                       udev_selinux_setfscreatecon(udev, node, S_IFBLK | mode);
                        mknod(node, S_IFBLK | mode, makedev(major,minor));
-                       selinux_resetfscreatecon(udev);
+                       udev_selinux_resetfscreatecon(udev);
                        chown(node, uid, gid);
                        chmod(node, S_IFBLK | mode);
                }
                i++;
        }
 
-       selinux_exit(udev);
+       udev_selinux_exit(udev);
        udev_unref(udev);
+       udev_log_close();
 exit:
        return 0;
 }