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