annotate libmpdvdkit2/dvd_udf.c @ 14128:d109c494f444

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