+ for (i = 0; i < the_file_list->count; i++) {
+ if (F_IS_HLINKED(FPTR(i)))
+ ndx_list[ndx_count++] = i;
+ }
+
+ if (!ndx_count) {
+ free(ndx_list);
+ return;
+ }
+
+ qsort(ndx_list, ndx_count, sizeof ndx_list[0],
+ (int (*)()) hlink_compare);
+
+ for (from = 0; from < ndx_count; from++) {
+ for (file = FPTR(ndx_list[from]), idev = F_HL_IDEV(file), prev = -1;
+ from < ndx_count-1;
+ file = file_next, idev = idev_next, prev = ndx_list[from++])
+ {
+ file_next = FPTR(ndx_list[from+1]);
+ idev_next = F_HL_IDEV(file_next);
+ if (!LINKED(idev, idev_next))
+ break;
+ pool_free(hlink_pool, 0, idev);
+ if (prev < 0)
+ file->flags |= FLAG_HLINK_FIRST;
+ F_HL_PREV(file) = prev;
+ }
+ pool_free(hlink_pool, 0, idev);
+ if (prev < 0)
+ file->flags &= ~FLAG_HLINKED;
+ else {
+ file->flags |= FLAG_HLINK_LAST;
+ F_HL_PREV(file) = prev;
+ }
+ }
+
+ pool_destroy(hlink_pool);
+ free(ndx_list);
+}
+
+static int maybe_hard_link(struct file_struct *file, int ndx,
+ const char *fname, int statret, STRUCT_STAT *stp,
+ const char *oldname, STRUCT_STAT *old_stp,
+ const char *realname, int itemizing, enum logcode code)