Beispiel #1
0
int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
{
  struct md5_ctx ctx;
  int title;
  int nr_of_files = 0;
  int tmp_errno;
  int nofiles_errno = ENOENT;
  /* Check arguments. */
  if( dvd == NULL || discid == NULL ) {
    errno = EINVAL;
    return -1;
  }
  /* Go through the first 10 IFO:s, in order, 
   * and md5sum them, i.e  VIDEO_TS.IFO and VTS_0?_0.IFO */
  md5_init_ctx( &ctx );
  for( title = 0; title < 10; title++ ) {
    dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
    if( dvd_file != NULL ) {
      ssize_t bytes_read;
      size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
      char *buffer = malloc( file_size );

      nr_of_files++;

      if( buffer == NULL ) {
        /* errno will be set to ENOMEM by malloc */
        return -1;
      }

      bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
      if( bytes_read != file_size ) {
        tmp_errno = errno;
        if(dvd->verbose >= 1) {
          fprintf( stderr, "libdvdread: DVDDiscId read returned %d bytes"
                   ", wanted %d\n", (int)bytes_read, (int)file_size );
        }
        free(buffer);
        DVDCloseFile( dvd_file );
        errno = tmp_errno;
        return -1;
      }
            
      md5_process_bytes( buffer, file_size,  &ctx );
            
      DVDCloseFile( dvd_file );
      free( buffer );
    } else {
      if(errno != ENOENT) {
        nofiles_errno = errno;
      }
    }
  }
  md5_finish_ctx( &ctx, discid );
  if(nr_of_files == 0) {
    errno = nofiles_errno;
    return -1;
  }
  return 0;
}
Beispiel #2
0
static int fs_open(const char *name, struct fuse_file_info *fi)
{
    struct ext_file_info *xfi = malloc(sizeof(struct ext_file_info));
    int res;

    if (!xfi)
	return -ENOMEM;

    /* Make sure dvd is open */
    if ((res = inc_refcnt(&mi)) < 0)
	return res;

    if (find_file(&mi, name, xfi)) {
	fi->fh = xfi;

	xfi->cache = NULL;
	xfi->cache_len = 0;
	xfi->cache_off = 0;
	
	/* If it's an IFO, read the whole file into the cache */
	if (IS_IFO(xfi->domain) && (xfi->cache = malloc(xfi->fi->len))) {
	    DVDFileSeek(xfi->fi->fd, 0);
	    if (DVDReadBytes(xfi->fi->fd, xfi->cache, xfi->fi->len) == xfi->fi->len) {
#ifdef FIX_IFO
		FIX_IFO(xfi->title, xfi->cache, xfi->fi->len);
#endif
	    } else {
		free(xfi->cache);
		xfi->cache = NULL;
	    }
	}
	return 0;
    }
   else {
       while (*name == '/')
           ++name;
       if (strcmp(name , ".volume_id") == 0) {
           fi->fh = xfi;

           xfi->cache = NULL;
           xfi->cache_len = 0;
           xfi->cache_off = 0;

           if(xfi->cache = malloc(VOL_ID_SIZE+1)) {
               xfi->fi=&mi.vol_id_info;
               xfi->fi->fd=-1; //read will not work unless fd is set
               memcpy(xfi->cache,mi.vol_id,VOL_ID_SIZE+1);
               fprintf(stderr,"%s\n",xfi->cache);
               return 0;
           }
       }
   }

    /* Failed so release our reference to dvd */
    dec_refcnt(&mi);

    free(xfi);
    return -ENOENT;
}
Beispiel #3
0
int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
{
  struct md5_ctx ctx;
  int title;
  int nr_of_files = 0;

  /* Check arguments. */
  if( dvd == NULL || discid == NULL )
    return 0;

  /* Go through the first 10 IFO:s, in order,
   * and md5sum them, i.e  VIDEO_TS.IFO and VTS_0?_0.IFO */
  md5_init_ctx( &ctx );
  for( title = 0; title < 10; title++ ) {
    dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
    if( dvd_file != NULL ) {
      ssize_t bytes_read;
      size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
      char *buffer_base = malloc( file_size + 2048 );
      char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);

      if( buffer_base == NULL ) {
          DVDCloseFile( dvd_file );
          fprintf( stderr, "libdvdread: DVDDiscId, failed to "
                   "allocate memory for file read!\n" );
          return -1;
      }

      bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
      if( bytes_read != file_size ) {
          fprintf( stderr, "libdvdread: DVDDiscId read returned %zd bytes"
                   ", wanted %zd\n", bytes_read, file_size );
          DVDCloseFile( dvd_file );
          free( buffer_base );
          return -1;
      }

      md5_process_bytes( buffer, file_size,  &ctx );

      DVDCloseFile( dvd_file );
      free( buffer_base );
      nr_of_files++;
    }
  }
  md5_finish_ctx( &ctx, discid );
  if(!nr_of_files)
    return -1;

  return 0;
}
Beispiel #4
0
int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
{
  struct md5_s ctx;
  int title;
  int title_sets;
  int nr_of_files = 0;
  ifo_handle_t *vmg_ifo;

  /* Check arguments. */
  if( dvd == NULL || discid == NULL )
    return 0;

  vmg_ifo = ifoOpen( dvd, 0 );
  if( !vmg_ifo ) {
    fprintf( stderr, "libdvdread: DVDDiscId, failed to "
      "open VMG IFO!\n" );
    return -1;
  }

  title_sets = vmg_ifo->vmgi_mat->vmg_nr_of_title_sets + 1;
  ifoClose( vmg_ifo );

  if( title_sets > 10 )
  	title_sets = 10;

  /* Go through the first IFO:s, in order, up until the tenth,
   * and md5sum them, i.e  VIDEO_TS.IFO and VTS_0?_0.IFO */
  InitMD5( &ctx );
  for( title = 0; title < title_sets; title++ ) {
    dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
    if( dvd_file != NULL ) {
      ssize_t bytes_read;
      ssize_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
      char *buffer_base = malloc( file_size + 2048 );

      if( buffer_base == NULL ) {
          DVDCloseFile( dvd_file );
          fprintf( stderr, "libdvdread: DVDDiscId, failed to "
                   "allocate memory for file read!\n" );
          return -1;
      }

      char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);

      bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
      if( bytes_read != file_size ) {
          fprintf( stderr, "libdvdread: DVDDiscId read returned %zd bytes"
                   ", wanted %zd\n", bytes_read, file_size );
          DVDCloseFile( dvd_file );
          free( buffer_base );
          return -1;
      }

      AddMD5( &ctx, buffer, file_size );

      DVDCloseFile( dvd_file );
      free( buffer_base );
      nr_of_files++;
    }
  }
  EndMD5( &ctx );
  memcpy( discid, ctx.buf, 16 );
  if(!nr_of_files)
    return -1;

  return 0;
}