2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
25 #include <sys/mount.h>
31 #include <libubox/list.h>
32 #include <libubox/vlist.h>
33 #include <libubox/blobmsg_json.h>
34 #include <libubox/avl-cmp.h>
36 #include "libblkid-tiny/libblkid-tiny.h"
44 struct vlist_node node;
60 static struct vlist_tree mounts;
61 static struct blob_buf b;
62 static LIST_HEAD(devices);
63 static int anon_mount, anon_swap, auto_mount, auto_swap, check_fs;
64 static unsigned int delay_root;
76 static const struct blobmsg_policy config_policy[__CFG_MAX] = {
77 [CFG_ANON_SWAP] = { .name = "anon_swap", .type = BLOBMSG_TYPE_INT32 },
78 [CFG_ANON_MOUNT] = { .name = "anon_mount", .type = BLOBMSG_TYPE_INT32 },
79 [CFG_AUTO_SWAP] = { .name = "auto_swap", .type = BLOBMSG_TYPE_INT32 },
80 [CFG_AUTO_MOUNT] = { .name = "auto_mount", .type = BLOBMSG_TYPE_INT32 },
81 [CFG_DELAY_ROOT] = { .name = "delay_root", .type = BLOBMSG_TYPE_INT32 },
82 [CFG_CHECK_FS] = { .name = "check_fs", .type = BLOBMSG_TYPE_INT32 },
95 static const struct uci_blob_param_list config_attr_list = {
96 .n_params = __CFG_MAX,
97 .params = config_policy,
100 static const struct blobmsg_policy mount_policy[__MOUNT_MAX] = {
101 [MOUNT_UUID] = { .name = "uuid", .type = BLOBMSG_TYPE_STRING },
102 [MOUNT_LABEL] = { .name = "label", .type = BLOBMSG_TYPE_STRING },
103 [MOUNT_DEVICE] = { .name = "device", .type = BLOBMSG_TYPE_STRING },
104 [MOUNT_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
105 [MOUNT_OPTIONS] = { .name = "options", .type = BLOBMSG_TYPE_STRING },
106 [MOUNT_ENABLE] = { .name = "enabled", .type = BLOBMSG_TYPE_INT32 },
109 static const struct uci_blob_param_list mount_attr_list = {
110 .n_params = __MOUNT_MAX,
111 .params = mount_policy,
123 static const struct blobmsg_policy swap_policy[__SWAP_MAX] = {
124 [SWAP_ENABLE] = { .name = "enabled", .type = BLOBMSG_TYPE_INT32 },
125 [SWAP_UUID] = { .name = "uuid", .type = BLOBMSG_TYPE_STRING },
126 [SWAP_LABEL] = { .name = "label", .type = BLOBMSG_TYPE_STRING },
127 [SWAP_DEVICE] = { .name = "device", .type = BLOBMSG_TYPE_STRING },
128 [SWAP_PRIO] = { .name = "priority", .type = BLOBMSG_TYPE_INT32 },
131 static const struct uci_blob_param_list swap_attr_list = {
132 .n_params = __SWAP_MAX,
133 .params = swap_policy,
142 # define MS_DIRSYNC (1 << 7)
146 # define MS_RELATIME (1 << 21)
149 #ifndef MS_STRICTATIME
150 # define MS_STRICTATIME (1 << 24)
153 static const struct mount_flag mount_flags[] = {
154 { "sync", MS_SYNCHRONOUS },
155 { "async", ~MS_SYNCHRONOUS },
156 { "dirsync", MS_DIRSYNC },
157 { "mand", MS_MANDLOCK },
158 { "nomand", ~MS_MANDLOCK },
159 { "atime", ~MS_NOATIME },
160 { "noatime", MS_NOATIME },
161 { "dev", ~MS_NODEV },
162 { "nodev", MS_NODEV },
163 { "diratime", ~MS_NODIRATIME },
164 { "nodiratime", MS_NODIRATIME },
165 { "exec", ~MS_NOEXEC },
166 { "noexec", MS_NOEXEC },
167 { "suid", ~MS_NOSUID },
168 { "nosuid", MS_NOSUID },
169 { "rw", ~MS_RDONLY },
171 { "relatime", MS_RELATIME },
172 { "norelatime", ~MS_RELATIME },
173 { "strictatime", MS_STRICTATIME },
176 static char *blobmsg_get_strdup(struct blob_attr *attr)
181 return strdup(blobmsg_get_string(attr));
184 static char *blobmsg_get_basename(struct blob_attr *attr)
189 return strdup(basename(blobmsg_get_string(attr)));
192 static void parse_mount_options(struct mount *m, char *optstr)
196 char *p, *opts, *last;
201 if (!optstr || !*optstr)
204 m->options = opts = calloc(1, strlen(optstr) + 1);
217 for (i = 0, is_flag = false; i < ARRAY_SIZE(mount_flags); i++) {
218 if (!strcmp(last, mount_flags[i].name)) {
219 if (mount_flags[i].flag < 0)
220 m->flags &= (uint32_t)mount_flags[i].flag;
222 m->flags |= (uint32_t)mount_flags[i].flag;
229 opts += sprintf(opts, "%s%s", (opts > m->options) ? "," : "", last);
238 static int mount_add(struct uci_section *s)
240 struct blob_attr *tb[__MOUNT_MAX] = { 0 };
243 blob_buf_init(&b, 0);
244 uci_to_blob(&b, s, &mount_attr_list);
245 blobmsg_parse(mount_policy, __MOUNT_MAX, tb, blob_data(b.head), blob_len(b.head));
247 if (!tb[MOUNT_LABEL] && !tb[MOUNT_UUID] && !tb[MOUNT_DEVICE])
250 if (tb[MOUNT_ENABLE] && !blobmsg_get_u32(tb[MOUNT_ENABLE]))
253 m = malloc(sizeof(struct mount));
254 m->type = TYPE_MOUNT;
255 m->uuid = blobmsg_get_strdup(tb[MOUNT_UUID]);
256 m->label = blobmsg_get_strdup(tb[MOUNT_LABEL]);
257 m->target = blobmsg_get_strdup(tb[MOUNT_TARGET]);
258 m->device = blobmsg_get_basename(tb[MOUNT_DEVICE]);
260 parse_mount_options(m, blobmsg_get_strdup(tb[MOUNT_OPTIONS]));
262 m->overlay = m->extroot = 0;
263 if (m->target && !strcmp(m->target, "/"))
265 if (m->target && !strcmp(m->target, "/overlay"))
266 m->extroot = m->overlay = 1;
269 vlist_add(&mounts, &m->node, m->uuid);
271 vlist_add(&mounts, &m->node, m->label);
273 vlist_add(&mounts, &m->node, m->device);
278 static int swap_add(struct uci_section *s)
280 struct blob_attr *tb[__SWAP_MAX] = { 0 };
283 blob_buf_init(&b, 0);
284 uci_to_blob(&b, s, &swap_attr_list);
285 blobmsg_parse(swap_policy, __SWAP_MAX, tb, blob_data(b.head), blob_len(b.head));
287 if (!tb[SWAP_UUID] && !tb[SWAP_LABEL] && !tb[SWAP_DEVICE])
290 m = malloc(sizeof(struct mount));
291 memset(m, 0, sizeof(struct mount));
293 m->uuid = blobmsg_get_strdup(tb[SWAP_UUID]);
294 m->label = blobmsg_get_strdup(tb[SWAP_LABEL]);
295 m->device = blobmsg_get_basename(tb[SWAP_DEVICE]);
297 m->prio = blobmsg_get_u32(tb[SWAP_PRIO]);
299 m->prio = ((m->prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER;
301 if ((!tb[SWAP_ENABLE]) || blobmsg_get_u32(tb[SWAP_ENABLE])) {
302 /* store complete swap path */
304 m->target = blobmsg_get_strdup(tb[SWAP_DEVICE]);
307 vlist_add(&mounts, &m->node, m->uuid);
309 vlist_add(&mounts, &m->node, m->label);
311 vlist_add(&mounts, &m->node, m->device);
317 static int global_add(struct uci_section *s)
319 struct blob_attr *tb[__CFG_MAX] = { 0 };
321 blob_buf_init(&b, 0);
322 uci_to_blob(&b, s, &config_attr_list);
323 blobmsg_parse(config_policy, __CFG_MAX, tb, blob_data(b.head), blob_len(b.head));
325 if ((tb[CFG_ANON_MOUNT]) && blobmsg_get_u32(tb[CFG_ANON_MOUNT]))
327 if ((tb[CFG_ANON_SWAP]) && blobmsg_get_u32(tb[CFG_ANON_SWAP]))
330 if ((tb[CFG_AUTO_MOUNT]) && blobmsg_get_u32(tb[CFG_AUTO_MOUNT]))
332 if ((tb[CFG_AUTO_SWAP]) && blobmsg_get_u32(tb[CFG_AUTO_SWAP]))
335 if (tb[CFG_DELAY_ROOT])
336 delay_root = blobmsg_get_u32(tb[CFG_DELAY_ROOT]);
338 if ((tb[CFG_CHECK_FS]) && blobmsg_get_u32(tb[CFG_CHECK_FS]))
344 static struct mount* find_swap(const char *uuid, const char *label, const char *device)
348 vlist_for_each_element(&mounts, m, node) {
349 if (m->type != TYPE_SWAP)
351 if (uuid && m->uuid && !strcmp(m->uuid, uuid))
353 if (label && m->label && !strcmp(m->label, label))
355 if (device && m->device && !strcmp(m->device, device))
362 static struct mount* find_block(const char *uuid, const char *label, const char *device,
367 vlist_for_each_element(&mounts, m, node) {
368 if (m->type != TYPE_MOUNT)
370 if (m->uuid && uuid && !strcmp(m->uuid, uuid))
372 if (m->label && label && !strcmp(m->label, label))
374 if (m->target && target && !strcmp(m->target, target))
376 if (m->device && device && !strcmp(m->device, device))
383 static void mounts_update(struct vlist_tree *tree, struct vlist_node *node_new,
384 struct vlist_node *node_old)
388 static int config_load(char *cfg)
390 struct uci_context *ctx;
391 struct uci_package *pkg;
392 struct uci_element *e;
394 vlist_init(&mounts, avl_strcmp, mounts_update);
396 ctx = uci_alloc_context();
399 snprintf(path, 32, "%s/etc/config", cfg);
400 uci_set_confdir(ctx, path);
403 if (uci_load(ctx, "fstab", &pkg))
406 vlist_update(&mounts);
407 uci_foreach_element(&pkg->sections, e) {
408 struct uci_section *s = uci_to_section(e);
410 if (!strcmp(s->type, "mount"))
412 if (!strcmp(s->type, "swap"))
414 if (!strcmp(s->type, "global"))
417 vlist_flush(&mounts);
422 static struct blkid_struct_probe* _probe_path(char *path)
424 struct blkid_struct_probe *pr;
426 pr = malloc(sizeof(*pr));
431 memset(pr, 0, sizeof(*pr));
432 probe_block(path, pr);
434 if (pr->err || !pr->id) {
442 static int _cache_load(const char *path)
444 int gl_flags = GLOB_NOESCAPE | GLOB_MARK;
448 if (glob(path, gl_flags, NULL, &gl) < 0)
451 for (j = 0; j < gl.gl_pathc; j++) {
452 struct blkid_struct_probe *pr = _probe_path(gl.gl_pathv[j]);
454 list_add_tail(&pr->list, &devices);
462 static void cache_load(int mtd)
465 _cache_load("/dev/mtdblock*");
466 _cache_load("/dev/mmcblk*");
467 _cache_load("/dev/sd*");
468 _cache_load("/dev/sdc*");
469 _cache_load("/dev/hd*");
470 _cache_load("/dev/md*");
471 _cache_load("/dev/mapper/*");
474 static int print_block_info(struct blkid_struct_probe *pr)
476 printf("%s:", pr->dev);
478 printf(" UUID=\"%s\"", pr->uuid);
481 printf(" LABEL=\"%s\"", pr->label);
484 printf(" NAME=\"%s\"", pr->name);
487 printf(" VERSION=\"%s\"", pr->version);
489 printf(" TYPE=\"%s\"\n", pr->id->name);
494 static int print_block_uci(struct blkid_struct_probe *pr)
496 if (!strcmp(pr->id->name, "swap")) {
497 printf("config 'swap'\n");
499 printf("config 'mount'\n");
500 printf("\toption\ttarget\t'/mnt/%s'\n", basename(pr->dev));
503 printf("\toption\tuuid\t'%s'\n", pr->uuid);
505 printf("\toption\tdevice\t'%s'\n", pr->dev);
506 printf("\toption\tenabled\t'0'\n\n");
511 static struct blkid_struct_probe* find_block_info(char *uuid, char *label, char *path)
513 struct blkid_struct_probe *pr = NULL;
516 list_for_each_entry(pr, &devices, list)
517 if (!strcmp(pr->uuid, uuid))
521 list_for_each_entry(pr, &devices, list)
522 if (strcmp(pr->label, label))
526 list_for_each_entry(pr, &devices, list)
527 if (!strcmp(pr->dev, path))
533 static char* find_mount_point(char *block)
535 FILE *fp = fopen("/proc/mounts", "r");
536 static char line[256];
537 int len = strlen(block);
543 while (fgets(line, sizeof(line), fp)) {
544 if (!strncmp(line, block, len)) {
545 char *p = &line[len + 1];
546 char *t = strstr(p, " ");
563 static void mkdir_p(char *dir)
565 char *l = strrchr(dir, '/');
575 static void check_filesystem(struct blkid_struct_probe *pr)
579 char *e2fsck = "/usr/sbin/e2fsck";
581 if (strncmp(pr->id->name, "ext", 3)) {
582 fprintf(stderr, "check_filesystem: %s is not supported\n", pr->id->name);
586 if (stat(e2fsck, &statbuf) < 0) {
587 fprintf(stderr, "check_filesystem: %s not found\n", e2fsck);
593 execl(e2fsck, e2fsck, "-p", pr->dev, NULL);
595 } else if (pid > 0) {
598 waitpid(pid, &status, 0);
599 if (WEXITSTATUS(status))
600 fprintf(stderr, "check_filesystem: %s returned %d\n", e2fsck, WEXITSTATUS(status));
604 static void handle_swapfiles(bool on)
608 struct blkid_struct_probe *pr;
610 vlist_for_each_element(&mounts, m, node)
612 if (m->type != TYPE_SWAP || !m->target)
615 if (stat(m->target, &s) || !S_ISREG(s.st_mode))
618 pr = _probe_path(m->target);
623 if (!strcmp(pr->id->name, "swap")) {
625 swapon(pr->dev, m->prio);
634 static int mount_device(struct blkid_struct_probe *pr, int hotplug)
642 device = basename(pr->dev);
644 if (!strcmp(pr->id->name, "swap")) {
645 if (hotplug && !auto_swap)
647 m = find_swap(pr->uuid, pr->label, device);
649 swapon(pr->dev, (m) ? (m->prio) : (0));
654 if (hotplug && !auto_mount)
657 if (find_mount_point(pr->dev)) {
658 fprintf(stderr, "%s is already mounted\n", pr->dev);
662 m = find_block(pr->uuid, pr->label, device, NULL);
667 char *target = m->target;
672 snprintf(_target, sizeof(_target), "/mnt/%s", device);
678 check_filesystem(pr);
680 err = mount(pr->dev, target, pr->id->name, m->flags,
681 (m->options) ? (m->options) : (""));
683 fprintf(stderr, "mounting %s (%s) as %s failed (%d) - %s\n",
684 pr->dev, pr->id->name, target, err, strerror(err));
686 handle_swapfiles(true);
691 char target[] = "/mnt/mmcblk123";
694 snprintf(target, sizeof(target), "/mnt/%s", device);
698 check_filesystem(pr);
700 err = mount(pr->dev, target, pr->id->name, 0, "");
702 fprintf(stderr, "mounting %s (%s) as %s failed (%d) - %s\n",
703 pr->dev, pr->id->name, target, err, strerror(err));
705 handle_swapfiles(true);
712 static int umount_device(struct blkid_struct_probe *pr)
715 char *device = basename(pr->dev);
722 if (!strcmp(pr->id->name, "swap"))
725 mp = find_mount_point(pr->dev);
729 m = find_block(pr->uuid, pr->label, device, NULL);
733 err = umount2(mp, MNT_DETACH);
735 fprintf(stderr, "unmounting %s (%s) failed (%d) - %s\n",
736 pr->dev, mp, err, strerror(err));
738 fprintf(stderr, "unmounted %s (%s)\n",
744 static int main_hotplug(int argc, char **argv)
747 char *action, *device, *mount_point;
749 action = getenv("ACTION");
750 device = getenv("DEVNAME");
752 if (!action || !device)
754 snprintf(path, sizeof(path), "/dev/%s", device);
756 if (!strcmp(action, "remove")) {
758 mount_point = find_mount_point(path);
760 err = umount2(mount_point, MNT_DETACH);
763 fprintf(stderr, "umount of %s failed (%d) - %s\n",
764 mount_point, err, strerror(err));
767 } else if (strcmp(action, "add")) {
768 fprintf(stderr, "Unkown action %s\n", action);
773 if (config_load(NULL))
777 return mount_device(find_block_info(NULL, NULL, path), 1);
780 static int find_block_mtd(char *name, char *part, int plen)
782 FILE *fp = fopen("/proc/mtd", "r");
783 static char line[256];
789 while (!index && fgets(line, sizeof(line), fp)) {
790 if (strstr(line, name)) {
791 char *eol = strstr(line, ":");
806 snprintf(part, plen, "/dev/mtdblock%s", index);
811 static int check_extroot(char *path)
813 struct blkid_struct_probe *pr = NULL;
816 if (find_block_mtd("rootfs", fs, sizeof(fs)))
819 list_for_each_entry(pr, &devices, list) {
820 if (!strcmp(pr->dev, fs)) {
824 char uuid[64] = { 0 };
826 snprintf(tag, sizeof(tag), "%s/etc/.extroot-uuid", path);
828 fp = fopen(tag, "w+");
830 fprintf(stderr, "extroot: failed to write uuid tag file\n");
831 /* return 0 to continue boot regardless of error */
839 fp = fopen(tag, "r");
841 fprintf(stderr, "extroot: failed to open uuid tag file\n");
845 fgets(uuid, sizeof(uuid), fp);
847 if (!strcmp(uuid, pr->uuid))
849 fprintf(stderr, "extroot: uuid tag does not match rom uuid\n");
855 static int mount_extroot(char *cfg)
857 char overlay[] = "/tmp/extroot/overlay";
858 char mnt[] = "/tmp/extroot/mnt";
860 struct blkid_struct_probe *pr;
864 if (config_load(cfg))
867 m = find_block(NULL, NULL, NULL, "/");
869 m = find_block(NULL, NULL, NULL, "/overlay");
871 if (!m || !m->extroot)
874 pr = find_block_info(m->uuid, m->label, NULL);
876 if (!pr && delay_root){
877 fprintf(stderr, "extroot: is not ready yet, retrying in %u seconds\n", delay_root);
881 pr = find_block_info(m->uuid, m->label, NULL);
884 if (strncmp(pr->id->name, "ext", 3)) {
885 fprintf(stderr, "extroot: %s is not supported, try ext4\n", pr->id->name);
893 check_filesystem(pr);
895 err = mount(pr->dev, path, pr->id->name, 0, (m->options) ? (m->options) : (""));
898 fprintf(stderr, "mounting %s (%s) as %s failed (%d) - %s\n",
899 pr->dev, pr->id->name, path, err, strerror(err));
900 } else if (m->overlay) {
901 err = check_extroot(path);
910 static int main_extroot(int argc, char **argv)
912 struct blkid_struct_probe *pr;
914 char fs_data[32] = { 0 };
917 if (!getenv("PREINIT"))
921 fprintf(stderr, "Usage: block extroot mountpoint\n");
928 find_block_mtd("rootfs", fs, sizeof(fs));
932 pr = find_block_info(NULL, NULL, fs);
936 find_block_mtd("rootfs_data", fs_data, sizeof(fs_data));
938 pr = find_block_info(NULL, NULL, fs_data);
939 if (pr && !strcmp(pr->id->name, "jffs2")) {
940 char cfg[] = "/tmp/jffs_cfg";
943 if (!mount(fs_data, cfg, "jffs2", MS_NOATIME, NULL)) {
944 err = mount_extroot(cfg);
945 umount2(cfg, MNT_DETACH);
948 rmdir("/tmp/overlay");
954 return mount_extroot(NULL);
957 static int main_mount(int argc, char **argv)
959 struct blkid_struct_probe *pr;
961 if (config_load(NULL))
965 list_for_each_entry(pr, &devices, list)
968 handle_swapfiles(true);
973 static int main_umount(int argc, char **argv)
975 struct blkid_struct_probe *pr;
977 if (config_load(NULL))
980 handle_swapfiles(false);
983 list_for_each_entry(pr, &devices, list)
989 static int main_detect(int argc, char **argv)
991 struct blkid_struct_probe *pr;
994 printf("config 'global'\n");
995 printf("\toption\tanon_swap\t'0'\n");
996 printf("\toption\tanon_mount\t'0'\n");
997 printf("\toption\tauto_swap\t'1'\n");
998 printf("\toption\tauto_mount\t'1'\n");
999 printf("\toption\tdelay_root\t'5'\n");
1000 printf("\toption\tcheck_fs\t'0'\n\n");
1001 list_for_each_entry(pr, &devices, list)
1002 print_block_uci(pr);
1007 static int main_info(int argc, char **argv)
1010 struct blkid_struct_probe *pr;
1014 list_for_each_entry(pr, &devices, list)
1015 print_block_info(pr);
1020 for (i = 2; i < argc; i++) {
1023 if (stat(argv[i], &s)) {
1024 fprintf(stderr, "failed to stat %s\n", argv[i]);
1027 if (!S_ISBLK(s.st_mode)) {
1028 fprintf(stderr, "%s is not a block device\n", argv[i]);
1031 pr = find_block_info(NULL, NULL, argv[i]);
1033 print_block_info(pr);
1039 static int main_swapon(int argc, char **argv)
1042 fprintf(stderr, "Usage: swapon <-s> <-a> [DEVICE]\n\n\tStart swapping on [DEVICE]\n -a\tStart swapping on all swap devices\n -s\tShow summary\n");
1046 if (!strcmp(argv[1], "-s")) {
1047 FILE *fp = fopen("/proc/swaps", "r");
1048 char *lineptr = NULL;
1052 fprintf(stderr, "failed to open /proc/swaps\n");
1055 while (getline(&lineptr, &s, fp) > 0)
1060 } else if (!strcmp(argv[1], "-a")) {
1061 struct blkid_struct_probe *pr;
1064 list_for_each_entry(pr, &devices, list) {
1065 if (strcmp(pr->id->name, "swap"))
1067 if (swapon(pr->dev, 0))
1068 fprintf(stderr, "failed to swapon %s\n", pr->dev);
1074 if (stat(argv[1], &s) || (!S_ISBLK(s.st_mode) && !S_ISREG(s.st_mode))) {
1075 fprintf(stderr, "%s is not a block device or file\n", argv[1]);
1078 err = swapon(argv[1], 0);
1080 fprintf(stderr, "failed to swapon %s (%d)\n", argv[1], err);
1088 static int main_swapoff(int argc, char **argv)
1091 fprintf(stderr, "Usage: swapoff [-a] [DEVICE]\n\n\tStop swapping on DEVICE\n -a\tStop swapping on all swap devices\n");
1095 if (!strcmp(argv[1], "-a")) {
1096 FILE *fp = fopen("/proc/swaps", "r");
1100 fprintf(stderr, "failed to open /proc/swaps\n");
1103 fgets(line, sizeof(line), fp);
1104 while (fgets(line, sizeof(line), fp)) {
1105 char *end = strchr(line, ' ');
1111 err = swapoff(line);
1113 fprintf(stderr, "failed to swapoff %s (%d)\n", line, err);
1120 if (stat(argv[1], &s) || (!S_ISBLK(s.st_mode) && !S_ISREG(s.st_mode))) {
1121 fprintf(stderr, "%s is not a block device or file\n", argv[1]);
1124 err = swapoff(argv[1]);
1126 fprintf(stderr, "fsiled to swapoff %s (%d)\n", argv[1], err);
1134 int main(int argc, char **argv)
1136 char *base = basename(*argv);
1140 if (!strcmp(base, "swapon"))
1141 return main_swapon(argc, argv);
1143 if (!strcmp(base, "swapoff"))
1144 return main_swapoff(argc, argv);
1146 if ((argc > 1) && !strcmp(base, "block")) {
1147 if (!strcmp(argv[1], "info"))
1148 return main_info(argc, argv);
1150 if (!strcmp(argv[1], "detect"))
1151 return main_detect(argc, argv);
1153 if (!strcmp(argv[1], "hotplug"))
1154 return main_hotplug(argc, argv);
1156 if (!strcmp(argv[1], "extroot"))
1157 return main_extroot(argc, argv);
1159 if (!strcmp(argv[1], "mount"))
1160 return main_mount(argc, argv);
1162 if (!strcmp(argv[1], "umount"))
1163 return main_umount(argc, argv);
1166 fprintf(stderr, "Usage: block <info|mount|umount|detect>\n");