8d465bb8e5c8201663fede3bbb002a16334b2c5b
[debian/amanda] / server-src / disk_history.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /* $Id: disk_history.c,v 1.12 2006/01/16 00:07:01 martinea Exp $
27  *
28  * functions for obtaining backup history
29  */
30
31 #include "amanda.h"
32 #include "disk_history.h"
33
34 static DUMP_ITEM *disk_hist = NULL;
35
36 void clear_list P((void))
37 {
38     DUMP_ITEM *item, *this;
39
40     item = disk_hist;
41     while (item != NULL)
42     {
43         this = item;
44         item = item->next;
45         while(this->tapes != NULL) {
46             tapelist_t *tapes = this->tapes;
47             this->tapes = tapes->next;
48             amfree(tapes->label);
49             amfree(tapes->files);
50             amfree(tapes);
51         }
52         amfree(this);
53     }
54     disk_hist = NULL;
55 }
56
57 /* add item, maintain list ordered by oldest date last */
58 void add_dump(date, level, tape, file, partnum)
59 char *date;
60 int level;
61 char *tape;
62 int file;
63 int partnum;
64 {
65     DUMP_ITEM *new, *item, *before;
66     int isafile = 0;
67
68     new = (DUMP_ITEM *)alloc(sizeof(DUMP_ITEM));
69     strncpy(new->date, date, sizeof(new->date)-1);
70     new->date[sizeof(new->date)-1] = '\0';
71     new->level = level;
72     strncpy(new->tape, tape, sizeof(new->tape)-1);
73     new->tape[sizeof(new->tape)-1] = '\0';
74     new->file = file;
75     if(partnum == -1) new->is_split = 0;
76     else new->is_split = 1;
77     new->tapes = NULL;
78
79    if(new->tape[0] == '/') isafile = 1; /* XXX kludgey, like this whole thing */
80
81     if (disk_hist == NULL)
82     {
83         disk_hist = new;
84         new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
85         new->next = NULL;
86         return;
87     }
88
89     /* see if we already have part of this dump somewhere */
90     if(new->is_split){
91         for(item = disk_hist; item; item = item->next){
92             if (!strcmp(item->date, new->date) &&
93                     item->level == new->level && item->is_split){
94                 item->tapes = append_to_tapelist(item->tapes, tape, file, isafile);
95                 amfree(new);
96                 return;
97             }
98         }
99     }
100
101     new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
102
103     /* prepend this item to the history list, if it's newer */
104     /* XXX this should probably handle them being on the same date with
105        datestamp_uax or something */
106     if (strcmp(disk_hist->date, new->date) <= 0)
107     {
108         new->next = disk_hist;
109         disk_hist = new;
110         return;
111     }
112
113     /* append this item to the history list, if it's older */
114     before = disk_hist;
115     item = disk_hist->next;
116     while ((item != NULL) && (strcmp(item->date, new->date) > 0))
117     {
118         before = item;
119         item = item->next;
120     }
121     new->next = item;
122     before->next = new;
123 }
124
125
126 DUMP_ITEM *first_dump P((void))
127 {
128     return disk_hist;
129 }
130
131 DUMP_ITEM *next_dump(item)
132 DUMP_ITEM *item;
133 {
134     return item->next;
135 }