comparison dvd_udf.c @ 26:0d82d0f30c98 src

cosmetics: Convert all tabs to spaces.
author diego
date Tue, 23 Sep 2008 09:14:45 +0000
parents 447c5319a522
children 98951f8ec89c
comparison
equal deleted inserted replaced
25:17258a7b3239 26:0d82d0f30c98
42 #include "dvd_reader.h" 42 #include "dvd_reader.h"
43 #include "dvd_udf.h" 43 #include "dvd_udf.h"
44 44
45 /* Private but located in/shared with dvd_reader.c */ 45 /* Private but located in/shared with dvd_reader.c */
46 extern int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number, 46 extern int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
47 size_t block_count, unsigned char *data, 47 size_t block_count, unsigned char *data,
48 int encrypted ); 48 int encrypted );
49 49
50 /* It's required to either fail or deliver all the blocks asked for. */ 50 /* It's required to either fail or deliver all the blocks asked for. */
51 static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number, 51 static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number,
52 size_t block_count, unsigned char *data, 52 size_t block_count, unsigned char *data,
53 int encrypted ) 53 int encrypted )
54 { 54 {
55 int ret; 55 int ret;
56 size_t count = block_count; 56 size_t count = block_count;
57 57
58 while(count > 0) { 58 while(count > 0) {
158 free(c); 158 free(c);
159 } 159 }
160 160
161 161
162 static int GetUDFCache(dvd_reader_t *device, UDFCacheType type, 162 static int GetUDFCache(dvd_reader_t *device, UDFCacheType type,
163 uint32_t nr, void *data) 163 uint32_t nr, void *data)
164 { 164 {
165 int n; 165 int n;
166 struct udf_cache *c; 166 struct udf_cache *c;
167 167
168 if(DVDUDFCacheLevel(device, -1) <= 0) 168 if(DVDUDFCacheLevel(device, -1) <= 0)
220 220
221 return 0; 221 return 0;
222 } 222 }
223 223
224 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type, 224 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type,
225 uint32_t nr, void *data) 225 uint32_t nr, void *data)
226 { 226 {
227 int n; 227 int n;
228 struct udf_cache *c; 228 struct udf_cache *c;
229 void *tmp; 229 void *tmp;
230 230
321 321
322 /* For direct data access, LSB first */ 322 /* For direct data access, LSB first */
323 #define GETN1(p) ((uint8_t)data[p]) 323 #define GETN1(p) ((uint8_t)data[p])
324 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8)) 324 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8))
325 #define GETN3(p) ((uint32_t)data[p] | ((uint32_t)data[(p) + 1] << 8) \ 325 #define GETN3(p) ((uint32_t)data[p] | ((uint32_t)data[(p) + 1] << 8) \
326 | ((uint32_t)data[(p) + 2] << 16)) 326 | ((uint32_t)data[(p) + 2] << 16))
327 #define GETN4(p) ((uint32_t)data[p] \ 327 #define GETN4(p) ((uint32_t)data[p] \
328 | ((uint32_t)data[(p) + 1] << 8) \ 328 | ((uint32_t)data[(p) + 1] << 8) \
329 | ((uint32_t)data[(p) + 2] << 16) \ 329 | ((uint32_t)data[(p) + 2] << 16) \
330 | ((uint32_t)data[(p) + 3] << 24)) 330 | ((uint32_t)data[(p) + 3] << 24))
331 /* This is wrong with regard to endianess */ 331 /* This is wrong with regard to endianess */
332 #define GETN(p, n, target) memcpy(target, &data[p], n) 332 #define GETN(p, n, target) memcpy(target, &data[p], n)
333 333
334 static int Unicodedecode( uint8_t *data, int len, char *target ) 334 static int Unicodedecode( uint8_t *data, int len, char *target )
335 { 335 {
359 *Location = GETN4(4); 359 *Location = GETN4(4);
360 return 0; 360 return 0;
361 } 361 }
362 362
363 static int UDFShortAD( uint8_t *data, struct AD *ad, 363 static int UDFShortAD( uint8_t *data, struct AD *ad,
364 struct Partition *partition ) 364 struct Partition *partition )
365 { 365 {
366 ad->Length = GETN4(0); 366 ad->Length = GETN4(0);
367 ad->Flags = ad->Length >> 30; 367 ad->Flags = ad->Length >> 30;
368 ad->Length &= 0x3FFFFFFF; 368 ad->Length &= 0x3FFFFFFF;
369 ad->Location = GETN4(4); 369 ad->Location = GETN4(4);
400 return 0; 400 return 0;
401 } 401 }
402 402
403 403
404 static int UDFPartition( uint8_t *data, uint16_t *Flags, uint16_t *Number, 404 static int UDFPartition( uint8_t *data, uint16_t *Flags, uint16_t *Number,
405 char *Contents, uint32_t *Start, uint32_t *Length ) 405 char *Contents, uint32_t *Start, uint32_t *Length )
406 { 406 {
407 *Flags = GETN2(20); 407 *Flags = GETN2(20);
408 *Number = GETN2(22); 408 *Number = GETN2(22);
409 GETN(24, 32, Contents); 409 GETN(24, 32, Contents);
410 *Start = GETN4(188); 410 *Start = GETN4(188);
426 if (lbsize != DVD_VIDEO_LB_LEN) return 1; 426 if (lbsize != DVD_VIDEO_LB_LEN) return 1;
427 return 0; 427 return 0;
428 } 428 }
429 429
430 static int UDFFileEntry( uint8_t *data, uint8_t *FileType, 430 static int UDFFileEntry( uint8_t *data, uint8_t *FileType,
431 struct Partition *partition, struct AD *ad ) 431 struct Partition *partition, struct AD *ad )
432 { 432 {
433 uint16_t flags; 433 uint16_t flags;
434 uint32_t L_EA, L_AD; 434 uint32_t L_EA, L_AD;
435 unsigned int p; 435 unsigned int p;
436 436
464 } 464 }
465 return 0; 465 return 0;
466 } 466 }
467 467
468 static int UDFFileIdentifier( uint8_t *data, uint8_t *FileCharacteristics, 468 static int UDFFileIdentifier( uint8_t *data, uint8_t *FileCharacteristics,
469 char *FileName, struct AD *FileICB ) 469 char *FileName, struct AD *FileICB )
470 { 470 {
471 uint8_t L_FI; 471 uint8_t L_FI;
472 uint16_t L_IU; 472 uint16_t L_IU;
473 473
474 *FileCharacteristics = GETN1(18); 474 *FileCharacteristics = GETN1(18);
486 * FileType: Type of the file 486 * FileType: Type of the file
487 * File: Location of file the ICB is pointing to 487 * File: Location of file the ICB is pointing to
488 * return 1 on success, 0 on error; 488 * return 1 on success, 0 on error;
489 */ 489 */
490 static int UDFMapICB( dvd_reader_t *device, struct AD ICB, uint8_t *FileType, 490 static int UDFMapICB( dvd_reader_t *device, struct AD ICB, uint8_t *FileType,
491 struct Partition *partition, struct AD *File ) 491 struct Partition *partition, struct AD *File )
492 { 492 {
493 uint8_t LogBlock_base[DVD_VIDEO_LB_LEN + 2048]; 493 uint8_t LogBlock_base[DVD_VIDEO_LB_LEN + 2048];
494 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); 494 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048);
495 uint32_t lbnum; 495 uint32_t lbnum;
496 uint16_t TagID; 496 uint16_t TagID;
529 * FileICB: Location of ICB of the found file 529 * FileICB: Location of ICB of the found file
530 * return 1 on success, 0 on error; 530 * return 1 on success, 0 on error;
531 */ 531 */
532 static int UDFScanDir( dvd_reader_t *device, struct AD Dir, char *FileName, 532 static int UDFScanDir( dvd_reader_t *device, struct AD Dir, char *FileName,
533 struct Partition *partition, struct AD *FileICB, 533 struct Partition *partition, struct AD *FileICB,
534 int cache_file_info) 534 int cache_file_info)
535 { 535 {
536 char filename[ MAX_UDF_FILE_NAME_LEN ]; 536 char filename[ MAX_UDF_FILE_NAME_LEN ];
537 uint8_t directory_base[ 2 * DVD_VIDEO_LB_LEN + 2048]; 537 uint8_t directory_base[ 2 * DVD_VIDEO_LB_LEN + 2048];
538 uint8_t *directory = (uint8_t *)(((uintptr_t)directory_base & ~((uintptr_t)2047)) + 2048); 538 uint8_t *directory = (uint8_t *)(((uintptr_t)directory_base & ~((uintptr_t)2047)) + 2048);
539 uint32_t lbnum; 539 uint32_t lbnum;
639 return 0; 639 return 0;
640 } 640 }
641 641
642 642
643 static int UDFGetAVDP( dvd_reader_t *device, 643 static int UDFGetAVDP( dvd_reader_t *device,
644 struct avdp_t *avdp) 644 struct avdp_t *avdp)
645 { 645 {
646 uint8_t Anchor_base[ DVD_VIDEO_LB_LEN + 2048 ]; 646 uint8_t Anchor_base[ DVD_VIDEO_LB_LEN + 2048 ];
647 uint8_t *Anchor = (uint8_t *)(((uintptr_t)Anchor_base & ~((uintptr_t)2047)) + 2048); 647 uint8_t *Anchor = (uint8_t *)(((uintptr_t)Anchor_base & ~((uintptr_t)2047)) + 2048);
648 uint32_t lbnum, MVDS_location, MVDS_length; 648 uint32_t lbnum, MVDS_location, MVDS_length;
649 uint16_t TagID; 649 uint16_t TagID;
708 * Looks for partition on the disc. Returns 1 if partition found, 0 on error. 708 * Looks for partition on the disc. Returns 1 if partition found, 0 on error.
709 * partnum: Number of the partition, starting at 0. 709 * partnum: Number of the partition, starting at 0.
710 * part: structure to fill with the partition information 710 * part: structure to fill with the partition information
711 */ 711 */
712 static int UDFFindPartition( dvd_reader_t *device, int partnum, 712 static int UDFFindPartition( dvd_reader_t *device, int partnum,
713 struct Partition *part ) 713 struct Partition *part )
714 { 714 {
715 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ]; 715 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ];
716 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); 716 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048);
717 uint32_t lbnum, MVDS_location, MVDS_length; 717 uint32_t lbnum, MVDS_location, MVDS_length;
718 uint16_t TagID; 718 uint16_t TagID;
767 /* We only care for the partition, not the volume */ 767 /* We only care for the partition, not the volume */
768 return part->valid; 768 return part->valid;
769 } 769 }
770 770
771 uint32_t UDFFindFile( dvd_reader_t *device, char *filename, 771 uint32_t UDFFindFile( dvd_reader_t *device, char *filename,
772 uint32_t *filesize ) 772 uint32_t *filesize )
773 { 773 {
774 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ]; 774 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ];
775 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); 775 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048);
776 uint32_t lbnum; 776 uint32_t lbnum;
777 uint16_t TagID; 777 uint16_t TagID;
849 * Returns 1 if descriptor found, 0 on error. 849 * Returns 1 if descriptor found, 0 on error.
850 * id, tagid of descriptor 850 * id, tagid of descriptor
851 * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN). 851 * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN).
852 */ 852 */
853 static int UDFGetDescriptor( dvd_reader_t *device, int id, 853 static int UDFGetDescriptor( dvd_reader_t *device, int id,
854 uint8_t *descriptor, int bufsize) 854 uint8_t *descriptor, int bufsize)
855 { 855 {
856 uint32_t lbnum, MVDS_location, MVDS_length; 856 uint32_t lbnum, MVDS_location, MVDS_length;
857 struct avdp_t avdp; 857 struct avdp_t avdp;
858 uint16_t TagID; 858 uint16_t TagID;
859 uint32_t lastsector; 859 uint32_t lastsector;
883 UDFDescriptor( descriptor, &TagID ); 883 UDFDescriptor( descriptor, &TagID );
884 if( (TagID == id) && ( !desc_found ) ) 884 if( (TagID == id) && ( !desc_found ) )
885 /* Descriptor */ 885 /* Descriptor */
886 desc_found = 1; 886 desc_found = 1;
887 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) 887 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 )
888 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) 888 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 )
889 && ( !desc_found) ); 889 && ( !desc_found) );
890 890
891 if( !desc_found ) { 891 if( !desc_found ) {
892 /* Backup volume descriptor */ 892 /* Backup volume descriptor */
893 MVDS_location = avdp.rvds.location; 893 MVDS_location = avdp.rvds.location;
894 MVDS_length = avdp.rvds.length; 894 MVDS_length = avdp.rvds.length;
920 * volid, place to put the string 920 * volid, place to put the string
921 * volid_size, size of the buffer volid points to 921 * volid_size, size of the buffer volid points to
922 * returns the size of buffer needed for all data 922 * returns the size of buffer needed for all data
923 */ 923 */
924 int UDFGetVolumeIdentifier(dvd_reader_t *device, char *volid, 924 int UDFGetVolumeIdentifier(dvd_reader_t *device, char *volid,
925 unsigned int volid_size) 925 unsigned int volid_size)
926 { 926 {
927 struct pvd_t pvd; 927 struct pvd_t pvd;
928 unsigned int volid_len; 928 unsigned int volid_len;
929 929
930 /* get primary volume descriptor */ 930 /* get primary volume descriptor */
949 * the buffer should be >=128 bytes to store the whole volumesetidentifier 949 * the buffer should be >=128 bytes to store the whole volumesetidentifier
950 * returns the size of the available volsetid information (128) 950 * returns the size of the available volsetid information (128)
951 * or 0 on error 951 * or 0 on error
952 */ 952 */
953 int UDFGetVolumeSetIdentifier(dvd_reader_t *device, uint8_t *volsetid, 953 int UDFGetVolumeSetIdentifier(dvd_reader_t *device, uint8_t *volsetid,
954 unsigned int volsetid_size) 954 unsigned int volsetid_size)
955 { 955 {
956 struct pvd_t pvd; 956 struct pvd_t pvd;
957 957
958 /* get primary volume descriptor */ 958 /* get primary volume descriptor */
959 if(!UDFGetPVD(device, &pvd)) 959 if(!UDFGetPVD(device, &pvd))