Changes in uspace/app/vol/vol.c [b82985e:629b480] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vol/vol.c

    rb82985e r629b480  
    11/*
    2  * Copyright (c) 2017 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <io/table.h>
    3737#include <loc.h>
     38#include <stdbool.h>
    3839#include <stdio.h>
    3940#include <stdlib.h>
     
    5354} vol_cmd_t;
    5455
    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)
     56static errno_t vol_cmd_eject(const char *volspec, bool physical)
    11057{
    11158        vol_t *vol = NULL;
     
    11966        }
    12067
    121         rc = vol_cmd_part_by_mp(vol, volspec, &part_id);
     68        rc = vol_part_by_mp(vol, volspec, &part_id);
    12269        if (rc != EOK) {
    12370                printf("Error looking up volume '%s'.\n", volspec);
     
    12572        }
    12673
    127         rc = vol_part_eject(vol, part_id);
     74        rc = vol_part_eject(vol, part_id, physical ? vef_physical :
     75            vef_none);
    12876        if (rc != EOK) {
    12977                printf("Error ejecting volume.\n");
     
    323271{
    324272        printf("Syntax:\n");
    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);
     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);
    331280}
    332281
     
    336285        char *volspec;
    337286        vol_cmd_t vcmd;
     287        bool physical = false;
    338288        int i;
    339289        errno_t rc = EINVAL;
     
    351301                } else if (str_cmp(cmd, "eject") == 0) {
    352302                        vcmd = vcmd_eject;
     303                        if (str_cmp(argv[i], "-s") == 0) {
     304                                physical = true;
     305                                ++i;
     306                        }
     307
    353308                        if (argc <= i) {
    354309                                printf("Parameter missing.\n");
     
    382337        switch (vcmd) {
    383338        case vcmd_eject:
    384                 rc = vol_cmd_eject(volspec);
     339                rc = vol_cmd_eject(volspec, physical);
    385340                break;
    386341        case vcmd_insert:
Note: See TracChangeset for help on using the changeset viewer.