]> git.sesse.net Git - vlc/blobdiff - plugins/dvd/dvd_udf.c
* BeOS fixes. renamed iovec.h to input_iovec.h because of namespace issues.
[vlc] / plugins / dvd / dvd_udf.c
index 1434db25fd1bef7ca7ae5a681c656c65906488d9..8147aa4f5cdcfa71ef559d7cabb26c88420276d8 100644 (file)
@@ -1,16 +1,17 @@
 /*****************************************************************************
  * 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.2 2001/02/18 01:42:05 stef Exp $
+ * $Id: dvd_udf.c,v 1.8 2001/05/31 03:12:49 sam 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
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
+
 /*
  * Preamble
  */
 #include "defs.h"
 
+#ifdef HAVE_CSS
+#   define MODULE_NAME dvd
+#else /* HAVE_CSS */
+#   define MODULE_NAME dvdnocss
+#endif /* HAVE_CSS */
+
+#include "modules_inner.h"
+
 #include <stdio.h>
-#include <unistd.h>
 #include <string.h>
 #include <fcntl.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
+
 #include "common.h"
 #include "intf_msg.h"
 #include "dvd_css.h"
@@ -76,23 +95,44 @@ 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 )
 {
+#if !defined( WIN32 )
     if( i_fd < 0 )
+#else
+    DWORD read;
+
+    if( (HANDLE) i_fd == INVALID_HANDLE_VALUE )
+#endif
     {
         return 0;
     }
 
+#if !defined( WIN32 )
     if( lseek( i_fd, i_lba * (off_t) DVD_LB_SIZE, SEEK_SET ) < 0 )
+#else
+    if( SetFilePointer( (HANDLE) i_fd, i_lba * (off_t) DVD_LB_SIZE,
+        NULL, FILE_BEGIN ) == -1 )
+#endif
     {
         intf_ErrMsg( "UDF: Postion not found" );
         return 0;
     }
 
+#if !defined( WIN32 )
     return read( i_fd, pi_data, i_block_count *DVD_LB_SIZE);
+#else
+    if(!ReadFile( (HANDLE) i_fd, pi_data, i_block_count * DVD_LB_SIZE,
+        &read, NULL) || read != i_block_count * DVD_LB_SIZE )
+    {
+        return 0;
+    }
+
+    return read;
+#endif
 }
 
 
@@ -235,8 +275,8 @@ static int UDFPartition( u8 * pi_data, u16 * pi_flags, u16 * pi_nb,
 
 /*****************************************************************************
  * 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 )
 {
@@ -348,7 +388,7 @@ static int UDFFileIdentifier( u8 * pi_data, u8 * pi_file_characteristics,
 
 /*****************************************************************************
  * 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
@@ -388,7 +428,7 @@ static int UDFMapICB( struct ad_s icb, u8 * pi_file_type, struct ad_s * p_file,
 
 /*****************************************************************************
  * 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
@@ -397,7 +437,7 @@ static int UDFMapICB( struct ad_s icb, u8 * pi_file_type, struct ad_s * p_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;
@@ -406,7 +446,7 @@ static int UDFScanDir( struct ad_s dir, char * psz_filename,
   
     /* 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 ) )
@@ -439,17 +479,54 @@ static int UDFScanDir( struct ad_s dir, char * psz_filename,
     } while( i_lba <=
       partition.i_start + dir.i_location + ( dir.i_length - 1 ) / DVD_LB_SIZE );
 
+#else
+
+    if( UDFReadLB( partition.i_fd, 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.i_fd, 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];
@@ -587,13 +664,13 @@ static int UDFFindPartition( int i_part_nb, struct partition_s *p_partition )
 }
 
 
-/******************************************************************************
+/*****************************************************************************
  * UDFFindFile: 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 )
 {
     struct partition_s  partition;
@@ -690,3 +767,4 @@ u32 UDFFindFile( int i_fd, char * psz_path )
 
     return partition.i_start + file.i_location;
 }
+