2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
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.
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.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amqde.c,v 1.1.2.1.2.1 2004/08/05 11:35:35 martinea Exp $
29 * the central header file included by all amanda sources
35 * amanda's version of things.
38 #define estrdup stralloc
41 hash_table *parse_exclude_path(char *, char *);
42 int should_exclude(hash_table * hash, char *path);
46 typedef struct __dirtrax {
48 struct __dirtrax *next;
51 typedef struct __diretrax_track_ll {
52 dirtrax_t *first, *last;
70 #ifdef HAVE_UNSIGNED_LONG_LONG
71 unsigned long long total = 0;
73 unsigned long total = 0;
76 dirtrax_t *trax = NULL, *new, *c;
77 char *exclude_path = NULL;
81 hash_table *hash = NULL;
85 while ((ch = getopt(argc, argv, "s:x:")) != EOF) {
93 exclude_path = (optarg);
96 fprintf(stderr, "unknown argument \'%c\'", ch);
105 fprintf(stderr, "must specify a path to dump\n");
109 fprintf(stderr, "must specify -s\n");
116 hash = parse_exclude_path(path, exclude_path);
119 if (chdir(path) != 0) {
120 fprintf(stderr, "could not chdir to %s\n", path);
123 if (lstat(".", &top) != 0) {
124 fprintf(stderr, "could not stat %s\n", path);
127 trax = emalloc(sizeof(*trax));
128 trax->dirname = estrdup(".");
131 ll.first = ll.last = trax;
133 for (new = ll.first; new; new = ll.first) {
134 if (!(d = opendir(new->dirname))) {
135 goto forcleanup; /* basically continue; */
138 * skip directories if we cross a device
140 if (lstat(new->dirname, &st) != 0)
141 goto forwclosedircleanup;
142 if (top.st_dev != st.st_dev || top.st_rdev != st.st_rdev)
143 goto forwclosedircleanup;
145 while ((de = readdir(d))) {
147 if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
150 ap_snprintf(buf, sizeof(buf) - 1, "%s/%s", new->dirname, de->d_name);
153 if (should_exclude(hash, buf))
157 if (lstat(buf, &st) != 0)
160 if (S_ISDIR(st.st_mode)) {
161 c = emalloc(sizeof(*c));
162 c->dirname = estrdup(buf);
167 if (st.st_mtime < since && st.st_ctime < since)
169 if ((st.st_blocks * 512) < st.st_size)
170 total += (st.st_blocks * 512);
174 * add in some overhead, these are estimates
183 ll.first = new->next;
189 * This is dumped out in k so upstream utilies can handle it without
190 * having to handle unsigned long long. The theory is that if you
191 * need to use these estimates, then you proably have a system that
195 #ifdef HAVE_UNSIGNED_LONG_LONG
196 fprintf(stderr, "amqde estimate: %llu kb\n", total/1024);
198 fprintf(stderr, "amqde estimate: %lu kb\n", total/1024);
206 * at the moment, we don't actually parse the include file because it means
207 * implementing globbing, which is a pain in the arse.
209 * This is quick and dirty, after all.
213 parse_exclude_path(rootpath, infile)
225 should_exclude(hash, path)