annotate libmpdvdkit2/dvd_udf.c @ 8023:3738cc2269a3

get stream back from the demuxer
author arpi
date Fri, 01 Nov 2002 16:10:15 +0000
parents 596919e4f601
children fc5aba542810
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
2 * This code is based on dvdudf by:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
3 * Christian Wolff <scarabaeus@convergence.de>.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
4 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
5 * Modifications by:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
6 * Billy Biggs <vektor@dumbterm.net>.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
7 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
8 * dvdudf: parse and read the UDF volume information of a DVD Video
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
9 * Copyright (C) 1999 Christian Wolff for convergence integrated media
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
10 * GmbH The author can be reached at scarabaeus@convergence.de, the
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
11 * project's page is at http://linuxtv.org/dvd/
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
12 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
13 * This program is free software; you can redistribute it and/or modify
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
14 * it under the terms of the GNU General Public License as published by
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or (at
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
16 * your option) any later version.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
17 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
18 * This program is distributed in the hope that it will be useful, but
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
21 * General Public License for more details.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
22 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
24 * along with this program; if not, write to the Free Software
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26 * 02111-1307, USA. Or, point your browser to
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 * http://www.gnu.org/copyleft/gpl.html
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30 #include <stdio.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31 #include <stdlib.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
32 #include <string.h>
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
33 //#include <assert.h>
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
34 #include <sys/ioctl.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
35 #include <sys/types.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
36 #include <sys/stat.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
37 #include <unistd.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
38 #include <inttypes.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
39
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
40 #include "dvd_reader.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
41 #include "dvd_udf.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
42
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
43 /* Private but located in/shared with dvd_reader.c */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
44 extern int DVDReadBlocksUDFRaw( dvd_reader_t *device, uint32_t lb_number,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
45 size_t block_count, unsigned char *data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
46 int encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
47
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
48 /* It's required to either fail or deliver all the blocks asked for. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
49 static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
50 size_t block_count, unsigned char *data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
51 int encrypted )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
52 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
53 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
54 size_t count = block_count;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
55
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
56 while(count > 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
57
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
58 ret = DVDReadBlocksUDFRaw(device, lb_number, count, data, encrypted);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
59
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
60 if(ret <= 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
61 /* One of the reads failed or nothing more to read, too bad.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
62 * We won't even bother returning the reads that went ok. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
63 return ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
64 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
65
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
66 count -= (size_t)ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
67 lb_number += (uint32_t)ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
68 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
69
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
70 return block_count;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
71 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
72
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
73
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
74 #ifndef NULL
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
75 #define NULL ((void *)0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
76 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
77
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
78 struct Partition {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
79 int valid;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
80 char VolumeDesc[128];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
81 uint16_t Flags;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
82 uint16_t Number;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
83 char Contents[32];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
84 uint32_t AccessType;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
85 uint32_t Start;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
86 uint32_t Length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89 struct AD {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
90 uint32_t Location;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91 uint32_t Length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92 uint8_t Flags;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
93 uint16_t Partition;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96 /* For direct data access, LSB first */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
97 #define GETN1(p) ((uint8_t)data[p])
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
98 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
99 #define GETN3(p) ((uint32_t)data[p] | ((uint32_t)data[(p) + 1] << 8) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 | ((uint32_t)data[(p) + 2] << 16))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 #define GETN4(p) ((uint32_t)data[p] \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 | ((uint32_t)data[(p) + 1] << 8) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 | ((uint32_t)data[(p) + 2] << 16) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 | ((uint32_t)data[(p) + 3] << 24))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
105 /* This is wrong with regard to endianess */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
106 #define GETN(p, n, target) memcpy(target, &data[p], n)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
107
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 static int Unicodedecode( uint8_t *data, int len, char *target )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
109 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110 int p = 1, i = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
111
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
112 if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
113 if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
114 if( p < len ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
115 target[ i++ ] = data[ p++ ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
116 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
117 } while( p < len );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
118
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 target[ i ] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123 static int UDFDescriptor( uint8_t *data, uint16_t *TagID )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
124 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
125 *TagID = GETN2(0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
126 // TODO: check CRC 'n stuff
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
127 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
128 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
129
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
130 static int UDFExtentAD( uint8_t *data, uint32_t *Length, uint32_t *Location )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
131 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
132 *Length = GETN4(0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
133 *Location = GETN4(4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
134 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
135 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
136
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
137 static int UDFShortAD( uint8_t *data, struct AD *ad,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
138 struct Partition *partition )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
139 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
140 ad->Length = GETN4(0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
141 ad->Flags = ad->Length >> 30;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
142 ad->Length &= 0x3FFFFFFF;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
143 ad->Location = GETN4(4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
144 ad->Partition = partition->Number; // use number of current partition
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
145 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
146 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
147
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
148 static int UDFLongAD( uint8_t *data, struct AD *ad )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
149 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
150 ad->Length = GETN4(0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
151 ad->Flags = ad->Length >> 30;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
152 ad->Length &= 0x3FFFFFFF;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
153 ad->Location = GETN4(4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
154 ad->Partition = GETN2(8);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
155 //GETN(10, 6, Use);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
156 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
157 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
158
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
159 static int UDFExtAD( uint8_t *data, struct AD *ad )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
160 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
161 ad->Length = GETN4(0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
162 ad->Flags = ad->Length >> 30;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
163 ad->Length &= 0x3FFFFFFF;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
164 ad->Location = GETN4(12);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
165 ad->Partition = GETN2(16);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
166 //GETN(10, 6, Use);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
167 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
168 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
169
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
170 static int UDFICB( uint8_t *data, uint8_t *FileType, uint16_t *Flags )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
171 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
172 *FileType = GETN1(11);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
173 *Flags = GETN2(18);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
174 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
175 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
176
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
177
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
178 static int UDFPartition( uint8_t *data, uint16_t *Flags, uint16_t *Number,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
179 char *Contents, uint32_t *Start, uint32_t *Length )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
180 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
181 *Flags = GETN2(20);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
182 *Number = GETN2(22);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
183 GETN(24, 32, Contents);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
184 *Start = GETN4(188);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
185 *Length = GETN4(192);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
186 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
187 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
188
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
189 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
190 * Reads the volume descriptor and checks the parameters. Returns 0 on OK, 1
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
191 * on error.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
192 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
193 static int UDFLogVolume( uint8_t *data, char *VolumeDescriptor )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
194 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
195 uint32_t lbsize, MT_L, N_PM;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
196 Unicodedecode(&data[84], 128, VolumeDescriptor);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
197 lbsize = GETN4(212); // should be 2048
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
198 MT_L = GETN4(264); // should be 6
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
199 N_PM = GETN4(268); // should be 1
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
200 if (lbsize != DVD_VIDEO_LB_LEN) return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
201 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
202 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
203
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
204 static int UDFFileEntry( uint8_t *data, uint8_t *FileType,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
205 struct Partition *partition, struct AD *ad )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
206 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
207 uint16_t flags;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
208 uint32_t L_EA, L_AD;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
209 unsigned int p;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
210
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
211 UDFICB( &data[ 16 ], FileType, &flags );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
212
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
213 /* Init ad for an empty file (i.e. there isn't a AD, L_AD == 0 ) */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
214 ad->Length = GETN4( 60 ); // Really 8 bytes a 56
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
215 ad->Flags = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
216 ad->Location = 0; // what should we put here?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
217 ad->Partition = partition->Number; // use number of current partition
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
218
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
219 L_EA = GETN4( 168 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
220 L_AD = GETN4( 172 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
221 p = 176 + L_EA;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
222 while( p < 176 + L_EA + L_AD ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
223 switch( flags & 0x0007 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
224 case 0: UDFShortAD( &data[ p ], ad, partition ); p += 8; break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
225 case 1: UDFLongAD( &data[ p ], ad ); p += 16; break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
226 case 2: UDFExtAD( &data[ p ], ad ); p += 20; break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
227 case 3:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
228 switch( L_AD ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
229 case 8: UDFShortAD( &data[ p ], ad, partition ); break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
230 case 16: UDFLongAD( &data[ p ], ad ); break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
231 case 20: UDFExtAD( &data[ p ], ad ); break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
232 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
233 p += L_AD;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
234 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
235 default:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
236 p += L_AD; break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
237 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
238 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
239 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
240 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
241
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
242 static int UDFFileIdentifier( uint8_t *data, uint8_t *FileCharacteristics,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
243 char *FileName, struct AD *FileICB )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
244 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
245 uint8_t L_FI;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
246 uint16_t L_IU;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
247
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
248 *FileCharacteristics = GETN1(18);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
249 L_FI = GETN1(19);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
250 UDFLongAD(&data[20], FileICB);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
251 L_IU = GETN2(36);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
252 if (L_FI) Unicodedecode(&data[38 + L_IU], L_FI, FileName);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
253 else FileName[0] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
254 return 4 * ((38 + L_FI + L_IU + 3) / 4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
255 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
256
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
257 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
258 * Maps ICB to FileAD
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
259 * ICB: Location of ICB of directory to scan
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
260 * FileType: Type of the file
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
261 * File: Location of file the ICB is pointing to
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
262 * return 1 on success, 0 on error;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
263 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
264 static int UDFMapICB( dvd_reader_t *device, struct AD ICB, uint8_t *FileType,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
265 struct Partition *partition, struct AD *File )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
266 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
267 uint8_t LogBlock[DVD_VIDEO_LB_LEN];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
268 uint32_t lbnum;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
269 uint16_t TagID;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
270
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
271 lbnum = partition->Start + ICB.Location;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
272 do {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
273 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
274 TagID = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
275 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
276 UDFDescriptor( LogBlock, &TagID );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
277 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
278
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
279 if( TagID == 261 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
280 UDFFileEntry( LogBlock, FileType, partition, File );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
281 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
282 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
283 } while( ( lbnum <= partition->Start + ICB.Location + ( ICB.Length - 1 )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
284 / DVD_VIDEO_LB_LEN ) && ( TagID != 261 ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
285
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
286 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
287 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
288
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
289 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
290 * Dir: Location of directory to scan
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
291 * FileName: Name of file to look for
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
292 * FileICB: Location of ICB of the found file
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
293 * return 1 on success, 0 on error;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
294 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
295 static int UDFScanDir( dvd_reader_t *device, struct AD Dir, char *FileName,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
296 struct Partition *partition, struct AD *FileICB )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
297 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
298 char filename[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
299 uint8_t directory[ 2 * DVD_VIDEO_LB_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
300 uint32_t lbnum;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
301 uint16_t TagID;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
302 uint8_t filechar;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
303 unsigned int p;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
304
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
305 /* Scan dir for ICB of file */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
306 lbnum = partition->Start + Dir.Location;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
307
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
308 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
309 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
310 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
311
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
312 p = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
313 while( p < Dir.Length ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
314 if( p > DVD_VIDEO_LB_LEN ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
315 ++lbnum;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
316 p -= DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
317 Dir.Length -= DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
318 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
319 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
320 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
321 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
322 UDFDescriptor( &directory[ p ], &TagID );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
323 if( TagID == 257 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
324 p += UDFFileIdentifier( &directory[ p ], &filechar,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
325 filename, FileICB );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
326 if( !strcasecmp( FileName, filename ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
327 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
328 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
329 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
330 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
331 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
332 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
333
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
334 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
335 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
336
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
337 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
338 * Looks for partition on the disc. Returns 1 if partition found, 0 on error.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
339 * partnum: Number of the partition, starting at 0.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
340 * part: structure to fill with the partition information
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
341 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
342 static int UDFFindPartition( dvd_reader_t *device, int partnum,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
343 struct Partition *part )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
344 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
345 uint8_t LogBlock[ DVD_VIDEO_LB_LEN ], Anchor[ DVD_VIDEO_LB_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
346 uint32_t lbnum, MVDS_location, MVDS_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
347 uint16_t TagID;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
348 uint32_t lastsector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
349 int i, terminate, volvalid;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
350
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
351 /* Find Anchor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
352 lastsector = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
353 lbnum = 256; /* Try #1, prime anchor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
354 terminate = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
355
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
356 for(;;) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
357 if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
358 UDFDescriptor( Anchor, &TagID );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
359 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
360 TagID = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
361 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
362 if (TagID != 2) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
363 /* Not an anchor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
364 if( terminate ) return 0; /* Final try failed */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
365
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
366 if( lastsector ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
367
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
368 /* We already found the last sector. Try #3, alternative
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
369 * backup anchor. If that fails, don't try again.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
370 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
371 lbnum = lastsector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
372 terminate = 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
373 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
374 /* TODO: Find last sector of the disc (this is optional). */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
375 if( lastsector ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
376 /* Try #2, backup anchor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
377 lbnum = lastsector - 256;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
378 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
379 /* Unable to find last sector */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
380 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
381 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
382 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
383 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
384 /* It's an anchor! We can leave */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
385 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
386 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
387 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
388 /* Main volume descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
389 UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
390
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
391 part->valid = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
392 volvalid = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
393 part->VolumeDesc[ 0 ] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
394 i = 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
395 do {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
396 /* Find Volume Descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
397 lbnum = MVDS_location;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
398 do {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
399
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
400 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
401 TagID = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
402 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
403 UDFDescriptor( LogBlock, &TagID );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
404 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
405
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
406 if( ( TagID == 5 ) && ( !part->valid ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
407 /* Partition Descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
408 UDFPartition( LogBlock, &part->Flags, &part->Number,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
409 part->Contents, &part->Start, &part->Length );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
410 part->valid = ( partnum == part->Number );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
411 } else if( ( TagID == 6 ) && ( !volvalid ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
412 /* Logical Volume Descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
413 if( UDFLogVolume( LogBlock, part->VolumeDesc ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
414 /* TODO: sector size wrong! */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
415 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
416 volvalid = 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
417 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
418 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
419
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
420 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
421 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
422 && ( ( !part->valid ) || ( !volvalid ) ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
423
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
424 if( ( !part->valid) || ( !volvalid ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
425 /* Backup volume descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
426 UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
427 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
428 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
429
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
430 /* We only care for the partition, not the volume */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
431 return part->valid;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
432 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
433
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
434 uint32_t UDFFindFile( dvd_reader_t *device, char *filename,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
435 uint32_t *filesize )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
436 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
437 uint8_t LogBlock[ DVD_VIDEO_LB_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
438 uint32_t lbnum;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
439 uint16_t TagID;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
440 struct Partition partition;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
441 struct AD RootICB, File, ICB;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
442 char tokenline[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
443 char *token;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
444 uint8_t filetype;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
445
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
446 *filesize = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
447 tokenline[0] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
448 strcat( tokenline, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
449
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
450 /* Find partition, 0 is the standard location for DVD Video.*/
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
451 if( !UDFFindPartition( device, 0, &partition ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
452
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
453 /* Find root dir ICB */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
454 lbnum = partition.Start;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
455 do {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
456 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
457 TagID = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
458 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
459 UDFDescriptor( LogBlock, &TagID );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
460 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
461
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
462 /* File Set Descriptor */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
463 if( TagID == 256 ) { // File Set Descriptor
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
464 UDFLongAD( &LogBlock[ 400 ], &RootICB );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
465 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
466 } while( ( lbnum < partition.Start + partition.Length )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
467 && ( TagID != 8 ) && ( TagID != 256 ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
468
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
469 /* Sanity checks. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
470 if( TagID != 256 ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
471 if( RootICB.Partition != 0 ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
472
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
473 /* Find root dir */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
474 if( !UDFMapICB( device, RootICB, &filetype, &partition, &File ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
475 if( filetype != 4 ) return 0; /* Root dir should be dir */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
476
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
477 /* Tokenize filepath */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
478 token = strtok(tokenline, "/");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
479 while( token != NULL ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
480 if( !UDFScanDir( device, File, token, &partition, &ICB ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
481 if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
482 token = strtok( NULL, "/" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
483 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
484
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
485 /* Sanity check. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
486 if( File.Partition != 0 ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
487
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
488 *filesize = File.Length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
489 /* Hack to not return partition.Start for empty files. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
490 if( !File.Location )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
491 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
492 else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
493 return partition.Start + File.Location;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
494 }