Mercurial > libdvdread4.hg
comparison dvd_udf.c @ 20:fce16251755c src
Remove all trailing whitespace,
patch by Erik Hovland *erik$hovland dot org%
author | rathann |
---|---|
date | Sat, 06 Sep 2008 21:55:51 +0000 |
parents | df4a5625b81d |
children | 4aa618ae094f |
comparison
equal
deleted
inserted
replaced
19:7f7e87bd7536 | 20:fce16251755c |
---|---|
8 * | 8 * |
9 * dvdudf: parse and read the UDF volume information of a DVD Video | 9 * dvdudf: parse and read the UDF volume information of a DVD Video |
10 * Copyright (C) 1999 Christian Wolff for convergence integrated media | 10 * Copyright (C) 1999 Christian Wolff for convergence integrated media |
11 * GmbH The author can be reached at scarabaeus@convergence.de, the | 11 * GmbH The author can be reached at scarabaeus@convergence.de, the |
12 * project's page is at http://linuxtv.org/dvd/ | 12 * project's page is at http://linuxtv.org/dvd/ |
13 * | 13 * |
14 * This program is free software; you can redistribute it and/or modify | 14 * This program is free software; you can redistribute it and/or modify |
15 * it under the terms of the GNU General Public License as published by | 15 * it under the terms of the GNU General Public License as published by |
16 * the Free Software Foundation; either version 2 of the License, or (at | 16 * the Free Software Foundation; either version 2 of the License, or (at |
17 * your option) any later version. | 17 * your option) any later version. |
18 * | 18 * |
19 * This program is distributed in the hope that it will be useful, but | 19 * This program is distributed in the hope that it will be useful, but |
20 * WITHOUT ANY WARRANTY; without even the implied warranty of | 20 * WITHOUT ANY WARRANTY; without even the implied warranty of |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 * General Public License for more details. | 22 * General Public License for more details. |
23 * | 23 * |
24 * You should have received a copy of the GNU General Public License | 24 * You should have received a copy of the GNU General Public License |
25 * along with this program; if not, write to the Free Software | 25 * along with this program; if not, write to the Free Software |
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
27 * 02111-1307, USA. Or, point your browser to | 27 * 02111-1307, USA. Or, point your browser to |
28 * http://www.gnu.org/copyleft/gpl.html | 28 * http://www.gnu.org/copyleft/gpl.html |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include <stdio.h> | 33 #include <stdio.h> |
34 #include <stdlib.h> | 34 #include <stdlib.h> |
35 #include <string.h> | 35 #include <string.h> |
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 |
232 return 0; | 232 return 0; |
233 | 233 |
234 c = (struct udf_cache *)GetUDFCacheHandle(device); | 234 c = (struct udf_cache *)GetUDFCacheHandle(device); |
235 | 235 |
236 if(c == NULL) { | 236 if(c == NULL) { |
237 c = calloc(1, sizeof(struct udf_cache)); | 237 c = calloc(1, sizeof(struct udf_cache)); |
238 /* fprintf(stderr, "calloc: %d\n", sizeof(struct udf_cache)); */ | 238 /* fprintf(stderr, "calloc: %d\n", sizeof(struct udf_cache)); */ |
239 if(c == NULL) | 239 if(c == NULL) |
240 return 0; | 240 return 0; |
241 SetUDFCacheHandle(device, c); | 241 SetUDFCacheHandle(device, c); |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 switch(type) { | 245 switch(type) { |
246 case AVDPCache: | 246 case AVDPCache: |
247 c->avdp = *(struct avdp_t *)data; | 247 c->avdp = *(struct avdp_t *)data; |
248 c->avdp_valid = 1; | 248 c->avdp_valid = 1; |
249 break; | 249 break; |
250 case PVDCache: | 250 case PVDCache: |
251 c->pvd = *(struct pvd_t *)data; | 251 c->pvd = *(struct pvd_t *)data; |
252 c->pvd_valid = 1; | 252 c->pvd_valid = 1; |
253 break; | 253 break; |
254 case PartitionCache: | 254 case PartitionCache: |
255 c->partition = *(struct Partition *)data; | 255 c->partition = *(struct Partition *)data; |
256 c->partition_valid = 1; | 256 c->partition_valid = 1; |
257 break; | 257 break; |
258 case RootICBCache: | 258 case RootICBCache: |
259 c->rooticb = *(struct AD *)data; | 259 c->rooticb = *(struct AD *)data; |
260 c->rooticb_valid = 1; | 260 c->rooticb_valid = 1; |
261 break; | 261 break; |
262 case LBUDFCache: | 262 case LBUDFCache: |
263 for(n = 0; n < c->lb_num; n++) { | 263 for(n = 0; n < c->lb_num; n++) { |
264 if(c->lbs[n].lb == nr) { | 264 if(c->lbs[n].lb == nr) { |
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 { |
336 int p = 1, i = 0; | 336 int p = 1, i = 0; |
337 | 337 |
338 if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { | 338 if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { |
339 if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */ | 339 if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */ |
344 | 344 |
345 target[ i ] = '\0'; | 345 target[ i ] = '\0'; |
346 return 0; | 346 return 0; |
347 } | 347 } |
348 | 348 |
349 static int UDFDescriptor( uint8_t *data, uint16_t *TagID ) | 349 static int UDFDescriptor( uint8_t *data, uint16_t *TagID ) |
350 { | 350 { |
351 *TagID = GETN2(0); | 351 *TagID = GETN2(0); |
352 /* TODO: check CRC 'n stuff */ | 352 /* TODO: check CRC 'n stuff */ |
353 return 0; | 353 return 0; |
354 } | 354 } |
355 | 355 |
356 static int UDFExtentAD( uint8_t *data, uint32_t *Length, uint32_t *Location ) | 356 static int UDFExtentAD( uint8_t *data, uint32_t *Length, uint32_t *Location ) |
357 { | 357 { |
358 *Length = GETN4(0); | 358 *Length = GETN4(0); |
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); |
425 N_PM = GETN4(268); /* should be 1 */ | 425 N_PM = GETN4(268); /* should be 1 */ |
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; |
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; |
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; |
650 uint32_t lastsector; | 650 uint32_t lastsector; |
651 int terminate; | 651 int terminate; |
652 struct avdp_t; | 652 struct avdp_t; |
653 | 653 |
654 if(GetUDFCache(device, AVDPCache, 0, avdp)) | 654 if(GetUDFCache(device, AVDPCache, 0, avdp)) |
655 return 1; | 655 return 1; |
656 | 656 |
657 /* Find Anchor */ | 657 /* Find Anchor */ |
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; |
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; |
943 | 943 |
944 /** | 944 /** |
945 * Gets the Volume Set Identifier, as a 128-byte dstring (not decoded) | 945 * Gets the Volume Set Identifier, as a 128-byte dstring (not decoded) |
946 * WARNING This is not a null terminated string | 946 * WARNING This is not a null terminated string |
947 * volsetid, place to put the data | 947 * volsetid, place to put the data |
948 * volsetid_size, size of the buffer volsetid points to | 948 * volsetid_size, size of the buffer volsetid points to |
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, |