From 08f565c3f86d1930132906a83e8af17a3e5d96a7 Mon Sep 17 00:00:00 2001 From: "G.raud" Date: Sat, 1 Dec 2012 01:01:51 +0100 Subject: [PATCH] dvdimgdecss.c: dvdsize(): new function --- dvdimgdecss.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dvdimgdecss.c b/dvdimgdecss.c index 63c5a21..9afd92b 100644 --- a/dvdimgdecss.c +++ b/dvdimgdecss.c @@ -93,6 +93,7 @@ static void usage( ) printf( "\t%s [-f] [-c] \n", progname ); } +static int dvdsize ( const char * ); static int savetitleblocks( dvd_reader_t *, titleblocks_t (*)[TITLE_MAX] ); static int fileblock ( dvd_reader_t *, char *, block_t * ); static int removetitles ( blockl_t, titleblocks_t [] ); @@ -192,6 +193,45 @@ int main( int argc, char *argv[] ) exit( status ); } +/* Return the size in sectors (whether it is a file or a special device) */ +static int dvdsize( const char *dvdfile ) +{ + off_t size; + struct stat buf; + int dvd, rc; + + rc = stat( dvdfile, &buf ); + if( rc < 0 ) { + fprintf( stderr, "%s: stat DVD (%s) failed (%s)\n", + progname, dvdfile, strerror( errno ) ); + return -1; + } + + if( !buf.st_rdev ) + size = buf.st_size; + else { + dvd = open( dvdfile, O_RDONLY ); + if( dvd < 0 ) { + fprintf( stderr, "%s: opening the DVD (%s) failed (%s)\n", + progname, dvdfile, strerror( errno ) ); + return -1; + } + size = lseek( dvd, 0, SEEK_END ); + if( size < 0 ) { + fprintf( stderr, "%s: seeking at the end of the DVD failed (%s)\n", + progname, strerror( errno ) ); + return -1; + } + if( close( dvd ) < 0 ) + fprintf( stderr, "%s: closing of the DVD failed (%s)\n", + progname, strerror( errno ) ); + } + + if( size % DVD_VIDEO_LB_LEN ) + fprintf( stderr, "%s: DVD size is not a block multiple\n", progname ); + return size / DVD_VIDEO_LB_LEN; +} + /* Save the sector positions of the title/domain files */ static int savetitleblocks( dvd_reader_t *dvd, titleblocks_t (*titles)[TITLE_MAX] ) { -- 2.11.4.GIT