Index: src/common/libmondo-stream.c
===================================================================
--- src/common/libmondo-stream.c	(révision 1099)
+++ src/common/libmondo-stream.c	(copie de travail)
@@ -13,6 +13,7 @@
 
 #include "my-stuff.h"
 #include "mr_mem.h"
+#include "mr_slist.h"
 #include "mondostructures.h"
 #include "libmondo-devices.h"
 #include "lib-common-externs.h"
@@ -60,7 +61,7 @@
 /**
  * The tape catalog that keeps track of files written to tape.
  */
-struct s_tapecatalog *g_tapecatalog;
+static slist* tapecatalog = NULL;
 
 /* @} - end of globalGroup */
 
@@ -132,22 +133,29 @@
 	sleep(1);
 	paranoid_pclose(g_tape_stream);
 	log_it("closein_tape() -- leaving");
-/*
-  for(i=0; i < g_tapecatalog->entries; i++)
-    {
-      log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);
-    }
-*/
 	if (!bkpinfo->please_dont_eject) {
 		eject_device(bkpinfo->media_device);
 	}
 	mr_free(blk);
-	mr_free(g_tapecatalog);
+	slist_free(&tapecatalog);
 	return (retval);
 }
 
 
+/**
+ * log a tape catalog entry in a slist
+ */
+void log_entry(int index, void *data)
+{
+  assert (data);
+  struct s_tapecat_entry* entry = (struct s_tapecat_entry*) data;
 
+  log_it("i=%d type=%s num=%d aux=%ld posK=%lld", index,
+	 (entry->type == fileset) ? "fileset" : "bigslice",
+	 entry->number, entry->aux, entry->tape_posK);
+}
+
+
 /**
  * Close the global output file descriptor which Mondo has been using to write
  * to the tape device (via buffer or dd).
@@ -180,7 +188,7 @@
 		write_header_block_to_stream((off_t)0, "end-of-backup",
 									 BLK_END_OF_BACKUP);
 	retval += write_header_block_to_stream((off_t)0, "end-of-tape", BLK_END_OF_TAPE);	/* just in case */
-/* write 1MB of crap */
+	/* write 1MB of crap */
 	for (i = 0; i < 256 * 1024; i++) {
 		blk[i] = (int) (random() & 0xFF);
 	}
@@ -191,35 +199,14 @@
 			start_to_write_to_next_tape(bkpinfo);
 		}
 	}
-/* write 1MB of zeroes */
-/*
-    for (i = 0; i < 256*1024; i++)
-      {
-        blk[i] = 0;
-      }
-    for (i = 0; i < 4; i++)
-      {
-        fwrite (blk, 1, 256*1024, g_tape_stream);
-        if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024))
-          {
-            start_to_write_to_next_tape (bkpinfo);
-          }
-      }
-*/
 	sleep(2);
 	paranoid_pclose(g_tape_stream);
 	log_it("closeout_tape() -- leaving");
-	for (i = 0; i < g_tapecatalog->entries; i++) {
-		log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i,
-			   (g_tapecatalog->el[i].type ==
-				fileset) ? "fileset" : "bigslice",
-			   g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux,
-			   g_tapecatalog->el[i].tape_posK);
-	}
+	slist_foreach(tapecatalog, &log_entry);
 	//  if (!bkpinfo->please_dont_eject)
 	//    { eject_device(bkpinfo->media_device); }
 	mr_free(blk);
-	mr_free(g_tapecatalog);
+	slist_free(&tapecatalog);
 	return (retval);
 }
 
@@ -502,7 +489,8 @@
 {
 	long long final_alleged_writeK, final_projected_certain_writeK,
 		final_actually_certain_writeK = 0, cposK, bufsize_K;
-	int last, curr, i;
+	int i;
+	slist *curr, *last;
 	t_archtype type = other;
 	char command[MAX_STR_LEN];
 	char tmpdir[MAX_STR_LEN];
@@ -532,30 +520,34 @@
 		log_it("Warning - failed to copy %s to backcatalog at %s",
 			   latest_fname, tmpdir);
 	}
-	last = g_tapecatalog->entries - 1;
-	if (last <= 0) {
+	if (tapecatalog == NULL || tapecatalog->data == NULL) {
 		iamhere("Too early to start deleting from collection.");
 		return (0);
 	}
-	final_alleged_writeK = g_tapecatalog->el[last].tape_posK;
+	final_alleged_writeK = ((struct s_tapecat_entry *) tapecatalog->data)->tape_posK;
 	final_projected_certain_writeK = final_alleged_writeK - bufsize_K;
-	for (curr = last; curr >= 0; curr--) {
-		cposK = g_tapecatalog->el[curr].tape_posK;
+	curr = tapecatalog;
+	while (curr) {
+		cposK = ((struct s_tapecat_entry *) curr->data)->tape_posK;
 		if (cposK < final_projected_certain_writeK) {
 			final_actually_certain_writeK = cposK;
 			break;
 		}
+		curr = curr->next;
 	}
-	if (curr < 0) {
+	if (curr == NULL) {
 		iamhere
 			("Not far enough into tape to start deleting old archives from collection.");
 		return (0);
 	}
-//  log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K);
-
-	for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
-		sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
+	//  log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K);
+	last = curr->next;
+	i = 0;
+	while (last && i < 10) {
+		sprintf(old_fname, "%s/%s", tmpdir, ((struct s_tapecat_entry *) last->data)->fname);
 		unlink(old_fname);
+		i++;
+		last = last->next;
 	}
 	return (0);
 }
@@ -636,8 +628,6 @@
 	/*@ end vars *************************************************** */
 
 	assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
-	g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
-	g_tapecatalog->entries = 0;
 	g_tape_posK = 0;
 	if (g_tape_stream) {
 		log_it("FYI - I won't 'openin' the tape. It's already open.");
@@ -648,14 +638,14 @@
 	make_hole_for_file(outfname);
 
 	set_tape_block_size_with_mt(bkpinfo->media_device,
-								bkpinfo->internal_tape_block_size);
+				    bkpinfo->internal_tape_block_size);
 
 //  start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
 	log_it("Opening IN tape");
 	if (!
 		(g_tape_stream =
 		 open_device_via_buffer(bkpinfo->media_device, 'r',
-								bkpinfo->internal_tape_block_size))) {
+					bkpinfo->internal_tape_block_size))) {
 		log_OS_error(g_tape_fifo);
 		log_to_screen("Cannot openin stream device");
 		return (1);
@@ -733,8 +723,6 @@
 			cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
 /*  initialise the catalog */
 	g_current_media_number = 1;
-	g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
-	g_tapecatalog->entries = 0;
 /* log stuff */
 	log_it("Opening OUT cdstream with the command");
 	log_it(command);
@@ -764,8 +752,6 @@
 		log_it("FYI - I won't 'openout' the tape. It's already open.");
 		return (0);
 	}
-	g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
-	g_tapecatalog->entries = 0;
 	g_tape_posK = 0;
 
 	set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
@@ -1073,10 +1059,9 @@
  * @param fn The original full pathname of the file we're recording.
  * @return The index of the record we just added.
  */
-int register_in_tape_catalog(t_archtype type, int number, long aux,
-							 char *fn)
+void register_in_tape_catalog(t_archtype type, int number, 
+			      long aux, char *fn)
 {
-	int last;
 	char fname[MAX_TAPECAT_FNAME_LEN];
 	char *p;
 
@@ -1088,20 +1073,14 @@
 	}
 	strncpy(fname, p, MAX_TAPECAT_FNAME_LEN);
 	fname[MAX_TAPECAT_FNAME_LEN] = '\0';
-	last = g_tapecatalog->entries;
-	if (last >= MAX_TAPECATALOG_ENTRIES) {
-		log_it
-			("Warning - can't log #%d in tape catalog - too many entries already",
-			 number);
-		return (-1);
-	}
-	g_tapecatalog->el[last].type = type;
-	g_tapecatalog->el[last].number = number;
-	g_tapecatalog->el[last].aux = aux;
-	g_tapecatalog->el[last].tape_posK = g_tape_posK;
-	strcpy(g_tapecatalog->el[last].fname, fname);
-	g_tapecatalog->entries++;
-	return (last);				// returns the index of the record we've jsut added
+
+	struct s_tapecat_entry* entry = (struct s_tapecat_entry*) mr_malloc(sizeof(struct s_tapecat_entry));
+	entry->type = type;
+	entry->number = number;
+	entry->aux = aux;
+	entry->tape_posK = g_tape_posK;
+	strncpy(entry->fname, fname, MAX_TAPECAT_FNAME_LEN);
+	slist_insert(&tapecatalog, (void*) entry);
 }
 
 
@@ -1375,38 +1354,38 @@
  * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
  * @return 0 for success, nonzero for failure.
  */
-int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo)
+void write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo)
 {
-	int i, last, res = 0;
 	char *fname;
+	slist *curr;
 
 	log_msg(2, "I am now writing back catalog to tape");
 	malloc_string(fname);
-	last = g_tapecatalog->entries - 1;
-	for (i = 0; i <= last; i++) {
+	curr = tapecatalog;
+	while (curr) {
 		sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
-				g_tapecatalog->el[i].fname);
+			((struct s_tapecat_entry*) curr->data)->fname);
 		if (!does_file_exist(fname)) {
 			log_msg(6, "Can't write %s - it doesn't exist.", fname);
 		} else {
 			write_header_block_to_stream(length_of_file(fname),
-										 "start-backcatalog-afio-or-slice",
-										 BLK_START_AN_AFIO_OR_SLICE);
+						     "start-backcatalog-afio-or-slice",
+						     BLK_START_AN_AFIO_OR_SLICE);
 			log_msg(2, "Writing %s", fname);
 			if (write_file_to_stream_from_file(bkpinfo, fname)) {
 				res++;
 				log_msg(2, "%s failed", fname);
 			}
-			if (i != last) {
+			if (curr->next != NULL) {
 				write_header_block_to_stream((off_t)0,
-											 "stop-backcatalog-afio-or-slice",
-											 BLK_STOP_AN_AFIO_OR_SLICE);
+							     "stop-backcatalog-afio-or-slice",
+							     BLK_STOP_AN_AFIO_OR_SLICE);
 			}
 		}
+		curr = curr->next;
 	}
 	mr_free(fname);
 	log_msg(2, "Finished writing back catalog to tape");
-	return (res);
 }
 
 
Index: src/common/libmondo-stream.h
===================================================================
--- src/common/libmondo-stream.h	(révision 1099)
+++ src/common/libmondo-stream.h	(copie de travail)
@@ -22,15 +22,15 @@
 							   FILE * foutstream, long long orig_size);
 int read_header_block_from_stream(long long *plen, char *filename,
 								  int *pcontrol_char);
-int register_in_tape_catalog(t_archtype type, int number, long aux,
-							 char *fn);
+void register_in_tape_catalog(t_archtype type, int number, 
+			      long aux, char *fn);
 bool should_we_write_to_next_tape(long mediasize,
 								  off_t length_of_incoming_file);
 int skip_incoming_files_until_we_find_this_one(char
 											   *the_file_I_was_reading);
 int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo);
 int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo);
-int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
+void write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
 int write_data_disks_to_stream(char *fname);
 int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo,
 								   char *infile);
@@ -44,3 +44,5 @@
 							  char *acl_fname);
 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname,
 							 char *acl_fname);
+/* log a tapecatalog entry from a slist */
+void log_entry(int index, void *data);
