/*****************************************************************************
* dvd_udf.c: udf filesystem tools.
- * ---
+ *****************************************************************************
* Mainly used to find asolute logical block adress of *.ifo files. It only
* contains the basic udf handling functions
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: dvd_udf.c,v 1.3 2001/02/20 07:49:12 sam Exp $
+ * $Id: dvd_udf.c,v 1.19 2002/03/06 01:20:56 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
*
* based on:
* - dvdudf by Christian Wolff <scarabaeus@convergence.de>
+ * - fixes by Billy Biggs <vektor@dumbterm.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#define MODULE_NAME dvd
-#include "modules_inner.h"
-
-/*
+/*****************************************************************************
* Preamble
- */
-#include "defs.h"
-
+ *****************************************************************************/
#include <stdio.h>
-#include <unistd.h>
#include <string.h>
#include <fcntl.h>
-#include "common.h"
-#include "intf_msg.h"
-#include "dvd_css.h"
+#include <videolan/vlc.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#elif defined( _MSC_VER ) && defined( _WIN32 )
+# include <io.h>
+#endif
+
+#ifdef STRNCASECMP_IN_STRINGS_H
+# include <strings.h>
+#endif
+
+#ifdef GOD_DAMN_DMCA
+# include "dummy_dvdcss.h"
+#else
+# include <videolan/dvdcss.h>
+#endif
+
+#include "dvd.h"
#include "dvd_ifo.h"
-#include "input_dvd.h"
#define UDFADshort 1
#define UDFADlong 2
typedef struct partition_s
{
- boolean_t b_valid;
- u8 pi_volume_desc[128];
- u16 i_flags;
- u16 i_number;
- u8 pi_contents[32];
- u32 i_access_type;
- u32 i_start;
- u32 i_length;
- int i_fd;
+ boolean_t b_valid;
+ u8 pi_volume_desc[128];
+ u16 i_flags;
+ u16 i_number;
+ u8 pi_contents[32];
+ u32 i_access_type;
+ u32 i_start;
+ u32 i_length;
+ dvdcss_handle dvdhandle;
} partition_t;
typedef struct ad_s
/*****************************************************************************
* UDFReadLB: reads absolute Logical Block of the disc
- * ---
- * returns number of read bytes on success, 0 on error
+ *****************************************************************************
+ * Returns number of read bytes on success, 0 on error
*****************************************************************************/
-static int UDFReadLB( int i_fd, off_t i_lba, size_t i_block_count, u8 *pi_data )
+static int UDFReadLB( dvdcss_handle dvdhandle, off_t i_lba,
+ size_t i_block_count, u8 *pi_data )
{
- if( i_fd < 0 )
+ if( dvdcss_seek( dvdhandle, i_lba, DVDCSS_NOFLAGS ) < 0 )
{
+ intf_ErrMsg( "dvd error: block %i not found", i_lba );
return 0;
}
- if( lseek( i_fd, i_lba * (off_t) DVD_LB_SIZE, SEEK_SET ) < 0 )
- {
- intf_ErrMsg( "UDF: Postion not found" );
- return 0;
- }
-
- return read( i_fd, pi_data, i_block_count *DVD_LB_SIZE);
+ return dvdcss_read( dvdhandle, pi_data, i_block_count, DVDCSS_NOFLAGS );
}
/*****************************************************************************
* UDFLogVolume: reads the volume descriptor and checks the parameters
- * ---
- * returns 0 on OK, 1 on error
+ *****************************************************************************
+ * Returns 0 on OK, 1 on error
*****************************************************************************/
static int UDFLogVolume(u8 * pi_data, char * p_volume_descriptor )
{
if( i_lb_size != DVD_LB_SIZE )
{
- intf_ErrMsg( "UDF: Non valid sector size (%d)", i_lb_size );
+ intf_ErrMsg( "dvd error: invalid UDF sector size (%d)", i_lb_size );
return 1;
}
/*****************************************************************************
* UDFMapICB: Maps ICB to FileAD
- * ---
+ *****************************************************************************
* ICB: Location of ICB of directory to scan
* FileType: Type of the file
* File: Location of file the ICB is pointing to
do
{
- if( !UDFReadLB( partition.i_fd, i_lba++, 1, pi_lb ) )
+ if( !UDFReadLB( partition.dvdhandle, i_lba++, 1, pi_lb ) )
{
i_tag_id = 0;
}
/*****************************************************************************
* UDFScanDir: serach filename in dir
- * ---
+ *****************************************************************************
* Dir: Location of directory to scan
* FileName: Name of file to look for
* FileICB: Location of ICB of the found file
static int UDFScanDir( struct ad_s dir, char * psz_filename,
struct ad_s * p_file_icb, struct partition_s partition )
{
- u8 pi_lb[DVD_LB_SIZE];
+ u8 pi_lb[2*DVD_LB_SIZE];
u32 i_lba;
u16 i_tag_id;
u8 i_file_char;
/* Scan dir for ICB of file */
i_lba = partition.i_start + dir.i_location;
-
+#if 0
do
{
- if( !UDFReadLB( partition.i_fd, i_lba++, 1, pi_lb ) )
+ if( !UDFReadLB( partition.dvdhandle, i_lba++, 1, pi_lb ) )
{
i_tag_id = 0;
}
} while( i_lba <=
partition.i_start + dir.i_location + ( dir.i_length - 1 ) / DVD_LB_SIZE );
+#else
+
+ if( UDFReadLB( partition.dvdhandle, i_lba, 2, pi_lb ) <= 0 ) {
+ return 0;
+ }
+
+ p = 0;
+ while( p < dir.i_length )
+ {
+ if( p > DVD_LB_SIZE )
+ {
+ ++i_lba;
+ p -= DVD_LB_SIZE;
+ dir.i_length -= DVD_LB_SIZE;
+ if( UDFReadLB( partition.dvdhandle, i_lba, 2, pi_lb ) <= 0 )
+ {
+ return 0;
+ }
+ }
+
+ UDFDescriptor( &pi_lb[p], &i_tag_id );
+
+ if( i_tag_id == 257 )
+ {
+ p += UDFFileIdentifier( &pi_lb[p], &i_file_char,
+ psz_temp, p_file_icb, partition );
+ if( !strcasecmp( psz_filename, psz_temp ) )
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+#endif
return 0;
}
-
-/******************************************************************************
+/*****************************************************************************
* UDFFindPartition: looks for a partition on the disc
- * ---
+ *****************************************************************************
* partnum: number of the partition, starting at 0
* part: structure to fill with the partition information
* return 1 if partition found, 0 on error;
- ******************************************************************************/
+ *****************************************************************************/
static int UDFFindPartition( int i_part_nb, struct partition_s *p_partition )
{
u8 pi_lb[DVD_LB_SIZE];
/* Search anchor loop */
while( 1 )
{
- if( UDFReadLB( p_partition->i_fd, i_lba, 1, pi_anchor ) )
+ if( UDFReadLB( p_partition->dvdhandle, i_lba, 1, pi_anchor ) )
{
UDFDescriptor( pi_anchor, &i_tag_id );
}
do
{
- if( !UDFReadLB( p_partition->i_fd, i_lba++, 1, pi_lb ) )
+ if( !UDFReadLB( p_partition->dvdhandle, i_lba++, 1, pi_lb ) )
{
i_tag_id = 0;
}
}
-/******************************************************************************
- * UDFFindFile: looks for a file on the UDF disc/imagefile
- * ---
+/*****************************************************************************
+ * DVDUDFFindFile: looks for a file on the UDF disc/imagefile
+ *****************************************************************************
* Path has to be the absolute pathname on the UDF filesystem,
* starting with '/'.
* returns absolute LB number, or 0 on error
- ******************************************************************************/
-u32 UDFFindFile( int i_fd, char * psz_path )
+ *****************************************************************************/
+u32 DVDUDFFindFile( dvdcss_handle dvdhandle, char * psz_path )
{
struct partition_s partition;
struct ad_s root_icb;
strcat( psz_tokenline, psz_path );
/* Init file descriptor of UDF filesystem (== DVD) */
- partition.i_fd = i_fd;
+ partition.dvdhandle = dvdhandle;
/* Find partition 0, standard partition for DVD-Video */
i_partition = 0;
if( !UDFFindPartition( i_partition, &partition ) )
{
- intf_ErrMsg( "UDF: Partition 0 not found" );
+ intf_ErrMsg( "dvd error: partition 0 not found" );
return 0;
}
do
{
- if( !UDFReadLB( i_fd, i_lba++, 1, pi_lb ) )
+ if( !UDFReadLB( dvdhandle, i_lba++, 1, pi_lb ) )
{
i_tag_id = 0;
}
if( i_tag_id != 256 )
{
- intf_ErrMsg( "UDF: Bad descriptor" );
+ intf_ErrMsg( "dvd error: bad UDF descriptor" );
return 0;
}
if( root_icb.i_partition != i_partition )
{
- intf_ErrMsg( "UDF: Bad partition" );
+ intf_ErrMsg( "dvd error: bad UDF partition" );
return 0;
}
/* Find root dir */
if( !UDFMapICB( root_icb, &i_file_type, &file, partition ) )
{
- intf_ErrMsg( "UDF: Can't find root dir" );
+ intf_ErrMsg( "dvd error: can't find root dir" );
return 0;
}
/* root dir should be dir */
if( i_file_type != 4 )
{
- intf_ErrMsg( "UDF: Root dir error" );
+ intf_ErrMsg( "dvd error: root dir error" );
return 0;
}
{
if( !UDFScanDir( file, psz_token, &icb, partition ) )
{
- intf_ErrMsg( "UDF: Scan dir error" );
+ intf_ErrMsg( "dvd error: scan dir error" );
return 0;
}
if( !UDFMapICB ( icb, &i_file_type, &file, partition ) )
{
- intf_ErrMsg( "UDF: ICB error" );
+ intf_ErrMsg( "dvd error: ICB error" );
return 0;
}
return partition.i_start + file.i_location;
}
+