From c35a92cd0cceb42d78886f632e128f183bd2ee18 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 6 Jul 2020 17:30:20 +0100 Subject: [PATCH] [iso] speed up scanning of ISOs with lots of deep directory entries * ISOs with tons of Rock Ridge deep directory entries (such as OPNsense) can be very slow to scan due to the nature of deep directory parsing, which requires processing the whole ISO9660 fs, for each deep directory file, in order to find the relevant LSN entry. * Since we don't expect much of the content we care about to reside in a deep directory entry, we amend the code to cut short the scan of any directory that contains such elements. * Note that this only applies for ISO scan and it does nothing to speed up the ISO extraction process. * Related to issue #1575 --- src/iso.c | 24 +++++++++++++++++++----- src/rufus.rc | 10 +++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/iso.c b/src/iso.c index cd1cb2c1..1e809014 100644 --- a/src/iso.c +++ b/src/iso.c @@ -631,7 +631,7 @@ static void update_md5sum(void) free(md5_data); } -// Returns 0 on success, nonzero on error +// Returns 0 on success, >0 on error, <0 to ignore current dir static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) { HANDLE file_handle = NULL; @@ -668,9 +668,20 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) _CDIO_LIST_FOREACH(p_entnode, p_entlist) { if (FormatStatus) goto out; p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode); - if ((p_statbuf->rr.b3_rock == yep) && enable_rockridge) { - if (p_statbuf->rr.u_su_fields & ISO_ROCK_SUF_PL) + if (scan_only && (p_statbuf->rr.b3_rock == yep) && enable_rockridge) { + if (p_statbuf->rr.u_su_fields & ISO_ROCK_SUF_PL) { img_report.has_deep_directories = TRUE; + // Due to the nature of the parsing of Rock Ridge deep directories + // which requires performing a *very costly* search of the whole + // ISO9660 file system to find the matching LSN, ISOs with loads of + // deep directory entries (e.g. OPNsense) are very slow to parse... + // To speed up the scan process, and since we expect deep directory + // entries to appear below anything we care for, we cut things + // short by telling the parent not to bother any further once we + // find that we are dealing with a deep directory. + r = -1; + goto out; + } } // Eliminate . and .. entries if ( (strcmp(p_statbuf->filename, ".") == 0) @@ -702,15 +713,18 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) } safe_free(psz_sanpath); } - if (iso_extract_files(p_iso, psz_iso_name)) + r = iso_extract_files(p_iso, psz_iso_name); + if (r > 0) goto out; + if (r < 0) // Stop processing current dir + break; } else { file_length = p_statbuf->total_size; if (check_iso_props(psz_path, file_length, psz_basename, psz_fullpath, &props)) { continue; } print_extracted_file(psz_fullpath, file_length); - for (i=0; i