Changeset 8565a42 in mainline for uspace/srv/fs/udf/udf_file.c
- Timestamp:
- 2018-03-02T20:34:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1a81f69, d5e5fd1
- Parents:
- 3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
- git-committer:
- GitHub <noreply@…> (2018-03-02 20:34:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/udf/udf_file.c
r3061bc1 r8565a42 65 65 if (rc != EOK) 66 66 return rc; 67 67 68 68 udf_ext_ad_t *exd = (udf_ext_ad_t *) block->data; 69 69 uint32_t start = node->instance->partitions[ 70 70 FLE16(exd->extent_location.partition_num)].start + 71 71 FLE32(exd->extent_location.lblock_num); 72 72 73 73 log_msg(LOG_DEFAULT, LVL_DEBUG, 74 74 "Extended allocator: start=%d, block_num=%d, len=%d", start, 75 75 FLE32(exd->extent_location.lblock_num), FLE32(exd->info_length)); 76 76 77 77 uint32_t len = FLE32(exd->info_length); 78 78 block_put(block); 79 79 80 80 return udf_read_allocation_sequence(node, NULL, icb_flag, start, len); 81 81 } … … 97 97 { 98 98 node->alloc_size = 0; 99 99 100 100 switch (icb_flag) { 101 101 case UDF_SHORT_AD: 102 102 log_msg(LOG_DEFAULT, LVL_DEBUG, 103 103 "ICB: sequence of allocation descriptors - icbflag = short_ad_t"); 104 104 105 105 /* 106 106 * Identify number of current partition. Virtual partition … … 110 110 size_t pd_num = (size_t) -1; 111 111 size_t min_start = 0; 112 112 113 113 for (size_t i = 0; i < node->instance->partition_cnt; i++) { 114 114 if ((node->index >= node->instance->partitions[i].start) && … … 121 121 } 122 122 } 123 123 124 124 if (pd_num == (size_t) -1) 125 125 return ENOENT; 126 126 127 127 /* 128 128 * According to doc, in this we should stop our loop if pass … … 133 133 * which we check inside of loop. 134 134 */ 135 135 136 136 while (true) { 137 137 udf_short_ad_t *short_d = 138 138 (udf_short_ad_t *) (af + start_alloc + 139 139 node->alloc_size * sizeof(udf_short_ad_t)); 140 140 141 141 if (FLE32(short_d->length) == 0) 142 142 break; 143 143 144 144 /* 145 145 * ECMA 167 4/12 - next sequence of allocation descriptors … … 152 152 break; 153 153 } 154 154 155 155 node->allocators = realloc(node->allocators, 156 156 (node->alloc_size + 1) * sizeof(udf_allocator_t)); … … 161 161 node->alloc_size++; 162 162 } 163 163 164 164 node->allocators = realloc(node->allocators, 165 165 node->alloc_size * sizeof(udf_allocator_t)); 166 166 break; 167 167 168 168 case UDF_LONG_AD: 169 169 log_msg(LOG_DEFAULT, LVL_DEBUG, 170 170 "ICB: sequence of allocation descriptors - icbflag = long_ad_t"); 171 171 172 172 while (true) { 173 173 udf_long_ad_t *long_d = 174 174 (udf_long_ad_t *) (af + start_alloc + 175 175 node->alloc_size * sizeof(udf_long_ad_t)); 176 176 177 177 if (FLE32(long_d->length) == 0) 178 178 break; 179 179 180 180 uint32_t pos_long_ad = udf_long_ad_to_pos(node->instance, long_d); 181 181 182 182 /* 183 183 * ECMA 167 4/12 - next sequence of allocation descriptors … … 188 188 break; 189 189 } 190 190 191 191 node->allocators = realloc(node->allocators, 192 192 (node->alloc_size + 1) * sizeof(udf_allocator_t)); … … 194 194 EXT_LENGTH(FLE32(long_d->length)); 195 195 node->allocators[node->alloc_size].position = pos_long_ad; 196 196 197 197 node->alloc_size++; 198 198 } 199 199 200 200 node->allocators = realloc(node->allocators, 201 201 node->alloc_size * sizeof(udf_allocator_t)); 202 202 break; 203 203 204 204 case UDF_EXTENDED_AD: 205 205 log_msg(LOG_DEFAULT, LVL_DEBUG, 206 206 "ICB: sequence of allocation descriptors - icbflag = extended_ad_t"); 207 207 break; 208 208 209 209 case UDF_DATA_AD: 210 210 log_msg(LOG_DEFAULT, LVL_DEBUG, 211 211 "ICB: sequence of allocation descriptors - icbflag = 3, node contains data itself"); 212 212 213 213 node->data = malloc(node->data_size); 214 214 if (!node->data) 215 215 return ENOMEM; 216 216 217 217 memcpy(node->data, (af + start_alloc), node->data_size); 218 218 node->alloc_size = 0; 219 219 break; 220 220 } 221 221 222 222 return EOK; 223 223 } … … 237 237 while (true) { 238 238 fs_index_t pos = node->index; 239 239 240 240 block_t *block = NULL; 241 241 errno_t rc = block_get(&block, node->instance->service_id, pos, … … 243 243 if (rc != EOK) 244 244 return rc; 245 245 246 246 udf_descriptor_tag_t *data = (udf_descriptor_tag_t *) block->data; 247 247 if (data->checksum != udf_tag_checksum((uint8_t *) data)) { … … 249 249 return EINVAL; 250 250 } 251 251 252 252 /* One sector size descriptors */ 253 253 switch (FLE16(data->id)) { 254 254 case UDF_FILE_ENTRY: 255 255 log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: File entry descriptor found"); 256 256 257 257 udf_file_entry_descriptor_t *file = 258 258 (udf_file_entry_descriptor_t *) block->data; … … 260 260 node->data_size = FLE64(file->info_lenght); 261 261 node->type = (file->icbtag.file_type == UDF_ICBTYPE_DIR) ? NODE_DIR : NODE_FILE; 262 262 263 263 rc = udf_read_allocation_sequence(node, (uint8_t *) file, icb_flag, 264 264 FLE32(file->ea_lenght) + UDF_FE_OFFSET, FLE32(file->ad_lenght)); 265 265 block_put(block); 266 266 return rc; 267 267 268 268 case UDF_EFILE_ENTRY: 269 269 log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: Extended file entry descriptor found"); 270 270 271 271 udf_extended_file_entry_descriptor_t *efile = 272 272 (udf_extended_file_entry_descriptor_t *) block->data; … … 274 274 node->data_size = FLE64(efile->info_lenght); 275 275 node->type = (efile->icbtag.file_type == UDF_ICBTYPE_DIR) ? NODE_DIR : NODE_FILE; 276 276 277 277 rc = udf_read_allocation_sequence(node, (uint8_t *) efile, icb_flag, 278 278 FLE32(efile->ea_lenght) + UDF_EFE_OFFSET, FLE32(efile->ad_lenght)); 279 279 block_put(block); 280 280 return rc; 281 281 282 282 case UDF_ICB_TERMINAL: 283 283 log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: Terminal entry descriptor found"); … … 285 285 return EOK; 286 286 } 287 287 288 288 pos++; 289 289 290 290 rc = block_put(block); 291 291 if (rc != EOK) 292 292 return rc; 293 293 } 294 294 295 295 return EOK; 296 296 } … … 323 323 size_t fid_sum = 0; 324 324 size_t n = 0; 325 325 326 326 while (node->data_size - fid_sum >= MIN_FID_LEN) { 327 327 udf_descriptor_tag_t *desc = … … 333 333 return ENOENT; 334 334 } 335 335 336 336 *fid = (udf_file_identifier_descriptor_t *) 337 337 (node->data + fid_sum); 338 338 339 339 /* According to ECMA 167 4/14.4.9 */ 340 340 size_t padding = 4 * (((*fid)->lenght_file_id + … … 343 343 size_t size_fid = (*fid)->lenght_file_id + 344 344 FLE16((*fid)->lenght_iu) + padding + 38; 345 345 346 346 fid_sum += size_fid; 347 347 348 348 /* aAcording to ECMA 167 4/8.6 */ 349 349 if (((*fid)->lenght_file_id != 0) && 350 350 (((*fid)->file_characteristics & 4) == 0)) { 351 351 n++; 352 352 353 353 if (n == pos + 1) 354 354 return EOK; 355 355 } 356 356 } 357 357 358 358 return ENOENT; 359 359 } … … 374 374 if (node->data == NULL) 375 375 return udf_get_fid_in_allocator(fid, block, node, pos); 376 376 377 377 return udf_get_fid_in_data(fid, node, pos); 378 378 } … … 392 392 { 393 393 void *buf = malloc(node->instance->sector_size); 394 394 395 395 // FIXME: Check for NULL return value 396 396 397 397 size_t j = 0; 398 398 size_t n = 0; 399 399 size_t len = 0; 400 400 401 401 while (j < node->alloc_size) { 402 402 size_t i = 0; … … 408 408 return rc; 409 409 } 410 410 411 411 /* 412 412 * Last item in allocator is a part of sector. We take … … 422 422 break; 423 423 } 424 424 425 425 rc = udf_get_fid_in_sector(fid, block, node, pos, &n, &buf, &len); 426 426 if (rc == EOK) { … … 428 428 return EOK; 429 429 } 430 430 431 431 if (rc == EINVAL) { 432 432 // FIXME: Memory leak 433 433 return ENOENT; 434 434 } 435 435 436 436 if (rc == ENOENT) { 437 437 if (block) { 438 438 rc = block_put(*block); 439 439 *block = NULL; 440 440 441 441 if (rc != EOK) 442 442 return rc; 443 443 } 444 444 } 445 445 446 446 i++; 447 447 } 448 448 449 449 j++; 450 450 } 451 451 452 452 if (buf) 453 453 free(buf); 454 454 455 455 return ENOENT; 456 456 } … … 474 474 { 475 475 void *fidbuf = malloc(node->instance->sector_size); 476 476 477 477 // FIXME: Check for NULL return value 478 478 479 479 bool buf_flag; 480 480 481 481 if (*len > 0) { 482 482 memcpy(fidbuf, *buf, *len); … … 484 484 } else 485 485 buf_flag = false; 486 486 487 487 size_t fid_sum = 0; 488 488 while (node->instance->sector_size - fid_sum > 0) { 489 489 if (node->instance->sector_size - fid_sum >= MIN_FID_LEN) { 490 490 void *fid_data; 491 491 492 492 if (buf_flag) { 493 493 memcpy((fidbuf + *len), (*block)->data, … … 496 496 } else 497 497 fid_data = (*block)->data + fid_sum; 498 498 499 499 udf_descriptor_tag_t *desc = 500 500 (udf_descriptor_tag_t *) fid_data; 501 501 502 502 if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) { 503 503 if (fidbuf) 504 504 free(fidbuf); 505 505 506 506 if (*buf) { 507 507 free(*buf); … … 509 509 *len = 0; 510 510 } 511 511 512 512 return EINVAL; 513 513 } 514 514 515 515 *fid = (udf_file_identifier_descriptor_t *) fid_data; 516 516 517 517 /* According to ECMA 167 4/14.4.9 */ 518 518 size_t padding = 4 * (((*fid)->lenght_file_id + … … 525 525 else 526 526 fid_sum += size_fid; 527 527 528 528 /* According to ECMA 167 4/8.6 */ 529 529 if (((*fid)->lenght_file_id != 0) && … … 533 533 if (fidbuf) 534 534 free(fidbuf); 535 535 536 536 return EOK; 537 537 } 538 538 } 539 539 540 540 if (fidbuf) { 541 541 buf_flag = false; … … 543 543 fidbuf = NULL; 544 544 } 545 545 546 546 if (*buf) { 547 547 free(*buf); … … 552 552 if (*buf) 553 553 free(*buf); 554 554 555 555 *len = node->instance->sector_size - fid_sum; 556 556 *buf = malloc(*len); 557 557 buf_flag = false; 558 558 memcpy(*buf, ((*block)->data + fid_sum), *len); 559 559 560 560 return ENOENT; 561 561 } 562 562 } 563 563 564 564 return ENOENT; 565 565 } … … 581 581 size_t i = 0; 582 582 size_t l = 0; 583 583 584 584 while (i < node->alloc_size) { 585 585 if (pos >= l + node->allocators[i].length) { … … 589 589 break; 590 590 } 591 591 592 592 size_t sector_cnt = ALL_UP(l, node->instance->sector_size); 593 593 size_t sector_num = pos / node->instance->sector_size; 594 594 595 595 block_t *block = NULL; 596 596 errno_t rc = block_get(&block, node->instance->service_id, … … 601 601 return rc; 602 602 } 603 603 604 604 size_t sector_pos = pos % node->instance->sector_size; 605 605 606 606 if (sector_pos + len < node->instance->sector_size) 607 607 *read_len = len; 608 608 else 609 609 *read_len = node->instance->sector_size - sector_pos; 610 610 611 611 if (ALL_UP(node->allocators[i].length, node->instance->sector_size) == 612 612 sector_num - sector_cnt + 1) { … … 618 618 *read_len = len; 619 619 } 620 620 621 621 async_data_read_finalize(callid, block->data + sector_pos, *read_len); 622 622 return block_put(block);
Note:
See TracChangeset
for help on using the changeset viewer.