From b3b0150502af55eec34a0e0a60ed880c909e3719 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 31 Oct 2007 16:55:55 +0000 Subject: [PATCH] Gave simple -ls an implemention with minimal memory consumption --- test/xorriso.c | 9 ++-- test/xorriso_timestamp.h | 2 +- test/xorrisoburn.c | 103 +++++++++++++++++++++++++-------------- test/xorrisoburn.h | 8 +++ 4 files changed, 80 insertions(+), 42 deletions(-) diff --git a/test/xorriso.c b/test/xorriso.c index 7e1d64c0..16417760 100644 --- a/test/xorriso.c +++ b/test/xorriso.c @@ -4068,16 +4068,17 @@ no_memory:; } if(flag&2) { ret= Xorriso_ls_filev(xorriso, nump, argv + (*idx), flag&1); - if(ret<=0) - {ret= 0; goto ex;} + } else if(nump==1 && strcmp(patterns[0],"*")==0){ + /* save temporary memory by calling simpler function */ + ret= Xorriso_ls(xorriso, (flag&1)|4); } else { ret= Xorriso_expand_pattern(xorriso, nump, patterns, &filec, &filev, 0); if(ret<=0) {ret= 0; goto ex;} ret= Xorriso_ls_filev(xorriso, filec, filev, flag&1); - if(ret<=0) - {ret= 0; goto ex;} } + if(ret<=0) + {ret= 0; goto ex;} ret= 1; ex:; diff --git a/test/xorriso_timestamp.h b/test/xorriso_timestamp.h index 9765251a..1078806e 100644 --- a/test/xorriso_timestamp.h +++ b/test/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2007.10.31.103338" +#define Xorriso_timestamP "2007.10.31.165413" diff --git a/test/xorrisoburn.c b/test/xorrisoburn.c index cd663807..0910b67f 100644 --- a/test/xorrisoburn.c +++ b/test/xorrisoburn.c @@ -1358,8 +1358,6 @@ much_too_long:; } -#ifdef Xorriso_lsi_outdated_unstructured_patterN - int Xorriso__node_name_cmp(const void *node1, const void *node2) { char *name1, *name2; @@ -1370,17 +1368,22 @@ int Xorriso__node_name_cmp(const void *node1, const void *node2) } -/* @param flag bit0= long format , bit1= only check for directory existence */ +/* This function needs less buffer memory than Xorriso_ls_filev() but cannot + perform structured pattern matching. + @param flag bit0= long format + bit1= only check for directory existence + bit2= do not apply search pattern but accept any file +*/ int Xorriso_ls(struct XorrisO *xorriso, int flag) { - int ret, is_dir= 0, i, filec, failed_at; + int ret, is_dir= 0, i, filec= 0, failed_at, no_sort= 0; struct iso_tree_node *node, **node_array= NULL; struct iso_tree_node_dir *dir_node; struct iso_volume *volume; struct iso_tree_iter *iter= NULL; - char sfe[4*SfileadrL], *npt, *rpt, perms[10]; + char sfe[4*SfileadrL], *npt, *rpt, perms[10], mem_text[80], limit_text[80]; mode_t st_mode; - off_t size; + off_t size, mem= 0; time_t mtime; struct tm tms, *tmpt; static char months[12][4]= { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -1413,46 +1416,74 @@ wdi_is_not_a_dir:; for(i= 0; (node= iso_tree_iter_next(iter)) != NULL; ) { npt= (char *) iso_tree_node_get_name(node); - - ret= Xorriso_regexec(xorriso, npt, &failed_at, 0); - if(ret) + if(!(flag&4)) { + ret= Xorriso_regexec(xorriso, npt, &failed_at, 0); + if(ret) continue; /* no match */ - + } filec++; } + /* Reset iteration */ iso_tree_iter_free(iter); iter= NULL; - Xorriso_process_msg_queues(xorriso,0); - node_array= calloc(sizeof(struct iso_tree *), filec+1); - if(node_array==NULL) { - sprintf(xorriso->info_text, - "Cannot allocate memory for %d directory entries", filec); - Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); - ret= -1; goto ex; - } - iter= iso_tree_node_children(dir_node); Xorriso_process_msg_queues(xorriso,0); - for(i= 0; (node= iso_tree_iter_next(iter)) != NULL && iinfo_text, + "Temporary memory needed for result sorting : %s", mem_text); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); + if(mem > xorriso->temp_mem_limit) { + Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1); + sprintf(xorriso->info_text, + "Cannot sort. List of matching files exceeds -temp_mem_limit (%s > %s)", + mem_text, limit_text); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0); + no_sort= 1; } - iso_tree_iter_free(iter); - iter= NULL; - Xorriso_process_msg_queues(xorriso,0); - filec= i; - if(filec<=0) - {ret= 1; goto ex;} - qsort(node_array, filec, sizeof(struct iso_tree *), Xorriso__node_name_cmp); + sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec); + Xorriso_info(xorriso,0); + + if(!no_sort) { + node_array= calloc(sizeof(struct iso_tree_node *), filec+1); + if(node_array==NULL) { + sprintf(xorriso->info_text, + "Cannot allocate memory for %d directory entries", filec); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); + ret= -1; goto ex; + } + + for(i= 0; (node= iso_tree_iter_next(iter)) != NULL && iinfo_text, "Temporary memory needed for pattern expansion : %s", mem_text); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); - if(count*sizeof(char *)+mem > xorriso->temp_mem_limit) { + if(mem > xorriso->temp_mem_limit) { Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1); sprintf(xorriso->info_text, "List of matching file addresses exceeds -temp_mem_limit (%s > %s)", diff --git a/test/xorrisoburn.h b/test/xorrisoburn.h index 2e3c5047..a394de78 100644 --- a/test/xorrisoburn.h +++ b/test/xorrisoburn.h @@ -59,6 +59,14 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag); int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev, int flag); +/* This function needs less buffer memory than Xorriso_ls_filev() but cannot + perform structured pattern matching. + @param flag bit0= long format + bit1= only check for directory existence + bit2= do not apply search pattern but accept any file +*/ +int Xorriso_ls(struct XorrisO *xorriso, int flag); + /* @param eff_path returns resulting effective path. Must provide at least SfileadrL bytes of storage. @param flag bit0= do not produce problem events (unless faulty path format)