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