]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/estimate.c
Apply Preben 'Peppe' Guldberg <peppe@wielders.org>
[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    Copyright (C) 2000-2004 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "filed.h"
32
33 static int tally_file(FF_PKT *ff_pkt, void *pkt);
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->JobStatus = JS_Running;
43
44    set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
45    stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, (void *)jcr);
46
47    return stat;
48 }
49
50 /*
51  * Called here by find() for each file included.
52  *
53  */
54 static int tally_file(FF_PKT *ff_pkt, void *ijcr)
55 {
56    JCR *jcr = (JCR *)ijcr;
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_DIREND:
71    case FT_SPEC:
72    case FT_RAW:
73    case FT_FIFO:
74       break;
75    case FT_DIRBEGIN:
76    case FT_NOACCESS:
77    case FT_NOFOLLOW:
78    case FT_NOSTAT:
79    case FT_DIRNOCHG:
80    case FT_NOCHG:
81    case FT_ISARCH:
82    case FT_NOOPEN:
83    default:
84       return 1;
85    }
86
87    if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode)) {
88       if (ff_pkt->statp.st_size > 0) {
89          jcr->JobBytes += ff_pkt->statp.st_size;
90       }
91 #ifdef HAVE_DARWIN_OS
92       if (ff_pkt->flags & FO_HFSPLUS) {
93          if (ff_pkt->hfsinfo.rsrclength > 0) {
94             jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
95          }
96          jcr->JobBytes += 32;    /* Finder info */
97       }
98 #endif
99    }
100    jcr->num_files_examined++;
101    jcr->JobFiles++;                  /* increment number of files seen */
102    if (jcr->listing) {
103       memcpy(&attr.statp, &ff_pkt->statp, sizeof(struct stat));
104       attr.type = ff_pkt->type;
105       attr.ofname = (POOLMEM *)ff_pkt->fname;
106       attr.olname = (POOLMEM *)ff_pkt->link;
107       print_ls_output(jcr, &attr);
108    }
109    return 1;
110 }