Changeset 5c702a8 in mainline
- Timestamp:
- 2012-08-27T17:21:38Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0d57c3e
- Parents:
- 5d94b16c
- Location:
- uspace/srv/fs/udf
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/udf/udf_cksum.c
r5d94b16c r5c702a8 73 73 }; 74 74 75 /** Calculate CRC1676 *77 */78 uint16_t udf_cksum(uint8_t *buf, size_t len)79 {80 uint16_t crc = 0;81 82 while (len-- > 0)83 crc = crc_table[(crc >> 8 ^ *buf++) & 0xff] ^ (crc << 8);84 85 return crc;86 }87 88 75 /** Unicode checksum 89 76 * … … 103 90 104 91 return crc; 105 }106 107 /** EA checksum108 *109 * Calculate a 16-bit checksum of the Implementation Use110 * Extended Attribute header or Application Use Extended Attribute111 * header. The fields AttributeType through ImplementationIdentifier112 * (or ApplicationIdentifier) inclusively represent the113 * data covered by the checksum (48 bytes).114 *115 */116 uint16_t udf_ea_cksum(uint8_t *data)117 {118 uint16_t checksum = 0;119 size_t count;120 121 for (count = 0; count < 48; count++)122 checksum += *data++;123 124 return checksum;125 92 } 126 93 -
uspace/srv/fs/udf/udf_cksum.h
r5d94b16c r5c702a8 39 39 #define UDF_TAG_SIZE 16 40 40 41 extern uint16_t udf_cksum(uint8_t *, size_t);42 41 extern uint16_t udf_unicode_cksum(uint16_t *, size_t); 43 extern uint16_t udf_ea_cksum(uint8_t *);44 42 extern uint8_t udf_tag_checksum(uint8_t *); 45 43 -
uspace/srv/fs/udf/udf_file.c
r5d94b16c r5c702a8 57 57 * 58 58 */ 59 int udf_read_extended_allocator(udf_node_t *node, uint16_t icb_flag,59 static int udf_read_extended_allocator(udf_node_t *node, uint16_t icb_flag, 60 60 uint32_t pos) 61 61 { … … 185 185 */ 186 186 if (FLE32(long_d->length) >> 30 == 3) { 187 udf_read_extended_allocator 187 udf_read_extended_allocator(node, icb_flag, pos_long_ad); 188 188 break; 189 189 } … … 296 296 } 297 297 298 /** Read ICB sequence of allocators in Unallocated space entry descriptor299 *300 * This function read ICB sequence if free space is saved by space table.301 * Not finished.302 *303 * @param uased Unallocated space entry descriptor304 * @param icb_flag Type of allocators in sequence.305 * According to ECMA 167 4/14.8.8306 * @param start_alloc Offset of the allocator307 * @param len Length of sequence308 *309 * @return EOK on success or a negative error code.310 *311 */312 int udf_read_free_space(uint8_t *uased, uint16_t icb_flag,313 uint32_t start_alloc, uint32_t len)314 {315 switch (icb_flag) {316 case UDF_SHORT_AD:317 log_msg(LVL_DEBUG,318 "UAICB: sequence of allocation descriptors - icbflag = short_ad_t");319 320 /* Identify number of current partition */321 322 size_t cnt = len / sizeof(udf_short_ad_t);323 size_t n = 0;324 325 while (n < cnt) {326 udf_short_ad_t *short_d =327 (udf_short_ad_t *) (uased + start_alloc + n * sizeof(udf_short_ad_t));328 329 if (short_d->length == 0)330 break;331 332 n++;333 }334 335 break;336 337 case UDF_LONG_AD:338 log_msg(LVL_DEBUG,339 "UAICB: sequence of allocation descriptors - icbflag = long_ad_t");340 341 cnt = len / sizeof(udf_long_ad_t);342 n = 0;343 344 while (n < cnt) {345 udf_long_ad_t *long_d =346 (udf_long_ad_t *) (uased + start_alloc + n * sizeof(udf_long_ad_t));347 348 if (long_d->length == 0)349 break;350 351 n++;352 }353 354 break;355 356 case UDF_EXTENDED_AD:357 log_msg(LVL_DEBUG,358 "UAICB: sequence of allocation descriptors - icbflag = extended_ad_t");359 break;360 361 case UDF_DATA_AD:362 log_msg(LVL_DEBUG,363 "UAICB: sequence of allocation descriptors - icbflag = 3, node contains data itself");364 break;365 }366 367 return EOK;368 }369 370 /** Read Unallocated space entry descriptor371 *372 * Read ICB sequence if free space is saved by space table.373 * Not finished.374 *375 */376 int udf_read_unallocated_space_entry(udf_instance_t * instance, uint64_t pos,377 uint32_t len)378 {379 block_t *block = NULL;380 int rc = block_get(&block, instance->service_id, pos, BLOCK_FLAGS_NONE);381 if (rc != EOK)382 return rc;383 384 udf_descriptor_tag_t *desc = (udf_descriptor_tag_t *) block->data;385 if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) {386 block_put(block);387 return EINVAL;388 }389 390 if (FLE16(desc->id) != UDF_UASPACE_ENTRY) {391 // FIXME: Memory leak392 return EINVAL;393 }394 395 udf_unallocated_space_entry_descriptor_t *uased =396 (udf_unallocated_space_entry_descriptor_t *) block->data;397 if (uased->icbtag.file_type != UDF_ICBTYPE_UASE) {398 // FIXME: Memory leak399 return EINVAL;400 }401 402 uint16_t icb_flag = uased->icbtag.flags & UDF_ICBFLAG_MASK;403 404 rc = udf_read_free_space((uint8_t *) uased, icb_flag,405 UDF_UASE_OFFSET, uased->ad_lenght);406 407 return block_put(block);408 }409 410 298 /** Read data from disk - filling UDF node by allocators 411 299 * … … 419 307 node->link_cnt = 1; 420 308 return udf_read_icb(node); 421 }422 423 /** Read directory entry424 *425 * @param fid Returned value426 * @param block Returned value427 * @param node UDF node428 * @param pos Number of FID which we need to find429 *430 * @return EOK on success or a negative error code.431 *432 */433 int udf_get_fid(udf_file_identifier_descriptor_t **fid, block_t **block,434 udf_node_t *node, aoff64_t pos)435 {436 if (node->data == NULL)437 return udf_get_fid_in_allocator(fid, block, node, pos);438 439 return udf_get_fid_in_data(fid, node, pos);440 309 } 441 310 … … 449 318 * 450 319 */ 451 int udf_get_fid_in_data(udf_file_identifier_descriptor_t **fid,320 static int udf_get_fid_in_data(udf_file_identifier_descriptor_t **fid, 452 321 udf_node_t *node, aoff64_t pos) 453 322 { … … 488 357 489 358 return ENOENT; 359 } 360 361 /** Read directory entry 362 * 363 * @param fid Returned value 364 * @param block Returned value 365 * @param node UDF node 366 * @param pos Number of FID which we need to find 367 * 368 * @return EOK on success or a negative error code. 369 * 370 */ 371 int udf_get_fid(udf_file_identifier_descriptor_t **fid, block_t **block, 372 udf_node_t *node, aoff64_t pos) 373 { 374 if (node->data == NULL) 375 return udf_get_fid_in_allocator(fid, block, node, pos); 376 377 return udf_get_fid_in_data(fid, node, pos); 490 378 } 491 379 -
uspace/srv/fs/udf/udf_file.h
r5d94b16c r5c702a8 197 197 extern int udf_read_allocation_sequence(udf_node_t *, uint8_t *, uint16_t, 198 198 uint32_t, uint32_t); 199 extern int udf_read_extended_allocator(udf_node_t *, uint16_t, uint32_t);200 199 extern int udf_read_file(size_t *, ipc_callid_t, udf_node_t *, aoff64_t, 201 200 size_t); 202 201 extern int udf_get_fid(udf_file_identifier_descriptor_t **, block_t **, 203 udf_node_t *, aoff64_t);204 extern int udf_get_fid_in_data(udf_file_identifier_descriptor_t **,205 202 udf_node_t *, aoff64_t); 206 203 extern int udf_get_fid_in_allocator(udf_file_identifier_descriptor_t **, … … 208 205 extern int udf_get_fid_in_sector(udf_file_identifier_descriptor_t **, 209 206 block_t **, udf_node_t *, aoff64_t, size_t *, void **, size_t *); 210 extern int udf_read_free_space(uint8_t *, uint16_t, uint32_t, uint32_t);211 extern int udf_read_unallocated_space_entry(udf_instance_t *, uint64_t,212 uint32_t);213 207 214 208 #endif /* UDF_FILE_H_ */ -
uspace/srv/fs/udf/udf_osta.c
r5d94b16c r5c702a8 96 96 * 97 97 */ 98 s ize_t udf_uncompress_unicode(size_t number_of_bytes, uint8_t *udf_compressed,99 uint 16_t *unicode, size_t unicode_max_len)98 static size_t udf_uncompress_unicode(size_t number_of_bytes, 99 uint8_t *udf_compressed, uint16_t *unicode, size_t unicode_max_len) 100 100 { 101 101 /* Use udf_compressed to store current byte being read. */ … … 129 129 130 130 return unicode_idx; 131 }132 133 /** Convert Unicode wide characters to OSTA CS0 compressed Unicode string.134 *135 * The Unicode MUST be in the byte order of the compiler in order136 * to obtain correct results. Returns an error if the compression ID137 * is invalid.138 *139 * NOTE: This routine assumes the implementation already knows,140 * by the local environment, how many bits are appropriate and therefore141 * does no checking to test if the input characters fit into that number142 * of bits or not.143 *144 * @param[in] number_of_chars Number of unicode characters.145 * @param[in] comp_id Compression ID to be used.146 * @param[in] unicode Unicode characters to compress.147 * @param[out] udf_compressed Compressed string, as bytes.148 *149 * @return The total number of bytes in the compressed OSTA CS0 string,150 * including the compression ID.151 *152 */153 size_t udf_compress_unicode(size_t number_of_chars, uint8_t comp_id,154 uint16_t *unicode, uint8_t *udf_compressed)155 {156 if ((comp_id != 8) && (comp_id != 16))157 return 0;158 159 /* Place compression code in first byte. */160 udf_compressed[0] = comp_id;161 162 size_t byte_idx = 1;163 size_t unicode_idx = 0;164 165 while (unicode_idx < number_of_chars) {166 if (comp_id == 16) {167 /*168 * First, place the high bits of the char169 * into the byte stream.170 */171 udf_compressed[byte_idx++] =172 (unicode[unicode_idx] & 0xFF00) >> 8;173 }174 175 /* Then place the low bits into the stream. */176 udf_compressed[byte_idx++] = unicode[unicode_idx] & 0x00FF;177 unicode_idx++;178 }179 180 return byte_idx;181 131 } 182 132 -
uspace/srv/fs/udf/udf_osta.h
r5d94b16c r5c702a8 52 52 #define PERIOD 0x002E 53 53 54 extern size_t udf_uncompress_unicode(size_t, uint8_t *, uint16_t *, size_t);55 extern size_t udf_compress_unicode(size_t, uint8_t, uint16_t *, uint8_t *);56 54 extern size_t udf_translate_name(uint16_t *, uint16_t *, size_t); 57 55 extern void udf_to_unix_name(char *, size_t, char *, size_t, udf_charspec_t *); -
uspace/srv/fs/udf/udf_types.h
r5d94b16c r5c702a8 142 142 } __attribute__((packed)) udf_unallocated_space_descriptor_t; 143 143 144 extern void udf_prepare_tag(udf_descriptor_tag_t *);145 146 144 #endif 147 145 -
uspace/srv/fs/udf/udf_volume.c
r5d94b16c r5c702a8 151 151 * 152 152 */ 153 void udf_prepare_tag(udf_descriptor_tag_t *tag)153 static void udf_prepare_tag(udf_descriptor_tag_t *tag) 154 154 { 155 155 GET_LE16(tag->id); … … 159 159 GET_LE16(tag->descriptor_crc_length); 160 160 GET_LE32(tag->location); 161 } 162 163 /** Read AVD by using one of default sector size from array 164 * 165 * @param service_id 166 * @param avd Returned value - Anchor Volume Descriptor 167 * @param sector_size Expected sector size 168 * 169 * @return EOK on success or a negative error code. 170 * 171 */ 172 static int udf_get_anchor_volume_descriptor_by_ssize(service_id_t service_id, 173 udf_anchor_volume_descriptor_t *avd, uint32_t sector_size) 174 { 175 int rc = block_read_bytes_direct(service_id, 176 UDF_AVDP_SECTOR * sector_size, 177 sizeof(udf_anchor_volume_descriptor_t), avd); 178 if (rc != EOK) 179 return rc; 180 181 if (avd->tag.checksum != udf_tag_checksum((uint8_t *) &avd->tag)) 182 return EINVAL; 183 184 // TODO: Should be tested in big-endian mode 185 udf_prepare_tag(&avd->tag); 186 187 if (avd->tag.id != UDF_TAG_AVDP) 188 return EINVAL; 189 190 GET_LE32(avd->main_extent.length); 191 GET_LE32(avd->main_extent.location); 192 GET_LE32(avd->reserve_extent.length); 193 GET_LE32(avd->reserve_extent.location); 194 195 return EOK; 161 196 } 162 197 … … 200 235 201 236 return EINVAL; 202 }203 204 /** Read AVD by using one of default sector size from array205 *206 * @param service_id207 * @param avd Returned value - Anchor Volume Descriptor208 * @param sector_size Expected sector size209 *210 * @return EOK on success or a negative error code.211 *212 */213 int udf_get_anchor_volume_descriptor_by_ssize(service_id_t service_id,214 udf_anchor_volume_descriptor_t *avd, uint32_t sector_size)215 {216 int rc = block_read_bytes_direct(service_id,217 UDF_AVDP_SECTOR * sector_size,218 sizeof(udf_anchor_volume_descriptor_t), avd);219 if (rc != EOK)220 return rc;221 222 if (avd->tag.checksum != udf_tag_checksum((uint8_t *) &avd->tag))223 return EINVAL;224 225 // TODO: Should be tested in BegEndian mode226 udf_prepare_tag(&avd->tag);227 228 if (avd->tag.id != UDF_TAG_AVDP)229 return EINVAL;230 231 GET_LE32(avd->main_extent.length);232 GET_LE32(avd->main_extent.location);233 GET_LE32(avd->reserve_extent.length);234 GET_LE32(avd->reserve_extent.location);235 236 return EOK;237 237 } 238 238 -
uspace/srv/fs/udf/udf_volume.h
r5d94b16c r5c702a8 215 215 extern int udf_get_anchor_volume_descriptor(service_id_t, 216 216 udf_anchor_volume_descriptor_t *); 217 extern int udf_get_anchor_volume_descriptor_by_ssize(service_id_t,218 udf_anchor_volume_descriptor_t *, uint32_t);219 217 extern int udf_read_volume_descriptor_sequence(service_id_t, udf_extent_t); 220 218 extern fs_index_t udf_long_ad_to_pos(udf_instance_t *, udf_long_ad_t *);
Note:
See TracChangeset
for help on using the changeset viewer.