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