Changes in uspace/app/vol/vol.c [629b480:b82985e] in mainline
- File:
-
- 1 edited
-
uspace/app/vol/vol.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vol/vol.c
r629b480 rb82985e 1 1 /* 2 * Copyright (c) 20 25Jiri Svoboda2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #include <io/table.h> 37 37 #include <loc.h> 38 #include <stdbool.h>39 38 #include <stdio.h> 40 39 #include <stdlib.h> … … 54 53 } vol_cmd_t; 55 54 56 static errno_t vol_cmd_eject(const char *volspec, bool physical) 55 /** Find volume by current mount point. */ 56 static errno_t vol_cmd_part_by_mp(vol_t *vol, const char *mp, 57 service_id_t *rid) 58 { 59 vol_part_info_t vinfo; 60 service_id_t *part_ids = NULL; 61 char *canon_mp_buf = NULL; 62 char *canon_mp; 63 size_t nparts; 64 size_t i; 65 errno_t rc; 66 67 canon_mp_buf = str_dup(mp); 68 if (canon_mp_buf == NULL) { 69 printf("Out of memory.\n"); 70 rc = ENOMEM; 71 goto out; 72 } 73 74 canon_mp = vfs_absolutize(canon_mp_buf, NULL); 75 if (canon_mp == NULL) { 76 printf("Invalid volume path '%s'.\n", mp); 77 rc = EINVAL; 78 goto out; 79 } 80 81 rc = vol_get_parts(vol, &part_ids, &nparts); 82 if (rc != EOK) { 83 printf("Error getting list of volumes.\n"); 84 goto out; 85 } 86 87 for (i = 0; i < nparts; i++) { 88 rc = vol_part_info(vol, part_ids[i], &vinfo); 89 if (rc != EOK) { 90 printf("Error getting volume information.\n"); 91 rc = EIO; 92 goto out; 93 } 94 95 if (str_cmp(vinfo.cur_mp, canon_mp) == 0) { 96 *rid = part_ids[i]; 97 rc = EOK; 98 goto out; 99 } 100 } 101 102 rc = ENOENT; 103 out: 104 free(part_ids); 105 free(canon_mp_buf); 106 return rc; 107 } 108 109 static errno_t vol_cmd_eject(const char *volspec) 57 110 { 58 111 vol_t *vol = NULL; … … 66 119 } 67 120 68 rc = vol_ part_by_mp(vol, volspec, &part_id);121 rc = vol_cmd_part_by_mp(vol, volspec, &part_id); 69 122 if (rc != EOK) { 70 123 printf("Error looking up volume '%s'.\n", volspec); … … 72 125 } 73 126 74 rc = vol_part_eject(vol, part_id, physical ? vef_physical : 75 vef_none); 127 rc = vol_part_eject(vol, part_id); 76 128 if (rc != EOK) { 77 129 printf("Error ejecting volume.\n"); … … 271 323 { 272 324 printf("Syntax:\n"); 273 printf(" %s List present volumes\n", NAME); 274 printf(" %s -c List volume configuration entries\n", NAME); 275 printf(" %s -h Print help\n", NAME); 276 printf(" %s eject [-s] <mp> Eject volume mounted in a directory\n", NAME); 277 printf(" -s to eject physically\n"); 278 printf(" %s insert <svc> Insert volume based on service identifier\n", NAME); 279 printf(" %s insert -p <mp> Insert volume based on filesystem path\n", NAME); 325 printf(" %s List present volumes\n", NAME); 326 printf(" %s -c List volume configuration entries\n", NAME); 327 printf(" %s -h Print help\n", NAME); 328 printf(" %s eject <mp> Eject volume mounted in a directory\n", NAME); 329 printf(" %s insert <svc> Insert volume based on service identifier\n", NAME); 330 printf(" %s insert -p <mp> Insert volume based on filesystem path\n", NAME); 280 331 } 281 332 … … 285 336 char *volspec; 286 337 vol_cmd_t vcmd; 287 bool physical = false;288 338 int i; 289 339 errno_t rc = EINVAL; … … 301 351 } else if (str_cmp(cmd, "eject") == 0) { 302 352 vcmd = vcmd_eject; 303 if (str_cmp(argv[i], "-s") == 0) {304 physical = true;305 ++i;306 }307 308 353 if (argc <= i) { 309 354 printf("Parameter missing.\n"); … … 337 382 switch (vcmd) { 338 383 case vcmd_eject: 339 rc = vol_cmd_eject(volspec , physical);384 rc = vol_cmd_eject(volspec); 340 385 break; 341 386 case vcmd_insert:
Note:
See TracChangeset
for help on using the changeset viewer.
