1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[iso] image extraction at last, for both UDF and ISO9660

* removed the need for ftruncate and CEILING
* revert "bad offset computation ICB" 'fix' (there never was a problem)
* use 64bit types and calls where needed
* minor utf8 fixes
This commit is contained in:
Pete Batard 2012-01-21 03:56:11 +00:00
parent 5f737e10ad
commit 0cca99b0ef
11 changed files with 41 additions and 51 deletions

View file

@ -41,10 +41,6 @@
#include <cdio/iso9660.h> #include <cdio/iso9660.h>
#include <cdio/udf.h> #include <cdio/udf.h>
#ifndef CEILING
#define CEILING(x, y) ((x+(y-1))/y)
#endif
#define print_vd_info(title, fn) \ #define print_vd_info(title, fn) \
if (fn(p_iso, &psz_str)) { \ if (fn(p_iso, &psz_str)) { \
uprintf(title ": %s\n", psz_str); \ uprintf(title ": %s\n", psz_str); \
@ -79,9 +75,8 @@ static void udf_list_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char
char* fullpath; char* fullpath;
const char* basename; const char* basename;
udf_dirent_t *p_udf_dirent2; udf_dirent_t *p_udf_dirent2;
uint64_t i, file_len, i_blocks;
uint8_t buf[UDF_BLOCKSIZE]; uint8_t buf[UDF_BLOCKSIZE];
ssize_t i_read; int64_t i_read, file_len;
if ((p_udf_dirent == NULL) || (psz_path == NULL)) if ((p_udf_dirent == NULL) || (psz_path == NULL))
return; return;
@ -108,28 +103,18 @@ uprintf("FULLPATH: %s\n", fullpath);
goto err; goto err;
} }
file_len = udf_get_file_length(p_udf_dirent); file_len = udf_get_file_length(p_udf_dirent);
i_blocks = CEILING(file_len, UDF_BLOCKSIZE); while (file_len > 0) {
for (i=0; i<i_blocks; i++) {
i_read = udf_read_block(p_udf_dirent, buf, 1); i_read = udf_read_block(p_udf_dirent, buf, 1);
if (i_read < 0) { if (i_read < 0) {
uprintf("Error reading UDF file %s at block %u\n", &fullpath[strlen(extract_dir)], i); uprintf("Error reading UDF file %s\n", &fullpath[strlen(extract_dir)]);
goto err; goto err;
} }
fwrite(buf, i_read, 1, fd); fwrite(buf, (size_t)min(file_len, i_read), 1, fd);
if (ferror(fd)) { if (ferror(fd)) {
uprintf("Error writing file %s\n", fullpath); uprintf("Error writing file %s\n", fullpath);
goto err; goto err;
} }
} file_len -= i_read;
// TODO: this is slowing us down! Compute the size to use with fwrite instead
fflush(fd);
/* Make sure the file size has the exact same byte size. Without the
truncate below, the file will a multiple of ISO_BLOCKSIZE. */
// TODO: use _chsize_s to handle 64
if (_chsize_s(_fileno(fd), file_len)) {
uprintf("Error adjusting file size for %s\n", fullpath);
goto err;
} }
fclose(fd); fclose(fd);
fd = NULL; fd = NULL;
@ -154,8 +139,9 @@ static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
CdioListNode_t* p_entnode; CdioListNode_t* p_entnode;
iso9660_stat_t *p_statbuf; iso9660_stat_t *p_statbuf;
CdioList_t* p_entlist; CdioList_t* p_entlist;
size_t i, i_blocks; size_t i;
lsn_t lsn; lsn_t lsn;
int64_t file_len;
if ((p_iso == NULL) || (psz_path == NULL)) if ((p_iso == NULL) || (psz_path == NULL))
return; return;
@ -186,8 +172,8 @@ static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
uprintf("Unable to create file %s\n", filename); uprintf("Unable to create file %s\n", filename);
goto out; goto out;
} }
i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE); file_len = p_statbuf->size;
for (i = 0; i < i_blocks ; i++) { for (i = 0; file_len > 0 ; i++) {
memset (buf, 0, ISO_BLOCKSIZE); memset (buf, 0, ISO_BLOCKSIZE);
lsn = p_statbuf->lsn + i; lsn = p_statbuf->lsn + i;
if (iso9660_iso_seek_read (p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) { if (iso9660_iso_seek_read (p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
@ -195,19 +181,12 @@ static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
iso_filename, (long unsigned int)lsn); iso_filename, (long unsigned int)lsn);
goto out; goto out;
} }
fwrite (buf, ISO_BLOCKSIZE, 1, fd); fwrite (buf, (size_t)min(file_len, ISO_BLOCKSIZE), 1, fd);
if (ferror(fd)) { if (ferror(fd)) {
uprintf("Error writing file %s\n", filename); uprintf("Error writing file %s\n", filename);
goto out; goto out;
} }
} file_len -= ISO_BLOCKSIZE;
// TODO: this is slowing us down! Compute the size to use with fwrite instead
fflush(fd);
/* Make sure the file size has the exact same byte size. Without the
truncate below, the file will a multiple of ISO_BLOCKSIZE. */
if (_chsize(_fileno(fd), p_statbuf->size)) {
uprintf("Error adjusting file size for %s\n", filename);
goto out;
} }
fclose(fd); fclose(fd);
fd = NULL; fd = NULL;

View file

@ -61,6 +61,10 @@ extern "C" {
typedef uint8_t ubyte; typedef uint8_t ubyte;
#if !defined(off64_t) #if !defined(off64_t)
typedef int64_t off64_t; typedef int64_t off64_t;
#endif
#if defined(_MSC_VER)
#define fseeko64 _fseeki64
#endif #endif
/* default HP/UX macros are broken */ /* default HP/UX macros are broken */

View file

@ -118,7 +118,7 @@ _stdio_seek(void *p_user_data, off64_t i_offset, int whence)
{ {
_UserData *const ud = (_UserData*)p_user_data; _UserData *const ud = (_UserData*)p_user_data;
if ( (i_offset=_fseeki64 (ud->fd, i_offset, whence)) ) { if ( (i_offset=fseeko64 (ud->fd, i_offset, whence)) ) {
cdio_error ("fseek (): %s", strerror (errno)); cdio_error ("fseek (): %s", strerror (errno));
} }

View file

@ -14,4 +14,6 @@ TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
SOURCES=iso9660.c \ SOURCES=iso9660.c \
iso9660_fs.c \ iso9660_fs.c \
rock.c xa.c rock.c \
utf8.c \
xa.c

View file

@ -274,7 +274,7 @@ bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst,
if (src == NULL || dst == NULL || src_charset == NULL || strcmp(src_charset, "UCS-2BE") != 0) if (src == NULL || dst == NULL || src_charset == NULL || strcmp(src_charset, "UCS-2BE") != 0)
return false; return false;
if (src_len < 0) { if (src_len == (size_t)-1) {
for (src_len = 0; ((uint16_t*)src)[src_len] !=0; src_len++); for (src_len = 0; ((uint16_t*)src)[src_len] !=0; src_len++);
src_len <<=2; src_len <<=2;
} }

View file

@ -27,6 +27,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\cdio\cdio_config.h" /> <ClInclude Include="..\..\cdio\cdio_config.h" />
<ClInclude Include="..\..\cdio\udf.h" />
<ClInclude Include="..\udf_fs.h" /> <ClInclude Include="..\udf_fs.h" />
<ClInclude Include="..\udf_private.h" /> <ClInclude Include="..\udf_private.h" />
</ItemGroup> </ItemGroup>

View file

@ -37,5 +37,8 @@
<ClInclude Include="..\..\cdio\cdio_config.h"> <ClInclude Include="..\..\cdio\cdio_config.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\cdio\udf.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -90,6 +90,7 @@ uint64_t udf_get_file_length(const udf_dirent_t *p_udf_dirent)
if (p_udf_dirent) { if (p_udf_dirent) {
return uint64_from_le(p_udf_dirent->fe.info_len); return uint64_from_le(p_udf_dirent->fe.info_len);
} }
// TODO: use INT64MAX
return 2147483647L; /* Error. Non-error case handled above. */ return 2147483647L; /* Error. Non-error case handled above. */
} }
@ -107,7 +108,7 @@ udf_is_dir(const udf_dirent_t *p_udf_dirent)
* block. * block.
*/ */
static lba_t static lba_t
offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset, offset_to_lba(const udf_dirent_t *p_udf_dirent, off64_t i_offset,
/*out*/ lba_t *pi_lba, /*out*/ uint32_t *pi_max_size) /*out*/ lba_t *pi_lba, /*out*/ uint32_t *pi_max_size)
{ {
udf_t *p_udf = p_udf_dirent->p_udf; udf_t *p_udf = p_udf_dirent->p_udf;
@ -123,8 +124,8 @@ offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset,
break; break;
case ICBTAG_STRATEGY_TYPE_4: case ICBTAG_STRATEGY_TYPE_4:
{ {
uint32_t icblen = 0; off64_t icblen = 0;
lba_t lsector; uint64_t lsector;
uint32_t ad_offset; uint32_t ad_offset;
int ad_num = 0; int ad_num = 0;
uint16_t addr_ilk = uint16_from_le(p_icb_tag->flags&ICBTAG_FLAG_AD_MASK); uint16_t addr_ilk = uint16_from_le(p_icb_tag->flags&ICBTAG_FLAG_AD_MASK);
@ -147,10 +148,10 @@ offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset,
} }
p_icb = (udf_short_ad_t *) p_icb = (udf_short_ad_t *)
GETICB( uint32_from_le(p_udf_fe->i_extended_attr) GETICB( uint32_from_le(p_udf_fe->i_extended_attr)
+ ad_offset*sizeof(udf_short_ad_t*) ); + ad_offset );
icblen = p_icb->len; icblen = p_icb->len;
ad_num++; ad_num++;
} while(i_offset >= (off_t)icblen); } while(i_offset >= icblen);
lsector = (i_offset / UDF_BLOCKSIZE) + p_icb->pos; lsector = (i_offset / UDF_BLOCKSIZE) + p_icb->pos;
@ -174,7 +175,7 @@ offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset,
} }
p_icb = (udf_long_ad_t *) p_icb = (udf_long_ad_t *)
GETICB( uint32_from_le(p_udf_fe->i_extended_attr) GETICB( uint32_from_le(p_udf_fe->i_extended_attr)
+ ad_offset*sizeof(udf_long_ad_t*) ); + ad_offset );
icblen = p_icb->len; icblen = p_icb->len;
ad_num++; ad_num++;
} while(i_offset >= (off_t)icblen); } while(i_offset >= (off_t)icblen);
@ -201,7 +202,7 @@ offset_to_lba(const udf_dirent_t *p_udf_dirent, off_t i_offset,
return CDIO_INVALID_LBA; return CDIO_INVALID_LBA;
} }
*pi_lba = lsector + p_udf->i_part_start; *pi_lba = (lba_t)lsector + p_udf->i_part_start;
return *pi_lba; return *pi_lba;
} }
default: default:
@ -233,7 +234,7 @@ udf_read_block(const udf_dirent_t *p_udf_dirent, void * buf, size_t count)
driver_return_code_t ret; driver_return_code_t ret;
uint32_t i_max_size=0; uint32_t i_max_size=0;
udf_t *p_udf = p_udf_dirent->p_udf; udf_t *p_udf = p_udf_dirent->p_udf;
lba_t i_lba = offset_to_lba(p_udf_dirent, (off_t)p_udf->i_position, &i_lba, lba_t i_lba = offset_to_lba(p_udf_dirent, p_udf->i_position, &i_lba,
&i_max_size); &i_max_size);
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);

View file

@ -85,7 +85,7 @@ const char VSD_STD_ID_TEA01[] = {'T', 'E', 'A', '0', '1'};
/* /*
* The UDF specs are pretty clear on how each data structure is made * The UDF specs are pretty clear on how each data structure is made
* up, but not very clear on how they relate to each other. Here is * up, but not very clear on how they relate to each other. Here is
* the skinny... This demostrates a filesystem with one file in the * the skinny... This demonstrates a filesystem with one file in the
* root directory. Subdirectories are treated just as normal files, * root directory. Subdirectories are treated just as normal files,
* but they have File Id Descriptors of their children as their file * but they have File Id Descriptors of their children as their file
* data. As for the Anchor Volume Descriptor Pointer, it can exist in * data. As for the Anchor Volume Descriptor Pointer, it can exist in

View file

@ -33,7 +33,7 @@
struct udf_s { struct udf_s {
bool b_stream; /* Use stream pointer, else use bool b_stream; /* Use stream pointer, else use
p_cdio. */ p_cdio. */
ssize_t i_position; /* Position in file if positive. */ off64_t i_position; /* Position in file if positive. */
CdioDataSource_t *stream; /* Stream pointer if stream */ CdioDataSource_t *stream; /* Stream pointer if stream */
CdIo_t *cdio; /* Cdio pointer if read device */ CdIo_t *cdio; /* Cdio pointer if read device */
anchor_vol_desc_ptr_t anchor_vol_desc_ptr; anchor_vol_desc_ptr_t anchor_vol_desc_ptr;

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 278 IDD_DIALOG DIALOGEX 12, 12, 206, 278
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.0.7.141" CAPTION "Rufus v1.0.7.142"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14 DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
@ -70,7 +70,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL, CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9 "SysLink",WS_TABSTOP,46,47,114,9
LTEXT "Version 1.0.7 (Build 141)",IDC_STATIC,46,19,78,8 LTEXT "Version 1.0.7 (Build 142)",IDC_STATIC,46,19,78,8
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
@ -208,8 +208,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,7,141 FILEVERSION 1,0,7,142
PRODUCTVERSION 1,0,7,141 PRODUCTVERSION 1,0,7,142
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -226,13 +226,13 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "akeo.ie" VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.0.7.141" VALUE "FileVersion", "1.0.7.142"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe" VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.0.7.141" VALUE "ProductVersion", "1.0.7.142"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"