+static inline int LINKHASH(const struct stat &info)
+{
+ int hash = info.st_dev;
+ unsigned long long i = info.st_ino;
+ hash ^= i;
+ i >>= 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);
+}
+
+/*
+ * 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;
+ }
+ }