]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/estimate.c
216b69d645c02e0d38277d4f8a45382a4abf227a
[bacula/bacula] / bacula / src / filed / estimate.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  *  Bacula File Daemon estimate.c
22  *   Make and estimate of the number of files and size to be saved.
23  *
24  *    Kern Sibbald, September MMI
25  *
26  *   Version $Id$
27  *
28  */
29
30 #include "bacula.h"
31 #include "filed.h"
32
33 static int tally_file(JCR *jcr, FF_PKT *ff_pkt, bool);
34
35 /*
36  * Find all the requested files and count them.
37  */
38 int make_estimate(JCR *jcr)
39 {
40    int stat;
41
42    jcr->setJobStatus(JS_Running);
43
44    set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
45    /* in accurate mode, we overwrite the find_one check function */
46    if (jcr->accurate) {
47       set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
48    }
49
50    stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, plugin_estimate);
51    accurate_free(jcr);
52    return stat;
53 }
54
55 /*
56  * Called here by find() for each file included.
57  *
58  */
59 static int tally_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
60 {
61    ATTR attr;
62
63    if (job_canceled(jcr)) {
64       return 0;
65    }
66    switch (ff_pkt->type) {
67    case FT_LNKSAVED:                  /* Hard linked, file already saved */
68    case FT_REGE:
69    case FT_REG:
70    case FT_LNK:
71    case FT_NORECURSE:
72    case FT_NOFSCHG:
73    case FT_INVALIDFS:
74    case FT_INVALIDDT:
75    case FT_REPARSE:
76    case FT_JUNCTION:
77    case FT_DIREND:
78    case FT_SPEC:
79    case FT_RAW:
80    case FT_FIFO:
81       break;
82    case FT_DIRBEGIN:
83    case FT_NOACCESS:
84    case FT_NOFOLLOW:
85    case FT_NOSTAT:
86    case FT_DIRNOCHG:
87    case FT_NOCHG:
88    case FT_ISARCH:
89    case FT_NOOPEN:
90    default:
91       return 1;
92    }
93
94    if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode)) {
95       if (ff_pkt->statp.st_size > 0) {
96          jcr->JobBytes += ff_pkt->statp.st_size;
97       }
98 #ifdef HAVE_DARWIN_OS
99       if (ff_pkt->flags & FO_HFSPLUS) {
100          if (ff_pkt->hfsinfo.rsrclength > 0) {
101             jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
102          }
103          jcr->JobBytes += 32;    /* Finder info */
104       }
105 #endif
106    }
107    jcr->num_files_examined++;
108    jcr->JobFiles++;                  /* increment number of files seen */
109    if (jcr->listing) {
110       memcpy(&attr.statp, &ff_pkt->statp, sizeof(struct stat));
111       attr.type = ff_pkt->type;
112       attr.ofname = (POOLMEM *)ff_pkt->fname;
113       attr.olname = (POOLMEM *)ff_pkt->link;
114       print_ls_output(jcr, &attr);
115    }
116    /* TODO: Add loop over jcr->file_list to get Accurate deleted files*/
117    return 1;
118 }