Mercurial > libdvdnav.hg
comparison dvdread/dvd_udf.c @ 358:e998b2df2200 src
cosmetics: tabs->spaces, hopefully the indentation is much better now
author | nicodvb |
---|---|
date | Sat, 10 May 2008 20:37:13 +0000 |
parents | 8949e15ebbd4 |
children | e2973c342e59 |
comparison
equal
deleted
inserted
replaced
357:8949e15ebbd4 | 358:e998b2df2200 |
---|---|
547 | 547 |
548 if(DVDUDFCacheLevel(device, -1) > 0) { | 548 if(DVDUDFCacheLevel(device, -1) > 0) { |
549 /* caching */ | 549 /* caching */ |
550 | 550 |
551 if(!GetUDFCache(device, LBUDFCache, lbnum, &cached_dir)) { | 551 if(!GetUDFCache(device, LBUDFCache, lbnum, &cached_dir)) { |
552 dir_lba = (Dir.Length + DVD_VIDEO_LB_LEN) / DVD_VIDEO_LB_LEN; | 552 dir_lba = (Dir.Length + DVD_VIDEO_LB_LEN) / DVD_VIDEO_LB_LEN; |
553 if((cached_dir_base = malloc(dir_lba * DVD_VIDEO_LB_LEN + 2048)) == NULL) { | 553 if((cached_dir_base = malloc(dir_lba * DVD_VIDEO_LB_LEN + 2048)) == NULL) { |
554 return 0; | 554 return 0; |
555 } | 555 } |
556 cached_dir = (uint8_t *)(((uintptr_t)cached_dir_base & ~((uintptr_t)2047)) + 2048); | 556 cached_dir = (uint8_t *)(((uintptr_t)cached_dir_base & ~((uintptr_t)2047)) + 2048); |
557 if( DVDReadLBUDF( device, lbnum, dir_lba, cached_dir, 0) <= 0 ) { | 557 if( DVDReadLBUDF( device, lbnum, dir_lba, cached_dir, 0) <= 0 ) { |
558 free(cached_dir_base); | 558 free(cached_dir_base); |
559 cached_dir_base = NULL; | 559 cached_dir_base = NULL; |
560 cached_dir = NULL; | 560 cached_dir = NULL; |
561 } | 561 } |
562 /* | 562 /* |
563 if(cached_dir) { | 563 if(cached_dir) { |
564 fprintf(stderr, "malloc dir: %d\n", | 564 fprintf(stderr, "malloc dir: %d\n", dir_lba * DVD_VIDEO_LB_LEN); |
565 dir_lba * DVD_VIDEO_LB_LEN); | 565 } |
566 } | 566 */ |
567 */ | 567 { |
568 { | 568 uint8_t *data[2]; |
569 uint8_t *data[2]; | 569 data[0] = cached_dir_base; |
570 data[0] = cached_dir_base; | 570 data[1] = cached_dir; |
571 data[1] = cached_dir; | 571 SetUDFCache(device, LBUDFCache, lbnum, data); |
572 SetUDFCache(device, LBUDFCache, lbnum, data); | 572 } |
573 } | |
574 } else | 573 } else |
575 in_cache = 1; | 574 in_cache = 1; |
576 | 575 |
577 if(cached_dir == NULL) | 576 if(cached_dir == NULL) |
578 return 0; | 577 return 0; |
579 | 578 |
580 p = 0; | 579 p = 0; |
581 | 580 |
582 while( p < Dir.Length ) { | 581 while( p < Dir.Length ) { |
583 UDFDescriptor( &cached_dir[ p ], &TagID ); | 582 UDFDescriptor( &cached_dir[ p ], &TagID ); |
584 if( TagID == 257 ) { | 583 if( TagID == 257 ) { |
585 p += UDFFileIdentifier( &cached_dir[ p ], &filechar, | 584 p += UDFFileIdentifier( &cached_dir[ p ], &filechar, filename, &tmpICB ); |
586 filename, &tmpICB ); | 585 if(cache_file_info && !in_cache) { |
587 if(cache_file_info && !in_cache) { | 586 uint8_t tmpFiletype; |
588 uint8_t tmpFiletype; | 587 struct AD tmpFile; |
589 struct AD tmpFile; | 588 |
590 | 589 if( !strcasecmp( FileName, filename ) ) { |
591 if( !strcasecmp( FileName, filename ) ) { | 590 *FileICB = tmpICB; |
592 *FileICB = tmpICB; | 591 found = 1; |
593 found = 1; | 592 } |
594 | 593 UDFMapICB(device, tmpICB, &tmpFiletype, partition, &tmpFile); |
595 } | 594 } else { |
596 UDFMapICB(device, tmpICB, &tmpFiletype, | 595 if( !strcasecmp( FileName, filename ) ) { |
597 partition, &tmpFile); | 596 *FileICB = tmpICB; |
598 } else { | 597 return 1; |
599 if( !strcasecmp( FileName, filename ) ) { | 598 } |
600 *FileICB = tmpICB; | 599 } |
601 return 1; | |
602 } | |
603 } | |
604 } else { | 600 } else { |
605 if(cache_file_info && (!in_cache) && found) { | 601 if(cache_file_info && (!in_cache) && found) |
606 return 1; | 602 return 1; |
607 } | 603 return 0; |
608 return 0; | |
609 } | 604 } |
610 } | 605 } |
611 if(cache_file_info && (!in_cache) && found) | 606 if(cache_file_info && (!in_cache) && found) |
612 return 1; | 607 return 1; |
613 return 0; | 608 return 0; |
616 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) | 611 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) |
617 return 0; | 612 return 0; |
618 | 613 |
619 p = 0; | 614 p = 0; |
620 while( p < Dir.Length ) { | 615 while( p < Dir.Length ) { |
621 if( p > DVD_VIDEO_LB_LEN ) { | 616 if( p > DVD_VIDEO_LB_LEN ) { |
622 ++lbnum; | 617 ++lbnum; |
623 p -= DVD_VIDEO_LB_LEN; | 618 p -= DVD_VIDEO_LB_LEN; |
624 Dir.Length -= DVD_VIDEO_LB_LEN; | 619 Dir.Length -= DVD_VIDEO_LB_LEN; |
625 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) { | 620 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) { |
626 return 0; | 621 return 0; |
627 } | |
628 } | 622 } |
629 UDFDescriptor( &directory[ p ], &TagID ); | 623 } |
630 if( TagID == 257 ) { | 624 UDFDescriptor( &directory[ p ], &TagID ); |
631 p += UDFFileIdentifier( &directory[ p ], &filechar, | 625 if( TagID == 257 ) { |
632 filename, FileICB ); | 626 p += UDFFileIdentifier( &directory[ p ], &filechar, |
633 if( !strcasecmp( FileName, filename ) ) { | 627 filename, FileICB ); |
634 return 1; | 628 if( !strcasecmp( FileName, filename ) ) { |
635 } | 629 return 1; |
636 } else | 630 } |
637 return 0; | 631 } else |
632 return 0; | |
638 } | 633 } |
639 | 634 |
640 return 0; | 635 return 0; |
641 } | 636 } |
642 | 637 |
669 if (TagID != 2) { | 664 if (TagID != 2) { |
670 /* Not an anchor */ | 665 /* Not an anchor */ |
671 if( terminate ) return 0; /* Final try failed */ | 666 if( terminate ) return 0; /* Final try failed */ |
672 | 667 |
673 if( lastsector ) { | 668 if( lastsector ) { |
674 | 669 /* |
675 /* We already found the last sector. Try #3, alternative | 670 * We already found the last sector. Try #3, alternative |
676 * backup anchor. If that fails, don't try again. | 671 * backup anchor. If that fails, don't try again. |
677 */ | 672 */ |
678 lbnum = lastsector; | 673 lbnum = lastsector; |
679 terminate = 1; | 674 terminate = 1; |
680 } else { | 675 } else { |
681 /* TODO: Find last sector of the disc (this is optional). */ | 676 /* TODO: Find last sector of the disc (this is optional). */ |
682 if( lastsector ) { | 677 if( lastsector ) { |
683 /* Try #2, backup anchor */ | 678 /* Try #2, backup anchor */ |
684 lbnum = lastsector - 256; | 679 lbnum = lastsector - 256; |
685 } else { | 680 } else { |
686 /* Unable to find last sector */ | 681 /* Unable to find last sector */ |
687 return 0; | 682 return 0; |
688 } | 683 } |
689 } | 684 } |
690 } else | 685 } else |
691 /* It's an anchor! We can leave */ | 686 /* It's an anchor! We can leave */ |
692 break; | 687 break; |
693 } | 688 } |
758 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) | 753 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) |
759 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) | 754 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) |
760 && ( ( !part->valid ) || ( !volvalid ) ) ); | 755 && ( ( !part->valid ) || ( !volvalid ) ) ); |
761 | 756 |
762 if( ( !part->valid) || ( !volvalid ) ) { | 757 if( ( !part->valid) || ( !volvalid ) ) { |
763 /* Backup volume descriptor */ | 758 /* Backup volume descriptor */ |
764 MVDS_location = avdp.mvds.location; | 759 MVDS_location = avdp.mvds.location; |
765 MVDS_length = avdp.mvds.length; | 760 MVDS_length = avdp.mvds.length; |
766 } | 761 } |
767 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) ); | 762 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) ); |
768 | 763 |
769 /* We only care for the partition, not the volume */ | 764 /* We only care for the partition, not the volume */ |
770 return part->valid; | 765 return part->valid; |