]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/estimate.c
fa020ff76b2518a809c55536c0a6af93de4c3084
[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  */
8 /*
9    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28 #include "bacula.h"
29 #include "filed.h"
30
31 static int tally_file(FF_PKT *ff_pkt, void *pkt);
32
33 /* 
34  * Find all the requested files and count them.
35  */
36 int make_estimate(JCR *jcr)
37 {
38    int stat;
39
40    jcr->JobStatus = JS_Running;
41
42    set_find_options(jcr->ff, jcr->incremental, jcr->mtime);
43
44    stat = find_files(jcr->ff, tally_file, (void *)jcr);
45
46    return stat;
47 }          
48
49 /* 
50  * Called here by find() for each file included.
51  *
52  *  *****FIXME*****   add FSMs File System Modules
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       break;
68    case FT_NOACCESS:
69    case FT_NOFOLLOW:
70    case FT_NOSTAT:
71    case FT_DIRNOCHG:
72    case FT_NOCHG:
73    case FT_ISARCH:
74    case FT_NORECURSE:
75    case FT_NOFSCHG:
76    case FT_NOOPEN:
77    default:
78       return 1;
79    }
80
81    if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode) && 
82          ff_pkt->statp.st_size > 0) {
83       jcr->JobBytes += ff_pkt->statp.st_size;
84    }
85
86    jcr->JobFiles++;                  /* increment number of files sent */
87    return 1;
88 }