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