diff options
author | Wayne Davison <wayned@samba.org> | 2005-03-05 00:21:44 +0000 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2005-03-05 00:21:44 +0000 |
commit | 9f2e3c3f528c564be9f9908614e9fcef7c80cd01 (patch) | |
tree | ba83f7f87d1424db0eaad117dce2c415957b4591 /hlink.c | |
parent | ee1d11c495d0083afdad1725860bec7011e8377d (diff) | |
download | rsync-9f2e3c3f528c564be9f9908614e9fcef7c80cd01.tar.gz rsync-9f2e3c3f528c564be9f9908614e9fcef7c80cd01.tar.bz2 rsync-9f2e3c3f528c564be9f9908614e9fcef7c80cd01.zip |
- Changed hlink_list[] to store file-list indexes instead of
pointers.
- Made hard_link_one() non-static so that the generator can call it.
Improved it to do itemized output.
- Replaced do_hard_links() with hard_link_cluster(), which changes
the hard-linking from a post-transfer loop into a per-cluster
operation that occurs incrementally as the transfer updates (or
finds unchanged) one item in the cluster.
Diffstat (limited to 'hlink.c')
-rw-r--r-- | hlink.c | 163 |
1 files changed, 90 insertions, 73 deletions
@@ -23,12 +23,18 @@ extern int dry_run; extern int verbose; extern int make_backups; +extern struct file_list *the_file_list; #ifdef SUPPORT_HARD_LINKS -static int hlink_compare(struct file_struct **file1, struct file_struct **file2) + +#define FPTR(i) (the_file_list->files[i]) +#define LINKED(p1,p2) (FPTR(p1)->F_DEV == FPTR(p2)->F_DEV \ + && FPTR(p1)->F_INODE == FPTR(p2)->F_INODE) + +static int hlink_compare(int *int1, int *int2) { - struct file_struct *f1 = *file1; - struct file_struct *f2 = *file2; + struct file_struct *f1 = FPTR(*int1); + struct file_struct *f2 = FPTR(*int2); if (f1->F_DEV != f2->F_DEV) return (int) (f1->F_DEV > f2->F_DEV ? 1 : -1); @@ -39,21 +45,17 @@ static int hlink_compare(struct file_struct **file1, struct file_struct **file2) return f_name_cmp(f1, f2); } -static struct file_struct **hlink_list; +static int *hlink_list; static int hlink_count; -#define LINKED(p1,p2) ((p1)->F_DEV == (p2)->F_DEV \ - && (p1)->F_INODE == (p2)->F_INODE) - /* Analyze the data in the hlink_list[], remove items that aren't multiply * linked, and replace the dev+inode data with the hlindex+next linked list. */ -static void link_idev_data(struct file_list *flist) +static void link_idev_data(void) { - struct file_struct *head; - int from, to, start; + int head, from, to, start; alloc_pool_t hlink_pool; - alloc_pool_t idev_pool = flist->hlink_pool; + alloc_pool_t idev_pool = the_file_list->hlink_pool; hlink_pool = pool_create(128 * 1024, sizeof (struct hlink), out_of_memory, POOL_INTERN); @@ -63,26 +65,27 @@ static void link_idev_data(struct file_list *flist) head = hlink_list[start]; while (from < hlink_count-1 && LINKED(hlink_list[from], hlink_list[from+1])) { - pool_free(idev_pool, 0, hlink_list[from]->link_u.idev); - hlink_list[from]->link_u.links = pool_talloc(hlink_pool, + pool_free(idev_pool, 0, FPTR(hlink_list[from])->link_u.idev); + FPTR(hlink_list[from])->link_u.links = pool_talloc(hlink_pool, struct hlink, 1, "hlink_list"); - hlink_list[from]->F_HLINDEX = to; - hlink_list[from]->F_NEXT = hlink_list[from+1]; + FPTR(hlink_list[from])->F_HLINDEX = to; + FPTR(hlink_list[from])->F_NEXT = hlink_list[from+1]; from++; } if (from > start) { - pool_free(idev_pool, 0, hlink_list[from]->link_u.idev); - hlink_list[from]->link_u.links = pool_talloc(hlink_pool, + pool_free(idev_pool, 0, FPTR(hlink_list[from])->link_u.idev); + FPTR(hlink_list[from])->link_u.links = pool_talloc(hlink_pool, struct hlink, 1, "hlink_list"); - hlink_list[from]->F_HLINDEX = to; - hlink_list[from]->F_NEXT = head; - hlink_list[from]->flags |= FLAG_HLINK_EOL; + FPTR(head)->flags |= FLAG_HLINK_TOL; + FPTR(hlink_list[from])->F_HLINDEX = to; + FPTR(hlink_list[from])->F_NEXT = head; + FPTR(hlink_list[from])->flags |= FLAG_HLINK_EOL; hlink_list[to++] = head; } else { - pool_free(idev_pool, 0, head->link_u.idev); - head->link_u.idev = NULL; + pool_free(idev_pool, 0, FPTR(head)->link_u.idev); + FPTR(head)->link_u.idev = NULL; } } @@ -93,33 +96,33 @@ static void link_idev_data(struct file_list *flist) hlink_pool = NULL; } else { hlink_count = to; - if (!(hlink_list = realloc_array(hlink_list, - struct file_struct *, hlink_count))) + hlink_list = realloc_array(hlink_list, int, hlink_count); + if (!hlink_list) out_of_memory("init_hard_links"); } - flist->hlink_pool = hlink_pool; + the_file_list->hlink_pool = hlink_pool; pool_destroy(idev_pool); } #endif -void init_hard_links(struct file_list *flist) +void init_hard_links(void) { #ifdef SUPPORT_HARD_LINKS int i; - if (flist->count < 2) + if (the_file_list->count < 2) return; if (hlink_list) free(hlink_list); - if (!(hlink_list = new_array(struct file_struct *, flist->count))) + if (!(hlink_list = new_array(int, the_file_list->count))) out_of_memory("init_hard_links"); hlink_count = 0; - for (i = 0; i < flist->count; i++) { - if (flist->files[i]->link_u.idev) - hlink_list[hlink_count++] = flist->files[i]; + for (i = 0; i < the_file_list->count; i++) { + if (FPTR(i)->link_u.idev) + hlink_list[hlink_count++] = i; } qsort(hlink_list, hlink_count, @@ -129,19 +132,19 @@ void init_hard_links(struct file_list *flist) free(hlink_list); hlink_list = NULL; } else - link_idev_data(flist); + link_idev_data(); #endif } -int hard_link_check(struct file_struct *file, int skip) +int hard_link_check(struct file_struct *file, int ndx, int skip) { #ifdef SUPPORT_HARD_LINKS if (!hlink_list || !file->link_u.links) return 0; if (skip && !(file->flags & FLAG_HLINK_EOL)) hlink_list[file->F_HLINDEX] = file->F_NEXT; - if (hlink_list[file->F_HLINDEX] != file) { - if (verbose > 1) { + if (hlink_list[file->F_HLINDEX] != ndx) { + if (verbose > 2) { rprintf(FINFO, "\"%s\" is a hard link\n", safe_fname(f_name(file))); } @@ -152,63 +155,77 @@ int hard_link_check(struct file_struct *file, int skip) } #ifdef SUPPORT_HARD_LINKS -static void hard_link_one(char *hlink1, char *hlink2) +int hard_link_one(struct file_struct *file, int ndx, char *fname, + int statret, STRUCT_STAT *st, char *toname, int terse, + int itemizing, enum logcode code) { - if (do_link(hlink1, hlink2)) { + if (do_link(toname, fname)) { if (verbose) { - rsyserr(FINFO, errno, "link %s => %s failed", - full_fname(hlink2), safe_fname(hlink1)); + rsyserr(FERROR, errno, "link %s => %s failed", + full_fname(fname), safe_fname(toname)); } + return -1; + } + + if (itemizing) { + itemize(file, ndx, statret, st, ITEM_HARD_LINKED, + terse ? "" : toname); + } + if (code && verbose && !terse) { + rprintf(code, "%s => %s\n", + safe_fname(fname), safe_fname(toname)); } - else if (verbose) - rprintf(FINFO, "%s => %s\n", safe_fname(hlink2), safe_fname(hlink1)); + return 0; } #endif - -/** - * Create any hard links in the global hlink_list. They were put - * there by running init_hard_links on the filelist. - **/ -void do_hard_links(int allowed_lull, int flist_count) +void hard_link_cluster(struct file_struct *file, int master, int itemizing, + enum logcode code) { #ifdef SUPPORT_HARD_LINKS - struct file_struct *file, *first; char hlink1[MAXPATHLEN]; char *hlink2; STRUCT_STAT st1, st2; - int i; + int statret, ndx = master; - if (!hlink_list) + if (link_stat(f_name_to(file, hlink1), &st1, 0) < 0) return; - - for (i = 0; i < hlink_count; i++) { - first = file = hlink_list[i]; - if (link_stat(f_name_to(first, hlink1), &st1, 0) < 0) + if (!(file->flags & FLAG_HLINK_TOL)) { + while (!(file->flags & FLAG_HLINK_EOL)) { + ndx = file->F_NEXT; + file = FPTR(ndx); + } + } + do { + ndx = file->F_NEXT; + file = FPTR(ndx); + if (ndx == master) continue; - while ((file = file->F_NEXT) != first) { - hlink2 = f_name(file); - if (link_stat(hlink2, &st2, 0) == 0) { - if (st2.st_dev == st1.st_dev - && st2.st_ino == st1.st_ino) - continue; - if (make_backups) { - if (!make_backup(hlink2)) - continue; - } else if (robust_unlink(hlink2)) { - if (verbose > 0) { - rsyserr(FINFO, errno, - "unlink %s failed", - full_fname(hlink2)); - } + hlink2 = f_name(file); + if ((statret = link_stat(hlink2, &st2, 0)) == 0) { + if (st2.st_dev == st1.st_dev + && st2.st_ino == st1.st_ino) { + if (itemizing) { + itemize(file, ndx, statret, + &st2, ITEM_HARD_LINKED, ""); + } + continue; + } + if (make_backups) { + if (!make_backup(hlink2)) continue; + } else if (robust_unlink(hlink2)) { + if (verbose > 0) { + rsyserr(FINFO, errno, + "unlink %s failed", + full_fname(hlink2)); } + continue; } - hard_link_one(hlink1, hlink2); } - if (allowed_lull) - maybe_send_keepalive(allowed_lull, flist_count); - } + hard_link_one(file, ndx, hlink2, statret, + &st2, hlink1, 0, itemizing, code); + } while (!(file->flags & FLAG_HLINK_EOL)); #endif } |