annotate dvdread/dvd_udf.c @ 356:da4ae9160df7 src

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