Imported Debian patch 2.5.1p3-1
[debian/amanda] / server-src / disk_history.c
index 21b2c1066228b6dd4fcac347e594d091a9920267..1e02f74225a8a575aa62d15fdd71b6f275ed34cd 100644 (file)
@@ -23,7 +23,7 @@
  * Authors: the Amanda Development Team.  Its members are listed in a
  * file named AUTHORS, in the root directory of this distribution.
  */
-/* $Id: disk_history.c,v 1.8.10.1 2002/03/24 19:23:23 jrjackson Exp $
+/* $Id: disk_history.c,v 1.13 2006/05/25 01:47:19 johnfranks Exp $
  *
  * functions for obtaining backup history
  */
@@ -33,7 +33,8 @@
 
 static DUMP_ITEM *disk_hist = NULL;
 
-void clear_list P((void))
+void
+clear_list(void)
 {
     DUMP_ITEM *item, *this;
 
@@ -42,35 +43,70 @@ void clear_list P((void))
     {
        this = item;
        item = item->next;
+       while(this->tapes != NULL) {
+           tapelist_t *tapes = this->tapes;
+           this->tapes = tapes->next;
+           amfree(tapes->label);
+           amfree(tapes->files);
+           amfree(tapes);
+       }
        amfree(this);
     }
     disk_hist = NULL;
 }
 
 /* add item, maintain list ordered by oldest date last */
-void add_dump(date, level, tape, file)
-char *date;
-int level;
-char *tape;
-int file;
+
+void
+add_dump(
+    char *     date,
+    int                level,
+    char *     tape,
+    off_t      file,
+    int                partnum)
 {
     DUMP_ITEM *new, *item, *before;
+    int isafile = 0;
 
-    new = (DUMP_ITEM *)alloc(sizeof(DUMP_ITEM));
-    strncpy(new->date, date, sizeof(new->date)-1);
-    new->date[sizeof(new->date)-1] = '\0';
+    new = (DUMP_ITEM *)alloc(SIZEOF(DUMP_ITEM));
+    strncpy(new->date, date, SIZEOF(new->date)-1);
+    new->date[SIZEOF(new->date)-1] = '\0';
     new->level = level;
-    strncpy(new->tape, tape, sizeof(new->tape)-1);
-    new->tape[sizeof(new->tape)-1] = '\0';
+    strncpy(new->tape, tape, SIZEOF(new->tape)-1);
+    new->tape[SIZEOF(new->tape)-1] = '\0';
     new->file = file;
+    if(partnum == -1) new->is_split = 0;
+    else new->is_split = 1;
+    new->tapes = NULL;
+
+    if(new->tape[0] == '/')
+       isafile = 1; /* XXX kludgey, like this whole thing */
 
     if (disk_hist == NULL)
     {
        disk_hist = new;
+       new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
        new->next = NULL;
        return;
     }
 
+    /* see if we already have part of this dump somewhere */
+    if(new->is_split){
+       for(item = disk_hist; item; item = item->next){
+           if (!strcmp(item->date, new->date) &&
+                   item->level == new->level && item->is_split){
+               item->tapes = append_to_tapelist(item->tapes, tape, file, isafile);
+               amfree(new);
+               return;
+           }
+       }
+    }
+
+    new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
+
+    /* prepend this item to the history list, if it's newer */
+    /* XXX this should probably handle them being on the same date with
+       datestamp_uax or something */
     if (strcmp(disk_hist->date, new->date) <= 0)
     {
        new->next = disk_hist;
@@ -78,6 +114,7 @@ int file;
        return;
     }
 
+    /* append this item to the history list, if it's older */
     before = disk_hist;
     item = disk_hist->next;
     while ((item != NULL) && (strcmp(item->date, new->date) > 0))
@@ -90,13 +127,8 @@ int file;
 }
 
 
-DUMP_ITEM *first_dump P((void))
+DUMP_ITEM *
+first_dump(void)
 {
     return disk_hist;
 }
-
-DUMP_ITEM *next_dump(item)
-DUMP_ITEM *item;
-{
-    return item->next;
-}