Changeset 9c2c7d2 in mainline for uspace/lib


Ignore:
Timestamp:
2017-07-06T15:52:15Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cd1eb9a
Parents:
d858a660
Message:

Fdisk should be able to set volume label for newly created partitions.

Location:
uspace/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vol.c

    rd858a660 r9c2c7d2  
    3939#include <loc.h>
    4040#include <stdlib.h>
     41#include <str.h>
    4142#include <vol.h>
    4243
     
    251252}
    252253
     254/** Get volume label support. */
     255int vol_part_get_lsupp(vol_t *vol, vol_fstype_t fstype,
     256    vol_label_supp_t *vlsupp)
     257{
     258        async_exch_t *exch;
     259        sysarg_t retval;
     260        ipc_call_t answer;
     261
     262        exch = async_exchange_begin(vol->sess);
     263        aid_t req = async_send_1(exch, VOL_PART_LSUPP, fstype, &answer);
     264        int rc = async_data_read_start(exch, vlsupp, sizeof(vol_label_supp_t));
     265        async_exchange_end(exch);
     266
     267        if (rc != EOK) {
     268                async_forget(req);
     269                return EIO;
     270        }
     271
     272        async_wait_for(req, &retval);
     273        if (retval != EOK)
     274                return EIO;
     275
     276        return EOK;
     277}
     278
    253279/** Create file system. */
    254 int vol_part_mkfs(vol_t *vol, service_id_t sid, vol_fstype_t fstype)
    255 {
    256         async_exch_t *exch;
    257         int retval;
    258 
    259         exch = async_exchange_begin(vol->sess);
    260         retval = async_req_2_0(exch, VOL_PART_MKFS, sid, fstype);
    261         async_exchange_end(exch);
     280int vol_part_mkfs(vol_t *vol, service_id_t sid, vol_fstype_t fstype,
     281    const char *label)
     282{
     283        async_exch_t *exch;
     284        ipc_call_t answer;
     285        sysarg_t retval;
     286
     287        exch = async_exchange_begin(vol->sess);
     288        aid_t req = async_send_2(exch, VOL_PART_MKFS, sid, fstype, &answer);
     289        retval = async_data_write_start(exch, label, str_size(label));
     290        async_exchange_end(exch);
     291
     292        if (retval != EOK) {
     293                async_forget(req);
     294                return retval;
     295        }
     296
     297        async_wait_for(req, &retval);
    262298
    263299        if (retval != EOK)
  • uspace/lib/c/include/ipc/vol.h

    rd858a660 r9c2c7d2  
    4343        VOL_PART_INFO,
    4444        VOL_PART_EMPTY,
    45         VOL_PART_MKFS
     45        VOL_PART_LSUPP,
     46        VOL_PART_MKFS,
    4647} vol_request_t;
    4748
  • uspace/lib/c/include/types/vol.h

    rd858a660 r9c2c7d2  
    3838#include <async.h>
    3939#include <ipc/vol.h>
     40#include <stdbool.h>
    4041
    4142typedef enum {
     
    7677} vol_part_info_t;
    7778
     79/** Volume label support */
     80typedef struct {
     81        /** Volume labels are supported */
     82        bool supported;
     83} vol_label_supp_t;
     84
    7885#endif
    7986
  • uspace/lib/c/include/vol.h

    rd858a660 r9c2c7d2  
    4848extern int vol_part_info(vol_t *, service_id_t, vol_part_info_t *);
    4949extern int vol_part_empty(vol_t *, service_id_t);
    50 extern int vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t);
     50extern int vol_part_get_lsupp(vol_t *, vol_fstype_t, vol_label_supp_t *);
     51extern int vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t, const char *);
    5152
    5253#endif
  • uspace/lib/fdisk/include/fdisk.h

    rd858a660 r9c2c7d2  
    3939#include <loc.h>
    4040#include <types/fdisk.h>
     41#include <types/vol.h>
    4142
    4243extern int fdisk_create(fdisk_t **);
     
    8182extern int fdisk_pkind_format(label_pkind_t, char **);
    8283
     84extern int fdisk_get_vollabel_support(fdisk_dev_t *, vol_fstype_t,
     85    vol_label_supp_t *);
     86
    8387#endif
    8488
  • uspace/lib/fdisk/include/types/fdisk.h

    rd858a660 r9c2c7d2  
    4343#include <types/vol.h>
    4444#include <vbd.h>
    45 #include <vol.h>
    4645
    4746/** Capacity unit */
     
    199198        /** File system type */
    200199        vol_fstype_t fstype;
     200        /** Volume label */
     201        char *label;
    201202} fdisk_part_spec_t;
    202203
  • uspace/lib/fdisk/src/fdisk.c

    rd858a660 r9c2c7d2  
    731731    fdisk_part_t **rpart)
    732732{
    733         fdisk_part_t *part;
     733        fdisk_part_t *part = NULL;
    734734        vbd_part_spec_t vpspec;
    735         vbd_part_id_t partid;
    736         int rc;
     735        vbd_part_id_t partid = 0;
     736        vol_part_info_t vpinfo;
     737        char *label;
     738        int rc;
     739
     740        label = str_dup(pspec->label);
     741        if (label == NULL)
     742                return ENOMEM;
    737743
    738744        rc = fdisk_part_spec_prepare(dev, pspec, &vpspec);
    739         if (rc != EOK)
    740                 return EIO;
     745        if (rc != EOK) {
     746                rc = EIO;
     747                goto error;
     748        }
    741749
    742750        rc = vbd_part_create(dev->fdisk->vbd, dev->sid, &vpspec, &partid);
    743         if (rc != EOK)
    744                 return EIO;
     751        if (rc != EOK) {
     752                rc = EIO;
     753                goto error;
     754        }
    745755
    746756        rc = fdisk_part_add(dev, partid, &part);
    747757        if (rc != EOK) {
    748                 /* Try rolling back */
    749                 (void) vbd_part_delete(dev->fdisk->vbd, partid);
    750                 return EIO;
     758                rc = EIO;
     759                goto error;
    751760        }
    752761
    753762        if (part->svc_id != 0) {
    754                 rc = vol_part_mkfs(dev->fdisk->vol, part->svc_id, pspec->fstype);
     763                rc = vol_part_mkfs(dev->fdisk->vol, part->svc_id, pspec->fstype,
     764                    pspec->label);
    755765                if (rc != EOK && rc != ENOTSUP) {
    756                         fdisk_part_remove(part);
    757                         (void) vbd_part_delete(dev->fdisk->vbd, partid);
    758                         return EIO;
    759                 }
    760 
    761                 part->pcnt = vpc_fs;
    762                 part->fstype = pspec->fstype;
     766                        rc = EIO;
     767                        goto error;
     768                }
     769
     770                /* Get the real label value */
     771                rc = vol_part_info(dev->fdisk->vol, part->svc_id, &vpinfo);
     772                if (rc != EOK) {
     773                        rc = EIO;
     774                        goto error;
     775                }
     776
     777                part->pcnt = vpinfo.pcnt;
     778                part->fstype = vpinfo.fstype;
     779                part->label = str_dup(vpinfo.label);
     780
     781                if (part->label == NULL) {
     782                        rc = EIO;
     783                        goto error;
     784                }
    763785        }
    764786
     
    766788                *rpart = part;
    767789        return EOK;
     790error:
     791        /* Try rolling back */
     792        if (part != NULL)
     793                fdisk_part_remove(part);
     794        if (partid != 0)
     795                (void) vbd_part_delete(dev->fdisk->vbd, partid);
     796        return rc;
    768797}
    769798
     
    11941223}
    11951224
     1225/** Get volume label support. */
     1226int fdisk_get_vollabel_support(fdisk_dev_t *dev, vol_fstype_t fstype,
     1227    vol_label_supp_t *vlsupp)
     1228{
     1229        return vol_part_get_lsupp(dev->fdisk->vol, fstype, vlsupp);
     1230}
     1231
    11961232/** @}
    11971233 */
Note: See TracChangeset for help on using the changeset viewer.