libisoburn  1.5.4
About: libisoburn is a frontend for the libraries libburn and libisofs which enables creation and expansion of ISO-9660 filesystems on all media and file types supported by libburn. It implements the API and command interpreter of program xorriso, and installs this program as small dynamically linked binary. xorriso is suitable for incremental data backup and for production of bootable ISO 9660 images. A statically linked version is available as GNU xorriso.
  Fossies Dox: libisoburn-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sort_cmp.c File Reference
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include "base_obj.h"
#include "lib_mgt.h"
#include "sort_cmp.h"
#include "iso_tree.h"
#include "iso_manip.h"
Include dependency graph for sort_cmp.c:

Go to the source code of this file.

Functions

int Xorriso__findi_sorted_ino_cmp (const void *p1, const void *p2)
 
int Xorriso__hln_cmp (const void *p1, const void *p2)
 
int Xorriso__findi_sorted_cmp (const void *p1, const void *p2)
 
int Xorriso_sort_node_array (struct XorrisO *xorriso, int flag)
 
int Xorriso__search_node (void *node_array[], int n, int(*cmp)(const void *p1, const void *p2), void *node, int *idx, int flag)
 
int Xorriso_search_in_hln_array (struct XorrisO *xorriso, void *node, int *idx, int flag)
 
int Xorriso__get_di (IsoNode *node, dev_t *dev, ino_t *ino, int flag)
 
int Xorriso__di_ino_cmp (const void *p1, const void *p2)
 
int Xorriso__di_cmp (const void *p1, const void *p2)
 
int Xorriso__sort_di (void *node_array[], int count, int flag)
 
int Xorriso_invalidate_di_item (struct XorrisO *xorriso, IsoNode *node, int flag)
 
int Xorriso_search_di_range (struct XorrisO *xorriso, IsoNode *node, int *idx, int *low, int *high, int flag)
 
int Xorriso__node_lba_cmp (const void *node1, const void *node2)
 
int Xorriso__node_name_cmp (const void *node1, const void *node2)
 
int Xorriso_sorted_node_array (struct XorrisO *xorriso, IsoDir *dir_node, int *nodec, IsoNode ***node_array, off_t boss_mem, int flag)
 
int Xorriso_remake_hln_array (struct XorrisO *xorriso, int flag)
 
int Xorriso_make_hln_array (struct XorrisO *xorriso, int flag)
 
int Xorriso_make_di_array (struct XorrisO *xorriso, int flag)
 
int Xorriso_hardlink_update (struct XorrisO *xorriso, int *compare_result, char *disk_path, char *iso_rr_path, int flag)
 
int Xorriso_finish_hl_update (struct XorrisO *xorriso, int flag)
 

Function Documentation

◆ Xorriso__di_cmp()

int Xorriso__di_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 225 of file sort_cmp.c.

226 {
227  int ret;
228  IsoNode *n1, *n2;
229 
230  ret= Xorriso__di_ino_cmp(p1, p2);
231  if(ret)
232  return(ret);
233  n1= *((IsoNode **) p1);
234  n2= *((IsoNode **) p2);
235  if(n1 != n2)
236  return(n1 < n2 ? -1 : 1);
237  return(0);
238 }
int Xorriso__di_ino_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:194

References Xorriso__di_ino_cmp().

Referenced by Xorriso__sort_di(), Xorriso_hardlink_update(), Xorriso_invalidate_di_item(), and Xorriso_search_di_range().

◆ Xorriso__di_ino_cmp()

int Xorriso__di_ino_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 194 of file sort_cmp.c.

195 {
196  int ret;
197  IsoNode *n1, *n2;
198  dev_t d1, d2;
199  ino_t i1, i2;
200 
201  n1= *((IsoNode **) p1);
202  n2= *((IsoNode **) p2);
203 
204  ret= Xorriso__get_di(n1, &d1, &i1, 0);
205  if(ret <= 0)
206  {d1= 0; i1= 0;}
207  ret= Xorriso__get_di(n2, &d2, &i2, 0);
208  if(ret <= 0)
209  {d2= 0; i2= 0;}
210 
211  if(d1 < d2)
212  return(-1);
213  if(d1 > d2)
214  return(1);
215  if(i1 < i2)
216  return(-1);
217  if(i1 > i2)
218  return(1);
219  if(d1 == 0 && i1 == 0 && n1 != n2)
220  return(n1 < n2 ? -1 : 1);
221  return(0);
222 }
int Xorriso__get_di(IsoNode *node, dev_t *dev, ino_t *ino, int flag)
Definition: sort_cmp.c:145

References Xorriso__get_di().

Referenced by Xorriso__di_cmp(), and Xorriso_search_di_range().

◆ Xorriso__findi_sorted_cmp()

int Xorriso__findi_sorted_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 69 of file sort_cmp.c.

70 {
71  int ret;
72 
73  ret= Xorriso__findi_sorted_ino_cmp(p1, p2);
74  if(ret)
75  return (ret > 0 ? 1 : -1);
76  if(p1 != p2)
77  return(p1 < p2 ? -1 : 1);
78  return(0);
79 }
int Xorriso__findi_sorted_ino_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:34

References Xorriso__findi_sorted_ino_cmp().

Referenced by Xorriso_sort_node_array().

◆ Xorriso__findi_sorted_ino_cmp()

int Xorriso__findi_sorted_ino_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 34 of file sort_cmp.c.

35 {
36  int ret;
37  IsoNode *n1, *n2;
38 
39  n1= *((IsoNode **) p1);
40  n2= *((IsoNode **) p2);
41 
42  ret= Xorriso__node_lba_cmp(&n1, &n2);
43  if(ret)
44  return (ret > 0 ? 1 : -1);
45  ret= iso_node_cmp_ino(n1, n2, 0);
46  return(ret);
47 }
int Xorriso__node_lba_cmp(const void *node1, const void *node2)
Definition: sort_cmp.c:308

References Xorriso__node_lba_cmp().

Referenced by Xorriso__findi_sorted_cmp(), Xorriso__hln_cmp(), Xorriso_restore_node_array(), Xorriso_search_hardlinks(), and Xorriso_search_in_hln_array().

◆ Xorriso__get_di()

int Xorriso__get_di ( IsoNode *  node,
dev_t *  dev,
ino_t *  ino,
int  flag 
)

Definition at line 145 of file sort_cmp.c.

146 {
147  int ret, i, i_end, imgid, error_code;
148  size_t value_length= 0;
149  char *value= NULL, *msg= NULL, severity[80];
150  unsigned char *vpt;
151  static char *name= "isofs.di";
152 
153 #ifdef NIX
154  /* <<< */
155  Xorriso_get_di_counteR++;
156 #endif /* NIX */
157 
158  msg= TSOB_FELD(char, ISO_MSGS_MESSAGE_LEN);
159  if(msg == NULL)
160  {ret= -1; goto ex;}
161  *dev= 0;
162  *ino= 0;
163  ret= iso_node_lookup_attr(node, name, &value_length, &value, 0);
164  if(ret <= 0) {
165  /* Drop any pending messages because there is no xorriso to take them */
166  iso_obtain_msgs("NEVER", &error_code, &imgid, msg, severity);
167  goto ex;
168  }
169  vpt= (unsigned char *) value;
170  if(vpt[0] > sizeof(ino_t)) {
171 
172  /* >>> obviously not the same system that recorded the device number */;
173 
174  }
175  for(i= 1; i <= vpt[0] && i < (int) value_length; i++)
176  *dev= ((*dev) << 8) | vpt[i];
177  i_end= i + vpt[i] + 1;
178  if(vpt[i] > sizeof(ino_t)) {
179 
180  /* >>> obviously not the same system that recorded the inode number */;
181 
182  }
183  for(i++; i < i_end && i < (int) value_length; i++)
184  *ino= ((*ino) << 8) | vpt[i];
185  free(value);
186  ret= 1;
187 ex:;
188  if(msg != NULL)
189  free(msg);
190  return(ret);
191 }
#define TSOB_FELD(typ, count)
Definition: sfile.h:15

References TSOB_FELD.

Referenced by Xorriso__di_ino_cmp(), and Xorriso_hardlink_update().

◆ Xorriso__hln_cmp()

int Xorriso__hln_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 53 of file sort_cmp.c.

54 {
55  int ret;
56 
57  ret= Xorriso__findi_sorted_ino_cmp(&p1, &p2);
58  if(ret)
59  return (ret > 0 ? 1 : -1);
60  if(p1 != p2)
61  return(p1 < p2 ? -1 : 1);
62  return(0);
63 }

References Xorriso__findi_sorted_ino_cmp().

Referenced by Xorriso_remake_hln_array().

◆ Xorriso__node_lba_cmp()

int Xorriso__node_lba_cmp ( const void *  node1,
const void *  node2 
)

Definition at line 308 of file sort_cmp.c.

309 {
310  int ret;
311  int lba1= 0, lba2= 0;
312 
313  ret= Xorriso__file_start_lba(*((IsoNode **) node1), &lba1, 0);
314  if(ret!=1)
315  lba1= 0;
316  ret= Xorriso__file_start_lba(*((IsoNode **) node2), &lba2, 0);
317  if(ret!=1)
318  lba2= 0;
319  return(lba1-lba2);
320 }
int Xorriso__file_start_lba(IsoNode *node, int *lba, int flag)
Definition: iso_tree.c:2259

References Xorriso__file_start_lba().

Referenced by Xorriso__findi_sorted_ino_cmp(), and Xorriso_findi_iter().

◆ Xorriso__node_name_cmp()

int Xorriso__node_name_cmp ( const void *  node1,
const void *  node2 
)

Definition at line 323 of file sort_cmp.c.

324 {
325  char *name1, *name2;
326 
327  name1= (char *) iso_node_get_name(*((IsoNode **) node1));
328  name2= (char *) iso_node_get_name(*((IsoNode **) node2));
329  return(strcmp(name1,name2));
330 }

Referenced by Xorriso_sorted_node_array().

◆ Xorriso__search_node()

int Xorriso__search_node ( void *  node_array[],
int  n,
int(*)(const void *p1, const void *p2)  cmp,
void *  node,
int *  idx,
int  flag 
)

Definition at line 92 of file sort_cmp.c.

95 {
96  int ret, l, r, p, pos;
97 
98  if(n == 0)
99  return(0);
100  l= 0;
101  r= n + 1;
102  while(1) {
103  p= (r - l) / 2;
104  if(p == 0)
105  break;
106  p+= l;
107 
108  /* NULL elements may indicate invalid nodes.Their first valid right neighbor
109  will serve as proxy. If none exists, then the test pushes leftwards.
110  */
111  for(pos= p - 1; pos < n; pos++)
112  if(node_array[pos] != NULL)
113  break;
114  if(pos < n)
115  ret= (*cmp)(&(node_array[pos]), &node);
116  else
117  ret= 1;
118 
119  if(ret < 0)
120  l= p;
121  else if(ret > 0)
122  r= p;
123  else {
124  *idx= pos;
125  return(1);
126  }
127  }
128  return(0);
129 }

Referenced by Xorriso_hardlink_update(), Xorriso_invalidate_di_item(), Xorriso_search_di_range(), and Xorriso_search_in_hln_array().

◆ Xorriso__sort_di()

int Xorriso__sort_di ( void *  node_array[],
int  count,
int  flag 
)

Definition at line 241 of file sort_cmp.c.

242 {
243  if(count <= 0)
244  return(0);
245  qsort(node_array, count, sizeof(IsoNode *), Xorriso__di_cmp);
246  return(1);
247 }
int Xorriso__di_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:225

References Xorriso__di_cmp().

Referenced by Xorriso_make_di_array().

◆ Xorriso_finish_hl_update()

int Xorriso_finish_hl_update ( struct XorrisO xorriso,
int  flag 
)

Definition at line 704 of file sort_cmp.c.

705 {
706  int ret, zero= 0;
707  char *argv[4];
708  struct Xorriso_lsT *disk_lst, *iso_lst;
709 
710  if(xorriso->di_array == NULL)
711  {ret= 1; goto ex;}
712  disk_lst= xorriso->di_disk_paths;
713  iso_lst= xorriso->di_iso_paths;
714  while(disk_lst != NULL && iso_lst != NULL) {
715  argv[0]= Xorriso_lst_get_text(iso_lst, 0);
716  argv[1]= "-exec";
717  argv[2]= "widen_hardlinks";
718  argv[3]= Xorriso_lst_get_text(disk_lst, 0);
719  zero= 0;
720  ret= Xorriso_option_find(xorriso, 4, argv, &zero, 0); /* -findi */
721  if(ret < 0)
722  goto ex;
723  disk_lst= Xorriso_lst_get_next(disk_lst, 0);
724  iso_lst= Xorriso_lst_get_next(iso_lst, 0);
725  }
726  ret= 1;
727 ex:;
728  if(!(flag & 1))
729  Xorriso_destroy_di_array(xorriso, 0);
730  return(ret);
731 }
struct Xorriso_lsT * Xorriso_lst_get_next(struct Xorriso_lsT *entry, int flag)
Obtain the address of the next item in the chain of messages.
Definition: aux_objects.c:624
char * Xorriso_lst_get_text(struct Xorriso_lsT *entry, int flag)
Obtain the text message from the current list item.
Definition: aux_objects.c:636
int Xorriso_destroy_di_array(struct XorrisO *xorriso, int flag)
Definition: base_obj.c:699
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv, int *idx, int flag)
Definition: opts_d_h.c:818
struct Xorriso_lsT * di_disk_paths
struct Xorriso_lsT * di_iso_paths
void ** di_array

References XorrisO::di_array, XorrisO::di_disk_paths, XorrisO::di_iso_paths, Xorriso_destroy_di_array(), Xorriso_lst_get_next(), Xorriso_lst_get_text(), and Xorriso_option_find().

Referenced by Xorriso_make_di_array(), Xorriso_option_hardlinks(), and Xorriso_write_session().

◆ Xorriso_hardlink_update()

int Xorriso_hardlink_update ( struct XorrisO xorriso,
int *  compare_result,
char *  disk_path,
char *  iso_rr_path,
int  flag 
)

Definition at line 575 of file sort_cmp.c.

577 {
578  int ret, hret, idx, low, high, i, do_overwrite= 0, did_fake_di= 0;
579  int follow_links, old_idx= -1;
580  IsoNode *node;
581  struct stat stbuf;
582  dev_t old_dev;
583  ino_t old_ino;
584 
585  if(xorriso->di_array == NULL)
586  return(1);
587  follow_links= xorriso->do_follow_links ||
588  (xorriso->do_follow_param && !(flag & 4));
589  ret= Xorriso_node_from_path(xorriso, NULL, iso_rr_path, &node, 0);
590  if(ret <= 0)
591  return(ret);
592  if(LIBISO_ISDIR(node))
593  return(1);
594 
595  /* Handle eventual hardlink split : */
596  /* This is achieved by setting the content change bit. Reason:
597  The node needs to be removed from di_array because its di is
598  not matching its array index any more. So it becomes invisible for
599  the join check of eventual later hardlink siblings. Therefore
600  it must be updated now, even if it has currently no siblings
601  which it leaves or which it joins.
602  */
603  if(!(flag & (1 | 2)))
604  do_overwrite= 1;
605 
606  Xorriso__get_di(node, &old_dev, &old_ino, 0);
607  ret= Xorriso__search_node(xorriso->di_array, xorriso->di_count,
608  Xorriso__di_cmp, node, &idx, 0);
609  if(ret < 0)
610  {ret= 0; goto ex;}
611  if(ret > 0)
612  old_idx= idx;
613 
614  /* Handle eventual hardlink joining : */
615 
616  if(follow_links)
617  ret= stat(disk_path, &stbuf);
618  else
619  ret= lstat(disk_path, &stbuf);
620  if(ret==-1)
621  {ret= 0; goto ex;}
622 
623  /* Are there new dev-ino-siblings in the image ? */
624  /* Fake isofs.di */
625  if(!(flag & 1)) {
626  ret= Xorriso_record_dev_inode(xorriso, disk_path, stbuf.st_dev,
627  stbuf.st_ino, node, iso_rr_path, 1);
628  if(ret <= 0)
629  {ret= -1; goto ex;}
630  did_fake_di= 1;
631  /* temporarily remove node from di_array so it does not disturb
632  search by its fake di info */;
633  if(old_idx >= 0)
634  xorriso->di_array[old_idx]= NULL;
635  }
636  ret= Xorriso_search_di_range(xorriso, node, &idx, &low, &high, 1);
637  if(did_fake_di) {
638  /* Revoke fake of isofs.di */
639  hret= Xorriso_record_dev_inode(xorriso, disk_path, old_dev, old_ino,
640  node, iso_rr_path, 1);
641  if(hret <= 0)
642  {ret= -1; goto ex;}
643  if(old_idx >= 0)
644  xorriso->di_array[old_idx]= node;
645  }
646  if(ret == 0)
647  {ret= 1; goto ex;}
648  if(ret < 0)
649  {ret= 0; goto ex;}
650 
651 
652 #ifdef Xorriso_hardlink_update_debuG
653  /* <<< */
654  if(low < high || idx < 0) {
655  fprintf(stderr,
656  "xorriso_DEBUG: old_idx= %d , low= %d , high= %d , iso= '%s' , disk='%s'\n",
657  old_idx, low, high, iso_rr_path, disk_path);
658  fprintf(stderr,
659  "xorriso_DEBUG: old_dev= %lu , old_ino= %.f , dev= %lu , ino= %.f\n",
660  (unsigned long) old_dev, (double) old_ino,
661  (unsigned long) stbuf.st_dev, (double) stbuf.st_ino);
662 
663  if(idx >= 0 && idx != old_idx)
664  fprintf(stderr, "xorriso_DEBUG: idx= %d , old_idx = %d\n", idx, old_idx);
665  }
666 #endif /* Xorriso_hardlink_update_debuG */
667 
668  /* Overwrite all valid siblings : */
669  for(i= low; i <= high; i++) {
670  if(i == idx || xorriso->di_array[i] == NULL)
671  continue;
672 
673 #ifdef Xorriso_hardlink_update_debuG
674  /* <<< */
675 {
676  ino_t ino;
677  dev_t dev;
678 
679  Xorriso__get_di(xorriso->di_array[i], &dev, &ino, 0);
680  fprintf(stderr, "xorriso_DEBUG: iso_sibling= '%s' , dev= %lu , ino= %.f\n",
681  node_path, (unsigned long) dev, (double) ino);
682 }
683 #endif /* Xorriso_hardlink_update_debuG */
684 
685  xorriso->di_do_widen[i / 8]|= 1 << (i % 8);
686  }
687 
688  ret= 1;
689 ex:;
690  if(do_overwrite)
691  *compare_result|= (1<<15);
692  if(old_idx >= 0 && (*compare_result & (3 << 21))) {
693  /* The old di info is obsolete */
694  if(xorriso->di_array[old_idx] != NULL)
695  iso_node_unref(xorriso->di_array[old_idx]);
696  xorriso->di_array[old_idx]= NULL;
697  }
698  return(ret);
699 }
int Xorriso_record_dev_inode(struct XorrisO *xorriso, char *disk_path, dev_t dev, ino_t ino, void *in_node, char *iso_path, int flag)
Definition: iso_manip.c:2235
int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume, char *path, IsoNode **node, int flag)
Definition: iso_tree.c:2650
#define LIBISO_ISDIR(node)
Definition: iso_tree.h:17
int Xorriso__search_node(void *node_array[], int n, int(*cmp)(const void *p1, const void *p2), void *node, int *idx, int flag)
Definition: sort_cmp.c:92
int Xorriso_search_di_range(struct XorrisO *xorriso, IsoNode *node, int *idx, int *low, int *high, int flag)
Definition: sort_cmp.c:272
int do_follow_links
char * di_do_widen
int do_follow_param

References XorrisO::di_array, XorrisO::di_count, XorrisO::di_do_widen, XorrisO::do_follow_links, XorrisO::do_follow_param, LIBISO_ISDIR, Xorriso__di_cmp(), Xorriso__get_di(), Xorriso__search_node(), Xorriso_node_from_path(), Xorriso_record_dev_inode(), and Xorriso_search_di_range().

Referenced by Xorriso_update_interpreter().

◆ Xorriso_invalidate_di_item()

int Xorriso_invalidate_di_item ( struct XorrisO xorriso,
IsoNode *  node,
int  flag 
)

Definition at line 250 of file sort_cmp.c.

252 {
253  int ret, idx;
254 
255  if(xorriso->di_array == NULL)
256  return(1);
257  ret= Xorriso__search_node(xorriso->di_array, xorriso->di_count,
258  Xorriso__di_cmp, node, &idx, 0);
259  if(ret <= 0)
260  return(ret == 0);
261  if(xorriso->di_array[idx] != NULL)
262  iso_node_unref(xorriso->di_array[idx]);
263  xorriso->di_array[idx]= NULL;
264  return(1);
265 }

References XorrisO::di_array, XorrisO::di_count, Xorriso__di_cmp(), and Xorriso__search_node().

Referenced by Xorriso_rmi().

◆ Xorriso_make_di_array()

int Xorriso_make_di_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 518 of file sort_cmp.c.

519 {
520  int ret, bytes;
521 
522 #ifdef NIX
523  /* <<< */
524  unsigned long old_gdic;
525  old_gdic= Xorriso_get_di_counteR;
526 #endif /* NIX */
527 
528  if((xorriso->ino_behavior & 8 ) && !(flag & 2))
529  return(2);
530  if(xorriso->di_array != NULL && !(flag & 1))
531  return(2);
532  Xorriso_finish_hl_update(xorriso, 0);
533 
534  ret= Xorriso_all_node_array(xorriso, 0, 0);
535  if(ret <= 0)
536  goto ex;
537  bytes= xorriso->node_array_size / 8 + 1;
538  xorriso->di_do_widen= calloc(bytes, 1);
539  if(xorriso->di_do_widen == NULL) {
540  Xorriso_no_malloc_memory(xorriso, NULL, 0);
541  ret= -1; goto ex;
542  }
543 
544  /* Transfer node_array to di_array without unrefering nodes */
545  xorriso->di_count= xorriso->node_counter;
546  xorriso->di_array= xorriso->node_array;
547  xorriso->node_counter= 0;
548  xorriso->node_array_size= 0;
549  xorriso->node_array= NULL;
550 
551  Xorriso__sort_di((void *) xorriso->di_array, xorriso->di_count, 0);
552 
553  ret= 1;
554 ex:;
555 
556 #ifdef NIX
557 /* <<< */
558  fprintf(stderr, "xorriso_DEBUG: sort_count= %lu\n",
559  Xorriso_get_di_counteR - old_gdic);
560 #endif /* NIX */
561 
562  return(ret);
563 }
int Xorriso_all_node_array(struct XorrisO *xorriso, int addon_nodes, int flag)
Definition: iso_manip.c:3709
int Xorriso_finish_hl_update(struct XorrisO *xorriso, int flag)
Definition: sort_cmp.c:704
int Xorriso__sort_di(void *node_array[], int count, int flag)
Definition: sort_cmp.c:241
int ino_behavior
void ** node_array
int node_counter
int node_array_size
int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
Definition: text_io.c:4077

References XorrisO::di_array, XorrisO::di_count, XorrisO::di_do_widen, XorrisO::ino_behavior, XorrisO::node_array, XorrisO::node_array_size, XorrisO::node_counter, Xorriso__sort_di(), Xorriso_all_node_array(), Xorriso_finish_hl_update(), and Xorriso_no_malloc_memory().

Referenced by Xorriso_option_hardlinks(), Xorriso_option_map_l(), and Xorriso_option_update().

◆ Xorriso_make_hln_array()

int Xorriso_make_hln_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 476 of file sort_cmp.c.

477 {
478  int ret;
479 
480  if(xorriso->hln_array != NULL && !(flag & 1)) {
481  /* If no fresh image manipulations occurred: keep old array */
482  if(!xorriso->hln_change_pending)
483  return(2);
484  ret= Xorriso_remake_hln_array(xorriso, 0);
485  return(ret);
486  }
487  Xorriso_destroy_hln_array(xorriso, 0);
488 
489  ret= Xorriso_all_node_array(xorriso, 0, 0);
490  if(ret <= 0)
491  goto ex;
492  Xorriso_sort_node_array(xorriso, 0);
493 
494  /* Transfer node_array to di_array without unrefering nodes */
495  xorriso->hln_count= xorriso->node_counter;
496  xorriso->hln_array= xorriso->node_array;
497  xorriso->node_counter= 0;
498  xorriso->node_array_size= 0;
499  xorriso->node_array= NULL;
500 
501  /* Allocate hln_targets */
502  ret= Xorriso_new_hln_array(xorriso, xorriso->temp_mem_limit, 1);
503  if(ret<=0) {
504  Xorriso_destroy_hln_array(xorriso, 0);
505  goto ex;
506  }
507  xorriso->node_targets_availmem= xorriso->temp_mem_limit;
508  xorriso->hln_change_pending= 0;
509  ret= 1;
510 ex:;
511  return(ret);
512 }
int Xorriso_new_hln_array(struct XorrisO *xorriso, off_t mem_limit, int flag)
Definition: base_obj.c:752
int Xorriso_destroy_hln_array(struct XorrisO *xorriso, int flag)
Definition: base_obj.c:675
int Xorriso_sort_node_array(struct XorrisO *xorriso, int flag)
Definition: sort_cmp.c:82
int Xorriso_remake_hln_array(struct XorrisO *xorriso, int flag)
Definition: sort_cmp.c:388
void ** hln_array
off_t node_targets_availmem
int hln_change_pending
int temp_mem_limit

References XorrisO::hln_array, XorrisO::hln_change_pending, XorrisO::hln_count, XorrisO::node_array, XorrisO::node_array_size, XorrisO::node_counter, XorrisO::node_targets_availmem, XorrisO::temp_mem_limit, Xorriso_all_node_array(), Xorriso_destroy_hln_array(), Xorriso_new_hln_array(), Xorriso_remake_hln_array(), and Xorriso_sort_node_array().

Referenced by Xorriso_option_hardlinks(), Xorriso_option_lsi(), and Xorriso_restore_sorted().

◆ Xorriso_remake_hln_array()

int Xorriso_remake_hln_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 388 of file sort_cmp.c.

389 {
390  int ret, addon_nodes= 0, i, old_count, old_pt, new_pt;
391  IsoNode **old_nodes;
392  char **old_targets;
393 
394  /* Count hln_targets of which the node has been deleted meanwhile */
395  for(i= 0; i < xorriso->hln_count; i++) {
396  if(xorriso->hln_targets[i] == NULL)
397  continue;
398  if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
399  continue;
400  addon_nodes++;
401  }
402  ret= Xorriso_all_node_array(xorriso, addon_nodes, 0);
403  if(ret <= 0)
404  goto ex;
405  if(addon_nodes > 0) {
406  /* Transfer delete nodes with hln_target to node array */
407  for(i= 0; i < xorriso->hln_count; i++) {
408  if(xorriso->hln_targets[i] == NULL)
409  continue;
410  if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
411  continue;
412  if(xorriso->node_counter < xorriso->node_array_size) {
413  xorriso->node_array[xorriso->node_counter++]= xorriso->hln_array[i];
414  iso_node_ref(xorriso->node_array[xorriso->node_counter - 1]);
415  }
416  }
417  }
418 
419  Xorriso_sort_node_array(xorriso, 0);
420  old_nodes= (IsoNode **) xorriso->hln_array;
421  old_targets= (char **) xorriso->hln_targets;
422  old_count= xorriso->hln_count;
423  xorriso->hln_array= 0;
424  xorriso->hln_targets= NULL;
425 
426  /* Transfer node_array to di_array without unrefering nodes */
427  xorriso->hln_count= xorriso->node_counter;
428  xorriso->hln_array= xorriso->node_array;
429  xorriso->node_counter= 0;
430  xorriso->node_array_size= 0;
431  xorriso->node_array= NULL;
432 
433  /* Allocate hln_targets */
434  ret= Xorriso_new_hln_array(xorriso, xorriso->temp_mem_limit, 1);
435  if(ret<=0)
436  goto ex;
437  xorriso->node_targets_availmem= xorriso->temp_mem_limit;
438  if(old_targets != NULL) {
439  /* Transfer targets from old target array */;
440  new_pt= old_pt= 0;
441  while(new_pt < xorriso->hln_count && old_pt < old_count) {
442  ret= Xorriso__hln_cmp(xorriso->hln_array[new_pt], old_nodes[old_pt]);
443  if(ret < 0) {
444  new_pt++;
445  } else if(ret > 0) {
446  old_pt++;
447  } else {
448  xorriso->hln_targets[new_pt]= old_targets[old_pt];
449  if(old_targets[old_pt] != NULL)
450  xorriso->temp_mem_limit-= strlen(old_targets[old_pt]) + 1;
451  old_targets[old_pt]= NULL;
452  new_pt++;
453  old_pt++;
454  }
455  }
456  for(old_pt= 0; old_pt < old_count; old_pt++)
457  if(old_targets[old_pt] != NULL) /* (should not happen) */
458  free(old_targets[old_pt]);
459  free((char *) old_targets);
460  }
461  if(old_nodes != NULL) {
462  for(old_pt= 0; old_pt < old_count; old_pt++)
463  if(old_nodes[old_pt] != NULL)
464  iso_node_unref(old_nodes[old_pt]);
465  free((char *) old_nodes);
466  }
467  xorriso->hln_change_pending= 0;
468  ret= 1;
469 ex:;
470  return(ret);
471 }
int Xorriso_node_is_valid(struct XorrisO *xorriso, IsoNode *in_node, int flag)
Definition: iso_tree.c:384
int Xorriso__hln_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:53
void ** hln_targets

References XorrisO::hln_array, XorrisO::hln_change_pending, XorrisO::hln_count, XorrisO::hln_targets, XorrisO::node_array, XorrisO::node_array_size, XorrisO::node_counter, XorrisO::node_targets_availmem, XorrisO::temp_mem_limit, Xorriso__hln_cmp(), Xorriso_all_node_array(), Xorriso_new_hln_array(), Xorriso_node_is_valid(), and Xorriso_sort_node_array().

Referenced by Xorriso_make_hln_array().

◆ Xorriso_search_di_range()

int Xorriso_search_di_range ( struct XorrisO xorriso,
IsoNode *  node,
int *  idx,
int *  low,
int *  high,
int  flag 
)

Definition at line 272 of file sort_cmp.c.

274 {
275  int ret, i, found;
276  int (*cmp)(const void *p1, const void *p2)= Xorriso__di_ino_cmp;
277 
278  if(flag & 2)
279  cmp= Xorriso__di_cmp;
280 
281  *high= *low= *idx= -1;
282  ret= Xorriso__search_node(xorriso->di_array, xorriso->di_count,
283  cmp, node, &found, 0);
284  if(ret <= 0)
285  return(0);
286  *low= *high= found;
287  for(i= found + 1; i < xorriso->di_count; i++)
288  if(xorriso->di_array[i] != NULL) {
289  if((*cmp)(&node, &(xorriso->di_array[i])) != 0)
290  break;
291  *high= i;
292  }
293  for(i= found - 1; i >= 0; i--)
294  if(xorriso->di_array[i] != NULL) {
295  if((*cmp)(&node, &(xorriso->di_array[i])) != 0)
296  break;
297  *low= i;
298  }
299  for(i= *low; i <= *high; i++)
300  if(xorriso->di_array[i] == node) {
301  *idx= i;
302  break;
303  }
304  return(*idx >= 0 || (flag & 1));
305 }

References XorrisO::di_array, XorrisO::di_count, Xorriso__di_cmp(), Xorriso__di_ino_cmp(), and Xorriso__search_node().

Referenced by Xorriso_hardlink_update(), and Xorriso_widen_hardlink().

◆ Xorriso_search_in_hln_array()

int Xorriso_search_in_hln_array ( struct XorrisO xorriso,
void *  node,
int *  idx,
int  flag 
)

Definition at line 132 of file sort_cmp.c.

134 {
135  int ret;
136 
137  if(xorriso->hln_array == NULL || xorriso->hln_count <= 0)
138  return(0);
139  ret= Xorriso__search_node(xorriso->hln_array, xorriso->hln_count,
140  Xorriso__findi_sorted_ino_cmp, node, idx, 0);
141  return ret;
142 }

References XorrisO::hln_array, XorrisO::hln_count, Xorriso__findi_sorted_ino_cmp(), and Xorriso__search_node().

Referenced by Xorriso_search_hardlinks().

◆ Xorriso_sort_node_array()

int Xorriso_sort_node_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 82 of file sort_cmp.c.

83 {
84  if(xorriso->node_counter <= 0)
85  return(0);
86  qsort(xorriso->node_array, xorriso->node_counter, sizeof(IsoNode *),
88  return(1);
89 }
int Xorriso__findi_sorted_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:69

References XorrisO::node_array, XorrisO::node_counter, and Xorriso__findi_sorted_cmp().

Referenced by Xorriso_findi_sorted(), Xorriso_make_hln_array(), Xorriso_remake_hln_array(), and Xorriso_restore_node_array().

◆ Xorriso_sorted_node_array()

int Xorriso_sorted_node_array ( struct XorrisO xorriso,
IsoDir *  dir_node,
int *  nodec,
IsoNode ***  node_array,
off_t  boss_mem,
int  flag 
)

Definition at line 337 of file sort_cmp.c.

341 {
342  int i, ret, failed_at;
343  char *npt;
344  IsoDirIter *iter= NULL;
345  IsoNode *node;
346  off_t mem;
347 
348  mem= ((*nodec)+1)*sizeof(IsoNode *);
349  ret= Xorriso_check_temp_mem_limit(xorriso, mem+boss_mem, flag&2);
350  if(ret<=0)
351  return(ret);
352 
353  *node_array= calloc(sizeof(IsoNode *), (*nodec)+1);
354  if(*node_array==NULL) {
355  sprintf(xorriso->info_text,
356  "Cannot allocate memory for %d directory entries", *nodec);
357  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
358  return(-1);
359  }
360 
361  ret= iso_dir_get_children(dir_node, &iter);
362  if(ret<0) {
363  Xorriso_cannot_create_iter(xorriso, ret, 0);
364  return(-1);
365  }
366 
367  for(i= 0; iso_dir_iter_next(iter, &node) == 1 && i<*nodec; ) {
368  npt= (char *) iso_node_get_name(node);
369  if(!(flag&4)) {
370  ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
371  if(ret)
372  continue; /* no match */
373  }
374  if(flag&1)
375  if(!LIBISO_ISDIR(node))
376  continue;
377  (*node_array)[i++]= node;
378  }
379  iso_dir_iter_free(iter);
380  *nodec= i;
381  if(*nodec<=0)
382  return(1);
383  qsort(*node_array, *nodec, sizeof(IsoNode *), Xorriso__node_name_cmp);
384  return(1);
385 }
int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error, int flag)
Definition: iso_manip.c:2509
int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at, int flag)
Definition: match.c:225
int Xorriso_check_temp_mem_limit(struct XorrisO *xorriso, off_t mem, int flag)
Definition: parse_exec.c:2896
int Xorriso__node_name_cmp(const void *node1, const void *node2)
Definition: sort_cmp.c:323
char info_text[10 *4096]
int Xorriso_msgs_submit(struct XorrisO *xorriso, int error_code, char msg_text[], int os_errno, char severity[], int flag)
Submit a problem message to the xorriso problem reporting and handling system.
Definition: text_io.c:2504

References XorrisO::info_text, LIBISO_ISDIR, Xorriso__node_name_cmp(), Xorriso_cannot_create_iter(), Xorriso_check_temp_mem_limit(), Xorriso_msgs_submit(), and Xorriso_regexec().

Referenced by Xorriso_ls(), and Xorriso_show_du_subs().