Imported Upstream version 3.3.3
[debian/amanda] / server-src / holding.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
5  * All Rights Reserved.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and its
8  * documentation for any purpose is hereby granted without fee, provided that
9  * the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of U.M. not be used in advertising or
12  * publicity pertaining to distribution of the software without specific,
13  * written prior permission.  U.M. makes no representations about the
14  * suitability of this software for any purpose.  It is provided "as is"
15  * without express or implied warranty.
16  *
17  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  *
24  * Authors: the Amanda Development Team.  Its members are listed in a
25  * file named AUTHORS, in the root directory of this distribution.
26  */
27 /*
28  * $Id: holding.h,v 1.23 2006/05/25 01:47:20 johnfranks Exp $
29  *
30  * Terminology:
31  *
32  * Holding disk: a top-level directory given in amanda.conf
33  * Holding directory: a subdirectory of a holding disk, usually named by 
34  *  datestamp.  These are not accessible through this API.
35  * Holding file: one or more os-level files in a holding directory, together
36  *  representing a single dump
37  * Holding file chunks: the individual os-level files (continuations) of
38  *  a holding file.
39  *
40  * Example:
41  *
42  * /data/holding                                       <-- holding disk
43  * /data/holding/20070306123456                        <-- holding dir
44  * /data/holding/20070306123456/videoserver._video_a   <-- holding file,
45                                                            holding file chunk
46  * /data/holding/20070306123456/videoserver._video_a.1 <-- holding file chunk
47  *
48  */
49
50 #ifndef HOLDING_H
51 #define HOLDING_H
52
53 #include "amanda.h"
54 #include "fileheader.h"
55
56 /* Get a list of holding disks.  This is equivalent to 
57  * getconf_holdingdisks() with holdingdisk_get_diskdir().
58  *
59  * @returns: newly allocated GSList of matching disks
60  */
61 GSList *
62 holding_get_disks(void);
63
64 /* Get a list of holding files, optionally limited to a single holding
65  * directory.  Can return a list either of full pathnames or of
66  * bare file names.
67  *
68  * @param hdir: holding directory to enumerate, or NULL for all
69  * @param fullpaths: if true, return full pathnames
70  * @returns: newly allocated GSList of matching files
71  */
72 GSList *
73 holding_get_files(char *hdir,
74                   int fullpaths);
75
76 /* Get a list of holding files chunks in the given holding
77  * file.  Always returns full paths.
78  *
79  * @param hfile: holding file to enumerate
80  * @returns: newly allocated GSList of matching holding file chunks
81  */
82 GSList *
83 holding_get_file_chunks(char *hfile);
84
85 /* Get a list of holding files that should be flushed, optionally
86  * matching only certain datestamps.  This function does *not*
87  * match the dumps against the disklist.
88  *
89  * @param dateargs: GSList of datestamps expressions to dump, or NULL 
90  * for all
91  * @returns: a newly allocated GSList listing all matching holding
92  * files
93  */
94 GSList *
95 holding_get_files_for_flush(GSList *dateargs);
96
97 /* Get a list of all datestamps for which dumps are in the holding
98  * disk.  This scans all dumps and takes the union of their
99  * datestamps (some/all of which may actually be timestamps, 
100  * depending on the setting of config option usetimestamps)
101  *
102  * @returns: a newly allocated GSList listing all datestamps
103  */
104 GSList *
105 holding_get_all_datestamps(void);
106
107 /* Get the total size of a holding file, including all holding
108  * file chunks, in kilobytes.
109  *
110  * @param holding_file: full pathname of holding file
111  * @param strip_headers: if true, don't count the headers in the
112  * total size
113  * @returns: total size in kbytes of the holding file, or -1 in an error
114  */
115 off_t
116 holding_file_size(char *holding_file,
117                   int strip_headers);
118
119 /* Unlink a holding file, including all holding file chunks.
120  *
121  * @param holding_file: full pathname of holding file
122  * @returns: 1 on success, else 0
123  */
124 int
125 holding_file_unlink(char *holding_file);
126
127 /* Given a pathname of a holding file, read the file header.
128  * the result parameter may be altered even if an error is
129  * returned.
130  *
131  * @param fname: full pathname of holding file
132  * @param file: (result) dumpfile_t structure
133  * @returns: 1 on success, else 0
134  */
135 int
136 holding_file_get_dumpfile(char *fname,
137                           dumpfile_t *file);
138
139 /*
140  * Maintenance
141  */
142
143 /* Clean up all holding disks, restoring from a possible crash or
144  * other errors.  This function is intentionally opaque, as the
145  * details of holding disk are hidden from other applications.
146  *
147  * All error and warning messages go to the debug log.
148  *
149  * @param corrupt_dle: function that is called for any DLEs for
150  * which corrupt dumps are found.
151  * @param verbose_output: if non-NULL, send progress messages to
152  * this file.
153  */
154 typedef void (*corrupt_dle_fn)(char *hostname, char *disk);
155 void
156 holding_cleanup(corrupt_dle_fn corrupt_dle,
157     FILE *verbose_output);
158
159 /*
160  * application-specific support
161  */
162
163 /* Set the orig_size in the header
164  *
165  * @param holding_file: full pathname of holding file.
166  * @param orig_size: the size.
167  */
168 void
169 holding_set_origsize(char *holding_file, off_t orig_size);
170
171 /* Rename holding files from the temporary names used during
172  * creation.
173  *
174  * This is currently called by driver.c, but will disappear when
175  * holding is fully converted to the device API
176  *
177  * @param holding_file: full pathname of holding file,
178  * without '.tmp'
179  * @param complete: if 0, set 'is_partial' to 1 in each file
180  * @returns: 1 on success, else 0
181  */
182 int
183 rename_tmp_holding(char *holding_file,
184                    int complete);
185
186 /* Set up a holding directory and do basic permission
187  * checks on it
188  *
189  * @param diskdir: holding directory to set up
190  * @returns: 1 on success, else 0
191  */
192 int
193 mkholdingdir(char *diskdir);
194
195 #endif /* HOLDING_H */