From 0cca99b0ef8db8e2bc37db6d01e05f245f818072 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Sat, 21 Jan 2012 03:56:11 +0000 Subject: [PATCH] [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 --- src/iso.c | 43 ++++++----------------- src/libcdio/cdio/types.h | 4 +++ src/libcdio/driver/_cdio_stdio.c | 2 +- src/libcdio/iso9660/.msvc/iso9660_sources | 4 ++- src/libcdio/iso9660/utf8.c | 2 +- src/libcdio/udf/.msvc/udf.vcxproj | 1 + src/libcdio/udf/.msvc/udf.vcxproj.filters | 3 ++ src/libcdio/udf/udf_file.c | 17 ++++----- src/libcdio/udf/udf_fs.c | 2 +- src/libcdio/udf/udf_private.h | 2 +- src/rufus.rc | 12 +++---- 11 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/iso.c b/src/iso.c index d90d0cdc..1e5d1475 100644 --- a/src/iso.c +++ b/src/iso.c @@ -41,10 +41,6 @@ #include #include -#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 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; diff --git a/src/libcdio/cdio/types.h b/src/libcdio/cdio/types.h index 1e2ac844..8b486246 100644 --- a/src/libcdio/cdio/types.h +++ b/src/libcdio/cdio/types.h @@ -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 */ diff --git a/src/libcdio/driver/_cdio_stdio.c b/src/libcdio/driver/_cdio_stdio.c index 293603f8..cb3749b9 100644 --- a/src/libcdio/driver/_cdio_stdio.c +++ b/src/libcdio/driver/_cdio_stdio.c @@ -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)); } diff --git a/src/libcdio/iso9660/.msvc/iso9660_sources b/src/libcdio/iso9660/.msvc/iso9660_sources index e6aee0a6..893f6204 100644 --- a/src/libcdio/iso9660/.msvc/iso9660_sources +++ b/src/libcdio/iso9660/.msvc/iso9660_sources @@ -14,4 +14,6 @@ TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \ SOURCES=iso9660.c \ iso9660_fs.c \ - rock.c xa.c \ No newline at end of file + rock.c \ + utf8.c \ + xa.c \ No newline at end of file diff --git a/src/libcdio/iso9660/utf8.c b/src/libcdio/iso9660/utf8.c index 3cd86718..b0d9cd78 100644 --- a/src/libcdio/iso9660/utf8.c +++ b/src/libcdio/iso9660/utf8.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; } diff --git a/src/libcdio/udf/.msvc/udf.vcxproj b/src/libcdio/udf/.msvc/udf.vcxproj index 67a2746f..aef5ead5 100644 --- a/src/libcdio/udf/.msvc/udf.vcxproj +++ b/src/libcdio/udf/.msvc/udf.vcxproj @@ -27,6 +27,7 @@ + diff --git a/src/libcdio/udf/.msvc/udf.vcxproj.filters b/src/libcdio/udf/.msvc/udf.vcxproj.filters index 52cfd21a..21b04bb8 100644 --- a/src/libcdio/udf/.msvc/udf.vcxproj.filters +++ b/src/libcdio/udf/.msvc/udf.vcxproj.filters @@ -37,5 +37,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/libcdio/udf/udf_file.c b/src/libcdio/udf/udf_file.c index 3b442443..ca1f66cd 100644 --- a/src/libcdio/udf/udf_file.c +++ b/src/libcdio/udf/udf_file.c @@ -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); diff --git a/src/libcdio/udf/udf_fs.c b/src/libcdio/udf/udf_fs.c index 7db183c1..dea4027d 100644 --- a/src/libcdio/udf/udf_fs.c +++ b/src/libcdio/udf/udf_fs.c @@ -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 diff --git a/src/libcdio/udf/udf_private.h b/src/libcdio/udf/udf_private.h index 61624f78..a90df14f 100644 --- a/src/libcdio/udf/udf_private.h +++ b/src/libcdio/udf/udf_private.h @@ -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; diff --git a/src/rufus.rc b/src/rufus.rc index b62fca66..67b7fecd 100644 --- a/src/rufus.rc +++ b/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 "http://rufus.akeo.ie",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"