annotate dvdread/dvd_udf.c @ 25065:54dba785e683

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