mirror of https://github.com/pbatard/rufus.git
[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:
parent
5f737e10ad
commit
0cca99b0ef
43
src/iso.c
43
src/iso.c
|
@ -41,10 +41,6 @@
|
|||
#include <cdio/iso9660.h>
|
||||
#include <cdio/udf.h>
|
||||
|
||||
#ifndef CEILING
|
||||
#define CEILING(x, y) ((x+(y-1))/y)
|
||||
#endif
|
||||
|
||||
#define print_vd_info(title, fn) \
|
||||
if (fn(p_iso, &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;
|
||||
const char* basename;
|
||||
udf_dirent_t *p_udf_dirent2;
|
||||
uint64_t i, file_len, i_blocks;
|
||||
uint8_t buf[UDF_BLOCKSIZE];
|
||||
ssize_t i_read;
|
||||
int64_t i_read, file_len;
|
||||
|
||||
if ((p_udf_dirent == NULL) || (psz_path == NULL))
|
||||
return;
|
||||
|
@ -108,28 +103,18 @@ uprintf("FULLPATH: %s\n", fullpath);
|
|||
goto err;
|
||||
}
|
||||
file_len = udf_get_file_length(p_udf_dirent);
|
||||
i_blocks = CEILING(file_len, UDF_BLOCKSIZE);
|
||||
for (i=0; i<i_blocks; i++) {
|
||||
while (file_len > 0) {
|
||||
i_read = udf_read_block(p_udf_dirent, buf, 1);
|
||||
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;
|
||||
}
|
||||
fwrite(buf, i_read, 1, fd);
|
||||
fwrite(buf, (size_t)min(file_len, i_read), 1, fd);
|
||||
if (ferror(fd)) {
|
||||
uprintf("Error writing file %s\n", fullpath);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
file_len -= i_read;
|
||||
}
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
|
@ -154,8 +139,9 @@ static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
|
|||
CdioListNode_t* p_entnode;
|
||||
iso9660_stat_t *p_statbuf;
|
||||
CdioList_t* p_entlist;
|
||||
size_t i, i_blocks;
|
||||
size_t i;
|
||||
lsn_t lsn;
|
||||
int64_t file_len;
|
||||
|
||||
if ((p_iso == NULL) || (psz_path == NULL))
|
||||
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);
|
||||
goto out;
|
||||
}
|
||||
i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||
for (i = 0; i < i_blocks ; i++) {
|
||||
file_len = p_statbuf->size;
|
||||
for (i = 0; file_len > 0 ; i++) {
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
lsn = p_statbuf->lsn + i;
|
||||
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);
|
||||
goto out;
|
||||
}
|
||||
fwrite (buf, ISO_BLOCKSIZE, 1, fd);
|
||||
fwrite (buf, (size_t)min(file_len, ISO_BLOCKSIZE), 1, fd);
|
||||
if (ferror(fd)) {
|
||||
uprintf("Error writing file %s\n", filename);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
file_len -= ISO_BLOCKSIZE;
|
||||
}
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
|
|
|
@ -61,6 +61,10 @@ extern "C" {
|
|||
typedef uint8_t ubyte;
|
||||
#if !defined(off64_t)
|
||||
typedef int64_t off64_t;
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define fseeko64 _fseeki64
|
||||
#endif
|
||||
|
||||
/* default HP/UX macros are broken */
|
||||
|
|
|
@ -118,7 +118,7 @@ _stdio_seek(void *p_user_data, off64_t i_offset, int whence)
|
|||
{
|
||||
_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));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,4 +14,6 @@ TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
|
|||
|
||||
SOURCES=iso9660.c \
|
||||
iso9660_fs.c \
|
||||
rock.c xa.c
|
||||
rock.c \
|
||||
utf8.c \
|
||||
xa.c
|
|
@ -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)
|
||||
return false;
|
||||
|
||||
if (src_len < 0) {
|
||||
if (src_len == (size_t)-1) {
|
||||
for (src_len = 0; ((uint16_t*)src)[src_len] !=0; src_len++);
|
||||
src_len <<=2;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\cdio\cdio_config.h" />
|
||||
<ClInclude Include="..\..\cdio\udf.h" />
|
||||
<ClInclude Include="..\udf_fs.h" />
|
||||
<ClInclude Include="..\udf_private.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -37,5 +37,8 @@
|
|||
<ClInclude Include="..\..\cdio\cdio_config.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\cdio\udf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -90,6 +90,7 @@ uint64_t udf_get_file_length(const udf_dirent_t *p_udf_dirent)
|
|||
if (p_udf_dirent) {
|
||||
return uint64_from_le(p_udf_dirent->fe.info_len);
|
||||
}
|
||||
// TODO: use INT64MAX
|
||||
return 2147483647L; /* Error. Non-error case handled above. */
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,7 @@ udf_is_dir(const udf_dirent_t *p_udf_dirent)
|
|||
* block.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
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;
|
||||
case ICBTAG_STRATEGY_TYPE_4:
|
||||
{
|
||||
uint32_t icblen = 0;
|
||||
lba_t lsector;
|
||||
off64_t icblen = 0;
|
||||
uint64_t lsector;
|
||||
uint32_t ad_offset;
|
||||
int ad_num = 0;
|
||||
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 *)
|
||||
GETICB( uint32_from_le(p_udf_fe->i_extended_attr)
|
||||
+ ad_offset*sizeof(udf_short_ad_t*) );
|
||||
+ ad_offset );
|
||||
icblen = p_icb->len;
|
||||
ad_num++;
|
||||
} while(i_offset >= (off_t)icblen);
|
||||
} while(i_offset >= icblen);
|
||||
|
||||
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 *)
|
||||
GETICB( uint32_from_le(p_udf_fe->i_extended_attr)
|
||||
+ ad_offset*sizeof(udf_long_ad_t*) );
|
||||
+ ad_offset );
|
||||
icblen = p_icb->len;
|
||||
ad_num++;
|
||||
} 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;
|
||||
}
|
||||
|
||||
*pi_lba = lsector + p_udf->i_part_start;
|
||||
*pi_lba = (lba_t)lsector + p_udf->i_part_start;
|
||||
return *pi_lba;
|
||||
}
|
||||
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;
|
||||
uint32_t i_max_size=0;
|
||||
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);
|
||||
if (i_lba != CDIO_INVALID_LBA) {
|
||||
uint32_t i_max_blocks = CEILING(i_max_size, UDF_BLOCKSIZE);
|
||||
|
|
|
@ -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
|
||||
* 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,
|
||||
* but they have File Id Descriptors of their children as their file
|
||||
* data. As for the Anchor Volume Descriptor Pointer, it can exist in
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
struct udf_s {
|
||||
bool b_stream; /* Use stream pointer, else use
|
||||
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 */
|
||||
CdIo_t *cdio; /* Cdio pointer if read device */
|
||||
anchor_vol_desc_ptr_t anchor_vol_desc_ptr;
|
||||
|
|
12
src/rufus.rc
12
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
|
|||
IDD_DIALOG DIALOGEX 12, 12, 206, 278
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "Rufus v1.0.7.141"
|
||||
CAPTION "Rufus v1.0.7.142"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
|
||||
|
@ -70,7 +70,7 @@ BEGIN
|
|||
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,
|
||||
"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
|
||||
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
|
||||
|
@ -208,8 +208,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,7,141
|
||||
PRODUCTVERSION 1,0,7,141
|
||||
FILEVERSION 1,0,7,142
|
||||
PRODUCTVERSION 1,0,7,142
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -226,13 +226,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "akeo.ie"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "1.0.7.141"
|
||||
VALUE "FileVersion", "1.0.7.142"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "1.0.7.141"
|
||||
VALUE "ProductVersion", "1.0.7.142"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in New Issue