]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/find.c
First cut 1.27 see kes23Oct02
[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, 2001, 2002 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 /* Imported functions */
32 int find_one_file(FF_PKT *ff, int handle_file(FF_PKT *ff_pkt, void *hpkt), 
33                void *pkt, char *p, dev_t parent_device, int top_level);
34 void term_find_one(FF_PKT *ff);
35
36 size_t name_max;               /* filename max length */
37 size_t path_max;               /* path name max length */
38
39
40 /* ****FIXME**** debug until stable */
41 #undef bmalloc
42 #define bmalloc(x) sm_malloc(__FILE__, __LINE__, x)
43
44
45 /* 
46  * Initialize the find files "global" variables
47  */
48 FF_PKT *init_find_files()
49 {
50   FF_PKT *ff;    
51
52   ff = (FF_PKT *) bmalloc(sizeof(FF_PKT));
53   memset(ff, 0, sizeof(FF_PKT));
54
55   ff->sys_fname = get_pool_memory(PM_FNAME);
56
57   init_include_exclude_files(ff);           /* init lists */
58   ff->mtime_only = 1;
59   ff->one_file_system = 1;
60
61    /* Get system path and filename maximum lengths */
62    path_max = pathconf(".", _PC_PATH_MAX);
63    if (path_max < 1024) {
64       path_max = 1024;
65    }
66
67    name_max = pathconf(".", _PC_NAME_MAX);
68    if (name_max < 1024) {
69       name_max = 1024;
70    }
71    path_max++;                        /* add for EOS */
72    name_max++;                        /* add for EOS */
73
74   Dmsg1(100, "init_find_files ff=%p\n", ff);
75   return ff;
76 }
77
78 /* 
79  * Set find_files options. For the moment, we only
80  * provide for full/incremental saves, and setting
81  * of save_time. For additional options, see above
82  */
83 void
84 set_find_options(FF_PKT *ff, int incremental, time_t save_time)
85 {
86   Dmsg0(100, "Enter set_find_options()\n");
87   ff->incremental = incremental;
88   ff->save_time = save_time;
89   Dmsg0(100, "Leave set_find_options()\n");
90 }
91
92 /* 
93  * Find all specified files (determined by calls to 
94  * name_add()
95  * This routine calls the (handle_file) subroutine with all
96  * sorts of good information for the final disposition of
97  * the file.
98  * 
99  * Call this subroutine with a callback subroutine as the first
100  * argument and a packet as the second argument, this packet
101  * will be passed back to the callback subroutine as the last
102  * argument.
103  *
104  * The callback subroutine gets called with:
105  *  arg1 -- the FF_PKT containing filename, link, stat, ftype, flags, etc
106  *  arg2 -- the user supplied packet
107  *
108  */
109 int
110 find_files(FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt), void *his_pkt) 
111 {
112    char *file;
113    struct s_included_file *inc = NULL;
114
115    while ((inc = get_next_included_file(ff, inc))) {
116       file = inc->fname;
117       strcpy(ff->VerifyOpts, inc->VerifyOpts); /* Copy options for this file */
118       Dmsg1(50, "find_files: file=%s\n", file);
119       if (!file_is_excluded(ff, file)) {
120          if (!find_one_file(ff, callback, his_pkt, file, (dev_t)-1, 1)) {
121             return 0;                  /* error return */
122          }
123       }
124    }
125    return 1;
126 }
127
128 /*
129  * Terminate find_files() and release
130  * all allocated memory   
131  */
132 void
133 term_find_files(FF_PKT *ff)
134 {
135   term_include_exclude_files(ff);
136   term_find_one(ff);
137   free_pool_memory(ff->sys_fname);
138   free(ff);
139   return;
140 }