Line data Source code
1 : /*
2 : Bacula® - The Network Backup Solution
3 :
4 : Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
5 :
6 : The main author of Bacula is Kern Sibbald, with contributions from
7 : many others, a complete list can be found in the file AUTHORS.
8 : This program is Free Software; you can redistribute it and/or
9 : modify it under the terms of version three of the GNU Affero General Public
10 : License as published by the Free Software Foundation and included
11 : in the file LICENSE.
12 :
13 : This program is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU Affero General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 : 02110-1301, USA.
22 :
23 : Bacula® is a registered trademark of Kern Sibbald.
24 : The licensor of Bacula is the Free Software Foundation Europe
25 : (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 : Switzerland, email:ftf@fsfeurope.org.
27 : */
28 : /*
29 : This file was derived from GNU TAR source code. Except for a few key
30 : ideas, it has been entirely rewritten for Bacula.
31 :
32 : Kern Sibbald, MM
33 :
34 : Thanks to the TAR programmers.
35 : */
36 : /*
37 : This file was derived from the findlib code from bacula-5.0.3, and
38 : heavily modified. Therefore, I have retained the bacula copyright notice.
39 : The specific bacula files were:
40 : src/findlib/find.c
41 : src/findlib/find_one.c.
42 : The comment by Kern above, about TAR, was from find_one.c.
43 :
44 : Graham Keeling, 2014.
45 : */
46 :
47 : #include "../burp.h"
48 : #include "../alloc.h"
49 : #include "../conf.h"
50 : #include "../fsops.h"
51 : #include "../linkhash.h"
52 : #include "../log.h"
53 : #include "../pathcmp.h"
54 : #include "../prepend.h"
55 : #include "../regexp.h"
56 : #include "../strlist.h"
57 : #include "find.h"
58 :
59 : #ifdef HAVE_LINUX_OS
60 : #include <sys/statfs.h>
61 : #endif
62 : #ifdef HAVE_SUN_OS
63 : #include <sys/statvfs.h>
64 : #endif
65 :
66 : static int (*my_send_file)(struct asfd *, struct FF_PKT *, struct conf **);
67 :
68 : // Initialize the find files "global" variables
69 13 : struct FF_PKT *find_files_init(
70 : int callback(struct asfd *asfd, struct FF_PKT *ff, struct conf **confs))
71 : {
72 : struct FF_PKT *ff;
73 :
74 13 : if(!(ff=(struct FF_PKT *)calloc_w(1, sizeof(struct FF_PKT), __func__))
75 13 : || linkhash_init())
76 : return NULL;
77 13 : my_send_file=callback;
78 :
79 13 : return ff;
80 : }
81 :
82 13 : void find_files_free(struct FF_PKT **ff)
83 : {
84 13 : linkhash_free();
85 13 : free_v((void **)ff);
86 13 : }
87 :
88 : // Return 1 to include the file, 0 to exclude it.
89 52 : static int in_include_ext(struct strlist *incext, const char *fname)
90 : {
91 52 : int i=0;
92 : struct strlist *l;
93 52 : const char *cp=NULL;
94 : // If not doing include_ext, let the file get backed up.
95 52 : if(!incext) return 1;
96 :
97 : // The flag of the first item contains the maximum number of characters
98 : // that need to be checked.
99 : // FIX THIS: The next two functions do things very similar to this.
100 32 : for(cp=fname+strlen(fname)-1; i<incext->flag && cp>=fname; cp--, i++)
101 : {
102 14 : if(*cp!='.') continue;
103 3 : for(l=incext; l; l=l->next)
104 7 : if(!strcasecmp(l->path, cp+1))
105 : return 1;
106 : // If file has no extension, it cannot be included.
107 : return 0;
108 : }
109 : return 0;
110 : }
111 :
112 128 : static int in_exclude_ext(struct strlist *excext, const char *fname)
113 : {
114 128 : int i=0;
115 : struct strlist *l;
116 128 : const char *cp=NULL;
117 : // If not doing exclude_ext, let the file get backed up.
118 128 : if(!excext) return 0;
119 :
120 : // The flag of the first item contains the maximum number of characters
121 : // that need to be checked.
122 50 : for(cp=fname+strlen(fname)-1; i<excext->flag && cp>=fname; cp--, i++)
123 : {
124 20 : if(*cp!='.') continue;
125 5 : for(l=excext; l; l=l->next)
126 8 : if(!strcasecmp(l->path, cp+1))
127 : return 1;
128 : // If file has no extension, it is included.
129 : return 0;
130 : }
131 : return 0;
132 : }
133 :
134 : // Returns the level of compression.
135 8 : int in_exclude_comp(struct strlist *excom, const char *fname, int compression)
136 : {
137 8 : int i=0;
138 : struct strlist *l;
139 8 : const char *cp=NULL;
140 : // If not doing compression, or there are no excludes, return
141 : // straight away.
142 8 : if(!compression || !excom) return compression;
143 :
144 : // The flag of the first item contains the maximum number of characters
145 : // that need to be checked.
146 0 : for(cp=fname+strlen(fname)-1; i<excom->flag && cp>=fname; cp--, i++)
147 : {
148 0 : if(*cp!='.') continue;
149 0 : for(l=excom; l; l=l->next)
150 0 : if(!strcasecmp(l->path, cp+1))
151 : return 0;
152 : return compression;
153 : }
154 : return compression;
155 : }
156 :
157 : /* Return 1 to include the file, 0 to exclude it. */
158 : /* Currently not used - it needs more thinking about. */
159 : /*
160 : int in_include_regex(struct strlist *increg, const char *fname)
161 : {
162 : // If not doing include_regex, let the file get backed up.
163 : if(!increg) return 1;
164 : for(; increg; increg=increg->next)
165 : if(regex_check(increg->re, fname))
166 : return 1;
167 : return 0;
168 : }
169 : */
170 :
171 125 : static int in_exclude_regex(struct strlist *excreg, const char *fname)
172 : {
173 : // If not doing exclude_regex, let the file get backed up.
174 145 : for(; excreg; excreg=excreg->next)
175 23 : if(regex_check(excreg->re, fname))
176 : return 1;
177 : return 0;
178 : }
179 :
180 : // When recursing into directories, do not want to check the include_ext list.
181 : #ifndef UTEST
182 : static
183 : #endif
184 128 : int file_is_included_no_incext(struct conf **confs, const char *fname)
185 : {
186 128 : int ret=0;
187 128 : int longest=0;
188 128 : int matching=0;
189 128 : struct strlist *l=NULL;
190 128 : struct strlist *best=NULL;
191 :
192 128 : if(in_exclude_ext(get_strlist(confs[OPT_EXCEXT]), fname)
193 125 : || in_exclude_regex(get_strlist(confs[OPT_EXCREG]), fname))
194 : return 0;
195 :
196 : // Check include/exclude directories.
197 326 : for(l=get_strlist(confs[OPT_INCEXCDIR]); l; l=l->next)
198 : {
199 204 : matching=is_subdir(l->path, fname);
200 204 : if(matching>=longest)
201 : {
202 152 : longest=matching;
203 152 : best=l;
204 : }
205 : }
206 122 : if(!best) ret=0;
207 122 : else ret=best->flag;
208 :
209 122 : return ret;
210 : }
211 :
212 66 : static int file_is_included(struct conf **confs,
213 : const char *fname, bool top_level)
214 : {
215 : // Always save the top level directory.
216 : // This will help in the simulation of browsing backups because it
217 : // will mean that there is always a directory before any files:
218 : // d /home/graham
219 : // f /home/graham/somefile.txt
220 : // This means that we can use the stats of the directory (/home/graham
221 : // in this example) as the stats of the parent directories (/home,
222 : // for example). Trust me on this.
223 66 : if(!top_level
224 52 : && !in_include_ext(get_strlist(confs[OPT_INCEXT]), fname)) return 0;
225 :
226 63 : return file_is_included_no_incext(confs, fname);
227 : }
228 :
229 0 : static int fs_change_is_allowed(struct conf **confs, const char *fname)
230 : {
231 : struct strlist *l;
232 0 : if(get_int(confs[OPT_CROSS_ALL_FILESYSTEMS])) return 1;
233 0 : for(l=get_strlist(confs[OPT_FSCHGDIR]); l; l=l->next)
234 0 : if(!strcmp(l->path, fname)) return 1;
235 : return 0;
236 : }
237 :
238 6 : static int need_to_read_fifo(struct conf **confs, const char *fname)
239 : {
240 : struct strlist *l;
241 6 : if(get_int(confs[OPT_READ_ALL_FIFOS])) return 1;
242 7 : for(l=get_strlist(confs[OPT_FIFOS]); l; l=l->next)
243 5 : if(!strcmp(l->path, fname)) return 1;
244 : return 0;
245 : }
246 :
247 2 : static int need_to_read_blockdev(struct conf **confs, const char *fname)
248 : {
249 : struct strlist *l;
250 2 : if(get_int(confs[OPT_READ_ALL_BLOCKDEVS])) return 1;
251 3 : for(l=get_strlist(confs[OPT_BLOCKDEVS]); l; l=l->next)
252 3 : if(!strcmp(l->path, fname)) return 1;
253 : return 0;
254 : }
255 :
256 25 : static int nobackup_directory(struct strlist *nobackup, const char *path)
257 : {
258 : struct stat statp;
259 60 : for(; nobackup; nobackup=nobackup->next)
260 : {
261 7 : char *fullpath=NULL;
262 7 : if(!(fullpath=prepend_s(path, nobackup->path)))
263 2 : return -1;
264 14 : if(!lstat(fullpath, &statp))
265 : {
266 2 : free_w(&fullpath);
267 2 : return 1;
268 : }
269 5 : free_w(&fullpath);
270 : }
271 : return 0;
272 : }
273 :
274 29 : static int file_size_match(struct FF_PKT *ff_pkt, struct conf **confs)
275 : {
276 : uint64_t sizeleft;
277 29 : uint64_t min_file_size=get_uint64_t(confs[OPT_MIN_FILE_SIZE]);
278 29 : uint64_t max_file_size=get_uint64_t(confs[OPT_MAX_FILE_SIZE]);
279 29 : sizeleft=(uint64_t)ff_pkt->statp.st_size;
280 :
281 29 : if(min_file_size && sizeleft<min_file_size)
282 : return 0;
283 28 : if(max_file_size && sizeleft>max_file_size)
284 : return 0;
285 : return 1;
286 : }
287 :
288 : // Last checks before actually processing the file system entry.
289 66 : static int my_send_file_w(struct asfd *asfd, struct FF_PKT *ff, bool top_level, struct conf **confs)
290 : {
291 66 : if(!file_is_included(confs, ff->fname, top_level)) return 0;
292 :
293 : // Doing the file size match here also catches hard links.
294 63 : if(S_ISREG(ff->statp.st_mode)
295 29 : && !file_size_match(ff, confs))
296 : return 0;
297 :
298 : /*
299 : * Handle hard linked files
300 : * Maintain a list of hard linked files already backed up. This
301 : * allows us to ensure that the data of each file gets backed
302 : * up only once.
303 : */
304 61 : if(ff->statp.st_nlink > 1
305 56 : && (S_ISREG(ff->statp.st_mode)
306 28 : || S_ISCHR(ff->statp.st_mode)
307 24 : || S_ISBLK(ff->statp.st_mode)
308 24 : || S_ISFIFO(ff->statp.st_mode)
309 24 : || S_ISSOCK(ff->statp.st_mode)))
310 : {
311 : struct f_link *lp;
312 4 : struct f_link **bucket=NULL;
313 :
314 4 : if((lp=linkhash_search(&ff->statp, &bucket)))
315 : {
316 2 : if(!strcmp(lp->name, ff->fname)) return 0;
317 2 : ff->link=lp->name;
318 : /* Handle link, file already saved */
319 2 : ff->type=FT_LNK_H;
320 : }
321 : else
322 : {
323 2 : if(linkhash_add(ff->fname,
324 : &ff->statp, bucket)) return -1;
325 : }
326 : }
327 :
328 61 : return my_send_file(asfd, ff, confs);
329 : }
330 :
331 : static int found_regular_file(struct asfd *asfd,
332 : struct FF_PKT *ff_pkt, struct conf **confs,
333 : bool top_level)
334 : {
335 31 : ff_pkt->type=FT_REG;
336 31 : return my_send_file_w(asfd, ff_pkt, top_level, confs);
337 : }
338 :
339 1 : static int found_soft_link(struct asfd *asfd, struct FF_PKT *ff_pkt, struct conf **confs,
340 : char *fname, bool top_level)
341 : {
342 : ssize_t size;
343 1 : char *buffer=(char *)alloca(fs_full_path_max+102);
344 :
345 2 : if((size=readlink(fname, buffer, fs_full_path_max+101))<0)
346 : {
347 : /* Could not follow link */
348 0 : ff_pkt->type=FT_NOFOLLOW;
349 : }
350 : else
351 : {
352 1 : buffer[size]=0;
353 1 : ff_pkt->link=buffer; /* point to link */
354 1 : ff_pkt->type=FT_LNK_S; /* got a soft link */
355 : }
356 1 : return my_send_file_w(asfd, ff_pkt, top_level, confs);
357 : }
358 :
359 13 : static int fstype_matches(struct asfd *asfd,
360 : struct conf **confs, const char *fname, int inex)
361 : {
362 : #if defined(HAVE_LINUX_OS) \
363 : || defined(HAVE_SUN_OS)
364 : struct strlist *l;
365 : #if defined(HAVE_LINUX_OS)
366 : struct statfs buf;
367 13 : if(statfs(fname, &buf))
368 : #elif defined(HAVE_SUN_OS)
369 : struct statvfs buf;
370 : if(statvfs(fname, &buf))
371 : #endif
372 : {
373 0 : logw(asfd, get_cntr(confs), "Could not statfs %s: %s\n",
374 0 : fname, strerror(errno));
375 0 : return -1;
376 : }
377 13 : for(l=get_strlist(confs[inex]); l; l=l->next)
378 : #if defined(HAVE_LINUX_OS)
379 0 : if(l->flag==buf.f_type)
380 : #elif defined(HAVE_SUN_OS)
381 : if(strcmp(l->path,buf.f_basetype)==0)
382 : #endif
383 : return -1;
384 : #endif
385 : return 0;
386 : }
387 :
388 : #if defined(HAVE_WIN32)
389 : static void windows_reparse_point_fiddling(struct FF_PKT *ff_pkt)
390 : {
391 : /*
392 : * We have set st_rdev to 1 if it is a reparse point, otherwise 0,
393 : * if st_rdev is 2, it is a mount point.
394 : */
395 : /*
396 : * A reparse point (WIN32_REPARSE_POINT)
397 : * is something special like one of the following:
398 : * IO_REPARSE_TAG_DFS 0x8000000A
399 : * IO_REPARSE_TAG_DFSR 0x80000012
400 : * IO_REPARSE_TAG_HSM 0xC0000004
401 : * IO_REPARSE_TAG_HSM2 0x80000006
402 : * IO_REPARSE_TAG_SIS 0x80000007
403 : * IO_REPARSE_TAG_SYMLINK 0xA000000C
404 : *
405 : * A junction point is a:
406 : * IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
407 : * which can be either a link to a Volume (WIN32_MOUNT_POINT)
408 : * or a link to a directory (WIN32_JUNCTION_POINT)
409 : *
410 : * Ignore WIN32_REPARSE_POINT and WIN32_JUNCTION_POINT
411 : */
412 : if (ff_pkt->statp.st_rdev == WIN32_REPARSE_POINT) {
413 : ff_pkt->type = FT_REPARSE;
414 : } else if (ff_pkt->statp.st_rdev == WIN32_JUNCTION_POINT) {
415 : ff_pkt->type = FT_JUNCTION;
416 : }
417 : }
418 : #endif
419 :
420 : // Prototype because process_entries_in_directory() recurses using find_files().
421 : static int find_files(struct asfd *asfd,
422 : struct FF_PKT *ff_pkt, struct conf **confs,
423 : char *fname, dev_t parent_device, bool top_level);
424 :
425 17 : static int process_entries_in_directory(struct asfd *asfd, char **nl,
426 : int count, char **link, size_t len, size_t *link_len,
427 : struct conf **confs, struct FF_PKT *ff_pkt, dev_t our_device)
428 : {
429 17 : int m=0;
430 17 : int ret=0;
431 76 : for(m=0; m<count; m++)
432 : {
433 : size_t i;
434 59 : char *p=NULL;
435 59 : char *q=NULL;
436 : size_t plen;
437 :
438 59 : p=nl[m];
439 :
440 59 : if(strlen(p)+len>=*link_len)
441 : {
442 0 : *link_len=len+strlen(p)+1;
443 0 : if(!(*link=(char *)
444 0 : realloc_w(*link, (*link_len)+1, __func__)))
445 : return -1;
446 : }
447 59 : q=(*link)+len;
448 59 : plen=strlen(p);
449 159 : for(i=0; i<plen; i++)
450 100 : *q++=*p++;
451 59 : *q=0;
452 59 : ff_pkt->flen=i;
453 :
454 59 : if(file_is_included_no_incext(confs, *link))
455 : {
456 50 : ret=find_files(asfd, ff_pkt,
457 : confs, *link, our_device, false /*top_level*/);
458 : }
459 : else
460 : {
461 : struct strlist *x;
462 : // Excluded, but there might be a subdirectory that is
463 : // included.
464 26 : for(x=get_strlist(confs[OPT_INCEXCDIR]); x; x=x->next)
465 : {
466 17 : if(x->flag
467 14 : && is_subdir(*link, x->path))
468 : {
469 : struct strlist *y;
470 4 : if((ret=find_files(asfd, ff_pkt,
471 : confs, x->path,
472 : our_device, false)))
473 : break;
474 : // Now need to skip subdirectories of
475 : // the thing that we just stuck in
476 : // find_one_file(), or we might get
477 : // some things backed up twice.
478 6 : for(y=x->next; y; y=y->next)
479 2 : if(y->next
480 1 : && is_subdir(x->path, y->path))
481 1 : y=y->next;
482 : }
483 : }
484 : }
485 59 : free_w(&(nl[m]));
486 59 : if(ret) break;
487 : }
488 17 : return ret;
489 : }
490 :
491 25 : static int found_directory(struct asfd *asfd,
492 : struct FF_PKT *ff_pkt, struct conf **confs,
493 : char *fname, dev_t parent_device, bool top_level)
494 : {
495 25 : int ret=-1;
496 25 : char *link=NULL;
497 : size_t link_len;
498 : size_t len;
499 25 : int nbret=0;
500 25 : int count=0;
501 : dev_t our_device;
502 25 : char **nl=NULL;
503 :
504 25 : our_device=ff_pkt->statp.st_dev;
505 :
506 25 : if((nbret=nobackup_directory(get_strlist(confs[OPT_NOBACKUP]),
507 25 : ff_pkt->fname)))
508 : {
509 2 : if(nbret<0) goto end; // Error.
510 2 : ret=0; // Do not back it up.
511 2 : goto end;
512 : }
513 :
514 : /* Build a canonical directory name with a trailing slash in link var */
515 23 : len=strlen(fname);
516 23 : link_len=len+200;
517 23 : if(!(link=(char *)malloc_w(link_len+2, __func__)))
518 : goto end;
519 23 : snprintf(link, link_len, "%s", fname);
520 :
521 : /* Strip all trailing slashes */
522 23 : while(len >= 1 && IsPathSeparator(link[len - 1])) len--;
523 : /* add back one */
524 23 : link[len++]='/';
525 23 : link[len]=0;
526 :
527 23 : ff_pkt->link=link;
528 23 : ff_pkt->type=FT_DIR;
529 :
530 : #if defined(HAVE_WIN32)
531 : windows_reparse_point_fiddling(ff_pkt);
532 : #endif
533 :
534 23 : if(my_send_file_w(asfd, ff_pkt, top_level, confs))
535 : goto end;
536 23 : if(ff_pkt->type==FT_REPARSE || ff_pkt->type==FT_JUNCTION)
537 : {
538 : // Ignore.
539 : ret=0;
540 : goto end;
541 : }
542 :
543 23 : if(top_level
544 10 : || (parent_device!=ff_pkt->statp.st_dev
545 : #if defined(HAVE_WIN32)
546 : || ff_pkt->statp.st_rdev==WIN32_MOUNT_POINT
547 : #endif
548 : ))
549 : {
550 13 : if(fstype_matches(asfd, confs, ff_pkt->fname, OPT_EXCFS)
551 13 : || (get_strlist(confs[OPT_INCFS])
552 0 : && !fstype_matches(asfd, confs, ff_pkt->fname, OPT_INCFS)))
553 : {
554 0 : if(top_level)
555 0 : logw(asfd, get_cntr(confs),
556 : "Skipping '%s' because of file system include or exclude.\n", fname);
557 0 : ret=my_send_file_w(asfd, ff_pkt, top_level, confs);
558 0 : goto end;
559 : }
560 13 : if(!top_level && !fs_change_is_allowed(confs, ff_pkt->fname))
561 : {
562 0 : ff_pkt->type=FT_NOFSCHG;
563 : // Just backup the directory and return.
564 0 : ret=my_send_file_w(asfd, ff_pkt, top_level, confs);
565 0 : goto end;
566 : }
567 : }
568 :
569 23 : ff_pkt->link=ff_pkt->fname;
570 :
571 23 : errno=0;
572 23 : switch(entries_in_directory_alphasort(fname,
573 : &nl, &count, get_int(confs[OPT_ATIME])))
574 : {
575 : case 0: break;
576 : case 1:
577 0 : ff_pkt->type=FT_NOOPEN;
578 0 : ret=my_send_file_w(asfd, ff_pkt, top_level, confs);
579 : default:
580 : goto end;
581 : }
582 :
583 23 : if(nl)
584 : {
585 17 : if(process_entries_in_directory(asfd, nl, count,
586 : &link, len, &link_len, confs, ff_pkt, our_device))
587 : goto end;
588 : }
589 : ret=0;
590 : end:
591 25 : free_w(&link);
592 25 : free_v((void **)&nl);
593 25 : return ret;
594 : }
595 :
596 9 : static int found_other(struct asfd *asfd, struct FF_PKT *ff_pkt,
597 : struct conf **confs, bool top_level)
598 : {
599 : #ifdef HAVE_FREEBSD_OS
600 : /*
601 : * On FreeBSD, all block devices are character devices, so
602 : * to be able to read a raw disk, we need the check for
603 : * a character device.
604 : * crw-r----- 1 root operator - 116, 0x00040002 Jun 9 19:32 /dev/ad0s3
605 : * crw-r----- 1 root operator - 116, 0x00040002 Jun 9 19:32 /dev/rad0s3
606 : */
607 : if((S_ISBLK(ff_pkt->statp.st_mode) || S_ISCHR(ff_pkt->statp.st_mode))
608 : && need_to_read_blockdev(confs, ff_pkt->fname))
609 : {
610 : #else
611 9 : if(S_ISBLK(ff_pkt->statp.st_mode)
612 2 : && need_to_read_blockdev(confs, ff_pkt->fname))
613 : {
614 : #endif
615 : /* raw partition */
616 2 : ff_pkt->type=FT_RAW;
617 : }
618 7 : else if(S_ISFIFO(ff_pkt->statp.st_mode)
619 6 : && need_to_read_fifo(confs, ff_pkt->fname))
620 : {
621 4 : ff_pkt->type=FT_FIFO;
622 : }
623 : else
624 : {
625 : /* The only remaining are special (character, ...) files */
626 3 : ff_pkt->type=FT_SPEC;
627 : }
628 9 : return my_send_file_w(asfd, ff_pkt, top_level, confs);
629 : }
630 :
631 68 : static int find_files(struct asfd *asfd, struct FF_PKT *ff_pkt, struct conf **confs,
632 : char *fname, dev_t parent_device, bool top_level)
633 : {
634 68 : ff_pkt->fname=fname;
635 68 : ff_pkt->link=fname;
636 :
637 : #ifdef HAVE_WIN32
638 : if(win32_lstat(fname, &ff_pkt->statp, &ff_pkt->winattr))
639 : #else
640 136 : if(lstat(fname, &ff_pkt->statp))
641 : #endif
642 : {
643 2 : ff_pkt->type=FT_NOSTAT;
644 2 : return my_send_file_w(asfd, ff_pkt, top_level, confs);
645 : }
646 :
647 66 : if(S_ISREG(ff_pkt->statp.st_mode))
648 62 : return found_regular_file(asfd, ff_pkt, confs, top_level);
649 35 : else if(S_ISLNK(ff_pkt->statp.st_mode))
650 : {
651 : #ifdef S_IFLNK
652 : /* A symlink.
653 : If they have specified the symlink in a read_blockdev
654 : argument, treat it as a block device.
655 : */
656 : struct strlist *l;
657 4 : for(l=get_strlist(confs[OPT_BLOCKDEVS]); l; l=l->next)
658 : {
659 3 : if(!strcmp(l->path, fname))
660 : {
661 2 : ff_pkt->statp.st_mode ^= S_IFLNK;
662 2 : ff_pkt->statp.st_mode |= S_IFBLK;
663 2 : return found_other(asfd, ff_pkt, confs,
664 : top_level);
665 : }
666 : }
667 : #endif
668 1 : return found_soft_link(asfd, ff_pkt, confs, fname, top_level);
669 : }
670 32 : else if(S_ISDIR(ff_pkt->statp.st_mode))
671 25 : return found_directory(asfd, ff_pkt, confs, fname,
672 : parent_device, top_level);
673 : else
674 7 : return found_other(asfd, ff_pkt, confs, top_level);
675 : }
676 :
677 14 : int find_files_begin(struct asfd *asfd,
678 : struct FF_PKT *ff_pkt, struct conf **confs, char *fname)
679 : {
680 14 : return find_files(asfd, ff_pkt,
681 : confs, fname, (dev_t)-1, 1 /* top_level */);
682 : }
|