Mercurial > libdvdread4.hg
annotate dvd_udf.c @ 83:bed968b9bd99 src
If the start offset points past the last_byte (outside the region read) stop
reading PTTs and adjust nr_of_srpts.
Fixes Transformers 3 and Cars 2.
Patch by John Stebbins ^stebbins*jetheaddev+com/
author | rathann |
---|---|
date | Thu, 03 Oct 2013 21:57:48 +0000 |
parents | 1b8797855771 |
children | 9f5802d2767a |
rev | line source |
---|---|
3 | 1 /* |
2 * This code is based on dvdudf by: | |
3 * Christian Wolff <scarabaeus@convergence.de>. | |
4 * | |
5 * Modifications by: | |
6 * Billy Biggs <vektor@dumbterm.net>. | |
22 | 7 * Björn Englund <d4bjorn@dtek.chalmers.se>. |
3 | 8 * |
9 * dvdudf: parse and read the UDF volume information of a DVD Video | |
10 * Copyright (C) 1999 Christian Wolff for convergence integrated media | |
11 * GmbH The author can be reached at scarabaeus@convergence.de, the | |
12 * project's page is at http://linuxtv.org/dvd/ | |
20 | 13 * |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
14 * This file is part of libdvdread. |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
15 * |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
16 * libdvdread is free software; you can redistribute it and/or modify |
3 | 17 * it under the terms of the GNU General Public License as published by |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
18 * the Free Software Foundation; either version 2 of the License, or |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
19 * (at your option) any later version. |
20 | 20 * |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
21 * libdvdread is distributed in the hope that it will be useful, |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
24 * GNU General Public License for more details. |
20 | 25 * |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
26 * You should have received a copy of the GNU General Public License along |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
27 * with libdvdread; if not, write to the Free Software Foundation, Inc., |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
3 | 29 */ |
20 | 30 |
3 | 31 #include <stdio.h> |
32 #include <stdlib.h> | |
33 #include <string.h> | |
78
1b8797855771
Add missing strings.h #include for strcasecmp() / strncasecmp().
diego
parents:
72
diff
changeset
|
34 #include <strings.h> |
3 | 35 |
36 #include <sys/types.h> | |
37 #include <sys/stat.h> | |
38 #include <unistd.h> | |
39 #include <inttypes.h> | |
40 | |
62
3bc841283972
Move UDFReadBlocksRaw declaration to dvdread_internal.h.
diego
parents:
49
diff
changeset
|
41 #include "dvdread_internal.h" |
33
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
31
diff
changeset
|
42 #include "dvdread/dvd_reader.h" |
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
31
diff
changeset
|
43 #include "dvdread/dvd_udf.h" |
3 | 44 |
45 /* It's required to either fail or deliver all the blocks asked for. */ | |
46 static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number, | |
26 | 47 size_t block_count, unsigned char *data, |
48 int encrypted ) | |
3 | 49 { |
50 int ret; | |
51 size_t count = block_count; | |
52 | |
53 while(count > 0) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
54 |
3 | 55 ret = UDFReadBlocksRaw(device, lb_number, count, data, encrypted); |
56 | |
57 if(ret <= 0) { | |
58 /* One of the reads failed or nothing more to read, too bad. | |
59 * We won't even bother returning the reads that went ok. */ | |
60 return ret; | |
61 } | |
62 | |
63 count -= (size_t)ret; | |
64 lb_number += (uint32_t)ret; | |
65 } | |
66 | |
67 return block_count; | |
68 } | |
69 | |
70 | |
71 #ifndef NULL | |
72 #define NULL ((void *)0) | |
73 #endif | |
74 | |
75 struct Partition { | |
76 int valid; | |
77 char VolumeDesc[128]; | |
78 uint16_t Flags; | |
79 uint16_t Number; | |
80 char Contents[32]; | |
81 uint32_t AccessType; | |
82 uint32_t Start; | |
83 uint32_t Length; | |
84 }; | |
85 | |
86 struct AD { | |
87 uint32_t Location; | |
88 uint32_t Length; | |
89 uint8_t Flags; | |
90 uint16_t Partition; | |
91 }; | |
92 | |
93 struct extent_ad { | |
94 uint32_t location; | |
95 uint32_t length; | |
96 }; | |
97 | |
98 struct avdp_t { | |
99 struct extent_ad mvds; | |
100 struct extent_ad rvds; | |
101 }; | |
102 | |
103 struct pvd_t { | |
104 uint8_t VolumeIdentifier[32]; | |
105 uint8_t VolumeSetIdentifier[128]; | |
106 }; | |
107 | |
108 struct lbudf { | |
109 uint32_t lb; | |
110 uint8_t *data; | |
111 /* needed for proper freeing */ | |
112 uint8_t *data_base; | |
113 }; | |
114 | |
115 struct icbmap { | |
116 uint32_t lbn; | |
117 struct AD file; | |
118 uint8_t filetype; | |
119 }; | |
120 | |
121 struct udf_cache { | |
122 int avdp_valid; | |
123 struct avdp_t avdp; | |
124 int pvd_valid; | |
125 struct pvd_t pvd; | |
126 int partition_valid; | |
127 struct Partition partition; | |
128 int rooticb_valid; | |
129 struct AD rooticb; | |
130 int lb_num; | |
131 struct lbudf *lbs; | |
132 int map_num; | |
133 struct icbmap *maps; | |
134 }; | |
135 | |
136 typedef enum { | |
137 PartitionCache, RootICBCache, LBUDFCache, MapCache, AVDPCache, PVDCache | |
138 } UDFCacheType; | |
139 | |
140 void FreeUDFCache(void *cache) | |
141 { | |
142 struct udf_cache *c = (struct udf_cache *)cache; | |
143 if(c == NULL) | |
144 return; | |
145 | |
146 if(c->lbs) { | |
147 int n; | |
148 for(n = 0; n < c->lb_num; n++) | |
149 free(c->lbs[n].data_base); | |
150 free(c->lbs); | |
151 } | |
152 if(c->maps) | |
153 free(c->maps); | |
154 free(c); | |
155 } | |
156 | |
157 | |
158 static int GetUDFCache(dvd_reader_t *device, UDFCacheType type, | |
26 | 159 uint32_t nr, void *data) |
3 | 160 { |
161 int n; | |
162 struct udf_cache *c; | |
163 | |
164 if(DVDUDFCacheLevel(device, -1) <= 0) | |
165 return 0; | |
166 | |
167 c = (struct udf_cache *)GetUDFCacheHandle(device); | |
168 | |
169 if(c == NULL) | |
170 return 0; | |
171 | |
172 switch(type) { | |
173 case AVDPCache: | |
174 if(c->avdp_valid) { | |
175 *(struct avdp_t *)data = c->avdp; | |
176 return 1; | |
177 } | |
178 break; | |
179 case PVDCache: | |
180 if(c->pvd_valid) { | |
181 *(struct pvd_t *)data = c->pvd; | |
182 return 1; | |
183 } | |
184 break; | |
185 case PartitionCache: | |
186 if(c->partition_valid) { | |
187 *(struct Partition *)data = c->partition; | |
188 return 1; | |
189 } | |
190 break; | |
191 case RootICBCache: | |
192 if(c->rooticb_valid) { | |
193 *(struct AD *)data = c->rooticb; | |
194 return 1; | |
195 } | |
196 break; | |
197 case LBUDFCache: | |
198 for(n = 0; n < c->lb_num; n++) { | |
199 if(c->lbs[n].lb == nr) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
200 *(uint8_t **)data = c->lbs[n].data; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
201 return 1; |
3 | 202 } |
203 } | |
204 break; | |
205 case MapCache: | |
206 for(n = 0; n < c->map_num; n++) { | |
207 if(c->maps[n].lbn == nr) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
208 *(struct icbmap *)data = c->maps[n]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
209 return 1; |
3 | 210 } |
211 } | |
212 break; | |
213 default: | |
214 break; | |
215 } | |
216 | |
217 return 0; | |
218 } | |
219 | |
220 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type, | |
26 | 221 uint32_t nr, void *data) |
3 | 222 { |
223 int n; | |
224 struct udf_cache *c; | |
225 void *tmp; | |
226 | |
227 if(DVDUDFCacheLevel(device, -1) <= 0) | |
228 return 0; | |
229 | |
230 c = (struct udf_cache *)GetUDFCacheHandle(device); | |
231 | |
232 if(c == NULL) { | |
20 | 233 c = calloc(1, sizeof(struct udf_cache)); |
3 | 234 /* fprintf(stderr, "calloc: %d\n", sizeof(struct udf_cache)); */ |
235 if(c == NULL) | |
236 return 0; | |
237 SetUDFCacheHandle(device, c); | |
238 } | |
239 | |
240 | |
241 switch(type) { | |
242 case AVDPCache: | |
20 | 243 c->avdp = *(struct avdp_t *)data; |
3 | 244 c->avdp_valid = 1; |
245 break; | |
246 case PVDCache: | |
20 | 247 c->pvd = *(struct pvd_t *)data; |
3 | 248 c->pvd_valid = 1; |
249 break; | |
250 case PartitionCache: | |
20 | 251 c->partition = *(struct Partition *)data; |
3 | 252 c->partition_valid = 1; |
253 break; | |
254 case RootICBCache: | |
20 | 255 c->rooticb = *(struct AD *)data; |
3 | 256 c->rooticb_valid = 1; |
257 break; | |
258 case LBUDFCache: | |
259 for(n = 0; n < c->lb_num; n++) { | |
260 if(c->lbs[n].lb == nr) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
261 /* replace with new data */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
262 c->lbs[n].data_base = ((uint8_t **)data)[0]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
263 c->lbs[n].data = ((uint8_t **)data)[1]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
264 c->lbs[n].lb = nr; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
265 return 1; |
3 | 266 } |
267 } | |
268 c->lb_num++; | |
269 tmp = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); | |
270 /* | |
271 fprintf(stderr, "realloc lb: %d * %d = %d\n", | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
272 c->lb_num, sizeof(struct lbudf), |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
273 c->lb_num * sizeof(struct lbudf)); |
3 | 274 */ |
275 if(tmp == NULL) { | |
276 if(c->lbs) free(c->lbs); | |
277 c->lb_num = 0; | |
278 return 0; | |
279 } | |
280 c->lbs = tmp; | |
281 c->lbs[n].data_base = ((uint8_t **)data)[0]; | |
282 c->lbs[n].data = ((uint8_t **)data)[1]; | |
283 c->lbs[n].lb = nr; | |
284 break; | |
285 case MapCache: | |
286 for(n = 0; n < c->map_num; n++) { | |
287 if(c->maps[n].lbn == nr) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
288 /* replace with new data */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
289 c->maps[n] = *(struct icbmap *)data; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
290 c->maps[n].lbn = nr; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
291 return 1; |
3 | 292 } |
293 } | |
294 c->map_num++; | |
295 tmp = realloc(c->maps, c->map_num * sizeof(struct icbmap)); | |
296 /* | |
297 fprintf(stderr, "realloc maps: %d * %d = %d\n", | |
298 c->map_num, sizeof(struct icbmap), | |
299 c->map_num * sizeof(struct icbmap)); | |
300 */ | |
301 if(tmp == NULL) { | |
302 if(c->maps) free(c->maps); | |
303 c->map_num = 0; | |
304 return 0; | |
305 } | |
306 c->maps = tmp; | |
307 c->maps[n] = *(struct icbmap *)data; | |
308 c->maps[n].lbn = nr; | |
309 break; | |
310 default: | |
311 return 0; | |
312 } | |
313 | |
314 return 1; | |
315 } | |
316 | |
317 | |
318 /* For direct data access, LSB first */ | |
319 #define GETN1(p) ((uint8_t)data[p]) | |
320 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8)) | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
321 #define GETN3(p) ((uint32_t)data[p] | ((uint32_t)data[(p) + 1] << 8) \ |
26 | 322 | ((uint32_t)data[(p) + 2] << 16)) |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
323 #define GETN4(p) ((uint32_t)data[p] \ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
324 | ((uint32_t)data[(p) + 1] << 8) \ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
325 | ((uint32_t)data[(p) + 2] << 16) \ |
26 | 326 | ((uint32_t)data[(p) + 3] << 24)) |
3 | 327 /* This is wrong with regard to endianess */ |
328 #define GETN(p, n, target) memcpy(target, &data[p], n) | |
329 | |
20 | 330 static int Unicodedecode( uint8_t *data, int len, char *target ) |
3 | 331 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
332 int p = 1, i = 0; |
72
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
333 int err = 0; |
3 | 334 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
335 if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { |
72
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
336 if( data[ 0 ] == 16 ) err |= data[p++]; /* character cannot be converted to 8bit, return error */ |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
337 if( p < len ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
338 target[ i++ ] = data[ p++ ]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
339 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
340 } while( p < len ); |
3 | 341 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
342 target[ i ] = '\0'; |
72
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
343 return !err; |
3 | 344 } |
345 | |
20 | 346 static int UDFDescriptor( uint8_t *data, uint16_t *TagID ) |
3 | 347 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
348 *TagID = GETN2(0); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
349 /* TODO: check CRC 'n stuff */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
350 return 0; |
3 | 351 } |
352 | |
20 | 353 static int UDFExtentAD( uint8_t *data, uint32_t *Length, uint32_t *Location ) |
3 | 354 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
355 *Length = GETN4(0); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
356 *Location = GETN4(4); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
357 return 0; |
3 | 358 } |
359 | |
20 | 360 static int UDFShortAD( uint8_t *data, struct AD *ad, |
26 | 361 struct Partition *partition ) |
3 | 362 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
363 ad->Length = GETN4(0); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
364 ad->Flags = ad->Length >> 30; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
365 ad->Length &= 0x3FFFFFFF; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
366 ad->Location = GETN4(4); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
367 ad->Partition = partition->Number; /* use number of current partition */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
368 return 0; |
3 | 369 } |
370 | |
371 static int UDFLongAD( uint8_t *data, struct AD *ad ) | |
372 { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
373 ad->Length = GETN4(0); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
374 ad->Flags = ad->Length >> 30; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
375 ad->Length &= 0x3FFFFFFF; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
376 ad->Location = GETN4(4); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
377 ad->Partition = GETN2(8); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
378 /* GETN(10, 6, Use); */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
379 return 0; |
3 | 380 } |
381 | |
382 static int UDFExtAD( uint8_t *data, struct AD *ad ) | |
383 { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
384 ad->Length = GETN4(0); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
385 ad->Flags = ad->Length >> 30; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
386 ad->Length &= 0x3FFFFFFF; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
387 ad->Location = GETN4(12); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
388 ad->Partition = GETN2(16); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
389 /* GETN(10, 6, Use); */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
390 return 0; |
3 | 391 } |
392 | |
393 static int UDFICB( uint8_t *data, uint8_t *FileType, uint16_t *Flags ) | |
394 { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
395 *FileType = GETN1(11); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
396 *Flags = GETN2(18); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
397 return 0; |
3 | 398 } |
399 | |
400 | |
401 static int UDFPartition( uint8_t *data, uint16_t *Flags, uint16_t *Number, | |
26 | 402 char *Contents, uint32_t *Start, uint32_t *Length ) |
3 | 403 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
404 *Flags = GETN2(20); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
405 *Number = GETN2(22); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
406 GETN(24, 32, Contents); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
407 *Start = GETN4(188); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
408 *Length = GETN4(192); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
409 return 0; |
3 | 410 } |
411 | |
412 /** | |
413 * Reads the volume descriptor and checks the parameters. Returns 0 on OK, 1 | |
414 * on error. | |
415 */ | |
416 static int UDFLogVolume( uint8_t *data, char *VolumeDescriptor ) | |
417 { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
418 uint32_t lbsize, MT_L, N_PM; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
419 Unicodedecode(&data[84], 128, VolumeDescriptor); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
420 lbsize = GETN4(212); /* should be 2048 */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
421 MT_L = GETN4(264); /* should be 6 */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
422 N_PM = GETN4(268); /* should be 1 */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
423 if (lbsize != DVD_VIDEO_LB_LEN) return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
424 return 0; |
3 | 425 } |
426 | |
20 | 427 static int UDFFileEntry( uint8_t *data, uint8_t *FileType, |
26 | 428 struct Partition *partition, struct AD *ad ) |
3 | 429 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
430 uint16_t flags; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
431 uint32_t L_EA, L_AD; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
432 unsigned int p; |
3 | 433 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
434 UDFICB( &data[ 16 ], FileType, &flags ); |
3 | 435 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
436 /* Init ad for an empty file (i.e. there isn't a AD, L_AD == 0 ) */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
437 ad->Length = GETN4( 60 ); /* Really 8 bytes a 56 */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
438 ad->Flags = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
439 ad->Location = 0; /* what should we put here? */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
440 ad->Partition = partition->Number; /* use number of current partition */ |
3 | 441 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
442 L_EA = GETN4( 168 ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
443 L_AD = GETN4( 172 ); |
48 | 444 |
445 if (176 + L_EA + L_AD > DVD_VIDEO_LB_LEN) | |
446 return 0; | |
447 | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
448 p = 176 + L_EA; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
449 while( p < 176 + L_EA + L_AD ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
450 switch( flags & 0x0007 ) { |
31 | 451 case 0: |
452 UDFShortAD( &data[ p ], ad, partition ); | |
453 p += 8; | |
454 break; | |
455 case 1: | |
456 UDFLongAD( &data[ p ], ad ); | |
457 p += 16; | |
458 break; | |
459 case 2: | |
460 UDFExtAD( &data[ p ], ad ); | |
461 p += 20; | |
462 break; | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
463 case 3: |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
464 switch( L_AD ) { |
31 | 465 case 8: |
466 UDFShortAD( &data[ p ], ad, partition ); | |
467 break; | |
468 case 16: | |
469 UDFLongAD( &data[ p ], ad ); | |
470 break; | |
471 case 20: | |
472 UDFExtAD( &data[ p ], ad ); | |
473 break; | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
474 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
475 p += L_AD; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
476 break; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
477 default: |
31 | 478 p += L_AD; |
479 break; | |
3 | 480 } |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
481 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
482 return 0; |
3 | 483 } |
484 | |
485 static int UDFFileIdentifier( uint8_t *data, uint8_t *FileCharacteristics, | |
26 | 486 char *FileName, struct AD *FileICB ) |
3 | 487 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
488 uint8_t L_FI; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
489 uint16_t L_IU; |
3 | 490 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
491 *FileCharacteristics = GETN1(18); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
492 L_FI = GETN1(19); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
493 UDFLongAD(&data[20], FileICB); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
494 L_IU = GETN2(36); |
72
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
495 if (L_FI) { |
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
496 if (!Unicodedecode(&data[38 + L_IU], L_FI, FileName)) FileName[0] = 0; |
99af5ed114a4
Fix segfault when reading certain DVDs, for example "Thor".
rathann
parents:
62
diff
changeset
|
497 } else FileName[0] = '\0'; |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
498 return 4 * ((38 + L_FI + L_IU + 3) / 4); |
3 | 499 } |
500 | |
501 /** | |
502 * Maps ICB to FileAD | |
503 * ICB: Location of ICB of directory to scan | |
504 * FileType: Type of the file | |
505 * File: Location of file the ICB is pointing to | |
506 * return 1 on success, 0 on error; | |
507 */ | |
508 static int UDFMapICB( dvd_reader_t *device, struct AD ICB, uint8_t *FileType, | |
26 | 509 struct Partition *partition, struct AD *File ) |
3 | 510 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
511 uint8_t LogBlock_base[DVD_VIDEO_LB_LEN + 2048]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
512 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
513 uint32_t lbnum; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
514 uint16_t TagID; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
515 struct icbmap tmpmap; |
3 | 516 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
517 lbnum = partition->Start + ICB.Location; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
518 tmpmap.lbn = lbnum; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
519 if(GetUDFCache(device, MapCache, lbnum, &tmpmap)) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
520 *FileType = tmpmap.filetype; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
521 memcpy(File, &tmpmap.file, sizeof(tmpmap.file)); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
522 return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
523 } |
3 | 524 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
525 do { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
526 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
527 TagID = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
528 else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
529 UDFDescriptor( LogBlock, &TagID ); |
3 | 530 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
531 if( TagID == 261 ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
532 UDFFileEntry( LogBlock, FileType, partition, File ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
533 memcpy(&tmpmap.file, File, sizeof(tmpmap.file)); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
534 tmpmap.filetype = *FileType; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
535 SetUDFCache(device, MapCache, tmpmap.lbn, &tmpmap); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
536 return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
537 }; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
538 } while( ( lbnum <= partition->Start + ICB.Location + ( ICB.Length - 1 ) |
3 | 539 / DVD_VIDEO_LB_LEN ) && ( TagID != 261 ) ); |
540 | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
541 return 0; |
3 | 542 } |
543 | |
544 /** | |
545 * Dir: Location of directory to scan | |
546 * FileName: Name of file to look for | |
547 * FileICB: Location of ICB of the found file | |
548 * return 1 on success, 0 on error; | |
549 */ | |
550 static int UDFScanDir( dvd_reader_t *device, struct AD Dir, char *FileName, | |
551 struct Partition *partition, struct AD *FileICB, | |
26 | 552 int cache_file_info) |
3 | 553 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
554 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
555 uint8_t directory_base[ 2 * DVD_VIDEO_LB_LEN + 2048]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
556 uint8_t *directory = (uint8_t *)(((uintptr_t)directory_base & ~((uintptr_t)2047)) + 2048); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
557 uint32_t lbnum; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
558 uint16_t TagID; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
559 uint8_t filechar; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
560 unsigned int p; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
561 uint8_t *cached_dir_base = NULL, *cached_dir; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
562 uint32_t dir_lba; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
563 struct AD tmpICB; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
564 int found = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
565 int in_cache = 0; |
3 | 566 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
567 /* Scan dir for ICB of file */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
568 lbnum = partition->Start + Dir.Location; |
3 | 569 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
570 if(DVDUDFCacheLevel(device, -1) > 0) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
571 /* caching */ |
3 | 572 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
573 if(!GetUDFCache(device, LBUDFCache, lbnum, &cached_dir)) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
574 dir_lba = (Dir.Length + DVD_VIDEO_LB_LEN) / DVD_VIDEO_LB_LEN; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
575 if((cached_dir_base = malloc(dir_lba * DVD_VIDEO_LB_LEN + 2048)) == NULL) |
3 | 576 return 0; |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
577 cached_dir = (uint8_t *)(((uintptr_t)cached_dir_base & ~((uintptr_t)2047)) + 2048); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
578 if( DVDReadLBUDF( device, lbnum, dir_lba, cached_dir, 0) <= 0 ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
579 free(cached_dir_base); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
580 cached_dir_base = NULL; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
581 cached_dir = NULL; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
582 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
583 /* |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
584 if(cached_dir) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
585 fprintf(stderr, "malloc dir: %d\n", dir_lba * DVD_VIDEO_LB_LEN); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
586 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
587 */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
588 { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
589 uint8_t *data[2]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
590 data[0] = cached_dir_base; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
591 data[1] = cached_dir; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
592 SetUDFCache(device, LBUDFCache, lbnum, data); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
593 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
594 } else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
595 in_cache = 1; |
3 | 596 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
597 if(cached_dir == NULL) |
3 | 598 return 0; |
599 | |
600 p = 0; | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
601 |
3 | 602 while( p < Dir.Length ) { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
603 UDFDescriptor( &cached_dir[ p ], &TagID ); |
3 | 604 if( TagID == 257 ) { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
605 p += UDFFileIdentifier( &cached_dir[ p ], &filechar, |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
606 filename, &tmpICB ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
607 if(cache_file_info && !in_cache) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
608 uint8_t tmpFiletype; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
609 struct AD tmpFile; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
610 |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
611 if( !strcasecmp( FileName, filename ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
612 memcpy(FileICB, &tmpICB, sizeof(tmpICB)); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
613 found = 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
614 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
615 UDFMapICB(device, tmpICB, &tmpFiletype, partition, &tmpFile); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
616 } else { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
617 if( !strcasecmp( FileName, filename ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
618 memcpy(FileICB, &tmpICB, sizeof(tmpICB)); |
3 | 619 return 1; |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
620 } |
3 | 621 } |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
622 } else { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
623 if(cache_file_info && (!in_cache) && found) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
624 return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
625 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
626 } |
3 | 627 } |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
628 if(cache_file_info && (!in_cache) && found) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
629 return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
630 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
631 } |
3 | 632 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
633 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) |
3 | 634 return 0; |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
635 |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
636 p = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
637 while( p < Dir.Length ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
638 if( p > DVD_VIDEO_LB_LEN ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
639 ++lbnum; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
640 p -= DVD_VIDEO_LB_LEN; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
641 Dir.Length -= DVD_VIDEO_LB_LEN; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
642 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
643 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
644 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
645 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
646 UDFDescriptor( &directory[ p ], &TagID ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
647 if( TagID == 257 ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
648 p += UDFFileIdentifier( &directory[ p ], &filechar, |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
649 filename, FileICB ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
650 if( !strcasecmp( FileName, filename ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
651 return 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
652 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
653 } else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
654 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
655 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
656 |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
657 return 0; |
3 | 658 } |
659 | |
660 | |
661 static int UDFGetAVDP( dvd_reader_t *device, | |
26 | 662 struct avdp_t *avdp) |
3 | 663 { |
664 uint8_t Anchor_base[ DVD_VIDEO_LB_LEN + 2048 ]; | |
665 uint8_t *Anchor = (uint8_t *)(((uintptr_t)Anchor_base & ~((uintptr_t)2047)) + 2048); | |
666 uint32_t lbnum, MVDS_location, MVDS_length; | |
667 uint16_t TagID; | |
668 uint32_t lastsector; | |
669 int terminate; | |
20 | 670 struct avdp_t; |
3 | 671 |
672 if(GetUDFCache(device, AVDPCache, 0, avdp)) | |
673 return 1; | |
674 | |
675 /* Find Anchor */ | |
676 lastsector = 0; | |
677 lbnum = 256; /* Try #1, prime anchor */ | |
678 terminate = 0; | |
679 | |
680 for(;;) { | |
681 if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) { | |
682 UDFDescriptor( Anchor, &TagID ); | |
683 } else { | |
684 TagID = 0; | |
685 } | |
686 if (TagID != 2) { | |
687 /* Not an anchor */ | |
688 if( terminate ) return 0; /* Final try failed */ | |
689 | |
690 if( lastsector ) { | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
691 /* We already found the last sector. Try #3, alternative |
3 | 692 * backup anchor. If that fails, don't try again. |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
693 */ |
3 | 694 lbnum = lastsector; |
695 terminate = 1; | |
696 } else { | |
697 /* TODO: Find last sector of the disc (this is optional). */ | |
698 if( lastsector ) | |
699 /* Try #2, backup anchor */ | |
700 lbnum = lastsector - 256; | |
701 else | |
702 /* Unable to find last sector */ | |
703 return 0; | |
704 } | |
705 } else | |
706 /* It's an anchor! We can leave */ | |
707 break; | |
708 } | |
709 /* Main volume descriptor */ | |
710 UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location ); | |
711 avdp->mvds.location = MVDS_location; | |
712 avdp->mvds.length = MVDS_length; | |
713 | |
714 /* Backup volume descriptor */ | |
715 UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location ); | |
716 avdp->rvds.location = MVDS_location; | |
717 avdp->rvds.length = MVDS_length; | |
718 | |
719 SetUDFCache(device, AVDPCache, 0, avdp); | |
720 | |
721 return 1; | |
722 } | |
723 | |
724 /** | |
725 * Looks for partition on the disc. Returns 1 if partition found, 0 on error. | |
726 * partnum: Number of the partition, starting at 0. | |
727 * part: structure to fill with the partition information | |
728 */ | |
729 static int UDFFindPartition( dvd_reader_t *device, int partnum, | |
26 | 730 struct Partition *part ) |
3 | 731 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
732 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
733 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
734 uint32_t lbnum, MVDS_location, MVDS_length; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
735 uint16_t TagID; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
736 int i, volvalid; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
737 struct avdp_t avdp; |
3 | 738 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
739 if(!UDFGetAVDP(device, &avdp)) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
740 return 0; |
3 | 741 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
742 /* Main volume descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
743 MVDS_location = avdp.mvds.location; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
744 MVDS_length = avdp.mvds.length; |
3 | 745 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
746 part->valid = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
747 volvalid = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
748 part->VolumeDesc[ 0 ] = '\0'; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
749 i = 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
750 do { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
751 /* Find Volume Descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
752 lbnum = MVDS_location; |
3 | 753 do { |
754 | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
755 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
756 TagID = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
757 else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
758 UDFDescriptor( LogBlock, &TagID ); |
3 | 759 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
760 if( ( TagID == 5 ) && ( !part->valid ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
761 /* Partition Descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
762 UDFPartition( LogBlock, &part->Flags, &part->Number, |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
763 part->Contents, &part->Start, &part->Length ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
764 part->valid = ( partnum == part->Number ); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
765 } else if( ( TagID == 6 ) && ( !volvalid ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
766 /* Logical Volume Descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
767 if( UDFLogVolume( LogBlock, part->VolumeDesc ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
768 /* TODO: sector size wrong! */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
769 } else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
770 volvalid = 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
771 } |
3 | 772 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
773 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
774 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
775 && ( ( !part->valid ) || ( !volvalid ) ) ); |
3 | 776 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
777 if( ( !part->valid) || ( !volvalid ) ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
778 /* Backup volume descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
779 MVDS_location = avdp.mvds.location; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
780 MVDS_length = avdp.mvds.length; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
781 } |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
782 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) ); |
3 | 783 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
784 /* We only care for the partition, not the volume */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
785 return part->valid; |
3 | 786 } |
787 | |
788 uint32_t UDFFindFile( dvd_reader_t *device, char *filename, | |
26 | 789 uint32_t *filesize ) |
3 | 790 { |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
791 uint8_t LogBlock_base[ DVD_VIDEO_LB_LEN + 2048 ]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
792 uint8_t *LogBlock = (uint8_t *)(((uintptr_t)LogBlock_base & ~((uintptr_t)2047)) + 2048); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
793 uint32_t lbnum; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
794 uint16_t TagID; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
795 struct Partition partition; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
796 struct AD RootICB, File, ICB; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
797 char tokenline[ MAX_UDF_FILE_NAME_LEN ]; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
798 char *token; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
799 uint8_t filetype; |
3 | 800 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
801 *filesize = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
802 tokenline[0] = '\0'; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
803 strncat(tokenline, filename, MAX_UDF_FILE_NAME_LEN - 1); |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
804 memset(&ICB, 0, sizeof(ICB)); |
3 | 805 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
806 if(!(GetUDFCache(device, PartitionCache, 0, &partition) && |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
807 GetUDFCache(device, RootICBCache, 0, &RootICB))) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
808 /* Find partition, 0 is the standard location for DVD Video.*/ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
809 if( !UDFFindPartition( device, 0, &partition ) ) return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
810 SetUDFCache(device, PartitionCache, 0, &partition); |
3 | 811 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
812 /* Find root dir ICB */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
813 lbnum = partition.Start; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
814 do { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
815 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
816 TagID = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
817 else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
818 UDFDescriptor( LogBlock, &TagID ); |
3 | 819 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
820 /* File Set Descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
821 if( TagID == 256 ) /* File Set Descriptor */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
822 UDFLongAD( &LogBlock[ 400 ], &RootICB ); |
3 | 823 } while( ( lbnum < partition.Start + partition.Length ) |
824 && ( TagID != 8 ) && ( TagID != 256 ) ); | |
825 | |
826 /* Sanity checks. */ | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
827 if( TagID != 256 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
828 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
829 if( RootICB.Partition != 0 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
830 return 0; |
3 | 831 SetUDFCache(device, RootICBCache, 0, &RootICB); |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
832 } |
3 | 833 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
834 /* Find root dir */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
835 if( !UDFMapICB( device, RootICB, &filetype, &partition, &File ) ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
836 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
837 if( filetype != 4 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
838 return 0; /* Root dir should be dir */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
839 { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
840 int cache_file_info = 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
841 /* Tokenize filepath */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
842 token = strtok(tokenline, "/"); |
3 | 843 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
844 while( token != NULL ) { |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
845 if( !UDFScanDir( device, File, token, &partition, &ICB, |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
846 cache_file_info)) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
847 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
848 if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
849 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
850 if(!strcmp(token, "VIDEO_TS")) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
851 cache_file_info = 1; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
852 token = strtok( NULL, "/" ); |
3 | 853 } |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
854 } |
3 | 855 |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
856 /* Sanity check. */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
857 if( File.Partition != 0 ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
858 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
859 *filesize = File.Length; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
860 /* Hack to not return partition.Start for empty files. */ |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
861 if( !File.Location ) |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
862 return 0; |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
863 else |
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
864 return partition.Start + File.Location; |
3 | 865 } |
866 | |
867 | |
868 | |
869 /** | |
870 * Gets a Descriptor . | |
871 * Returns 1 if descriptor found, 0 on error. | |
872 * id, tagid of descriptor | |
873 * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN). | |
874 */ | |
875 static int UDFGetDescriptor( dvd_reader_t *device, int id, | |
26 | 876 uint8_t *descriptor, int bufsize) |
3 | 877 { |
878 uint32_t lbnum, MVDS_location, MVDS_length; | |
879 struct avdp_t avdp; | |
880 uint16_t TagID; | |
881 uint32_t lastsector; | |
882 int i, terminate; | |
883 int desc_found = 0; | |
884 /* Find Anchor */ | |
885 lastsector = 0; | |
886 lbnum = 256; /* Try #1, prime anchor */ | |
887 terminate = 0; | |
888 if(bufsize < DVD_VIDEO_LB_LEN) | |
889 return 0; | |
890 | |
891 if(!UDFGetAVDP(device, &avdp)) | |
892 return 0; | |
893 | |
894 /* Main volume descriptor */ | |
895 MVDS_location = avdp.mvds.location; | |
896 MVDS_length = avdp.mvds.length; | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
897 |
3 | 898 i = 1; |
899 do { | |
900 /* Find Descriptor */ | |
901 lbnum = MVDS_location; | |
902 do { | |
903 if( DVDReadLBUDF( device, lbnum++, 1, descriptor, 0 ) <= 0 ) | |
904 TagID = 0; | |
905 else | |
906 UDFDescriptor( descriptor, &TagID ); | |
907 if( (TagID == id) && ( !desc_found ) ) | |
908 /* Descriptor */ | |
909 desc_found = 1; | |
910 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) | |
26 | 911 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) |
912 && ( !desc_found) ); | |
3 | 913 |
914 if( !desc_found ) { | |
915 /* Backup volume descriptor */ | |
916 MVDS_location = avdp.rvds.location; | |
917 MVDS_length = avdp.rvds.length; | |
918 } | |
919 } while( i-- && ( !desc_found ) ); | |
920 | |
921 return desc_found; | |
922 } | |
923 | |
924 | |
925 static int UDFGetPVD(dvd_reader_t *device, struct pvd_t *pvd) | |
926 { | |
927 uint8_t pvd_buf_base[DVD_VIDEO_LB_LEN + 2048]; | |
928 uint8_t *pvd_buf = (uint8_t *)(((uintptr_t)pvd_buf_base & ~((uintptr_t)2047)) + 2048); | |
929 if(GetUDFCache(device, PVDCache, 0, pvd)) | |
930 return 1; | |
931 | |
49
1acf15da93ba
fixed buffer size dimension in UDFGetPVD(); patch A00 by John Stebbins
nicodvb
parents:
48
diff
changeset
|
932 if(!UDFGetDescriptor( device, 1, pvd_buf, DVD_VIDEO_LB_LEN)) |
3 | 933 return 0; |
934 | |
935 memcpy(pvd->VolumeIdentifier, &pvd_buf[24], 32); | |
936 memcpy(pvd->VolumeSetIdentifier, &pvd_buf[72], 128); | |
937 SetUDFCache(device, PVDCache, 0, pvd); | |
938 return 1; | |
939 } | |
940 | |
941 /** | |
942 * Gets the Volume Identifier string, in 8bit unicode (latin-1) | |
943 * volid, place to put the string | |
944 * volid_size, size of the buffer volid points to | |
945 * returns the size of buffer needed for all data | |
946 */ | |
947 int UDFGetVolumeIdentifier(dvd_reader_t *device, char *volid, | |
26 | 948 unsigned int volid_size) |
3 | 949 { |
950 struct pvd_t pvd; | |
951 unsigned int volid_len; | |
952 | |
953 /* get primary volume descriptor */ | |
954 if(!UDFGetPVD(device, &pvd)) | |
955 return 0; | |
956 | |
957 volid_len = pvd.VolumeIdentifier[31]; | |
958 if(volid_len > 31) | |
959 /* this field is only 32 bytes something is wrong */ | |
960 volid_len = 31; | |
961 if(volid_size > volid_len) | |
962 volid_size = volid_len; | |
963 Unicodedecode(pvd.VolumeIdentifier, volid_size, volid); | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
964 |
3 | 965 return volid_len; |
966 } | |
967 | |
968 /** | |
969 * Gets the Volume Set Identifier, as a 128-byte dstring (not decoded) | |
970 * WARNING This is not a null terminated string | |
971 * volsetid, place to put the data | |
20 | 972 * volsetid_size, size of the buffer volsetid points to |
3 | 973 * the buffer should be >=128 bytes to store the whole volumesetidentifier |
974 * returns the size of the available volsetid information (128) | |
975 * or 0 on error | |
976 */ | |
977 int UDFGetVolumeSetIdentifier(dvd_reader_t *device, uint8_t *volsetid, | |
26 | 978 unsigned int volsetid_size) |
3 | 979 { |
980 struct pvd_t pvd; | |
981 | |
982 /* get primary volume descriptor */ | |
983 if(!UDFGetPVD(device, &pvd)) | |
984 return 0; | |
985 | |
986 | |
987 if(volsetid_size > 128) | |
988 volsetid_size = 128; | |
989 | |
990 memcpy(volsetid, pvd.VolumeSetIdentifier, volsetid_size); | |
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
991 |
3 | 992 return 128; |
993 } |