+ * Check to see if we allow the file system type of a file or directory.
+ * If we do not have a list of file system types, we accept anything.
+ */
+static int accept_fstype(FF_PKT *ff, void *dummy) {
+ int i;
+ char fs[1000];
+ bool accept = true;
+
+ if (ff->fstypes.size()) {
+ accept = false;
+ if (!fstype(ff->fname, fs, sizeof(fs))) {
+ Dmsg1(50, "Cannot determine file system type for \"%s\"\n", ff->fname);
+ } else {
+ for (i = 0; i < ff->fstypes.size(); ++i) {
+ if (strcmp(fs, (char *)ff->fstypes.get(i)) == 0) {
+ Dmsg2(100, "Accepting fstype %s for \"%s\"\n", fs, ff->fname);
+ accept = true;
+ break;
+ }
+ Dmsg3(200, "fstype %s for \"%s\" does not match %s\n", fs,
+ ff->fname, ff->fstypes.get(i));
+ }
+ }
+ }
+ 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...
+ * Also, the man pages talk about things as if they were implemented.
+ *
+ * On Mac OS X, this succesfully differentiates between HFS+ and UFS
+ * volumes, which makes me trust it is OK for others, too.
+ */
+static bool volume_has_attrlist(const char *fname)
+{
+#ifdef HAVE_DARWIN_OS
+ struct statfs st;
+ struct volinfo_struct {
+ unsigned long length; /* Mandatory field */
+ vol_capabilities_attr_t info; /* Volume capabilities */
+ } vol;
+ struct attrlist attrList;
+
+ memset(&attrList, 0, sizeof(attrList));
+ attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
+ attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES;
+ if (statfs(fname, &st) == 0) {
+ /* We need to check on the mount point */
+ if (getattrlist(st.f_mntonname, &attrList, &vol, sizeof(vol), FSOPT_NOFOLLOW) == 0
+ && (vol.info.capabilities[VOL_CAPABILITIES_INTERFACES] & VOL_CAP_INT_ATTRLIST)
+ && (vol.info.valid[VOL_CAPABILITIES_INTERFACES] & VOL_CAP_INT_ATTRLIST)) {
+ return true;
+ }
+ }
+#endif
+ 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;
+}
+
+/*
+ * In incremental/diffential or accurate backup, we
+ * say if the current file has changed.
+ */
+static bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
+{
+ /* in special mode (like accurate backup), user can
+ * choose his comparison function.
+ */
+ if (ff_pkt->check_fct) {
+ return ff_pkt->check_fct(jcr, ff_pkt);
+ }
+
+ /* in normal modes (incr/diff), we use this default
+ * behaviour
+ */
+ if (ff_pkt->incremental &&
+ (ff_pkt->statp.st_mtime < ff_pkt->save_time &&
+ ((ff_pkt->flags & FO_MTIMEONLY) ||
+ ff_pkt->statp.st_ctime < ff_pkt->save_time)))
+ {
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Find a single file.