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