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