]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/estimate.c
ebl add restore command line options
[bacula/bacula] / bacula / src / filed / estimate.c
1 /*
2  *  Bacula File Daemon estimate.c
3  *   Make and estimate of the number of files and size to be saved.
4  *
5  *    Kern Sibbald, September MMI
6  *
7  *   Version $Id$
8  *
9  */
10 /*
11    Bacula® - The Network Backup Solution
12
13    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
14
15    The main author of Bacula is Kern Sibbald, with contributions from
16    many others, a complete list can be found in the file AUTHORS.
17    This program is Free Software; you can redistribute it and/or
18    modify it under the terms of version two of the GNU General Public
19    License as published by the Free Software Foundation plus additions
20    that are listed in the file LICENSE.
21
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public License
28    along with this program; if not, write to the Free Software
29    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30    02110-1301, USA.
31
32    Bacula® is a registered trademark of John Walker.
33    The licensor of Bacula is the Free Software Foundation Europe
34    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
35    Switzerland, email:ftf@fsfeurope.org.
36 */
37
38 #include "bacula.h"
39 #include "filed.h"
40
41 static int tally_file(FF_PKT *ff_pkt, void *pkt, bool);
42
43 /*
44  * Find all the requested files and count them.
45  */
46 int make_estimate(JCR *jcr)
47 {
48    int stat;
49
50    set_jcr_job_status(jcr, JS_Running);
51
52    set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
53    stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, (void *)jcr);
54
55    return stat;
56 }
57
58 /*
59  * Called here by find() for each file included.
60  *
61  */
62 static int tally_file(FF_PKT *ff_pkt, void *ijcr, bool top_level) 
63 {
64    JCR *jcr = (JCR *)ijcr;
65    ATTR attr;
66
67    if (job_canceled(jcr)) {
68       return 0;
69    }
70    switch (ff_pkt->type) {
71    case FT_LNKSAVED:                  /* Hard linked, file already saved */
72    case FT_REGE:
73    case FT_REG:
74    case FT_LNK:
75    case FT_NORECURSE:
76    case FT_NOFSCHG:
77    case FT_INVALIDFS:
78    case FT_INVALIDDT:
79    case FT_DIREND:
80    case FT_SPEC:
81    case FT_RAW:
82    case FT_FIFO:
83       break;
84    case FT_DIRBEGIN:
85    case FT_NOACCESS:
86    case FT_NOFOLLOW:
87    case FT_NOSTAT:
88    case FT_DIRNOCHG:
89    case FT_NOCHG:
90    case FT_ISARCH:
91    case FT_NOOPEN:
92    default:
93       return 1;
94    }
95
96    if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode)) {
97       if (ff_pkt->statp.st_size > 0) {
98          jcr->JobBytes += ff_pkt->statp.st_size;
99       }
100 #ifdef HAVE_DARWIN_OS
101       if (ff_pkt->flags & FO_HFSPLUS) {
102          if (ff_pkt->hfsinfo.rsrclength > 0) {
103             jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
104          }
105          jcr->JobBytes += 32;    /* Finder info */
106       }
107 #endif
108    }
109    jcr->num_files_examined++;
110    jcr->JobFiles++;                  /* increment number of files seen */
111    if (jcr->listing) {
112       memcpy(&attr.statp, &ff_pkt->statp, sizeof(struct stat));
113       attr.type = ff_pkt->type;
114       attr.ofname = (POOLMEM *)ff_pkt->fname;
115       attr.olname = (POOLMEM *)ff_pkt->link;
116       print_ls_output(jcr, &attr);
117    }
118    return 1;
119 }