Mercurial > mplayer.hg
annotate dvdread/dvd_udf.c @ 27431:bb738b9ea7c4
Use '#include <poll.h>' instead of '#include <sys/poll.h>'.
It is the standard location as defined by the Open Group.
author | diego |
---|---|
date | Thu, 14 Aug 2008 15:54:53 +0000 |
parents | dcf5fe229d37 |
children |
rev | line source |
---|---|
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1 /* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
7029 | 2 /* |
3 * This code is based on dvdudf by: | |
4 * Christian Wolff <scarabaeus@convergence.de>. | |
5 * | |
6 * Modifications by: | |
7 * Billy Biggs <vektor@dumbterm.net>. | |
10723 | 8 * Björn Englund <d4bjorn@dtek.chalmers.se>. |
7029 | 9 * |
10 * dvdudf: parse and read the UDF volume information of a DVD Video | |
11 * Copyright (C) 1999 Christian Wolff for convergence integrated media | |
12 * GmbH The author can be reached at scarabaeus@convergence.de, the | |
13 * project's page is at http://linuxtv.org/dvd/ | |
14 * | |
15 * This program is free software; you can redistribute it and/or modify | |
16 * it under the terms of the GNU General Public License as published by | |
17 * the Free Software Foundation; either version 2 of the License, or (at | |
18 * your option) any later version. | |
19 * | |
20 * This program is distributed in the hope that it will be useful, but | |
21 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
23 * General Public License for more details. | |
24 * | |
25 * You should have received a copy of the GNU General Public License | |
26 * along with this program; if not, write to the Free Software | |
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
28 * 02111-1307, USA. Or, point your browser to | |
29 * http://www.gnu.org/copyleft/gpl.html | |
30 */ | |
31 | |
15874 | 32 #include "config.h" |
33 | |
7029 | 34 #include <stdio.h> |
35 #include <stdlib.h> | |
36 #include <string.h> | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
37 |
7029 | 38 #include <sys/types.h> |
39 #include <sys/stat.h> | |
40 #include <unistd.h> | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
41 #include <errno.h> |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
42 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
43 #if defined(HAVE_INTTYPES_H) |
7029 | 44 #include <inttypes.h> |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
45 #elif defined(HAVE_STDINT_H) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
46 #include <stdint.h> |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
47 #endif |
7029 | 48 |
49 #include "dvd_reader.h" | |
50 #include "dvd_udf.h" | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
51 #include "dvdread_internal.h" |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
52 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
53 #ifndef EMEDIUMTYPE |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
54 #define EMEDIUMTYPE ENOENT |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
55 #endif |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
56 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
57 #ifndef HAVE_UINTPTR_T |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
58 #warning "Assuming that (unsigned long) can hold (void *)" |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
59 typedef unsigned long uintptr_t; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
60 #endif |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
61 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
62 #define DVD_ALIGN(ptr) (void *)((((uintptr_t)(ptr)) + (DVD_VIDEO_LB_LEN-1)) \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
63 / DVD_VIDEO_LB_LEN * DVD_VIDEO_LB_LEN) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
64 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
65 typedef struct { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
66 void *start; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
67 void *aligned; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
68 } dvdalign_ptrs_t; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
69 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
70 typedef struct { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
71 dvdalign_ptrs_t *ptrs; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
72 uint32_t ptrs_in_use; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
73 uint32_t ptrs_max; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
74 } dvdalign_t; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
75 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
76 extern void *GetAlignHandle(dvd_reader_t *device); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
77 extern void SetAlignHandle(dvd_reader_t *device, void *align); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
78 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
79 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
80 * Allocates aligned memory (for use with reads from raw/O_DIRECT devices). |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
81 * This memory must be freed with dvdalign_free() |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
82 * The size of the memory that is allocate is num_lbs*2048 bytes. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
83 * The memory will be suitably aligned for use with |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
84 * block reads from raw/O_DIRECT device. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
85 * @param num_lbs Number of logical blocks (2048 bytes) to allocate. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
86 * @return Returns pointer to allocated memory, or NULL on failure |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
87 * This isn't supposed to be fast/efficient, if that is needed |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
88 * this function should be rewritten to use posix_memalign or similar. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
89 * It's just needed for aligning memory for small block reads from |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
90 * raw/O_DIRECT devices. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
91 * We assume that 2048 is enough alignment for all systems at the moment. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
92 * Not thread safe. Only use this from one thread. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
93 * Depends on sizeof(unsigned long) being at least as large as sizeof(void *) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
94 */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
95 static void *dvdalign_lbmalloc(dvd_reader_t *device, uint32_t num_lbs) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
96 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
97 void *m; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
98 int n; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
99 dvdalign_t *a; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
100 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
101 m = malloc((num_lbs+1)*DVD_VIDEO_LB_LEN); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
102 if(m == NULL) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
103 return m; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
104 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
105 a = (dvdalign_t *)GetAlignHandle(device); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
106 if(a == NULL) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
107 a = malloc(sizeof(dvdalign_t)); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
108 if(a == NULL) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
109 return a; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
110 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
111 a->ptrs = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
112 a->ptrs_in_use = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
113 a->ptrs_max = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
114 SetAlignHandle(device, (void *)a); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
115 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
116 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
117 if(a->ptrs_in_use >= a->ptrs_max) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
118 a->ptrs = realloc(a->ptrs, (a->ptrs_max+10)*sizeof(dvdalign_ptrs_t)); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
119 if(a->ptrs == NULL) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
120 free(m); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
121 return NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
122 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
123 a->ptrs_max+=10; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
124 for(n = a->ptrs_in_use; n < a->ptrs_max; n++) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
125 a->ptrs[n].start = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
126 a->ptrs[n].aligned = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
127 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
128 n = a->ptrs_in_use; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
129 } else { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
130 for(n = 0; n < a->ptrs_max; n++) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
131 if(a->ptrs[n].start == NULL) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
132 break; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
133 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
134 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
135 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
136 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
137 a->ptrs[n].start = m; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
138 a->ptrs[n].aligned = DVD_ALIGN(m); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
139 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
140 a->ptrs_in_use++; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
141 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
142 /* If this function starts to be used too much print a warning. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
143 Either there is a memory leak somewhere or we need to rewrite this to |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
144 a more efficient version. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
145 */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
146 if(a->ptrs_in_use > 50) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
147 if(dvdread_verbose(device) >= 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
148 fprintf(stderr, "libdvdread: dvdalign_lbmalloc(), more allocs than supposed: %u\n", a->ptrs_in_use); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
149 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
150 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
151 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
152 return a->ptrs[n].aligned; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
153 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
154 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
155 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
156 * Frees memory allocated with dvdalign_lbmemory() |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
157 * @param ptr Pointer to memory space to free |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
158 * Not thread safe. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
159 */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
160 static void dvdalign_lbfree(dvd_reader_t *device, void *ptr) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
161 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
162 int n; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
163 dvdalign_t *a; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
164 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
165 a = (dvdalign_t *)GetAlignHandle(device); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
166 if(a && a->ptrs) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
167 for(n = 0; n < a->ptrs_max; n++) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
168 if(a->ptrs[n].aligned == ptr) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
169 free(a->ptrs[n].start); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
170 a->ptrs[n].start = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
171 a->ptrs[n].aligned = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
172 a->ptrs_in_use--; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
173 if(a->ptrs_in_use == 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
174 free(a->ptrs); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
175 a->ptrs = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
176 a->ptrs_max = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
177 free(a); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
178 a = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
179 SetAlignHandle(device, (void *)a); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
180 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
181 return; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
182 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
183 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
184 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
185 if(dvdread_verbose(device) >= 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
186 fprintf(stderr, "libdvdread: dvdalign_lbfree(), error trying to free mem: %08lx (%u)\n", (unsigned long)ptr, a ? a->ptrs_in_use : 0); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
187 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
188 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
189 |
7029 | 190 |
191 /* Private but located in/shared with dvd_reader.c */ | |
15874 | 192 extern int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
193 size_t block_count, unsigned char *data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
194 int encrypted ); |
7029 | 195 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
196 /** @internal |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
197 * Its required to either fail or deliver all the blocks asked for. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
198 * |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
199 * @param data Pointer to a buffer where data is returned. This must be large |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
200 * enough to hold lb_number*2048 bytes. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
201 * It must be aligned to system specific (2048) logical blocks size when |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
202 * reading from raw/O_DIRECT device. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
203 */ |
7029 | 204 static int DVDReadLBUDF( dvd_reader_t *device, uint32_t lb_number, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
205 size_t block_count, unsigned char *data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
206 int encrypted ) |
7029 | 207 { |
208 int ret; | |
209 size_t count = block_count; | |
210 | |
211 while(count > 0) { | |
212 | |
15874 | 213 ret = UDFReadBlocksRaw(device, lb_number, count, data, encrypted); |
7029 | 214 |
215 if(ret <= 0) { | |
216 /* One of the reads failed or nothing more to read, too bad. | |
217 * We won't even bother returning the reads that went ok. */ | |
218 return ret; | |
219 } | |
220 | |
221 count -= (size_t)ret; | |
222 lb_number += (uint32_t)ret; | |
223 } | |
224 | |
225 return block_count; | |
226 } | |
227 | |
228 | |
229 #ifndef NULL | |
230 #define NULL ((void *)0) | |
231 #endif | |
232 | |
233 struct Partition { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
234 int valid; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
235 char VolumeDesc[128]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
236 uint16_t Flags; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
237 uint16_t Number; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
238 char Contents[32]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
239 uint32_t AccessType; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
240 uint32_t Start; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
241 uint32_t Length; |
7029 | 242 }; |
243 | |
244 struct AD { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
245 uint32_t Location; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
246 uint32_t Length; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
247 uint8_t Flags; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
248 uint16_t Partition; |
7029 | 249 }; |
250 | |
10723 | 251 struct extent_ad { |
252 uint32_t location; | |
253 uint32_t length; | |
254 }; | |
255 | |
256 struct avdp_t { | |
257 struct extent_ad mvds; | |
258 struct extent_ad rvds; | |
259 }; | |
260 | |
261 struct pvd_t { | |
262 uint8_t VolumeIdentifier[32]; | |
263 uint8_t VolumeSetIdentifier[128]; | |
264 }; | |
265 | |
266 struct lbudf { | |
267 uint32_t lb; | |
268 uint8_t *data; | |
269 }; | |
270 | |
271 struct icbmap { | |
272 uint32_t lbn; | |
273 struct AD file; | |
274 uint8_t filetype; | |
275 }; | |
276 | |
15874 | 277 struct udf_cache { |
278 int avdp_valid; | |
279 struct avdp_t avdp; | |
280 int pvd_valid; | |
281 struct pvd_t pvd; | |
282 int partition_valid; | |
283 struct Partition partition; | |
284 int rooticb_valid; | |
285 struct AD rooticb; | |
286 int lb_num; | |
287 struct lbudf *lbs; | |
288 int map_num; | |
289 struct icbmap *maps; | |
290 }; | |
291 | |
292 typedef enum { | |
293 PartitionCache, RootICBCache, LBUDFCache, MapCache, AVDPCache, PVDCache | |
294 } UDFCacheType; | |
295 | |
296 extern void *GetUDFCacheHandle(dvd_reader_t *device); | |
297 extern void SetUDFCacheHandle(dvd_reader_t *device, void *cache); | |
298 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
299 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
300 void FreeUDFCache(dvd_reader_t *device, void *cache) |
15874 | 301 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
302 int n; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
303 |
15874 | 304 struct udf_cache *c = (struct udf_cache *)cache; |
305 if(c == NULL) { | |
306 return; | |
307 } | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
308 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
309 for(n = 0; n < c->lb_num; n++) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
310 if(c->lbs[n].data) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
311 /* free data */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
312 dvdalign_lbfree(device, c->lbs[n].data); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
313 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
314 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
315 c->lb_num = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
316 |
15874 | 317 if(c->lbs) { |
318 free(c->lbs); | |
319 } | |
320 if(c->maps) { | |
321 free(c->maps); | |
322 } | |
323 free(c); | |
324 } | |
325 | |
326 | |
327 static int GetUDFCache(dvd_reader_t *device, UDFCacheType type, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
328 uint32_t nr, void *data) |
15874 | 329 { |
330 int n; | |
331 struct udf_cache *c; | |
332 | |
333 if(DVDUDFCacheLevel(device, -1) <= 0) { | |
334 return 0; | |
335 } | |
336 | |
337 c = (struct udf_cache *)GetUDFCacheHandle(device); | |
338 | |
339 if(c == NULL) { | |
340 return 0; | |
341 } | |
342 | |
343 switch(type) { | |
344 case AVDPCache: | |
345 if(c->avdp_valid) { | |
346 *(struct avdp_t *)data = c->avdp; | |
347 return 1; | |
348 } | |
349 break; | |
350 case PVDCache: | |
351 if(c->pvd_valid) { | |
352 *(struct pvd_t *)data = c->pvd; | |
353 return 1; | |
354 } | |
355 break; | |
356 case PartitionCache: | |
357 if(c->partition_valid) { | |
358 *(struct Partition *)data = c->partition; | |
359 return 1; | |
360 } | |
361 break; | |
362 case RootICBCache: | |
363 if(c->rooticb_valid) { | |
364 *(struct AD *)data = c->rooticb; | |
365 return 1; | |
366 } | |
367 break; | |
368 case LBUDFCache: | |
369 for(n = 0; n < c->lb_num; n++) { | |
370 if(c->lbs[n].lb == nr) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
371 *(uint8_t **)data = c->lbs[n].data; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
372 return 1; |
15874 | 373 } |
374 } | |
375 break; | |
376 case MapCache: | |
377 for(n = 0; n < c->map_num; n++) { | |
378 if(c->maps[n].lbn == nr) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
379 *(struct icbmap *)data = c->maps[n]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
380 return 1; |
15874 | 381 } |
382 } | |
383 break; | |
384 default: | |
385 break; | |
386 } | |
387 | |
388 return 0; | |
389 } | |
390 | |
391 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
392 uint32_t nr, void *data) |
15874 | 393 { |
394 int n; | |
395 struct udf_cache *c; | |
396 | |
397 if(DVDUDFCacheLevel(device, -1) <= 0) { | |
398 return 0; | |
399 } | |
400 | |
401 c = (struct udf_cache *)GetUDFCacheHandle(device); | |
402 | |
403 if(c == NULL) { | |
404 c = calloc(1, sizeof(struct udf_cache)); | |
405 // fprintf(stderr, "calloc: %d\n", sizeof(struct udf_cache)); | |
406 if(c == NULL) { | |
407 return 0; | |
408 } | |
409 SetUDFCacheHandle(device, c); | |
410 } | |
411 | |
412 | |
413 switch(type) { | |
414 case AVDPCache: | |
415 c->avdp = *(struct avdp_t *)data; | |
416 c->avdp_valid = 1; | |
417 break; | |
418 case PVDCache: | |
419 c->pvd = *(struct pvd_t *)data; | |
420 c->pvd_valid = 1; | |
421 break; | |
422 case PartitionCache: | |
423 c->partition = *(struct Partition *)data; | |
424 c->partition_valid = 1; | |
425 break; | |
426 case RootICBCache: | |
427 c->rooticb = *(struct AD *)data; | |
428 c->rooticb_valid = 1; | |
429 break; | |
430 case LBUDFCache: | |
431 for(n = 0; n < c->lb_num; n++) { | |
432 if(c->lbs[n].lb == nr) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
433 /* replace with new data */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
434 c->lbs[n].data = *(uint8_t **)data; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
435 c->lbs[n].lb = nr; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
436 return 1; |
15874 | 437 } |
438 } | |
439 c->lb_num++; | |
440 c->lbs = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); | |
441 /* | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
442 fprintf(stderr, "realloc lb: %d * %d = %d\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
443 c->lb_num, sizeof(struct lbudf), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
444 c->lb_num * sizeof(struct lbudf)); |
15874 | 445 */ |
446 if(c->lbs == NULL) { | |
447 c->lb_num = 0; | |
448 return 0; | |
449 } | |
450 c->lbs[n].data = *(uint8_t **)data; | |
451 c->lbs[n].lb = nr; | |
452 break; | |
453 case MapCache: | |
454 for(n = 0; n < c->map_num; n++) { | |
455 if(c->maps[n].lbn == nr) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
456 /* replace with new data */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
457 c->maps[n] = *(struct icbmap *)data; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
458 c->maps[n].lbn = nr; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
459 return 1; |
15874 | 460 } |
461 } | |
462 c->map_num++; | |
463 c->maps = realloc(c->maps, c->map_num * sizeof(struct icbmap)); | |
464 /* | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
465 fprintf(stderr, "realloc maps: %d * %d = %d\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
466 c->map_num, sizeof(struct icbmap), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
467 c->map_num * sizeof(struct icbmap)); |
15874 | 468 */ |
469 if(c->maps == NULL) { | |
470 c->map_num = 0; | |
471 return 0; | |
472 } | |
473 c->maps[n] = *(struct icbmap *)data; | |
474 c->maps[n].lbn = nr; | |
475 break; | |
476 default: | |
477 return 0; | |
478 } | |
479 | |
480 return 1; | |
481 } | |
482 | |
483 | |
7029 | 484 /* For direct data access, LSB first */ |
485 #define GETN1(p) ((uint8_t)data[p]) | |
486 #define GETN2(p) ((uint16_t)data[p] | ((uint16_t)data[(p) + 1] << 8)) | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
487 #define GETN3(p) ((uint32_t)data[p] | ((uint32_t)data[(p) + 1] << 8) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
488 | ((uint32_t)data[(p) + 2] << 16)) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
489 #define GETN4(p) ((uint32_t)data[p] \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
490 | ((uint32_t)data[(p) + 1] << 8) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
491 | ((uint32_t)data[(p) + 2] << 16) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
492 | ((uint32_t)data[(p) + 3] << 24)) |
7029 | 493 /* This is wrong with regard to endianess */ |
494 #define GETN(p, n, target) memcpy(target, &data[p], n) | |
495 | |
496 static int Unicodedecode( uint8_t *data, int len, char *target ) | |
497 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
498 int p = 1, i = 0; |
7029 | 499 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
500 if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
501 if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
502 if( p < len ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
503 target[ i++ ] = data[ p++ ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
504 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
505 } while( p < len ); |
7029 | 506 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
507 target[ i ] = '\0'; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
508 return 0; |
7029 | 509 } |
510 | |
511 static int UDFDescriptor( uint8_t *data, uint16_t *TagID ) | |
512 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
513 *TagID = GETN2(0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
514 // TODO: check CRC 'n stuff |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
515 return 0; |
7029 | 516 } |
517 | |
518 static int UDFExtentAD( uint8_t *data, uint32_t *Length, uint32_t *Location ) | |
519 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
520 *Length = GETN4(0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
521 *Location = GETN4(4); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
522 return 0; |
7029 | 523 } |
524 | |
525 static int UDFShortAD( uint8_t *data, struct AD *ad, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
526 struct Partition *partition ) |
7029 | 527 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
528 ad->Length = GETN4(0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
529 ad->Flags = ad->Length >> 30; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
530 ad->Length &= 0x3FFFFFFF; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
531 ad->Location = GETN4(4); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
532 ad->Partition = partition->Number; // use number of current partition |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
533 return 0; |
7029 | 534 } |
535 | |
536 static int UDFLongAD( uint8_t *data, struct AD *ad ) | |
537 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
538 ad->Length = GETN4(0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
539 ad->Flags = ad->Length >> 30; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
540 ad->Length &= 0x3FFFFFFF; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
541 ad->Location = GETN4(4); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
542 ad->Partition = GETN2(8); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
543 //GETN(10, 6, Use); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
544 return 0; |
7029 | 545 } |
546 | |
547 static int UDFExtAD( uint8_t *data, struct AD *ad ) | |
548 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
549 ad->Length = GETN4(0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
550 ad->Flags = ad->Length >> 30; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
551 ad->Length &= 0x3FFFFFFF; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
552 ad->Location = GETN4(12); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
553 ad->Partition = GETN2(16); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
554 //GETN(10, 6, Use); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
555 return 0; |
7029 | 556 } |
557 | |
558 static int UDFICB( uint8_t *data, uint8_t *FileType, uint16_t *Flags ) | |
559 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
560 *FileType = GETN1(11); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
561 *Flags = GETN2(18); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
562 return 0; |
7029 | 563 } |
564 | |
565 | |
566 static int UDFPartition( uint8_t *data, uint16_t *Flags, uint16_t *Number, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
567 char *Contents, uint32_t *Start, uint32_t *Length ) |
7029 | 568 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
569 *Flags = GETN2(20); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
570 *Number = GETN2(22); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
571 GETN(24, 32, Contents); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
572 *Start = GETN4(188); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
573 *Length = GETN4(192); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
574 return 0; |
7029 | 575 } |
576 | |
577 /** | |
578 * Reads the volume descriptor and checks the parameters. Returns 0 on OK, 1 | |
579 * on error. | |
580 */ | |
581 static int UDFLogVolume( uint8_t *data, char *VolumeDescriptor ) | |
582 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
583 uint32_t lbsize, MT_L, N_PM; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
584 Unicodedecode(&data[84], 128, VolumeDescriptor); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
585 lbsize = GETN4(212); // should be 2048 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
586 MT_L = GETN4(264); // should be 6 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
587 N_PM = GETN4(268); // should be 1 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
588 if (lbsize != DVD_VIDEO_LB_LEN) return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
589 return 0; |
7029 | 590 } |
591 | |
592 static int UDFFileEntry( uint8_t *data, uint8_t *FileType, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
593 struct Partition *partition, struct AD *ad ) |
7029 | 594 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
595 uint16_t flags; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
596 uint32_t L_EA, L_AD; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
597 unsigned int p; |
7029 | 598 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
599 UDFICB( &data[ 16 ], FileType, &flags ); |
7029 | 600 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
601 /* Init ad for an empty file (i.e. there isn't a AD, L_AD == 0 ) */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
602 ad->Length = GETN4( 60 ); // Really 8 bytes a 56 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
603 ad->Flags = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
604 ad->Location = 0; // what should we put here? |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
605 ad->Partition = partition->Number; // use number of current partition |
7029 | 606 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
607 L_EA = GETN4( 168 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
608 L_AD = GETN4( 172 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
609 p = 176 + L_EA; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
610 while( p < 176 + L_EA + L_AD ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
611 switch( flags & 0x0007 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
612 case 0: UDFShortAD( &data[ p ], ad, partition ); p += 8; break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
613 case 1: UDFLongAD( &data[ p ], ad ); p += 16; break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
614 case 2: UDFExtAD( &data[ p ], ad ); p += 20; break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
615 case 3: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
616 switch( L_AD ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
617 case 8: UDFShortAD( &data[ p ], ad, partition ); break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
618 case 16: UDFLongAD( &data[ p ], ad ); break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
619 case 20: UDFExtAD( &data[ p ], ad ); break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
620 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
621 p += L_AD; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
622 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
623 default: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
624 p += L_AD; break; |
7029 | 625 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
626 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
627 return 0; |
7029 | 628 } |
629 | |
630 static int UDFFileIdentifier( uint8_t *data, uint8_t *FileCharacteristics, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
631 char *FileName, struct AD *FileICB ) |
7029 | 632 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
633 uint8_t L_FI; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
634 uint16_t L_IU; |
7029 | 635 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
636 *FileCharacteristics = GETN1(18); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
637 L_FI = GETN1(19); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
638 UDFLongAD(&data[20], FileICB); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
639 L_IU = GETN2(36); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
640 if (L_FI) Unicodedecode(&data[38 + L_IU], L_FI, FileName); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
641 else FileName[0] = '\0'; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
642 return 4 * ((38 + L_FI + L_IU + 3) / 4); |
7029 | 643 } |
644 | |
645 /** | |
646 * Maps ICB to FileAD | |
647 * ICB: Location of ICB of directory to scan | |
648 * FileType: Type of the file | |
649 * File: Location of file the ICB is pointing to | |
650 * return 1 on success, 0 on error; | |
651 */ | |
652 static int UDFMapICB( dvd_reader_t *device, struct AD ICB, uint8_t *FileType, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
653 struct Partition *partition, struct AD *File ) |
7029 | 654 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
655 uint8_t *LogBlock; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
656 uint32_t lbnum; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
657 uint16_t TagID; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
658 struct icbmap tmpmap; |
7029 | 659 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
660 lbnum = partition->Start + ICB.Location; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
661 tmpmap.lbn = lbnum; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
662 if(GetUDFCache(device, MapCache, lbnum, &tmpmap)) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
663 *FileType = tmpmap.filetype; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
664 *File = tmpmap.file; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
665 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
666 } |
15874 | 667 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
668 LogBlock = dvdalign_lbmalloc(device, 1); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
669 if(!LogBlock) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
670 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
671 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
672 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
673 do { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
674 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
675 TagID = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
676 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
677 UDFDescriptor( LogBlock, &TagID ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
678 } |
7029 | 679 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
680 if( TagID == 261 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
681 UDFFileEntry( LogBlock, FileType, partition, File ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
682 tmpmap.file = *File; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
683 tmpmap.filetype = *FileType; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
684 SetUDFCache(device, MapCache, tmpmap.lbn, &tmpmap); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
685 dvdalign_lbfree(device, LogBlock); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
686 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
687 }; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
688 } while( ( lbnum <= partition->Start + ICB.Location + ( ICB.Length - 1 ) |
7029 | 689 / DVD_VIDEO_LB_LEN ) && ( TagID != 261 ) ); |
690 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
691 dvdalign_lbfree(device, LogBlock); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
692 return 0; |
7029 | 693 } |
694 | |
695 /** | |
696 * Dir: Location of directory to scan | |
697 * FileName: Name of file to look for | |
698 * FileICB: Location of ICB of the found file | |
699 * return 1 on success, 0 on error; | |
700 */ | |
701 static int UDFScanDir( dvd_reader_t *device, struct AD Dir, char *FileName, | |
15874 | 702 struct Partition *partition, struct AD *FileICB, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
703 int cache_file_info) |
7029 | 704 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
705 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
706 uint8_t *directory; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
707 uint32_t lbnum; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
708 uint16_t TagID; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
709 uint8_t filechar; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
710 unsigned int p; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
711 uint8_t *cached_dir = NULL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
712 uint32_t dir_lba; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
713 struct AD tmpICB; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
714 int found = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
715 int in_cache = 0; |
7029 | 716 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
717 /* Scan dir for ICB of file */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
718 lbnum = partition->Start + Dir.Location; |
15874 | 719 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
720 if(DVDUDFCacheLevel(device, -1) > 0) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
721 /* caching */ |
15874 | 722 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
723 if(!GetUDFCache(device, LBUDFCache, lbnum, &cached_dir)) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
724 dir_lba = (Dir.Length + DVD_VIDEO_LB_LEN) / DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
725 if((cached_dir = dvdalign_lbmalloc(device, dir_lba)) == NULL) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
726 return 0; |
15874 | 727 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
728 if( DVDReadLBUDF( device, lbnum, dir_lba, cached_dir, 0) <= 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
729 dvdalign_lbfree(device, cached_dir); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
730 cached_dir = NULL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
731 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
732 SetUDFCache(device, LBUDFCache, lbnum, &cached_dir); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
733 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
734 in_cache = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
735 } |
15874 | 736 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
737 if(cached_dir == NULL) { |
15874 | 738 return 0; |
739 } | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
740 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
741 p = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
742 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
743 while( p < Dir.Length ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
744 UDFDescriptor( &cached_dir[ p ], &TagID ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
745 if( TagID == 257 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
746 p += UDFFileIdentifier( &cached_dir[ p ], &filechar, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
747 filename, &tmpICB ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
748 if(cache_file_info && !in_cache) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
749 uint8_t tmpFiletype; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
750 struct AD tmpFile; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
751 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
752 if( !strcasecmp( FileName, filename ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
753 *FileICB = tmpICB; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
754 found = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
755 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
756 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
757 UDFMapICB(device, tmpICB, &tmpFiletype, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
758 partition, &tmpFile); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
759 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
760 if( !strcasecmp( FileName, filename ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
761 *FileICB = tmpICB; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
762 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
763 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
764 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
765 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
766 if(cache_file_info && (!in_cache) && found) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
767 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
768 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
769 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
770 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
771 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
772 if(cache_file_info && (!in_cache) && found) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
773 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
774 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
775 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
776 } |
7029 | 777 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
778 directory = dvdalign_lbmalloc(device, 2); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
779 if(!directory) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
780 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
781 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
782 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
783 dvdalign_lbfree(device, directory); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
784 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
785 } |
7029 | 786 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
787 p = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
788 while( p < Dir.Length ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
789 if( p > DVD_VIDEO_LB_LEN ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
790 ++lbnum; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
791 p -= DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
792 Dir.Length -= DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
793 if( DVDReadLBUDF( device, lbnum, 2, directory, 0 ) <= 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
794 dvdalign_lbfree(device, directory); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
795 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
796 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
797 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
798 UDFDescriptor( &directory[ p ], &TagID ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
799 if( TagID == 257 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
800 p += UDFFileIdentifier( &directory[ p ], &filechar, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
801 filename, FileICB ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
802 if( !strcasecmp( FileName, filename ) ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
803 dvdalign_lbfree(device, directory); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
804 return 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
805 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
806 } else { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
807 dvdalign_lbfree(device, directory); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
808 return 0; |
7029 | 809 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
810 } |
7029 | 811 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
812 dvdalign_lbfree(device, directory); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
813 return 0; |
7029 | 814 } |
815 | |
10723 | 816 |
817 static int UDFGetAVDP( dvd_reader_t *device, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
818 struct avdp_t *avdp) |
10723 | 819 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
820 uint8_t *Anchor; |
10723 | 821 uint32_t lbnum, MVDS_location, MVDS_length; |
822 uint16_t TagID; | |
823 uint32_t lastsector; | |
824 int terminate; | |
825 struct avdp_t; | |
826 | |
15874 | 827 if(GetUDFCache(device, AVDPCache, 0, avdp)) { |
828 return 1; | |
829 } | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
830 |
10723 | 831 /* Find Anchor */ |
832 lastsector = 0; | |
833 lbnum = 256; /* Try #1, prime anchor */ | |
834 terminate = 0; | |
835 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
836 Anchor = dvdalign_lbmalloc(device, 1); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
837 if(!Anchor) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
838 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
839 } |
10723 | 840 for(;;) { |
841 if( DVDReadLBUDF( device, lbnum, 1, Anchor, 0 ) > 0 ) { | |
842 UDFDescriptor( Anchor, &TagID ); | |
843 } else { | |
844 TagID = 0; | |
845 } | |
846 if (TagID != 2) { | |
847 /* Not an anchor */ | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
848 if( terminate ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
849 dvdalign_lbfree(device, Anchor); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
850 errno = EMEDIUMTYPE; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
851 return 0; /* Final try failed */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
852 } |
10723 | 853 |
854 if( lastsector ) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
855 /* We already found the last sector. Try #3, alternative |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
856 * backup anchor. If that fails, don't try again. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
857 */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
858 lbnum = lastsector; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
859 terminate = 1; |
10723 | 860 } else { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
861 /* TODO: Find last sector of the disc (this is optional). */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
862 if( lastsector ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
863 /* Try #2, backup anchor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
864 lbnum = lastsector - 256; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
865 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
866 /* Unable to find last sector */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
867 dvdalign_lbfree(device, Anchor); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
868 errno = EMEDIUMTYPE; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
869 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
870 } |
10723 | 871 } |
872 } else { | |
873 /* It's an anchor! We can leave */ | |
874 break; | |
875 } | |
876 } | |
877 /* Main volume descriptor */ | |
878 UDFExtentAD( &Anchor[ 16 ], &MVDS_length, &MVDS_location ); | |
879 avdp->mvds.location = MVDS_location; | |
880 avdp->mvds.length = MVDS_length; | |
881 | |
882 /* Backup volume descriptor */ | |
883 UDFExtentAD( &Anchor[ 24 ], &MVDS_length, &MVDS_location ); | |
884 avdp->rvds.location = MVDS_location; | |
885 avdp->rvds.length = MVDS_length; | |
886 | |
15874 | 887 SetUDFCache(device, AVDPCache, 0, avdp); |
888 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
889 dvdalign_lbfree(device, Anchor); |
10723 | 890 return 1; |
891 } | |
892 | |
7029 | 893 /** |
894 * Looks for partition on the disc. Returns 1 if partition found, 0 on error. | |
895 * partnum: Number of the partition, starting at 0. | |
896 * part: structure to fill with the partition information | |
897 */ | |
898 static int UDFFindPartition( dvd_reader_t *device, int partnum, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
899 struct Partition *part ) |
7029 | 900 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
901 uint8_t *LogBlock; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
902 uint32_t lbnum, MVDS_location, MVDS_length; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
903 uint16_t TagID; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
904 int i, volvalid; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
905 struct avdp_t avdp; |
7029 | 906 |
10723 | 907 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
908 if(!UDFGetAVDP(device, &avdp)) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
909 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
910 } |
10723 | 911 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
912 LogBlock = dvdalign_lbmalloc(device, 1); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
913 if(!LogBlock) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
914 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
915 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
916 /* Main volume descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
917 MVDS_location = avdp.mvds.location; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
918 MVDS_length = avdp.mvds.length; |
10723 | 919 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
920 part->valid = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
921 volvalid = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
922 part->VolumeDesc[ 0 ] = '\0'; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
923 i = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
924 do { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
925 /* Find Volume Descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
926 lbnum = MVDS_location; |
7029 | 927 do { |
928 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
929 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
930 TagID = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
931 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
932 UDFDescriptor( LogBlock, &TagID ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
933 } |
7029 | 934 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
935 if( ( TagID == 5 ) && ( !part->valid ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
936 /* Partition Descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
937 UDFPartition( LogBlock, &part->Flags, &part->Number, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
938 part->Contents, &part->Start, &part->Length ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
939 part->valid = ( partnum == part->Number ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
940 } else if( ( TagID == 6 ) && ( !volvalid ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
941 /* Logical Volume Descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
942 if( UDFLogVolume( LogBlock, part->VolumeDesc ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
943 /* TODO: sector size wrong! */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
944 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
945 volvalid = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
946 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
947 } |
7029 | 948 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
949 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
950 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
951 && ( ( !part->valid ) || ( !volvalid ) ) ); |
7029 | 952 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
953 if( ( !part->valid) || ( !volvalid ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
954 /* Backup volume descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
955 MVDS_location = avdp.mvds.location; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
956 MVDS_length = avdp.mvds.length; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
957 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
958 } while( i-- && ( ( !part->valid ) || ( !volvalid ) ) ); |
7029 | 959 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
960 dvdalign_lbfree(device, LogBlock); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
961 /* We only care for the partition, not the volume */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
962 return part->valid; |
7029 | 963 } |
964 | |
965 uint32_t UDFFindFile( dvd_reader_t *device, char *filename, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
966 uint32_t *filesize ) |
7029 | 967 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
968 uint8_t *LogBlock; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
969 uint32_t lbnum; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
970 uint16_t TagID; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
971 struct Partition partition; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
972 struct AD RootICB, File, ICB; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
973 char tokenline[ MAX_UDF_FILE_NAME_LEN ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
974 char *token; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
975 uint8_t filetype; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
976 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
977 if(filesize) { |
7029 | 978 *filesize = 0; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
979 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
980 tokenline[0] = '\0'; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
981 strcat( tokenline, filename ); |
7029 | 982 |
10723 | 983 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
984 if(!(GetUDFCache(device, PartitionCache, 0, &partition) && |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
985 GetUDFCache(device, RootICBCache, 0, &RootICB))) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
986 /* Find partition, 0 is the standard location for DVD Video.*/ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
987 if( !UDFFindPartition( device, 0, &partition ) ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
988 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
989 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
990 SetUDFCache(device, PartitionCache, 0, &partition); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
991 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
992 LogBlock = dvdalign_lbmalloc(device, 1); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
993 if(!LogBlock) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
994 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
995 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
996 /* Find root dir ICB */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
997 lbnum = partition.Start; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
998 do { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
999 if( DVDReadLBUDF( device, lbnum++, 1, LogBlock, 0 ) <= 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1000 TagID = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1001 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1002 UDFDescriptor( LogBlock, &TagID ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1003 } |
7029 | 1004 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1005 /* File Set Descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1006 if( TagID == 256 ) { // File Set Descriptor |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1007 UDFLongAD( &LogBlock[ 400 ], &RootICB ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1008 } |
7029 | 1009 } while( ( lbnum < partition.Start + partition.Length ) |
1010 && ( TagID != 8 ) && ( TagID != 256 ) ); | |
1011 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1012 dvdalign_lbfree(device, LogBlock); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1013 |
7029 | 1014 /* Sanity checks. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1015 if( TagID != 256 ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1016 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1017 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1018 if( RootICB.Partition != 0 ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1019 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1020 } |
15874 | 1021 SetUDFCache(device, RootICBCache, 0, &RootICB); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1022 } |
10723 | 1023 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1024 /* Find root dir */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1025 if( !UDFMapICB( device, RootICB, &filetype, &partition, &File ) ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1026 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1027 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1028 if( filetype != 4 ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1029 return 0; /* Root dir should be dir */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1030 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1031 { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1032 int cache_file_info = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1033 /* Tokenize filepath */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1034 token = strtok(tokenline, "/"); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1035 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1036 while( token != NULL ) { |
10723 | 1037 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1038 if( !UDFScanDir( device, File, token, &partition, &ICB, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1039 cache_file_info)) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1040 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1041 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1042 if( !UDFMapICB( device, ICB, &filetype, &partition, &File ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1043 return 0; |
10723 | 1044 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1045 if(!strcmp(token, "VIDEO_TS")) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1046 cache_file_info = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1047 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1048 token = strtok( NULL, "/" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1049 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1050 } |
10723 | 1051 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1052 /* Sanity check. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1053 if( File.Partition != 0 ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1054 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1055 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1056 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1057 if(filesize) { |
7029 | 1058 *filesize = File.Length; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1059 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1060 /* Hack to not return partition.Start for empty files. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1061 if( !File.Location ) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1062 return 0; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1063 } else { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1064 return partition.Start + File.Location; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1065 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1066 } |
10723 | 1067 |
1068 | |
1069 | |
1070 /** | |
1071 * Gets a Descriptor . | |
1072 * Returns 1 if descriptor found, 0 on error. | |
1073 * id, tagid of descriptor | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1074 * bufsize, size of BlockBuf (must be >= DVD_VIDEO_LB_LEN) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1075 * and aligned for raw/O_DIRECT read. |
10723 | 1076 */ |
1077 static int UDFGetDescriptor( dvd_reader_t *device, int id, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1078 uint8_t *descriptor, int bufsize) |
10723 | 1079 { |
1080 uint32_t lbnum, MVDS_location, MVDS_length; | |
1081 struct avdp_t avdp; | |
1082 uint16_t TagID; | |
1083 uint32_t lastsector; | |
1084 int i, terminate; | |
1085 int desc_found = 0; | |
1086 /* Find Anchor */ | |
1087 lastsector = 0; | |
1088 lbnum = 256; /* Try #1, prime anchor */ | |
1089 terminate = 0; | |
1090 if(bufsize < DVD_VIDEO_LB_LEN) { | |
1091 return 0; | |
1092 } | |
1093 | |
1094 if(!UDFGetAVDP(device, &avdp)) { | |
1095 return 0; | |
1096 } | |
1097 | |
1098 /* Main volume descriptor */ | |
1099 MVDS_location = avdp.mvds.location; | |
1100 MVDS_length = avdp.mvds.length; | |
1101 | |
1102 i = 1; | |
1103 do { | |
1104 /* Find Descriptor */ | |
1105 lbnum = MVDS_location; | |
1106 do { | |
1107 | |
1108 if( DVDReadLBUDF( device, lbnum++, 1, descriptor, 0 ) <= 0 ) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1109 TagID = 0; |
10723 | 1110 } else { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1111 UDFDescriptor( descriptor, &TagID ); |
10723 | 1112 } |
1113 | |
1114 if( (TagID == id) && ( !desc_found ) ) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1115 /* Descriptor */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1116 desc_found = 1; |
10723 | 1117 } |
1118 } while( ( lbnum <= MVDS_location + ( MVDS_length - 1 ) | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1119 / DVD_VIDEO_LB_LEN ) && ( TagID != 8 ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1120 && ( !desc_found) ); |
10723 | 1121 |
1122 if( !desc_found ) { | |
1123 /* Backup volume descriptor */ | |
1124 MVDS_location = avdp.rvds.location; | |
1125 MVDS_length = avdp.rvds.length; | |
1126 } | |
1127 } while( i-- && ( !desc_found ) ); | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1128 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1129 |
10723 | 1130 return desc_found; |
1131 } | |
1132 | |
1133 | |
1134 static int UDFGetPVD(dvd_reader_t *device, struct pvd_t *pvd) | |
1135 { | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1136 uint8_t *pvd_buf; |
10723 | 1137 |
15874 | 1138 if(GetUDFCache(device, PVDCache, 0, pvd)) { |
1139 return 1; | |
1140 } | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1141 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1142 pvd_buf = dvdalign_lbmalloc(device, 1); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1143 if(!pvd_buf) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1144 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1145 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1146 if(!UDFGetDescriptor( device, 1, pvd_buf, 1*DVD_VIDEO_LB_LEN)) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1147 dvdalign_lbfree(device, pvd_buf); |
10723 | 1148 return 0; |
1149 } | |
1150 | |
1151 memcpy(pvd->VolumeIdentifier, &pvd_buf[24], 32); | |
1152 memcpy(pvd->VolumeSetIdentifier, &pvd_buf[72], 128); | |
15874 | 1153 SetUDFCache(device, PVDCache, 0, pvd); |
10723 | 1154 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1155 dvdalign_lbfree(device, pvd_buf); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1156 |
10723 | 1157 return 1; |
1158 } | |
15874 | 1159 |
1160 /** | |
1161 * Gets the Volume Identifier string, in 8bit unicode (latin-1) | |
1162 * volid, place to put the string | |
1163 * volid_size, size of the buffer volid points to | |
1164 * returns the size of buffer needed for all data | |
1165 */ | |
1166 int UDFGetVolumeIdentifier(dvd_reader_t *device, char *volid, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1167 unsigned int volid_size) |
15874 | 1168 { |
1169 struct pvd_t pvd; | |
1170 unsigned int volid_len; | |
1171 | |
1172 /* get primary volume descriptor */ | |
1173 if(!UDFGetPVD(device, &pvd)) { | |
1174 return 0; | |
1175 } | |
1176 | |
1177 volid_len = pvd.VolumeIdentifier[31]; | |
1178 if(volid_len > 31) { | |
1179 /* this field is only 32 bytes something is wrong */ | |
1180 volid_len = 31; | |
1181 } | |
1182 if(volid_size > volid_len) { | |
1183 volid_size = volid_len; | |
1184 } | |
1185 Unicodedecode(pvd.VolumeIdentifier, volid_size, volid); | |
1186 | |
1187 return volid_len; | |
1188 } | |
1189 | |
1190 /** | |
1191 * Gets the Volume Set Identifier, as a 128-byte dstring (not decoded) | |
1192 * WARNING This is not a null terminated string | |
1193 * volsetid, place to put the data | |
1194 * volsetid_size, size of the buffer volsetid points to | |
1195 * the buffer should be >=128 bytes to store the whole volumesetidentifier | |
1196 * returns the size of the available volsetid information (128) | |
1197 * or 0 on error | |
1198 */ | |
1199 int UDFGetVolumeSetIdentifier(dvd_reader_t *device, uint8_t *volsetid, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1200 unsigned int volsetid_size) |
15874 | 1201 { |
1202 struct pvd_t pvd; | |
1203 | |
1204 /* get primary volume descriptor */ | |
1205 if(!UDFGetPVD(device, &pvd)) { | |
1206 return 0; | |
1207 } | |
1208 | |
1209 | |
1210 if(volsetid_size > 128) { | |
1211 volsetid_size = 128; | |
1212 } | |
1213 | |
1214 memcpy(volsetid, pvd.VolumeSetIdentifier, volsetid_size); | |
1215 | |
1216 return 128; | |
1217 } |