annotate libmpdvdkit2/dvd_udf.c @ 19072:e6f5f7c26166

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