]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/estimate.c
Update version
[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-2003 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(jcr->ff, jcr->incremental, jcr->mtime);
45
46    stat = find_files(jcr->ff, tally_file, (void *)jcr);
47
48    return stat;
49 }          
50
51 /* 
52  * Called here by find() for each file included.
53  *
54  */
55 static int tally_file(FF_PKT *ff_pkt, void *ijcr)
56 {
57    JCR *jcr = (JCR *) ijcr;
58
59    switch (ff_pkt->type) {
60    case FT_LNKSAVED:                  /* Hard linked, file already saved */
61       break;
62    case FT_REGE:
63    case FT_REG:
64    case FT_LNK:
65    case FT_DIR:
66    case FT_SPEC:
67    case FT_RAW:
68    case FT_FIFO:
69       break;
70    case FT_NOACCESS:
71    case FT_NOFOLLOW:
72    case FT_NOSTAT:
73    case FT_DIRNOCHG:
74    case FT_NOCHG:
75    case FT_ISARCH:
76    case FT_NORECURSE:
77    case FT_NOFSCHG:
78    case FT_NOOPEN:
79    default:
80       return 1;
81    }
82
83    if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode) && 
84          ff_pkt->statp.st_size > 0) {
85       jcr->JobBytes += ff_pkt->statp.st_size;
86    }
87
88    jcr->JobFiles++;                  /* increment number of files sent */
89    return 1;
90 }