Changeset f57ccb5 in mainline for uspace/lib/c
- Timestamp:
- 2015-08-11T16:03:59Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0bde8523
- Parents:
- 1b23e33
- Location:
- uspace/lib/c
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/uuid.c
r1b23e33 rf57ccb5 36 36 #include <uuid.h> 37 37 #include <stdlib.h> 38 #include <str.h> 38 39 39 40 /** Generate UUID. … … 87 88 } 88 89 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 */ 102 int 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 */ 167 int uuid_format(uuid_t *uuid, char **rstr) 168 { 169 return ENOTSUP; 170 } 171 172 89 173 /** @} 90 174 */ -
uspace/lib/c/generic/vbd.c
r1b23e33 rf57ccb5 330 330 } 331 331 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 */ 341 int 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 332 366 /** @} 333 367 */ -
uspace/lib/c/include/ipc/vbd.h
r1b23e33 rf57ccb5 46 46 VBD_PART_CREATE, 47 47 VBD_PART_DELETE, 48 VBD_SUGGEST_PTYPE 48 49 } vbd_request_t; 49 50 -
uspace/lib/c/include/types/label.h
r1b23e33 rf57ccb5 36 36 #define LIBC_TYPES_LABEL_H_ 37 37 38 #include <types/uuid.h> 39 38 40 /** Disk contents */ 39 41 typedef enum { … … 72 74 /** Label supports extended (and logical) partitions */ 73 75 lf_ext_supp = 0x1, 76 /** Partition type is in UUID format (otherwise in small number format) */ 77 lf_ptype_uuid = 0x2, 74 78 /** Currently it is possible to create a primary partition */ 75 lf_can_create_pri = 0x 2,79 lf_can_create_pri = 0x4, 76 80 /** Currently it is possible to create an extended partition */ 77 lf_can_create_ext = 0x 4,81 lf_can_create_ext = 0x8, 78 82 /** Currrently it is possible to create a logical partition */ 79 lf_can_create_log = 0x 883 lf_can_create_log = 0x10 80 84 } label_flags_t; 85 86 /** Partition type format */ 87 typedef enum { 88 /** Small number */ 89 lptf_num, 90 /** UUID */ 91 lptf_uuid 92 } label_pt_fmt; 93 94 /** Partition type */ 95 typedef 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) */ 108 typedef 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; 81 120 82 121 #endif -
uspace/lib/c/include/uuid.h
r1b23e33 rf57ccb5 37 37 38 38 #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> 48 40 49 41 extern int uuid_generate(uuid_t *); 50 42 extern void uuid_encode(uuid_t *, uint8_t *); 51 43 extern void uuid_decode(uint8_t *, uuid_t *); 44 extern int uuid_parse(const char *, uuid_t *, const char **); 45 extern int uuid_format(uuid_t *, char **); 52 46 53 47 #endif -
uspace/lib/c/include/vbd.h
r1b23e33 rf57ccb5 74 74 label_pkind_t pkind; 75 75 /** Partition type */ 76 uint64_t ptype;76 label_ptype_t ptype; 77 77 } vbd_part_spec_t; 78 78 … … 105 105 extern int vbd_part_delete(vbd_t *, vbd_part_id_t); 106 106 extern void vbd_pspec_init(vbd_part_spec_t *); 107 extern int vbd_suggest_ptype(vbd_t *, service_id_t, label_pcnt_t, 108 label_ptype_t *); 107 109 108 110 #endif
Note:
See TracChangeset
for help on using the changeset viewer.