Changeset f57ccb5 in mainline for uspace/lib/c


Ignore:
Timestamp:
2015-08-11T16:03:59Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0bde8523
Parents:
1b23e33
Message:

Set partition type based on selected filesystem type.

Location:
uspace/lib/c
Files:
1 added
6 edited

Legend:

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

    r1b23e33 rf57ccb5  
    3636#include <uuid.h>
    3737#include <stdlib.h>
     38#include <str.h>
    3839
    3940/** Generate UUID.
     
    8788}
    8889
     90/** Parse string UUID.
     91 *
     92 * If @a endptr is not NULL, it is set to point to the first character
     93 * following the UUID. If @a endptr is NULL, the string must not contain
     94 * any characters following the UUID, otherwise an error is returned.
     95 *
     96 * @param str    String beginning with UUID string representation
     97 * @param uuid   Place to store UUID
     98 * @param endptr Place to store pointer to end of UUID or @c NULL
     99 *
     100 * @return EOK on success or negative error code
     101 */
     102int uuid_parse(const char *str, uuid_t *uuid, const char **endptr)
     103{
     104        int rc;
     105        const char *eptr;
     106        uint32_t time_low;
     107        uint16_t time_mid;
     108        uint16_t time_ver;
     109        uint16_t clock;
     110        uint64_t node;
     111        int i;
     112
     113        rc = str_uint32_t(str, &eptr, 16, false, &time_low);
     114        if (rc != EOK || eptr != str + 8 || *eptr != '-')
     115                return EINVAL;
     116
     117        rc = str_uint16_t(str + 9, &eptr, 16, false, &time_mid);
     118        if (rc != EOK || eptr != str + 13 || *eptr != '-')
     119                return EINVAL;
     120
     121        rc = str_uint16_t(str + 14, &eptr, 16, false, &time_ver);
     122        if (rc != EOK || eptr != str + 18 || *eptr != '-')
     123                return EINVAL;
     124
     125        rc = str_uint16_t(str + 19, &eptr, 16, false, &clock);
     126        if (rc != EOK || eptr != str + 23 || *eptr != '-')
     127                return EINVAL;
     128
     129        rc = str_uint64_t(str + 24, &eptr, 16, false, &node);
     130        if (rc != EOK || eptr != str + 36 || *eptr != '\0')
     131                return EINVAL;
     132
     133        uuid->b[0] = time_low >> 24;
     134        uuid->b[1] = (time_low >> 16) & 0xff;
     135        uuid->b[2] = (time_low >> 8) & 0xff;
     136        uuid->b[3] = time_low & 0xff;
     137
     138        uuid->b[4] = time_mid >> 8;
     139        uuid->b[5] = time_mid & 0xff;
     140
     141        uuid->b[6] = time_ver >> 8;
     142        uuid->b[7] = time_ver & 0xff;
     143
     144        uuid->b[8] = clock >> 8;
     145        uuid->b[9] = clock & 0xff;
     146
     147        for (i = 0; i < 6; i++)
     148                uuid->b[10 + i] = (node >> 8 * (5 - i)) & 0xff;
     149
     150        if (endptr != NULL) {
     151                *endptr = str + 36;
     152        } else {
     153                if (*(str + 36) != '\0')
     154                        return EINVAL;
     155        }
     156
     157        return EOK;
     158}
     159
     160/** Format UUID into string representation.
     161 *
     162 * @param uuid UUID
     163 * @param rstr Place to store pointer to newly allocated string
     164 *
     165 * @return EOK on success, ENOMEM if out of memory
     166 */
     167int uuid_format(uuid_t *uuid, char **rstr)
     168{
     169        return ENOTSUP;
     170}
     171
     172
    89173/** @}
    90174 */
  • uspace/lib/c/generic/vbd.c

    r1b23e33 rf57ccb5  
    330330}
    331331
     332/** Suggest partition type based on partition content.
     333 *
     334 * @param vbd   Virtual Block Device
     335 * @param disk  Disk on which the partition will be created
     336 * @param pcnt  Partition content
     337 * @param ptype Place to store suggested partition type
     338 *
     339 * @return EOK on success or negative error code
     340 */
     341int vbd_suggest_ptype(vbd_t *vbd, service_id_t disk, label_pcnt_t pcnt,
     342    label_ptype_t *ptype)
     343{
     344        async_exch_t *exch;
     345        sysarg_t retval;
     346        ipc_call_t answer;
     347
     348        exch = async_exchange_begin(vbd->sess);
     349        aid_t req = async_send_2(exch, VBD_SUGGEST_PTYPE, disk, pcnt, &answer);
     350        int rc = async_data_read_start(exch, ptype, sizeof(label_ptype_t));
     351        async_exchange_end(exch);
     352
     353        if (rc != EOK) {
     354                async_forget(req);
     355                return EIO;
     356        }
     357
     358        async_wait_for(req, &retval);
     359        if (retval != EOK)
     360                return EIO;
     361
     362        return EOK;
     363}
     364
     365
    332366/** @}
    333367 */
  • uspace/lib/c/include/ipc/vbd.h

    r1b23e33 rf57ccb5  
    4646        VBD_PART_CREATE,
    4747        VBD_PART_DELETE,
     48        VBD_SUGGEST_PTYPE
    4849} vbd_request_t;
    4950
  • uspace/lib/c/include/types/label.h

    r1b23e33 rf57ccb5  
    3636#define LIBC_TYPES_LABEL_H_
    3737
     38#include <types/uuid.h>
     39
    3840/** Disk contents */
    3941typedef enum {
     
    7274        /** Label supports extended (and logical) partitions */
    7375        lf_ext_supp = 0x1,
     76        /** Partition type is in UUID format (otherwise in small number format) */
     77        lf_ptype_uuid = 0x2,
    7478        /** Currently it is possible to create a primary partition */
    75         lf_can_create_pri = 0x2,
     79        lf_can_create_pri = 0x4,
    7680        /** Currently it is possible to create an extended partition */
    77         lf_can_create_ext = 0x4,
     81        lf_can_create_ext = 0x8,
    7882        /** Currrently it is possible to create a logical partition */
    79         lf_can_create_log = 0x8
     83        lf_can_create_log = 0x10
    8084} label_flags_t;
     85
     86/** Partition type format */
     87typedef enum {
     88        /** Small number */
     89        lptf_num,
     90        /** UUID */
     91        lptf_uuid
     92} label_pt_fmt;
     93
     94/** Partition type */
     95typedef struct {
     96        /** Type format */
     97        label_pt_fmt fmt;
     98        /** Depending on @c fmt */
     99        union {
     100                /* Small number */
     101                uint8_t num;
     102                /** UUID */
     103                uuid_t uuid;
     104        } t;
     105} label_ptype_t;
     106
     107/** Partition content (used to get partition type suggestion) */
     108typedef enum {
     109        /** ExFAT */
     110        lpc_exfat,
     111        /** Ext4 */
     112        lpc_ext4,
     113        /** FAT12 or FAT16 */
     114        lpc_fat12_16,
     115        /** FAT32 */
     116        lpc_fat32,
     117        /** Minix file system */
     118        lpc_minix
     119} label_pcnt_t;
    81120
    82121#endif
  • uspace/lib/c/include/uuid.h

    r1b23e33 rf57ccb5  
    3737
    3838#include <stdint.h>
    39 
    40 enum {
    41         uuid_bytes = 16
    42 };
    43 
    44 /** Universally Unique Identifier */
    45 typedef struct {
    46         uint8_t b[uuid_bytes];
    47 } uuid_t;
     39#include <types/uuid.h>
    4840
    4941extern int uuid_generate(uuid_t *);
    5042extern void uuid_encode(uuid_t *, uint8_t *);
    5143extern void uuid_decode(uint8_t *, uuid_t *);
     44extern int uuid_parse(const char *, uuid_t *, const char **);
     45extern int uuid_format(uuid_t *, char **);
    5246
    5347#endif
  • uspace/lib/c/include/vbd.h

    r1b23e33 rf57ccb5  
    7474        label_pkind_t pkind;
    7575        /** Partition type */
    76         uint64_t ptype;
     76        label_ptype_t ptype;
    7777} vbd_part_spec_t;
    7878
     
    105105extern int vbd_part_delete(vbd_t *, vbd_part_id_t);
    106106extern void vbd_pspec_init(vbd_part_spec_t *);
     107extern int vbd_suggest_ptype(vbd_t *, service_id_t, label_pcnt_t,
     108    label_ptype_t *);
    107109
    108110#endif
Note: See TracChangeset for help on using the changeset viewer.