Make udf_read_block more like 2 read. Implementation is closer
to the description (although it needs more work.) udf_fs.h: break out udf_check_tag() *.h: /*! -> /** - is more like Javadoc.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
$Id: udf_file.c,v 1.8 2006/04/11 01:05:44 rocky Exp $
|
||||
$Id: udf_file.c,v 1.9 2006/04/11 05:47:58 rocky Exp $
|
||||
|
||||
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 2005, 2006 Rocky Bernstein <rockyb@users.sourceforge.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
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <cdio/bytesex.h>
|
||||
#include "udf_private.h"
|
||||
#include "udf_fs.h"
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
@@ -28,6 +29,8 @@
|
||||
|
||||
#include <stdio.h> /* Remove when adding cdio/logging.h */
|
||||
|
||||
#define MIN(a, b) (a>b) ? (a) : (b)
|
||||
|
||||
const char *
|
||||
udf_get_filename(const udf_dirent_t *p_udf_dirent)
|
||||
{
|
||||
@@ -93,36 +96,49 @@ udf_is_dir(const udf_dirent_t *p_udf_dirent)
|
||||
return p_udf_dirent->b_dir;
|
||||
}
|
||||
|
||||
/*!
|
||||
Attempts to read up to count bytes from file descriptor fd into
|
||||
the buffer starting at buf.
|
||||
/**
|
||||
Attempts to read up to count bytes from UDF directory entry
|
||||
p_udf_dirent into the buffer starting at buf. buf should be a
|
||||
multiple of UDF_BLOCKSIZE bytes.
|
||||
|
||||
If count is zero, read() returns zero and has no other results. If
|
||||
count is greater than SSIZE_MAX, the result is unspecified.
|
||||
|
||||
If there is an error, cast the result to driver_return_code_t for
|
||||
the specific error code.
|
||||
*/
|
||||
driver_return_code_t
|
||||
ssize_t
|
||||
udf_read_block(const udf_dirent_t *p_udf_dirent, void * buf, size_t count)
|
||||
{
|
||||
const udf_t *p_udf = p_udf_dirent->p_udf;
|
||||
uint8_t data[UDF_BLOCKSIZE];
|
||||
udf_file_entry_t *p_udf_fe = (udf_file_entry_t *) data;
|
||||
driver_return_code_t ret =
|
||||
udf_read_sectors(p_udf, data, p_udf_dirent->fe.unique_ID, 1);
|
||||
if (ret == DRIVER_OP_SUCCESS) {
|
||||
if (!udf_checktag(&p_udf_fe->tag, TAGID_FILE_ENTRY)) {
|
||||
uint32_t i_lba_start, i_lba_end;
|
||||
udf_get_lba( p_udf_fe, &i_lba_start, &i_lba_end);
|
||||
|
||||
if ( (i_lba_end - i_lba_start+1) < count ) {
|
||||
printf("Warning: don't know how to handle yet\n" );
|
||||
count = i_lba_end - i_lba_start+1;
|
||||
if (count == 0) return 0;
|
||||
else {
|
||||
const udf_t *p_udf = p_udf_dirent->p_udf;
|
||||
uint8_t data[UDF_BLOCKSIZE];
|
||||
const udf_file_entry_t *p_udf_fe = (udf_file_entry_t *) data;
|
||||
driver_return_code_t ret;
|
||||
const unsigned long int i_file_length = udf_get_file_length(p_udf_dirent);
|
||||
|
||||
ret = udf_read_sectors(p_udf, data, p_udf_dirent->fe.unique_ID, 1);
|
||||
if (ret == DRIVER_OP_SUCCESS) {
|
||||
if (!udf_checktag(&p_udf_fe->tag, TAGID_FILE_ENTRY)) {
|
||||
uint32_t i_lba_start, i_lba_end;
|
||||
udf_get_lba( p_udf_fe, &i_lba_start, &i_lba_end);
|
||||
|
||||
if ( (i_lba_end - i_lba_start+1) < count ) {
|
||||
printf("Warning: don't know how to handle yet\n" );
|
||||
count = i_lba_end - i_lba_start+1;
|
||||
} else {
|
||||
const uint32_t i_lba = p_udf->i_part_start+i_lba_start;
|
||||
ret = udf_read_sectors(p_udf, buf, i_lba, count);
|
||||
if (DRIVER_OP_SUCCESS == ret) {
|
||||
return MIN(i_file_length, count * UDF_BLOCKSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return DRIVER_OP_ERROR;
|
||||
}
|
||||
return udf_read_sectors(p_udf, buf, p_udf->i_part_start+i_lba_start,
|
||||
count);
|
||||
}
|
||||
else {
|
||||
return DRIVER_OP_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user