Changeset 72c72d4 in mainline


Ignore:
Timestamp:
2018-06-29T13:41:13Z (6 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.

Location:
uspace
Files:
5 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:
  • uspace/lib/c/generic/vol.c

    rdb9c889 r72c72d4  
    235235}
    236236
     237/** Unmount partition (and possibly eject the media). */
     238errno_t vol_part_eject(vol_t *vol, service_id_t sid)
     239{
     240        async_exch_t *exch;
     241        errno_t retval;
     242
     243        exch = async_exchange_begin(vol->sess);
     244        retval = async_req_1_0(exch, VOL_PART_EJECT, sid);
     245        async_exchange_end(exch);
     246
     247        if (retval != EOK)
     248                return retval;
     249
     250        return EOK;
     251}
     252
    237253/** Erase partition (to the extent where we will consider it not containing
    238254 * a file system.
  • uspace/lib/c/include/ipc/vol.h

    rdb9c889 r72c72d4  
    4242        VOL_PART_ADD,
    4343        VOL_PART_INFO,
     44        VOL_PART_EJECT,
    4445        VOL_PART_EMPTY,
    4546        VOL_PART_LSUPP,
    46         VOL_PART_MKFS,
     47        VOL_PART_MKFS
    4748} vol_request_t;
    4849
  • uspace/srv/volsrv/part.c

    rdb9c889 r72c72d4  
    478478errno_t vol_part_get_info(vol_part_t *part, vol_part_info_t *pinfo)
    479479{
     480        memset(pinfo, 0, sizeof(*pinfo));
     481
    480482        pinfo->pcnt = part->pcnt;
    481483        pinfo->fstype = part->fstype;
    482484        str_cpy(pinfo->label, sizeof(pinfo->label), part->label);
    483         str_cpy(pinfo->cur_mp, sizeof(pinfo->cur_mp), part->cur_mp);
     485        if (part->cur_mp != NULL)
     486                str_cpy(pinfo->cur_mp, sizeof(pinfo->cur_mp), part->cur_mp);
    484487        pinfo->cur_mp_auto = part->cur_mp_auto;
    485488        return EOK;
  • uspace/srv/volsrv/volsrv.c

    rdb9c889 r72c72d4  
    181181}
    182182
     183static void vol_part_eject_srv(cap_call_handle_t icall_handle, ipc_call_t *icall)
     184{
     185        service_id_t sid;
     186        vol_part_t *part;
     187        errno_t rc;
     188
     189        sid = IPC_GET_ARG1(*icall);
     190        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu)", sid);
     191
     192        rc = vol_part_find_by_id(sid, &part);
     193        if (rc != EOK) {
     194                async_answer_0(icall_handle, ENOENT);
     195                return;
     196        }
     197
     198        rc = vol_part_eject_part(part);
     199        if (rc != EOK) {
     200                async_answer_0(icall_handle, EIO);
     201                return;
     202        }
     203
     204        async_answer_0(icall_handle, EOK);
     205}
     206
    183207static void vol_part_empty_srv(cap_call_handle_t icall_handle, ipc_call_t *icall)
    184208{
     
    314338                        vol_part_info_srv(chandle, &call);
    315339                        break;
     340                case VOL_PART_EJECT:
     341                        vol_part_eject_srv(chandle, &call);
     342                        break;
    316343                case VOL_PART_EMPTY:
    317344                        vol_part_empty_srv(chandle, &call);
Note: See TracChangeset for help on using the changeset viewer.