]> git.sesse.net Git - vlc/blob - plugins/dvd/dvd_udf.c
-New more recent css authentication code.
[vlc] / plugins / dvd / dvd_udf.c
1 /*****************************************************************************
2  * dvd_udf.c: udf filesystem tools.
3  * ---
4  * Mainly used to find asolute logical block adress of *.ifo files
5  *****************************************************************************
6  * Copyright (C) 1998-2001 VideoLAN
7  * $Id: dvd_udf.c,v 1.1 2001/02/15 21:03:27 stef Exp $
8  *
9  * Author: Stéphane Borel <stef@via.ecp.fr>
10  *
11  * based on:
12  *  - dvdudf by Christian Wolff <scarabaeus@convergence.de>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
27  *****************************************************************************/
28 /*
29  * Preamble
30  */
31 #include "defs.h"
32
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <fcntl.h>
37 #include <netinet/in.h>
38
39 #include "common.h"
40 #include "intf_msg.h"
41 #include "input_dvd.h"
42
43 /*
44  * Local structures
45  */
46 typedef struct partition_s
47 {
48         int     i_valid;
49         u8      pi_volume_desc[128];
50         u16     i_flags;
51         u16     i_number;
52         u8      pi_contents[32];
53         u32     i_accessType;
54         u32     i_start;
55         u32     i_length;
56 } partition_t;
57
58 typedef struct ad_s
59 {
60         u32     i_location;
61         u32     i_length;
62         u8      i_flags;
63         u16     i_partition;
64 } ad_t;
65
66 /*
67  * Local functions
68  */
69
70 /*****************************************************************************
71  * UDFDecode: decode udf data that is unicode encoded
72  *****************************************************************************/
73 static int UDFDecode( u8 * pi_data, int i_len, char * psz_target )
74 {
75         int p = 1;
76     int i = 0;
77
78         if( !( pi_data[0] & 0x18 ) )
79     {
80                 psz_target[0] ='\0';
81                 return 0;
82         }
83
84         if( data[0] & 0x10 )
85     {           
86         /* ignore MSB of unicode16 */
87                 p++;
88
89                 while( p < i_len )
90         {
91                         psz_target[i++] = pi_data[p+=2];
92         }
93         }
94     else
95     {
96                 while( p < i_len )
97         {
98                         psz_target[i++] = pi_data[p++];
99         }
100         }
101         
102         psz_target[i]='\0';
103
104         return 0;
105 }
106
107 /*****************************************************************************
108  * UDFInit: some check and initialization in udf filesystem
109  *****************************************************************************/
110 int UDFInit( u8 * pi_data, udf_t * p_udf )
111 {
112         u32i    lbsize,MT_L,N_PM;
113
114         UDFDecode( &pi_data[84], 128, p_udf->psz_volume_desc );
115         lbsize  = GETN4(212);           // should be 2048
116         MT_L    = GETN4(264);           // should be 6
117         N_PM    = GETN4(268);           // should be 1
118
119         if( lbsize != DVD_LB_SIZE )
120     {
121                 return 1;
122     }
123
124     return 0;
125 }
126
127 /*****************************************************************************
128  * UDFFileEntry:
129  *****************************************************************************/
130 int UDFFileEntry (uint8_t *data, uint8_t *FileType, struct AD *ad)
131 {
132         uint8_t filetype;
133         uint16_t flags;
134         uint32_t L_EA,L_AD;
135         int p;
136
137         UDFICB(&data[16],&filetype,&flags);
138         FileType[0]=filetype;
139         L_EA=GETN4(168);
140         L_AD=GETN4(172);
141         p=176+L_EA;
142
143         while (p<176+L_EA+L_AD) {
144                 switch (flags&0x07) {
145                 case 0:
146                         UDFAD (&data[p], ad, UDFADshort);
147                         p += 0x08;
148                         break;
149                 case 1:
150                         UDFAD (&data[p], ad, UDFADlong);
151                         p += 0x10;
152                         break;
153                 case 2: UDFAD (&data[p], ad, UDFADext);
154                         p += 0x14;
155                         break;
156                 case 3:
157                         switch (L_AD) {
158                         case 0x08:
159                                 UDFAD (&data[p], ad, UDFADshort);
160                                 break;
161                         case 0x10:
162                                 UDFAD (&data[p], ad, UDFADlong);
163                                 break;
164                         case 0x14:
165                                 UDFAD (&data[p], ad, UDFADext);
166                                 break;
167                         }
168                 default:
169                         p += L_AD;
170                         break;
171                 }
172         }
173
174         return 0;
175 }
176
177 /*****************************************************************************
178  * UDFFileIdentifier:
179  *****************************************************************************/
180 int UDFFileIdentifier (uint8_t *data, uint8_t *FileCharacteristics, char *FileName, struct AD *FileICB)
181 {
182         uint8_t L_FI;
183         uint16_t L_IU;
184   
185         FileCharacteristics[0]=GETN1(18);
186         L_FI=GETN1(19);
187         UDFAD(&data[20],FileICB,UDFADlong);
188         L_IU=GETN2(36);
189
190         if (L_FI)
191                 _Unicodedecode (&data[38+L_IU],L_FI,FileName);
192         else
193                 FileName[0]='\0';
194
195         return 4*((38+L_FI+L_IU+3)/4);
196 }
197
198