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


Ignore:
File:
1 edited

Legend:

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

    r629b480 rb82985e  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2017 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <io/table.h>
    3737#include <loc.h>
    38 #include <stdbool.h>
    3938#include <stdio.h>
    4039#include <stdlib.h>
     
    5453} vol_cmd_t;
    5554
    56 static errno_t vol_cmd_eject(const char *volspec, bool physical)
     55/** Find volume by current mount point. */
     56static 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;
     103out:
     104        free(part_ids);
     105        free(canon_mp_buf);
     106        return rc;
     107}
     108
     109static errno_t vol_cmd_eject(const char *volspec)
    57110{
    58111        vol_t *vol = NULL;
     
    66119        }
    67120
    68         rc = vol_part_by_mp(vol, volspec, &part_id);
     121        rc = vol_cmd_part_by_mp(vol, volspec, &part_id);
    69122        if (rc != EOK) {
    70123                printf("Error looking up volume '%s'.\n", volspec);
     
    72125        }
    73126
    74         rc = vol_part_eject(vol, part_id, physical ? vef_physical :
    75             vef_none);
     127        rc = vol_part_eject(vol, part_id);
    76128        if (rc != EOK) {
    77129                printf("Error ejecting volume.\n");
     
    271323{
    272324        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);
    280331}
    281332
     
    285336        char *volspec;
    286337        vol_cmd_t vcmd;
    287         bool physical = false;
    288338        int i;
    289339        errno_t rc = EINVAL;
     
    301351                } else if (str_cmp(cmd, "eject") == 0) {
    302352                        vcmd = vcmd_eject;
    303                         if (str_cmp(argv[i], "-s") == 0) {
    304                                 physical = true;
    305                                 ++i;
    306                         }
    307 
    308353                        if (argc <= i) {
    309354                                printf("Parameter missing.\n");
     
    337382        switch (vcmd) {
    338383        case vcmd_eject:
    339                 rc = vol_cmd_eject(volspec, physical);
     384                rc = vol_cmd_eject(volspec);
    340385                break;
    341386        case vcmd_insert:
Note: See TracChangeset for help on using the changeset viewer.