Changes in uspace/app/bdsh/cmds/modules/mount/mount.c [e6cb880:41047bf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/mount/mount.c
re6cb880 r41047bf 30 30 #include <stdlib.h> 31 31 #include <vfs/vfs.h> 32 #include <adt/list.h> 32 33 #include <errno.h> 33 34 #include <getopt.h> 35 #include <inttypes.h> 34 36 #include "config.h" 35 37 #include "util.h" … … 43 45 static struct option const long_options[] = { 44 46 { "help", no_argument, 0, 'h' }, 47 { "instance", required_argument, 0, 'i' }, 45 48 { 0, 0, 0, 0 } 46 49 }; … … 51 54 { 52 55 static char helpfmt[] = 53 "Usage: %s <fstype> <mp> <dev>[<moptions>]\n";56 "Usage: %s <fstype> <mp> [dev] [<moptions>]\n"; 54 57 if (level == HELP_SHORT) { 55 58 printf("'%s' mounts a file system.\n", cmdname); … … 61 64 } 62 65 66 static void print_mtab_list(void) 67 { 68 LIST_INITIALIZE(mtab_list); 69 get_mtab_list(&mtab_list); 70 71 mtab_ent_t *old_ent = NULL; 72 73 list_foreach(mtab_list, cur) { 74 mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t, 75 link); 76 77 if (old_ent) 78 free(old_ent); 79 80 old_ent = mtab_ent; 81 82 printf("%s", mtab_ent->fs_name); 83 if (mtab_ent->instance) 84 printf("/%d", mtab_ent->instance); 85 printf(" on %s ", mtab_ent->mp); 86 87 if (str_size(mtab_ent->opts) > 0) 88 printf("opts=%s ", mtab_ent->opts); 89 90 printf("(service=%" PRIun ")\n", mtab_ent->service_id); 91 } 92 93 if (old_ent) 94 free(old_ent); 95 } 96 63 97 /* Main entry point for mount, accepts an array of arguments */ 64 98 int cmd_mount(char **argv) … … 66 100 unsigned int argc; 67 101 const char *mopts = ""; 102 const char *dev = ""; 68 103 int rc, c, opt_ind; 104 unsigned int instance = 0; 105 bool instance_set = false; 106 char **t_argv; 69 107 70 108 argc = cli_count_args(argv); 71 109 72 110 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 73 c = getopt_long(argc, argv, " h", long_options, &opt_ind);111 c = getopt_long(argc, argv, "i:h", long_options, &opt_ind); 74 112 switch (c) { 75 113 case 'h': 76 114 help_cmd_mount(HELP_LONG); 77 115 return CMD_SUCCESS; 116 case 'i': 117 instance = (unsigned int) strtol(optarg, NULL, 10); 118 instance_set = true; 119 break; 78 120 } 79 121 } 80 122 81 if ((argc < 4) || (argc > 5)) { 123 if (instance_set) { 124 argc -= 2; 125 t_argv = &argv[2]; 126 } else 127 t_argv = &argv[0]; 128 129 if ((argc == 2) || (argc > 5)) { 82 130 printf("%s: invalid number of arguments. Try `mount --help'\n", 83 131 cmdname); 84 132 return CMD_FAILURE; 85 133 } 134 if (argc == 1) { 135 print_mtab_list(); 136 return CMD_SUCCESS; 137 } 138 if (argc > 3) 139 dev = t_argv[3]; 86 140 if (argc == 5) 87 mopts = argv[4];141 mopts = t_argv[4]; 88 142 89 rc = mount( argv[1], argv[2], argv[3], mopts, 0);143 rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance); 90 144 if (rc != EOK) { 91 145 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n", 92 argv[1], argv[2],argv[3], rc);146 t_argv[1], t_argv[2], t_argv[3], rc); 93 147 return CMD_FAILURE; 94 148 }
Note:
See TracChangeset
for help on using the changeset viewer.