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