21b2c1066228b6dd4fcac347e594d091a9920267
[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.8.10.1 2002/03/24 19:23:23 jrjackson 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         amfree(this);
46     }
47     disk_hist = NULL;
48 }
49
50 /* add item, maintain list ordered by oldest date last */
51 void add_dump(date, level, tape, file)
52 char *date;
53 int level;
54 char *tape;
55 int file;
56 {
57     DUMP_ITEM *new, *item, *before;
58
59     new = (DUMP_ITEM *)alloc(sizeof(DUMP_ITEM));
60     strncpy(new->date, date, sizeof(new->date)-1);
61     new->date[sizeof(new->date)-1] = '\0';
62     new->level = level;
63     strncpy(new->tape, tape, sizeof(new->tape)-1);
64     new->tape[sizeof(new->tape)-1] = '\0';
65     new->file = file;
66
67     if (disk_hist == NULL)
68     {
69         disk_hist = new;
70         new->next = NULL;
71         return;
72     }
73
74     if (strcmp(disk_hist->date, new->date) <= 0)
75     {
76         new->next = disk_hist;
77         disk_hist = new;
78         return;
79     }
80
81     before = disk_hist;
82     item = disk_hist->next;
83     while ((item != NULL) && (strcmp(item->date, new->date) > 0))
84     {
85         before = item;
86         item = item->next;
87     }
88     new->next = item;
89     before->next = new;
90 }
91
92
93 DUMP_ITEM *first_dump P((void))
94 {
95     return disk_hist;
96 }
97
98 DUMP_ITEM *next_dump(item)
99 DUMP_ITEM *item;
100 {
101     return item->next;
102 }