Changeset 72c72d4 in mainline for uspace/app/vol/vol.c


Ignore:
Timestamp:
2018-06-29T13:41:13Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a9174e
Parents:
db9c889
git-author:
Jiri Svoboda <jiri@…> (2018-06-28 17:40:58)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-29 13:41:13)
Message:

Basic volume eject implementation.

File:
1 edited

Legend:

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

    rdb9c889 r72c72d4  
    5252} vol_cmd_t;
    5353
    54 static int vol_cmd_list(void)
     54/** Find volume by current mount point. */
     55static errno_t vol_cmd_part_by_mp(vol_t *vol, const char *mp,
     56    service_id_t *rid)
     57{
     58        vol_part_info_t vinfo;
     59        service_id_t *part_ids = NULL;
     60        char *canon_mp_buf = NULL;
     61        char *canon_mp;
     62        size_t nparts;
     63        size_t i;
     64        errno_t rc;
     65
     66        canon_mp_buf = str_dup(mp);
     67        if (canon_mp_buf == NULL) {
     68                printf("Out of memory.\n");
     69                rc = ENOMEM;
     70                goto out;
     71        }
     72
     73        canon_mp = vfs_absolutize(canon_mp_buf, NULL);
     74        if (canon_mp == NULL) {
     75                printf("Invalid volume path '%s'.\n", mp);
     76                rc = EINVAL;
     77                goto out;
     78        }
     79
     80        rc = vol_get_parts(vol, &part_ids, &nparts);
     81        if (rc != EOK) {
     82                printf("Error getting list of volumes.\n");
     83                goto out;
     84        }
     85
     86        for (i = 0; i < nparts; i++) {
     87                rc = vol_part_info(vol, part_ids[i], &vinfo);
     88                if (rc != EOK) {
     89                        printf("Error getting volume information.\n");
     90                        rc = EIO;
     91                        goto out;
     92                }
     93
     94                if (str_cmp(vinfo.cur_mp, canon_mp) == 0) {
     95                        *rid = part_ids[i];
     96                        rc = EOK;
     97                        goto out;
     98                }
     99        }
     100
     101        rc = ENOENT;
     102out:
     103        free(part_ids);
     104        free(canon_mp_buf);
     105        return rc;
     106}
     107
     108static errno_t vol_cmd_eject(const char *volspec)
     109{
     110        vol_t *vol = NULL;
     111        service_id_t part_id;
     112        errno_t rc;
     113
     114        rc = vol_create(&vol);
     115        if (rc != EOK) {
     116                printf("Error contacting volume service.\n");
     117                goto out;
     118        }
     119
     120        rc = vol_cmd_part_by_mp(vol, volspec, &part_id);
     121        if (rc != EOK) {
     122                printf("Error looking up volume '%s'.\n", volspec);
     123                goto out;
     124        }
     125
     126        rc = vol_part_eject(vol, part_id);
     127        if (rc != EOK) {
     128                printf("Error ejecting volume.\n");
     129                goto out;
     130        }
     131
     132        rc = EOK;
     133out:
     134        vol_destroy(vol);
     135        return rc;
     136}
     137
     138static errno_t vol_cmd_list(void)
    55139{
    56140        vol_t *vol = NULL;
     
    62146        size_t i;
    63147        table_t *table = NULL;
    64         int rc;
     148        errno_t rc;
    65149
    66150        rc = vol_create(&vol);
     
    139223        vol_cmd_t vcmd;
    140224        int i;
    141         int rc;
     225        errno_t rc;
    142226
    143227        if (argc < 2) {
     
    169253        switch (vcmd) {
    170254        case vcmd_eject:
    171                 rc = EOK;
     255                rc = vol_cmd_eject(volspec);
    172256                break;
    173257        case vcmd_help:
Note: See TracChangeset for help on using the changeset viewer.