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