udf.h, libudf.sym, udf_private.h: expose struct udf_dirent_s and udf_get_lba()

udf_file.c: udf_read_block() Raise level of severity on warning when requested
blocks exceed the number in the extent.
This commit is contained in:
R. Bernstein
2010-10-22 23:39:19 -04:00
parent f4462b558d
commit 122aecc0a9
4 changed files with 58 additions and 56 deletions

View File

@@ -1,7 +1,5 @@
/* /*
$Id: udf.h,v 1.22 2008/03/25 15:59:09 karl Exp $ Copyright (C) 2005, 2006, 2008, 2010 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -37,7 +35,25 @@ typedef uint16_t partition_num_t;
/** Opaque structures. */ /** Opaque structures. */
typedef struct udf_s udf_t; typedef struct udf_s udf_t;
typedef struct udf_file_s udf_file_t; typedef struct udf_file_s udf_file_t;
typedef struct udf_dirent_s udf_dirent_t;
typedef struct udf_dirent_s {
char *psz_name;
bool b_dir; /* true if this entry is a directory. */
bool b_parent; /* True if has parent directory (e.g. not root
directory). If not set b_dir will probably
be true. */
udf_t *p_udf;
uint32_t i_part_start;
uint32_t i_loc, i_loc_end;
uint64_t dir_left;
uint8_t *sector;
udf_fileid_desc_t *fid;
/* This field has to come last because it is variable in length. */
udf_file_entry_t fe;
} udf_dirent_t;;
/** /**
Imagine the below a \#define'd value rather than distinct values of Imagine the below a \#define'd value rather than distinct values of
@@ -69,7 +85,7 @@ extern "C" {
*/ */
driver_return_code_t udf_read_sectors (const udf_t *p_udf, void *ptr, driver_return_code_t udf_read_sectors (const udf_t *p_udf, void *ptr,
lsn_t i_start, long int i_blocks); lsn_t i_start, long int i_blocks);
/*! /*!
Open an UDF for reading. Maybe in the future we will have Open an UDF for reading. Maybe in the future we will have
@@ -94,7 +110,7 @@ extern "C" {
Caller must free result - use udf_file_free for that. Caller must free result - use udf_file_free for that.
*/ */
udf_dirent_t *udf_get_root (udf_t *p_udf, bool b_any_partition, udf_dirent_t *udf_get_root (udf_t *p_udf, bool b_any_partition,
partition_num_t i_partition); partition_num_t i_partition);
/** /**
* Gets the Volume Identifier string, in 8bit unicode (latin-1) * Gets the Volume Identifier string, in 8bit unicode (latin-1)
@@ -103,7 +119,7 @@ extern "C" {
* returns the size of buffer needed for all data * returns the size of buffer needed for all data
*/ */
int udf_get_volume_id(udf_t *p_udf, /*out*/ char *psz_volid, int udf_get_volume_id(udf_t *p_udf, /*out*/ char *psz_volid,
unsigned int i_volid); unsigned int i_volid);
/** /**
* Gets the Volume Set Identifier, as a 128-byte dstring (not decoded) * Gets the Volume Set Identifier, as a 128-byte dstring (not decoded)
@@ -115,7 +131,7 @@ extern "C" {
* or 0 on error * or 0 on error
*/ */
int udf_get_volumeset_id(udf_t *p_udf, /*out*/ uint8_t *volsetid, int udf_get_volumeset_id(udf_t *p_udf, /*out*/ uint8_t *volsetid,
unsigned int i_volsetid); unsigned int i_volsetid);
/*! /*!
Return a file pointer matching pzz_name. Return a file pointer matching pzz_name.
@@ -128,38 +144,41 @@ extern "C" {
10 characters are stored in PSZ_STR; a terminating null byte is added. 10 characters are stored in PSZ_STR; a terminating null byte is added.
The characters stored in PSZ_STR are: The characters stored in PSZ_STR are:
0 File type. 'd' for directory, 'c' for character 0 File type. 'd' for directory, 'c' for character
special, 'b' for block special, 'm' for multiplex, special, 'b' for block special, 'm' for multiplex,
'l' for symbolic link, 's' for socket, 'p' for fifo, 'l' for symbolic link, 's' for socket, 'p' for fifo,
'-' for regular, '?' for any other file type '-' for regular, '?' for any other file type
1 'r' if the owner may read, '-' otherwise. 1 'r' if the owner may read, '-' otherwise.
2 'w' if the owner may write, '-' otherwise. 2 'w' if the owner may write, '-' otherwise.
3 'x' if the owner may execute, 's' if the file is 3 'x' if the owner may execute, 's' if the file is
set-user-id, '-' otherwise. set-user-id, '-' otherwise.
'S' if the file is set-user-id, but the execute 'S' if the file is set-user-id, but the execute
bit isn't set. bit isn't set.
4 'r' if group members may read, '-' otherwise. 4 'r' if group members may read, '-' otherwise.
5 'w' if group members may write, '-' otherwise. 5 'w' if group members may write, '-' otherwise.
6 'x' if group members may execute, 's' if the file is 6 'x' if group members may execute, 's' if the file is
set-group-id, '-' otherwise. set-group-id, '-' otherwise.
'S' if it is set-group-id but not executable. 'S' if it is set-group-id but not executable.
7 'r' if any user may read, '-' otherwise. 7 'r' if any user may read, '-' otherwise.
8 'w' if any user may write, '-' otherwise. 8 'w' if any user may write, '-' otherwise.
9 'x' if any user may execute, 't' if the file is "sticky" 9 'x' if any user may execute, 't' if the file is "sticky"
(will be retained in swap space after execution), '-' (will be retained in swap space after execution), '-'
otherwise. otherwise.
'T' if the file is sticky but not executable. */ 'T' if the file is sticky but not executable. */
char *udf_mode_string (mode_t i_mode, char *psz_str); char *udf_mode_string (mode_t i_mode, char *psz_str);
bool udf_get_lba(const udf_file_entry_t *p_udf_fe,
/*out*/ uint32_t *start, /*out*/ uint32_t *end);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -21,6 +21,7 @@ udf_get_link_count
udf_get_part_number udf_get_part_number
udf_get_posix_filemode udf_get_posix_filemode
udf_opendir udf_opendir
udf_read_block
udf_readdir udf_readdir
udf_is_dir udf_is_dir
udf_open udf_open

View File

@@ -1,7 +1,5 @@
/* /*
$Id: udf_file.c,v 1.14 2008/04/18 16:02:10 karl Exp $ Copyright (C) 2005, 2006, 2008, 2010 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -220,6 +218,9 @@ offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset,
If count is zero, read() returns zero and has no other results. If If count is zero, read() returns zero and has no other results. If
count is greater than SSIZE_MAX, the result is unspecified. count is greater than SSIZE_MAX, the result is unspecified.
It is the caller's responsibility to ensure that count is less
than the number of blocks recorded via p_udf_dirent.
If there is an error, cast the result to driver_return_code_t for If there is an error, cast the result to driver_return_code_t for
the specific error code. the specific error code.
*/ */
@@ -236,8 +237,10 @@ udf_read_block(const udf_dirent_t *p_udf_dirent, void * buf, size_t count)
if (i_lba != CDIO_INVALID_LBA) { if (i_lba != CDIO_INVALID_LBA) {
uint32_t i_max_blocks = CEILING(i_max_size, UDF_BLOCKSIZE); uint32_t i_max_blocks = CEILING(i_max_size, UDF_BLOCKSIZE);
if ( i_max_blocks < count ) { if ( i_max_blocks < count ) {
printf("Warning: don't know how to handle yet\n" ); fprintf(stderr, "Warning: read count %u is larger than %u size of entry\n",
count = i_max_blocks; count, i_max_blocks);
fprintf(stderr, "Warning: read count truncated to %u\n", count);
count = i_max_blocks;
} }
ret = udf_read_sectors(p_udf, buf, i_lba, count); ret = udf_read_sectors(p_udf, buf, i_lba, count);
if (DRIVER_OP_SUCCESS == ret) { if (DRIVER_OP_SUCCESS == ret) {

View File

@@ -45,27 +45,6 @@ struct udf_s {
uint32_t fsd_offset; /* lba of fileset descriptor */ uint32_t fsd_offset; /* lba of fileset descriptor */
}; };
struct udf_dirent_s
{
char *psz_name;
bool b_dir; /* true if this entry is a directory. */
bool b_parent; /* True if has parent directory (e.g. not root
directory). If not set b_dir will probably
be true. */
udf_t *p_udf;
uint32_t i_part_start;
uint32_t i_loc, i_loc_end;
uint64_t dir_left;
uint8_t *sector;
udf_fileid_desc_t *fid;
/* This field has to come last because it is variable in length. */
udf_file_entry_t fe;
};
bool udf_get_lba(const udf_file_entry_t *p_udf_fe,
/*out*/ uint32_t *start, /*out*/ uint32_t *end);
#endif /* __CDIO_UDF_PRIVATE_H__ */ #endif /* __CDIO_UDF_PRIVATE_H__ */