Explicitly cast the length values down to an uint32 so that some
[rsync/rsync.git] / hlink.c
diff --git a/hlink.c b/hlink.c
index d4808fc..23f6a9b 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -28,7 +28,6 @@ extern int dry_run;
 extern int do_xfers;
 extern int link_dest;
 extern int make_backups;
-extern int flist_extra_ndx;
 extern int remove_source_files;
 extern int stdout_format_has_i;
 extern char *basis_dir[];
@@ -46,14 +45,14 @@ static int hlink_compare(int *int1, int *int2)
 {
        struct file_struct *f1 = FPTR(*int1);
        struct file_struct *f2 = FPTR(*int2);
-       struct idev *i1 = F_IDEV(f1);
-       struct idev *i2 = F_IDEV(f2);
+       struct idev *i1 = F_HL_IDEV(f1);
+       struct idev *i2 = F_HL_IDEV(f2);
 
        if (i1->dev != i2->dev)
-               return (int)(i1->dev > i2->dev ? 1 : -1);
+               return i1->dev > i2->dev ? 1 : -1;
 
        if (i1->ino != i2->ino)
-               return (int)(i1->ino > i2->ino ? 1 : -1);
+               return i1->ino > i2->ino ? 1 : -1;
 
        return f_name_cmp(f1, f2);
 }
@@ -77,12 +76,12 @@ static void link_idev_data(void)
 
        for (from = to = 0; from < hlink_count; from++) {
                start = from;
-               for (file = FPTR(hlink_list[from]), idev = F_IDEV(file);
+               for (file = FPTR(hlink_list[from]), idev = F_HL_IDEV(file);
                     from < hlink_count-1;
                     file = file_next, idev = idev_next)
                {
                        file_next = FPTR(hlink_list[from+1]);
-                       idev_next = F_IDEV(file_next);
+                       idev_next = F_HL_IDEV(file_next);
                        if (!LINKED(idev, idev_next))
                                break;
                        pool_free(idev_pool, 0, idev);
@@ -91,7 +90,7 @@ static void link_idev_data(void)
                        hl->hlindex = to;
                        hl->next = hlink_list[++from];
                        hl->dest_used = 0;
-                       F_HLIST(file) = hl;
+                       F_HL_LIST(file) = hl;
                }
                pool_free(idev_pool, 0, idev);
                if (from > start) {
@@ -104,9 +103,9 @@ static void link_idev_data(void)
                        hl->dest_used = 0;
                        hlink_list[to++] = head;
                        file->flags |= FLAG_HLINK_LAST;
-                       F_HLIST(file) = hl;
+                       F_HL_LIST(file) = hl;
                } else
-                       file->flags &= ~FLAG_HLINK_INFO;
+                       file->flags &= ~FLAG_HLINKED;
        }
 
        if (!to) {
@@ -123,11 +122,9 @@ static void link_idev_data(void)
        the_file_list->hlink_pool = hlink_pool;
        pool_destroy(idev_pool);
 }
-#endif
 
 void init_hard_links(void)
 {
-#ifdef SUPPORT_HARD_LINKS
        int i;
 
        if (hlink_list)
@@ -138,7 +135,7 @@ void init_hard_links(void)
 
        hlink_count = 0;
        for (i = 0; i < the_file_list->count; i++) {
-               if (IS_HLINKED(FPTR(i)))
+               if (F_IS_HLINKED(FPTR(i)))
                        hlink_list[hlink_count++] = i;
        }
 
@@ -150,20 +147,18 @@ void init_hard_links(void)
                hlink_list = NULL;
        } else
                link_idev_data();
-#endif
 }
 
-#ifdef SUPPORT_HARD_LINKS
 static int maybe_hard_link(struct file_struct *file, int ndx,
-                          char *fname, int statret, STRUCT_STAT *st,
-                          char *toname, STRUCT_STAT *to_st,
+                          const char *fname, int statret, STRUCT_STAT *stp,
+                          const char *toname, STRUCT_STAT *to_stp,
                           int itemizing, enum logcode code)
 {
        if (statret == 0) {
-               if (st->st_dev == to_st->st_dev
-                && st->st_ino == to_st->st_ino) {
+               if (stp->st_dev == to_stp->st_dev
+                && stp->st_ino == to_stp->st_ino) {
                        if (itemizing) {
-                               itemize(file, ndx, statret, st,
+                               itemize(file, ndx, statret, stp,
                                        ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
                                        0, "");
                        }
@@ -178,18 +173,16 @@ static int maybe_hard_link(struct file_struct *file, int ndx,
                        return -1;
                }
        }
-       return hard_link_one(file, ndx, fname, statret, st, toname,
+       return hard_link_one(file, ndx, fname, statret, stp, toname,
                             0, itemizing, code);
 }
-#endif
 
-int hard_link_check(struct file_struct *file, int ndx, char *fname,
-                   int statret, STRUCT_STAT *st, int itemizing,
+int hard_link_check(struct file_struct *file, int ndx, const char *fname,
+                   int statret, STRUCT_STAT *stp, int itemizing,
                    enum logcode code, int skip)
 {
-#ifdef SUPPORT_HARD_LINKS
        int head;
-       struct hlist *hl = F_HLIST(file);
+       struct hlist *hl = F_HL_LIST(file);
 
        if (skip && !(file->flags & FLAG_HLINK_LAST))
                head = hlink_list[hl->hlindex] = hl->next;
@@ -197,7 +190,7 @@ int hard_link_check(struct file_struct *file, int ndx, char *fname,
                head = hlink_list[hl->hlindex];
        if (ndx != head) {
                struct file_struct *head_file = FPTR(head);
-               struct hlist *hf_hl = F_HLIST(head_file);
+               struct hlist *hf_hl = F_HL_LIST(head_file);
                if (!stdout_format_has_i && verbose > 1) {
                        rprintf(FINFO, "\"%s\" is a hard link\n",
                                f_name(file, NULL));
@@ -228,7 +221,7 @@ int hard_link_check(struct file_struct *file, int ndx, char *fname,
                                                 || st2.st_ino != st3.st_ino)
                                                        continue;
                                                statret = 1;
-                                               st = &st3;
+                                               stp = &st3;
                                                if (verbose < 2 || !stdout_format_has_i) {
                                                        itemizing = 0;
                                                        code = FNONE;
@@ -238,30 +231,25 @@ int hard_link_check(struct file_struct *file, int ndx, char *fname,
                                        if (!unchanged_file(cmpbuf, file, &st3))
                                                continue;
                                        statret = 1;
-                                       st = &st3;
+                                       stp = &st3;
                                        if (unchanged_attrs(file, &st3))
                                                break;
                                } while (basis_dir[++j] != NULL);
                        }
-                       maybe_hard_link(file, ndx, fname, statret, st,
+                       maybe_hard_link(file, ndx, fname, statret, stp,
                                        toname, &st2, itemizing, code);
-                       if (remove_source_files == 1 && do_xfers) {
-                               char numbuf[4];
-                               SIVAL(numbuf, 0, ndx);
-                               send_msg(MSG_SUCCESS, numbuf, 4);
-                       }
+                       if (remove_source_files == 1 && do_xfers)
+                               send_msg_int(MSG_SUCCESS, ndx);
                        hl->hlindex = FINISHED_LINK;
                } else
                        hl->hlindex = SKIPPED_LINK;
                return 1;
        }
-#endif
        return 0;
 }
 
-#ifdef SUPPORT_HARD_LINKS
-int hard_link_one(struct file_struct *file, int ndx, char *fname,
-                 int statret, STRUCT_STAT *st, char *toname, int terse,
+int hard_link_one(struct file_struct *file, int ndx, const char *fname,
+                 int statret, STRUCT_STAT *stp, const char *toname, int terse,
                  int itemizing, enum logcode code)
 {
        if (do_link(toname, fname)) {
@@ -277,7 +265,7 @@ int hard_link_one(struct file_struct *file, int ndx, char *fname,
        }
 
        if (itemizing) {
-               itemize(file, ndx, statret, st,
+               itemize(file, ndx, statret, stp,
                        ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
                        terse ? "" : toname);
        }
@@ -285,18 +273,15 @@ int hard_link_one(struct file_struct *file, int ndx, char *fname,
                rprintf(code, "%s => %s\n", fname, toname);
        return 0;
 }
-#endif
-
 
 void hard_link_cluster(struct file_struct *file, int master, int itemizing,
                       enum logcode code, int dest_used)
 {
-#ifdef SUPPORT_HARD_LINKS
        char hlink1[MAXPATHLEN];
        char *hlink2;
        STRUCT_STAT st1, st2;
        int statret, ndx = master;
-       struct hlist *hl = F_HLIST(file);
+       struct hlist *hl = F_HL_LIST(file);
 
        hl->hlindex = FINISHED_LINK;
        if (dry_run)
@@ -307,25 +292,22 @@ void hard_link_cluster(struct file_struct *file, int master, int itemizing,
                while (!(file->flags & FLAG_HLINK_LAST)) {
                        ndx = hl->next;
                        file = FPTR(ndx);
-                       hl = F_HLIST(file);
+                       hl = F_HL_LIST(file);
                }
        }
        do {
                ndx = hl->next;
                file = FPTR(ndx);
-               hl = F_HLIST(file);
+               hl = F_HL_LIST(file);
                if (hl->hlindex != SKIPPED_LINK)
                        continue;
                hlink2 = f_name(file, NULL);
                statret = link_stat(hlink2, &st2, 0);
                maybe_hard_link(file, ndx, hlink2, statret, &st2,
                                hlink1, &st1, itemizing, code);
-               if (remove_source_files == 1 && do_xfers) {
-                       char numbuf[4];
-                       SIVAL(numbuf, 0, ndx);
-                       send_msg(MSG_SUCCESS, numbuf, 4);
-               }
+               if (remove_source_files == 1 && do_xfers)
+                       send_msg_int(MSG_SUCCESS, ndx);
                hl->hlindex = FINISHED_LINK;
        } while (!(file->flags & FLAG_HLINK_LAST));
-#endif
 }
+#endif