Welcome to mirror list, hosted at ThFree Co, Russian Federation.

estimate.cc « filed « src « core - github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a423cbc23fb057e42136e8aa2529297897556382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
   BAREOS® - Backup Archiving REcovery Open Sourced

   Copyright (C) 2001-2008 Free Software Foundation Europe e.V.
   Copyright (C) 2016-2022 Bareos GmbH & Co. KG

   This program is Free Software; you can redistribute it and/or
   modify it under the terms of version three of the GNU Affero General Public
   License as published by the Free Software Foundation and included
   in the file LICENSE.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301, USA.
*/
// Kern Sibbald, September MMI
/**
 * @file
 * Bareos File Daemon estimate.c
 * Make and estimate of the number of files and size to be saved.
 */

#include "include/bareos.h"
#include "filed/filed.h"
#include "filed/jcr_private.h"
#include "filed/accurate.h"

namespace filedaemon {

static int TallyFile(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool);

// Find all the requested files and count them.
int MakeEstimate(JobControlRecord* jcr)
{
  int status;

  jcr->setJobStatus(JS_Running);

  SetFindOptions((FindFilesPacket*)jcr->impl->ff, jcr->impl->incremental,
                 jcr->impl->since_time);
  /* in accurate mode, we overwrite the find_one check function */
  if (jcr->accurate) {
    SetFindChangedFunction((FindFilesPacket*)jcr->impl->ff, AccurateCheckFile);
  }

  status = FindFiles(jcr, (FindFilesPacket*)jcr->impl->ff, TallyFile,
                     PluginEstimate);
  AccurateFree(jcr);
  return status;
}

/**
 * Called here by find() for each file included.
 *
 */
static int TallyFile(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool)
{
  Attributes attr;

  if (JobCanceled(jcr)) { return 0; }
  switch (ff_pkt->type) {
    case FT_LNKSAVED: /* Hard linked, file already saved */
    case FT_REGE:
    case FT_REG:
    case FT_LNK:
    case FT_NORECURSE:
    case FT_NOFSCHG:
    case FT_INVALIDFS:
    case FT_INVALIDDT:
    case FT_REPARSE:
    case FT_JUNCTION:
    case FT_DIREND:
    case FT_SPEC:
    case FT_RAW:
    case FT_FIFO:
      break;
    case FT_DIRBEGIN:
    case FT_NOACCESS:
    case FT_NOFOLLOW:
    case FT_NOSTAT:
    case FT_DIRNOCHG:
    case FT_NOCHG:
    case FT_ISARCH:
    case FT_NOOPEN:
    default:
      return 1;
  }

  if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode)) {
    if (ff_pkt->statp.st_size > 0) { jcr->JobBytes += ff_pkt->statp.st_size; }
#ifdef HAVE_DARWIN_OS
    if (BitIsSet(FO_HFSPLUS, ff_pkt->flags)) {
      if (ff_pkt->hfsinfo.rsrclength > 0) {
        jcr->JobBytes += ff_pkt->hfsinfo.rsrclength;
      }
      jcr->JobBytes += 32; /* Finder info */
    }
#endif
  }
  jcr->impl->num_files_examined++;
  jcr->JobFiles++; /* increment number of files seen */
  if (jcr->impl->listing) {
    memcpy(&attr.statp, &ff_pkt->statp, sizeof(struct stat));
    attr.type = ff_pkt->type;
    attr.ofname = (POOLMEM*)ff_pkt->fname;
    attr.olname = (POOLMEM*)ff_pkt->link;
    PrintLsOutput(jcr, &attr);
  }
  return 1;
}
} /* namespace filedaemon */