X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffindlib%2Ffind_one.c;h=723d45ccf77a12ab09d76ee438270186b9d2426c;hb=c205f98aff775e96e18dc0af2f194e76f2ddaaa9;hp=24c06426b0ee89eb774d29d07be05de814301004;hpb=aaf83bbfd3460ac5b92ddf7c63dbf8f26d6ab88b;p=bacula%2Fbacula diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c old mode 100755 new mode 100644 index 24c06426b0..723d45ccf7 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -1,23 +1,34 @@ /* - Copyright (C) 2000-2005 Kern Sibbald + Bacula® - The Network Backup Solution - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU 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 General Public License for more details. - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + You should have received a copy of the GNU 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. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* - This file is based on GNU TAR source code. Except for a few key - ideas, it has been rewritten for Bacula. + This file was derived from GNU TAR source code. Except for a few key + ideas, it has been entirely rewritten for Bacula. Kern Sibbald, MM @@ -54,11 +65,61 @@ struct f_link { char name[1]; /* The name */ }; +typedef struct f_link link_t; +#define LINK_HASHTABLE_BITS 16 +#define LINK_HASHTABLE_SIZE (1<>= 16; + hash ^= i; + i >>= 16; + hash ^= i; + i >>= 16; + hash ^= i; + return hash & LINK_HASHTABLE_MASK; +} + +/* + * Create a new directory Find File packet, but copy + * some of the essential info from the current packet. + * However, be careful to zero out the rest of the + * packet. + */ +static FF_PKT *new_dir_ff_pkt(FF_PKT *ff_pkt) +{ + FF_PKT *dir_ff_pkt = (FF_PKT *)bmalloc(sizeof(FF_PKT)); + memcpy(dir_ff_pkt, ff_pkt, sizeof(FF_PKT)); + dir_ff_pkt->fname = bstrdup(ff_pkt->fname); + dir_ff_pkt->link = bstrdup(ff_pkt->link); + dir_ff_pkt->sys_fname = get_pool_memory(PM_FNAME); + dir_ff_pkt->included_files_list = NULL; + dir_ff_pkt->excluded_files_list = NULL; + dir_ff_pkt->excluded_paths_list = NULL; + dir_ff_pkt->linkhash = NULL; + dir_ff_pkt->fname_save = NULL; + dir_ff_pkt->link_save = NULL; + return dir_ff_pkt; +} + +/* + * Free the temp directory ff_pkt + */ static void free_dir_ff_pkt(FF_PKT *dir_ff_pkt) { free(dir_ff_pkt->fname); free(dir_ff_pkt->link); free_pool_memory(dir_ff_pkt->sys_fname); + if (dir_ff_pkt->fname_save) { + free_pool_memory(dir_ff_pkt->fname_save); + } + if (dir_ff_pkt->link_save) { + free_pool_memory(dir_ff_pkt->link_save); + } free(dir_ff_pkt); } @@ -90,6 +151,34 @@ static int accept_fstype(FF_PKT *ff, void *dummy) { return accept; } +/* + * Check to see if we allow the drive type of a file or directory. + * If we do not have a list of drive types, we accept anything. + */ +static int accept_drivetype(FF_PKT *ff, void *dummy) { + int i; + char dt[100]; + bool accept = true; + + if (ff->drivetypes.size()) { + accept = false; + if (!drivetype(ff->fname, dt, sizeof(dt))) { + Dmsg1(50, "Cannot determine drive type for \"%s\"\n", ff->fname); + } else { + for (i = 0; i < ff->drivetypes.size(); ++i) { + if (strcmp(dt, (char *)ff->drivetypes.get(i)) == 0) { + Dmsg2(100, "Accepting drive type %s for \"%s\"\n", dt, ff->fname); + accept = true; + break; + } + Dmsg3(200, "drive type %s for \"%s\" does not match %s\n", dt, + ff->fname, ff->drivetypes.get(i)); + } + } + } + return accept; +} + /* * This function determines whether we can use getattrlist() * It's odd, but we have to use the function to determine that... @@ -123,6 +212,51 @@ static bool volume_has_attrlist(const char *fname) return false; } +/* check if a file have changed during backup and display an error */ +bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt) +{ + struct stat statp; + Dmsg1(500, "has_file_changed fname=%s\n",ff_pkt->fname); + + if (ff_pkt->type != FT_REG) { /* not a regular file */ + return false; + } + + if (lstat(ff_pkt->fname, &statp) != 0) { + berrno be; + Jmsg(jcr, M_WARNING, 0, + _("Cannot stat file %s: ERR=%s\n"),ff_pkt->fname,be.bstrerror()); + return true; + } + + if (statp.st_mtime != ff_pkt->statp.st_mtime) { + /* TODO: add time of changes */ + Jmsg(jcr, M_ERROR, 0, _("%s mtime changed during backup.\n"), ff_pkt->fname); + return true; + } + + if (statp.st_ctime != ff_pkt->statp.st_ctime) { + /* TODO: add time of changes */ + Jmsg(jcr, M_ERROR, 0, _("%s ctime changed during backup.\n"), ff_pkt->fname); + return true; + } + + if (statp.st_size != ff_pkt->statp.st_size) { + /* TODO: add size change */ + Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname); + return true; + } + + if ((statp.st_blksize != ff_pkt->statp.st_blksize) || + (statp.st_blocks != ff_pkt->statp.st_blocks)) { + /* TODO: add size change */ + Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname); + return true; + } + + return false; +} + /* * Find a single file. * handle_file is the callback for handling the file. @@ -158,7 +292,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, restore_times.modtime = ff_pkt->statp.st_mtime; /* - * We check for allowed fstypes at top_level and fstype change (below). + * We check for allowed fstypes and drivetypes at top_level and fstype change (below). */ if (top_level) { if (!accept_fstype(ff_pkt, NULL)) { @@ -166,7 +300,29 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, if (ff_pkt->flags & FO_KEEPATIME) { utime(fname, &restore_times); } - Jmsg1(jcr, M_ERROR, 0, _("Top level directory \"%s\" has an unlisted fstype\n"), fname); + + char fs[100]; + + if (!fstype(ff_pkt->fname, fs, sizeof(fs))) { + bstrncpy(fs, "unknown", sizeof(fs)); + } + + Jmsg(jcr, M_INFO, 0, _("Top level directory \"%s\" has unlisted fstype \"%s\"\n"), fname, fs); + return 1; /* Just ignore this error - or the whole backup is cancelled */ + } + if (!accept_drivetype(ff_pkt, NULL)) { + ff_pkt->type = FT_INVALIDDT; + if (ff_pkt->flags & FO_KEEPATIME) { + utime(fname, &restore_times); + } + + char dt[100]; + + if (!drivetype(ff_pkt->fname, dt, sizeof(dt))) { + bstrncpy(dt, "unknown", sizeof(dt)); + } + + Jmsg(jcr, M_INFO, 0, _("Top level directory \"%s\" has an unlisted drive type \"%s\"\n"), fname, dt); return 1; /* Just ignore this error - or the whole backup is cancelled */ } ff_pkt->volhas_attrlist = volume_has_attrlist(fname); @@ -207,14 +363,6 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, } #endif -/* ***FIXME*** implement this */ -#if xxxxxxx - /* See if we are trying to dump the archive. */ - if (ar_dev && ff_pkt->statp.st_dev == ar_dev && ff_pkt->statp.st_ino == ar_ino) { - ff_pkt->type = FT_ISARCH; - return handle_file(ff_pkt, pkt, top_level); - } -#endif ff_pkt->LinkFI = 0; /* * Handle hard linked files @@ -232,15 +380,18 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, || S_ISSOCK(ff_pkt->statp.st_mode))) { struct f_link *lp; + if (ff_pkt->linkhash == NULL) { + ff_pkt->linkhash = (link_t **)bmalloc(LINK_HASHTABLE_SIZE * sizeof(link_t *)); + memset(ff_pkt->linkhash, 0, LINK_HASHTABLE_SIZE * sizeof(link_t *)); + } + const int linkhash = LINKHASH(ff_pkt->statp); /* Search link list of hard linked files */ - for (lp = ff_pkt->linklist; lp; lp = lp->next) + for (lp = ff_pkt->linkhash[linkhash]; lp; lp = lp->next) if (lp->ino == (ino_t)ff_pkt->statp.st_ino && lp->dev == (dev_t)ff_pkt->statp.st_dev) { /* If we have already backed up the hard linked file don't do it again */ if (strcmp(lp->name, fname) == 0) { - Jmsg1(jcr, M_WARNING, 0, _("Attempt to backup hard linked file %s twice ignored.\n"), - fname); return 1; /* ignore */ } ff_pkt->link = lp->name; @@ -255,8 +406,8 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, lp->ino = ff_pkt->statp.st_ino; lp->dev = ff_pkt->statp.st_dev; bstrncpy(lp->name, fname, len); - lp->next = ff_pkt->linklist; - ff_pkt->linklist = lp; + lp->next = ff_pkt->linkhash[linkhash]; + ff_pkt->linkhash[linkhash] = lp; ff_pkt->linked = lp; /* mark saved link */ } else { ff_pkt->linked = NULL; @@ -264,7 +415,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, /* This is not a link to a previously dumped file, so dump it. */ if (S_ISREG(ff_pkt->statp.st_mode)) { - off_t sizeleft; + boffset_t sizeleft; sizeleft = ff_pkt->statp.st_size; @@ -280,6 +431,9 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, if (ff_pkt->linked) { ff_pkt->linked->FileIndex = ff_pkt->FileIndex; } + if (ff_pkt->flags & FO_KEEPATIME) { + utime(fname, &restore_times); + } return rtn_stat; @@ -342,7 +496,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, link = (char *)bmalloc(link_len + 2); bstrncpy(link, fname, link_len); /* Strip all trailing slashes */ - while (len >= 1 && link[len - 1] == '/') + while (len >= 1 && IsPathSeparator(link[len - 1])) len--; link[len++] = '/'; /* add back one */ link[len] = 0; @@ -350,12 +504,17 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, ff_pkt->link = link; if (ff_pkt->incremental && (ff_pkt->statp.st_mtime < ff_pkt->save_time && - ff_pkt->statp.st_ctime < ff_pkt->save_time)) { + ((ff_pkt->flags & FO_MTIMEONLY) || + ff_pkt->statp.st_ctime < ff_pkt->save_time))) { /* Incremental option, directory entry not changed */ ff_pkt->type = FT_DIRNOCHG; } else { ff_pkt->type = FT_DIRBEGIN; } + /* We have set st_rdev to 1 if it is a reparse point, otherwise 0 */ + if (have_win32_api() && ff_pkt->statp.st_rdev) { + ff_pkt->type = FT_REPARSE; + } /* * Note, we return the directory to the calling program (handle_file) * when we first see the directory (FT_DIRBEGIN. @@ -365,7 +524,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, * in the directory is seen (i.e. the FT_DIREND). */ rtn_stat = handle_file(ff_pkt, pkt, top_level); - if (rtn_stat < 1) { /* ignore or error status */ + if (rtn_stat < 1 || ff_pkt->type == FT_REPARSE) { /* ignore or error status */ free(link); return rtn_stat; } @@ -383,15 +542,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, * be reset after all the files have been restored. */ Dmsg1(300, "Create temp ff packet for dir: %s\n", ff_pkt->fname); - FF_PKT *dir_ff_pkt = (FF_PKT *)bmalloc(sizeof(FF_PKT)); - memcpy(dir_ff_pkt, ff_pkt, sizeof(FF_PKT)); - dir_ff_pkt->fname = bstrdup(ff_pkt->fname); - dir_ff_pkt->link = bstrdup(ff_pkt->link); - dir_ff_pkt->sys_fname = get_pool_memory(PM_FNAME); - dir_ff_pkt->included_files_list = NULL; - dir_ff_pkt->excluded_files_list = NULL; - dir_ff_pkt->excluded_paths_list = NULL; - dir_ff_pkt->linklist = NULL; + FF_PKT *dir_ff_pkt = new_dir_ff_pkt(ff_pkt); /* * Do not descend into subdirectories (recurse) if the @@ -550,9 +701,15 @@ int term_find_one(FF_PKT *ff) { struct f_link *lp, *lc; int count = 0; + int i; + + if (ff->linkhash == NULL) return 0; + + for (i =0 ; i < LINK_HASHTABLE_SIZE; i ++) { /* Free up list of hard linked files */ - for (lp = ff->linklist; lp;) { + lp = ff->linkhash[i]; + while (lp) { lc = lp; lp = lp->next; if (lc) { @@ -560,6 +717,9 @@ int term_find_one(FF_PKT *ff) count++; } } - ff->linklist = NULL; + ff->linkhash[i] = NULL; + } + free(ff->linkhash); + ff->linkhash = NULL; return count; }