]> Zhao Yanbai Git Server - minix.git/commitdiff
fbdctl(8): move to proper location 88/3188/2
authorDavid van Moolenbroek <david@minix3.org>
Sat, 19 Sep 2015 23:06:10 +0000 (23:06 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Wed, 23 Sep 2015 12:03:10 +0000 (12:03 +0000)
- move from minix/commands to minix/usr.sbin;
- install into /usr/sbin instead of /usr/bin;
- move manual page into source directory;
- resolve compilation warning;
- convert to KNF.

Change-Id: I1206b52e8804a68a3a80f6d7f63916e7fcdc9e3f

distrib/sets/lists/minix/mi
minix/commands/Makefile
minix/man/man8/Makefile
minix/usr.sbin/Makefile
minix/usr.sbin/fbdctl/Makefile [moved from minix/commands/fbdctl/Makefile with 72% similarity]
minix/usr.sbin/fbdctl/fbdctl.8 [moved from minix/man/man8/fbdctl.8 with 100% similarity]
minix/usr.sbin/fbdctl/fbdctl.c [moved from minix/commands/fbdctl/fbdctl.c with 67% similarity]

index a5bedfbc0eab399a10763b990a810f66b9f265be..c63df142f622d7ecd5a05960e728b677c8d233ee 100644 (file)
 ./usr/bin/ex                           minix-sys
 ./usr/bin/expand                       minix-sys
 ./usr/bin/false                                minix-sys
-./usr/bin/fbdctl                       minix-sys
+./usr/bin/fbdctl                       minix-sys       obsolete
 ./usr/bin/fdisk                                minix-sys
 ./usr/bin/fetch                                minix-sys
 ./usr/bin/fgrep                                minix-sys
 ./usr/sbin/chown                       minix-sys
 ./usr/sbin/chroot                      minix-sys
 ./usr/sbin/diskctl                     minix-sys
+./usr/sbin/fbdctl                      minix-sys
 ./usr/sbin/group                       minix-sys
 ./usr/sbin/groupadd                    minix-sys
 ./usr/sbin/groupdel                    minix-sys
index 6cc5e60813290db431c6167f62f899caf8d3cc1a..645333f396c26f18f7dd9bc10614bc04e7f11bb0 100644 (file)
@@ -8,7 +8,7 @@ SUBDIR= add_route arp at backup \
        compress crc cron crontab \
        decomp16 DESCRIBE devmand devsize dhcpd \
        dhrystone \
-       eject fbdctl \
+       eject \
        fix format fsck.mfs \
        gcov-pull host \
        hostaddr ifconfig ifdef \
index 0adc6e22f9ac41798f8f6f9b3b03e92b2132aed6..1ad83005ca5aa7b2450f4c8bb3653b4e20acbd7a 100644 (file)
@@ -1,6 +1,6 @@
 MAN=   add_route.8 backup.8 boot.8 \
        cdprobe.8 cleantmp.8 config.8 cron.8 \
-       dhcpd.8 fbdctl.8 fdisk.8 \
+       dhcpd.8 fdisk.8 \
        getty.8 halt.8 hgfs.8 httpd.8 ifconfig.8 inet.8 init.8 \
        intr.8 irdpd.8 loadramdisk.8 \
        netconf.8 newroot.8 nonamed.8 \
index 6d6151cba2659207dbc0764befdd7bce37da6f09..8bb4944db0653b6a7dddfc32f2d261596ecbef5a 100644 (file)
@@ -2,6 +2,7 @@
 
 SUBDIR+=       btrace
 SUBDIR+=       diskctl
+SUBDIR+=       fbdctl
 SUBDIR+=       mkfs.mfs
 SUBDIR+=       mkproto
 
similarity index 72%
rename from minix/commands/fbdctl/Makefile
rename to minix/usr.sbin/fbdctl/Makefile
index 76c99c314e4b0357da491a1f9b0accb7ad14d232..3d9ff2b7060db135f6c554203cee2a7cff979563 100644 (file)
@@ -1,4 +1,4 @@
 PROG=  fbdctl
-MAN=
+MAN=   fbdctl.8
 
 .include <bsd.prog.mk>
similarity index 67%
rename from minix/commands/fbdctl/fbdctl.c
rename to minix/usr.sbin/fbdctl/fbdctl.c
index 5e951f06189e7ddaf599a41e0c7876caa1f9b085..957f97fa05ca13415cacb501a64c1bbb455613be 100644 (file)
@@ -2,40 +2,44 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <minix/ioctl.h>
 #include <minix/u64.h>
-#include <sys/ioc_fbd.h>
+#include <sys/ioctl.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 
-static int usage(char *name)
+#define PATH_DEV_FBD   "/dev/fbd"
+
+static void __dead
+usage(void)
 {
-       printf("usage:\n");
-       printf("  %s list\n", name);
-       printf("  %s add [-a start[-end]] [-s skip] [-c count] [-rw] "
-               "<action> [params]\n", name);
-       printf("  %s del N\n", name);
-       printf("\n");
-       printf("actions and params:\n");
-       printf("  corrupt [zero|persist|random]\n");
-       printf("  error [OK|EIO]\n");
-       printf("  misdir <start>-<end> <align>\n");
-       printf("  lost\n");
-       printf("  torn <lead>\n");
-       printf("use %s -d <device> to specify a device other than /dev/fbd\n",
-               name);
-
-       return EXIT_FAILURE;
+
+       fprintf(stderr, "usage:\n");
+       fprintf(stderr, "  %s list\n", getprogname());
+       fprintf(stderr, "  %s add [-a start[-end]] [-s skip] [-c count] [-rw] "
+           "<action> [params]\n", getprogname());
+       fprintf(stderr, "  %s del N\n", getprogname());
+       fprintf(stderr, "\n");
+       fprintf(stderr, "actions and params:\n");
+       fprintf(stderr, "  corrupt [zero|persist|random]\n");
+       fprintf(stderr, "  error [OK|EIO]\n");
+       fprintf(stderr, "  misdir <start>-<end> <align>\n");
+       fprintf(stderr, "  lost\n");
+       fprintf(stderr, "  torn <lead>\n");
+       fprintf(stderr, "use %s -d <device> to specify a device other than "
+           "%s\n", getprogname(), PATH_DEV_FBD);
+
+       exit(EXIT_FAILURE);
 }
 
-static void print_rule(struct fbd_rule *rule)
+static void
+print_rule(struct fbd_rule * rule)
 {
        printf("%-2d %04lX%08lX-%04lX%08lX %-4d %-5d %c%c ",
-               rule->num, ex64hi(rule->start), ex64lo(rule->start),
-               ex64hi(rule->end), ex64lo(rule->end), rule->skip,
-               rule->count, (rule->flags & FBD_FLAG_READ) ? 'r' : ' ',
-               (rule->flags & FBD_FLAG_WRITE) ? 'w' : ' ');
+           rule->num, ex64hi(rule->start), ex64lo(rule->start),
+           ex64hi(rule->end), ex64lo(rule->end), rule->skip,
+           rule->count, (rule->flags & FBD_FLAG_READ) ? 'r' : ' ',
+           (rule->flags & FBD_FLAG_WRITE) ? 'w' : ' ');
 
        switch (rule->action) {
        case FBD_ACTION_CORRUPT:
@@ -67,17 +71,16 @@ static void print_rule(struct fbd_rule *rule)
 
        case FBD_ACTION_MISDIR:
                printf("%-7s %04lX%08lX-%04lX%08lX %u",
-                       "misdir", ex64hi(rule->params.misdir.start),
-                       ex64lo(rule->params.misdir.start),
-                       ex64hi(rule->params.misdir.end),
-                       ex64lo(rule->params.misdir.end),
-                       rule->params.misdir.align);
+                   "misdir", ex64hi(rule->params.misdir.start),
+                   ex64lo(rule->params.misdir.start),
+                   ex64hi(rule->params.misdir.end),
+                   ex64lo(rule->params.misdir.end),
+                   rule->params.misdir.align);
                break;
 
        case FBD_ACTION_LOSTTORN:
                if (rule->params.losttorn.lead > 0)
-                       printf("%-7s %u", "torn",
-                               rule->params.losttorn.lead);
+                       printf("%-7s %u", "torn", rule->params.losttorn.lead);
                else
                        printf("%-7s", "lost");
        }
@@ -85,7 +88,8 @@ static void print_rule(struct fbd_rule *rule)
        printf("\n");
 }
 
-static int do_list(int fd)
+static int
+do_list(int fd)
 {
        struct fbd_rule rule;
        int i;
@@ -107,7 +111,8 @@ static int do_list(int fd)
        return EXIT_SUCCESS;
 }
 
-static int scan_hex64(char *input, u64_t *val)
+static int
+scan_hex64(char * input, u64_t * val)
 {
        u32_t lo, hi;
        char buf[9];
@@ -133,7 +138,8 @@ static int scan_hex64(char *input, u64_t *val)
        return 1;
 }
 
-static int scan_range(char *input, u64_t *start, u64_t *end, int need_end)
+static int
+scan_range(char * input, u64_t * start, u64_t * end, int need_end)
 {
        char *p;
 
@@ -147,7 +153,8 @@ static int scan_range(char *input, u64_t *start, u64_t *end, int need_end)
        return scan_hex64(input, start);
 }
 
-static int do_add(int fd, int argc, char **argv, int off)
+static int
+do_add(int fd, int argc, char ** argv, int off)
 {
        struct fbd_rule rule;
        int c, r;
@@ -158,7 +165,7 @@ static int do_add(int fd, int argc, char **argv, int off)
                switch (c) {
                case 'a':
                        if (!scan_range(optarg, &rule.start, &rule.end, 0))
-                               return usage(argv[0]);
+                               usage();
                        break;
                case 's':
                        rule.skip = atoi(optarg);
@@ -173,19 +180,19 @@ static int do_add(int fd, int argc, char **argv, int off)
                        rule.flags |= FBD_FLAG_WRITE;
                        break;
                default:
-                       return usage(argv[0]);
+                       usage();
                }
        }
 
        optind += off; /* compensate for the shifted argc/argv */
 
-       if (optind >= argc) return usage(argv[0]);
+       if (optind >= argc) usage();
 
        /* default to reads and writes */
        if (!rule.flags) rule.flags = FBD_FLAG_READ | FBD_FLAG_WRITE;
 
        if (!strcmp(argv[optind], "corrupt")) {
-               if (optind+1 >= argc) return usage(argv[0]);
+               if (optind+1 >= argc) usage();
 
                rule.action = FBD_ACTION_CORRUPT;
 
@@ -195,10 +202,10 @@ static int do_add(int fd, int argc, char **argv, int off)
                        rule.params.corrupt.type = FBD_CORRUPT_PERSIST;
                else if (!strcmp(argv[optind+1], "random"))
                        rule.params.corrupt.type = FBD_CORRUPT_RANDOM;
-               else return usage(argv[0]);
+               else usage();
        }
        else if (!strcmp(argv[optind], "error")) {
-               if (optind+1 >= argc) return usage(argv[0]);
+               if (optind+1 >= argc) usage();
 
                rule.action = FBD_ACTION_ERROR;
 
@@ -210,21 +217,21 @@ static int do_add(int fd, int argc, char **argv, int off)
                        else
                                rule.params.error.code = EIO;
                }
-               else return usage(argv[0]);
+               else usage();
        }
        else if (!strcmp(argv[optind], "misdir")) {
-               if (optind+2 >= argc) return usage(argv[0]);
+               if (optind+2 >= argc) usage();
 
                rule.action = FBD_ACTION_MISDIR;
 
                if (!scan_range(argv[optind+1], &rule.params.misdir.start,
-                               &rule.params.misdir.end, 1))
-                       return usage(argv[0]);
+                   &rule.params.misdir.end, 1))
+                       usage();
 
                rule.params.misdir.align = atoi(argv[optind+2]);
 
-               if ((int) rule.params.misdir.align <= 0)
-                       return usage(argv[0]);
+               if ((int)rule.params.misdir.align <= 0)
+                       usage();
        }
        else if (!strcmp(argv[optind], "lost")) {
                rule.action = FBD_ACTION_LOSTTORN;
@@ -232,16 +239,16 @@ static int do_add(int fd, int argc, char **argv, int off)
                rule.params.losttorn.lead = 0;
        }
        else if (!strcmp(argv[optind], "torn")) {
-               if (optind+1 >= argc) return usage(argv[0]);
+               if (optind+1 >= argc) usage();
 
                rule.action = FBD_ACTION_LOSTTORN;
 
                rule.params.losttorn.lead = atoi(argv[optind+1]);
 
-               if ((int) rule.params.losttorn.lead <= 0)
-                       return usage(argv[0]);
+               if ((int)rule.params.losttorn.lead <= 0)
+                       usage();
        }
-       else return usage(argv[0]);
+       else usage();
 
 #if DEBUG
        print_rule(&rule);
@@ -260,12 +267,13 @@ static int do_add(int fd, int argc, char **argv, int off)
        return EXIT_SUCCESS;
 }
 
-static int do_del(int fd, int argc, char **argv, int off)
+static int
+do_del(int fd, int argc, char ** argv, int off)
 {
        fbd_rulenum_t num;
 
        if (argc < off + 2)
-               return usage(argv[0]);
+               usage();
 
        num = atoi(argv[off + 1]);
 
@@ -280,17 +288,20 @@ static int do_del(int fd, int argc, char **argv, int off)
        return EXIT_SUCCESS;
 }
 
-int main(int argc, char **argv)
+int
+main(int argc, char ** argv)
 {
        int r, fd, off = 1;
-       char *dev = "/dev/fbd";
+       const char *dev = PATH_DEV_FBD;
+
+       setprogname(argv[0]);
 
        if (argc < 2)
-               return usage(argv[0]);
+               usage();
 
        if (!strcmp(argv[1], "-d")) {
                if (argc < 4)
-                       return usage(argv[0]);
+                       usage();
 
                dev = argv[2];
 
@@ -304,14 +315,14 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       else if (!strcmp(argv[off], "list"))
+       if (!strcmp(argv[off], "list"))
                r = do_list(fd);
        else if (!strcmp(argv[off], "add"))
                r = do_add(fd, argc, argv, off);
        else if (!strcmp(argv[off], "del"))
                r = do_del(fd, argc, argv, off);
        else
-               r = usage(argv[0]);
+               usage();
 
        close(fd);