]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/find.c
mtimeonly and keepatime in Include + first cut disk seeking + test win32 installer
[bacula/bacula] / bacula / src / findlib / find.c
1 /*
2  * Main routine for finding files on a file system.
3  *  The heart of the work is done in find_one.c
4  *
5  *  Kern E. Sibbald, MM
6  */
7 /*
8    Copyright (C) 2000-2003 Kern Sibbald and John Walker
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2 of
13    the License, or (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public
21    License along with this program; if not, write to the Free
22    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23    MA 02111-1307, USA.
24
25  */
26
27
28 #include "bacula.h"
29 #include "find.h"
30
31
32 int32_t name_max;              /* filename max length */
33 int32_t path_max;              /* path name max length */
34
35
36 /* ****FIXME**** debug until stable */
37 #undef bmalloc
38 #define bmalloc(x) sm_malloc(__FILE__, __LINE__, x)
39
40
41 /* 
42  * Initialize the find files "global" variables
43  */
44 FF_PKT *init_find_files()
45 {
46   FF_PKT *ff;    
47
48   ff = (FF_PKT *)bmalloc(sizeof(FF_PKT));
49   memset(ff, 0, sizeof(FF_PKT));
50
51   ff->sys_fname = get_pool_memory(PM_FNAME);
52
53   init_include_exclude_files(ff);           /* init lists */
54
55    /* Get system path and filename maximum lengths */
56    path_max = pathconf(".", _PC_PATH_MAX);
57    if (path_max < 1024) {
58       path_max = 1024;
59    }
60
61    name_max = pathconf(".", _PC_NAME_MAX);
62    if (name_max < 1024) {
63       name_max = 1024;
64    }
65    path_max++;                        /* add for EOS */
66    name_max++;                        /* add for EOS */
67
68   Dmsg1(100, "init_find_files ff=%p\n", ff);
69   return ff;
70 }
71
72 /* 
73  * Set find_files options. For the moment, we only
74  * provide for full/incremental saves, and setting
75  * of save_time. For additional options, see above
76  */
77 void
78 set_find_options(FF_PKT *ff, int incremental, time_t save_time)
79 {
80   Dmsg0(100, "Enter set_find_options()\n");
81   ff->incremental = incremental;
82   ff->save_time = save_time;
83   Dmsg0(100, "Leave set_find_options()\n");
84 }
85
86 /* 
87  * Find all specified files (determined by calls to 
88  * name_add()
89  * This routine calls the (handle_file) subroutine with all
90  * sorts of good information for the final disposition of
91  * the file.
92  * 
93  * Call this subroutine with a callback subroutine as the first
94  * argument and a packet as the second argument, this packet
95  * will be passed back to the callback subroutine as the last
96  * argument.
97  *
98  * The callback subroutine gets called with:
99  *  arg1 -- the FF_PKT containing filename, link, stat, ftype, flags, etc
100  *  arg2 -- the user supplied packet
101  *
102  */
103 int
104 find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void *his_pkt) 
105 {
106    struct s_included_file *inc = NULL;
107
108    while (!job_canceled(jcr) && (inc = get_next_included_file(ff, inc))) {
109       /* Copy options for this file */
110       bstrncpy(ff->VerifyOpts, inc->VerifyOpts, sizeof(ff->VerifyOpts)); 
111       Dmsg1(50, "find_files: file=%s\n", inc->fname);
112       if (!file_is_excluded(ff, inc->fname)) {
113          if (!find_one_file(jcr, ff, callback, his_pkt, inc->fname, 
114               (dev_t)-1, 1)) {
115             return 0;                  /* error return */
116          }
117       }
118    }
119    return 1;
120 }
121
122 /*
123  * Terminate find_files() and release
124  * all allocated memory   
125  */
126 int
127 term_find_files(FF_PKT *ff)
128 {
129   int hard_links;
130
131   term_include_exclude_files(ff);
132   free_pool_memory(ff->sys_fname);
133   hard_links = term_find_one(ff);
134   free(ff);
135   return hard_links;
136 }