Imported Upstream version 2.5.2p1
[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.13 2006/05/25 01:47:19 johnfranks 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
37 clear_list(void)
38 {
39     DUMP_ITEM *item, *this;
40
41     item = disk_hist;
42     while (item != NULL)
43     {
44         this = item;
45         item = item->next;
46         amfree(this->hostname);
47         while(this->tapes != NULL) {
48             tapelist_t *tapes = this->tapes;
49             this->tapes = tapes->next;
50             amfree(tapes->label);
51             amfree(tapes->files);
52             amfree(tapes);
53         }
54         amfree(this);
55     }
56     disk_hist = NULL;
57 }
58
59 /* add item, maintain list ordered by oldest date last */
60
61 void
62 add_dump(
63     char *      hostname,
64     char *      date,
65     int         level,
66     char *      tape,
67     off_t       file,
68     int         partnum)
69 {
70     DUMP_ITEM *new, *item, *before;
71     int isafile = 0;
72
73     new = (DUMP_ITEM *)alloc(SIZEOF(DUMP_ITEM));
74     strncpy(new->date, date, SIZEOF(new->date)-1);
75     new->date[SIZEOF(new->date)-1] = '\0';
76     new->level = level;
77     strncpy(new->tape, tape, SIZEOF(new->tape)-1);
78     new->tape[SIZEOF(new->tape)-1] = '\0';
79     new->file = file;
80     if(partnum == -1) new->is_split = 0;
81     else new->is_split = 1;
82     new->tapes = NULL;
83     new->hostname = stralloc(hostname);
84
85     if(new->tape[0] == '/')
86         isafile = 1; /* XXX kludgey, like this whole thing */
87
88     if (disk_hist == NULL)
89     {
90         disk_hist = new;
91         new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
92         new->next = NULL;
93         return;
94     }
95
96     /* see if we already have part of this dump somewhere */
97     if(new->is_split){
98         for(item = disk_hist; item; item = item->next){
99             if (!strcmp(item->date, new->date) &&
100                     item->level == new->level && item->is_split){
101                 item->tapes = append_to_tapelist(item->tapes, tape, file, isafile);
102                 amfree(new);
103                 return;
104             }
105         }
106     }
107
108     new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
109
110     /* prepend this item to the history list, if it's newer */
111     /* XXX this should probably handle them being on the same date with
112        datestamp_uax or something */
113     if (strcmp(disk_hist->date, new->date) <= 0)
114     {
115         new->next = disk_hist;
116         disk_hist = new;
117         return;
118     }
119
120     /* append this item to the history list, if it's older */
121     before = disk_hist;
122     item = disk_hist->next;
123     while ((item != NULL) && (strcmp(item->date, new->date) > 0))
124     {
125         before = item;
126         item = item->next;
127     }
128     new->next = item;
129     before->next = new;
130 }
131
132
133 DUMP_ITEM *
134 first_dump(void)
135 {
136     return disk_hist;
137 }