annotate libmpdvdkit2/dvd_udf.c @ 15231:e183a591efee

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