4 * CPDUP <options> source destination
6 * (c) Copyright 1997-1999 by Matthew Dillon and Dima Ruban. Permission to
7 * use and distribute based on the FreeBSD copyright. Supplied as-is,
8 * USE WITH EXTREME CAUTION.
10 * This program attempts to duplicate the source onto the destination as
11 * exactly as possible, retaining modify times, flags, perms, uid, and gid.
12 * It can duplicate devices, files (including hardlinks), softlinks,
13 * directories, and so forth. It is recursive by default! The duplication
14 * is inclusive of removal of files/directories on the destination that do
15 * not exist on the source. This program supports a per-directory exception
16 * file called .cpignore, or a user-specified exception file.
20 * - does not cross partition boundries on source
21 * - asks for confirmation on deletions unless -i0 is specified
22 * - refuses to replace a destination directory with a source file
23 * unless -s0 is specified.
24 * - terminates on error
28 * - does not copy file if mtime, flags, perms, and size match unless
31 * - copies to temporary and renames-over the original, allowing
32 * you to update live systems
34 * - copies uid, gid, mtime, perms, flags, softlinks, devices, hardlinks,
35 * and recurses through directories.
37 * - accesses a per-directory exclusion file, .cpignore, containing
38 * standard wildcarded ( ? / * style, NOT regex) exclusions.
40 * - tries to play permissions and flags smart in regards to overwriting
41 * schg files and doing related stuff.
43 * - Can do MD5 consistancy checks
45 * - Is able to do incremental mirroring/backups via hardlinks from
46 * the 'previous' version (supplied with -H path).
48 * $DragonFly: src/bin/cpdup/cpdup.c,v 1.11 2006/07/04 00:32:03 dillon Exp $
52 * Example: cc -O cpdup.c -o cpdup -lmd
54 * ".MD5.CHECKSUMS" contains md5 checksumms for the current directory.
55 * This file is stored on the source.
61 #define HMASK (HSIZE-1)
63 #define HLMASK (HLSIZE - 1)
67 struct Node *no_HNext;
86 struct hlink *hltable[HLSIZE];
88 void RemoveRecur(const char *dpath, dev_t devNo);
89 void InitList(List *list);
90 void ResetList(List *list);
91 int AddList(List *list, const char *name, int n);
92 static struct hlink *hltlookup(struct stat *);
93 static struct hlink *hltadd(struct stat *, const char *);
94 static char *checkHLPath(struct stat *st, const char *spath, const char *dpath);
95 static int shash(const char *s);
96 static void hltdelete(struct hlink *);
97 int YesNo(const char *path);
98 static int xrename(const char *src, const char *dst, u_long flags);
99 static int xlink(const char *src, const char *dst, u_long flags);
100 int WildCmp(const char *s1, const char *s2);
101 int DoCopy(const char *spath, const char *dpath, dev_t sdevNo, dev_t ddevNo);
103 int AskConfirmation = 1;
112 int EnableDirectoryRetries;
116 const char *UseCpFile;
117 const char *UseHLPath;
118 const char *MD5CacheFile;
119 const char *FSMIDCacheFile;
121 int64_t CountSourceBytes;
122 int64_t CountSourceItems;
123 int64_t CountCopiedItems;
124 int64_t CountReadBytes;
125 int64_t CountWriteBytes;
126 int64_t CountRemovedItems;
129 main(int ac, char **av)
134 struct timeval start;
136 gettimeofday(&start, NULL);
137 for (i = 1; i < ac; ++i) {
144 } else if (dst == NULL) {
147 fatal("too many arguments");
155 v = strtol(ptr, NULL, 0);
160 while (*ptr == 'v') {
164 if (*ptr >= '0' && *ptr <= '9')
165 VerboseOpt = strtol(ptr, NULL, 0);
174 UseCpFile = ".cpignore";
177 UseCpFile = (*ptr) ? ptr : av[++i];
180 UseHLPath = (*ptr) ? ptr : av[++i];
196 FSMIDCacheFile = ".FSMID.CHECK";
200 FSMIDCacheFile = av[++i];
204 MD5CacheFile = av[++i];
208 MD5CacheFile = ".MD5.CHECKSUMS";
211 setvbuf(stdout, NULL, _IOLBF, 0);
214 fatal("illegal option: %s\n", ptr - 2);
221 * dst may be NULL only if -m option is specified,
222 * which forces an update of the MD5 checksums
225 if (dst == NULL && UseMD5Opt == 0) {
230 DstBaseLen = strlen(dst);
231 i = DoCopy(src, dst, (dev_t)-1, (dev_t)-1);
233 i = DoCopy(src, NULL, (dev_t)-1, (dev_t)-1);
238 if (SummaryOpt && i == 0) {
242 gettimeofday(&end, NULL);
243 CountSourceBytes += sizeof(struct stat) * CountSourceItems;
244 CountReadBytes += sizeof(struct stat) * CountSourceItems;
245 CountWriteBytes += sizeof(struct stat) * CountCopiedItems;
246 CountWriteBytes += sizeof(struct stat) * CountRemovedItems;
248 duration = end.tv_sec - start.tv_sec;
250 duration += end.tv_usec - start.tv_usec;
251 if (duration == 0) duration = 1;
252 logstd("cpdup completed successfully\n");
253 logstd("%lld bytes source %lld bytes read %lld bytes written (%.1fX speedup)\n",
254 (long long)CountSourceBytes,
255 (long long)CountReadBytes,
256 (long long)CountWriteBytes,
257 ((double)CountSourceBytes * 2.0) / ((double)(CountReadBytes + CountWriteBytes)));
258 logstd("%lld source items %lld items copied %lld things deleted\n",
259 (long long)CountSourceItems,
260 (long long)CountCopiedItems,
261 (long long)CountRemovedItems);
262 logstd("%.1f seconds %5d Kbytes/sec synced %5d Kbytes/sec scanned\n",
263 (float)duration / (float)1000000,
264 (long)((long)1000000 * (CountReadBytes + CountWriteBytes) / duration / 1024.0),
265 (long)((long)1000000 * CountSourceBytes / duration / 1024.0));
267 exit((i == 0) ? 0 : 1);
270 static struct hlink *
271 hltlookup(struct stat *stp)
276 n = stp->st_ino & HLMASK;
278 for (hl = hltable[n]; hl; hl = hl->next)
279 if (hl->ino == stp->st_ino)
285 static struct hlink *
286 hltadd(struct stat *stp, const char *path)
291 if (!(new = malloc(sizeof (struct hlink)))) {
292 fprintf(stderr, "out of memory\n");
296 /* initialize and link the new element into the table */
297 new->ino = stp->st_ino;
299 strncpy(new->name, path, 2048);
302 n = stp->st_ino & HLMASK;
303 new->next = hltable[n];
305 hltable[n]->prev = new;
312 hltdelete(struct hlink *hl)
316 hl->next->prev = hl->prev;
317 hl->prev->next = hl->next;
320 hl->next->prev = NULL;
322 hltable[hl->ino & HLMASK] = hl->next;
329 * If UseHLPath is defined check to see if the file in question is
330 * the same as the source file, and if it is return a pointer to the
331 * -H path based file for hardlinking. Else return NULL.
334 checkHLPath(struct stat *st1, const char *spath, const char *dpath)
342 asprintf(&hpath, "%s%s", UseHLPath, dpath + DstBaseLen);
345 * stat info matches ?
347 if (stat(hpath, &sthl) < 0 ||
348 st1->st_size != sthl.st_size ||
349 st1->st_uid != sthl.st_uid ||
350 st1->st_gid != sthl.st_gid ||
351 st1->st_mtime != sthl.st_mtime
358 * If ForceOpt is set we have to compare the files
361 fd1 = open(spath, O_RDONLY);
362 fd2 = open(hpath, O_RDONLY);
365 if (fd1 >= 0 && fd2 >= 0) {
368 while ((n = read(fd1, IOBuf1, sizeof(IOBuf1))) > 0) {
369 if (read(fd2, IOBuf2, sizeof(IOBuf2)) != n)
371 if (bcmp(IOBuf1, IOBuf2, n) != 0)
390 DoCopy(const char *spath, const char *dpath, dev_t sdevNo, dev_t ddevNo)
394 int r, mres, fres, st2Valid;
400 r = mres = fres = st2Valid = 0;
404 if (lstat(spath, &st1) != 0)
406 st2.st_mode = 0; /* in case lstat fails */
407 st2.st_flags = 0; /* in case lstat fails */
408 if (dpath && lstat(dpath, &st2) == 0)
411 if (S_ISREG(st1.st_mode)) {
412 size = st1.st_blocks * 512;
413 if (st1.st_size % 512)
414 size += st1.st_size % 512 - 512;
421 if (S_ISREG(st1.st_mode) && st1.st_nlink > 1 && dpath) {
422 if ((hln = hltlookup(&st1)) != NULL) {
426 if (st2.st_ino == hln->dino) {
428 * hard link is already correct, nothing to do
431 logstd("%-32s nochange\n", (dpath) ? dpath : spath);
432 if (hln->nlinked == st1.st_nlink)
438 * hard link is not correct, attempt to unlink it
440 if (unlink(dpath) < 0) {
441 logerr("%-32s hardlink: unable to unlink: %s\n",
442 ((dpath) ? dpath : spath), strerror(errno));
449 if (xlink(hln->name, dpath, st1.st_flags) < 0) {
450 logerr("%-32s hardlink: unable to link to %s: %s\n",
451 (dpath ? dpath : spath), hln->name, strerror(errno)
457 if (hln->nlinked == st1.st_nlink) {
463 logstd("%-32s hardlink: %s\n",
464 (dpath ? dpath : spath),
465 (st2Valid ? "relinked" : "linked")
475 * first instance of hardlink must be copied normally
477 hln = hltadd(&st1, dpath);
482 * Do we need to copy the file/dir/link/whatever? Early termination
483 * if we do not. Always redo links. Directories are always traversed
484 * except when the FSMID options are used.
486 * NOTE: st2Valid is true only if dpath != NULL *and* dpath stats good.
491 st1.st_mode == st2.st_mode &&
492 st1.st_flags == st2.st_flags
494 if (S_ISLNK(st1.st_mode) || S_ISDIR(st1.st_mode)) {
496 * If FSMID tracking is turned on we can avoid recursing through
497 * an entire directory subtree if the FSMID matches.
499 #ifdef _ST_FSMID_PRESENT_
501 (UseFSMIDOpt && (fres = fsmid_check(st1.st_fsmid, dpath)) == 0)
503 if (VerboseOpt >= 3) {
505 logstd("%-32s fsmid-nochange\n", (dpath ? dpath : spath));
507 logstd("%-32s nochange\n", (dpath ? dpath : spath));
514 st1.st_size == st2.st_size &&
515 st1.st_uid == st2.st_uid &&
516 st1.st_gid == st2.st_gid &&
517 st1.st_mtime == st2.st_mtime
518 && (UseMD5Opt == 0 || (mres = md5_check(spath, dpath)) == 0)
519 #ifdef _ST_FSMID_PRESENT_
520 && (UseFSMIDOpt == 0 || (fres = fsmid_check(st1.st_fsmid, dpath)) == 0)
524 hln->dino = st2.st_ino;
525 if (VerboseOpt >= 3) {
527 logstd("%-32s md5-nochange\n", (dpath ? dpath : spath));
528 else if (UseFSMIDOpt)
529 logstd("%-32s fsmid-nochange\n", (dpath ? dpath : spath));
531 logstd("%-32s nochange\n", (dpath ? dpath : spath));
533 CountSourceBytes += size;
540 if (st2Valid && !S_ISDIR(st1.st_mode) && S_ISDIR(st2.st_mode)) {
542 logerr("%-32s SAFETY - refusing to copy file over directory\n",
543 (dpath ? dpath : spath)
546 return(0); /* continue with the cpdup anyway */
548 if (QuietOpt == 0 || AskConfirmation) {
549 logstd("%-32s WARNING: non-directory source will blow away\n"
550 "%-32s preexisting dest directory, continuing anyway!\n",
551 ((dpath) ? dpath : spath), "");
554 RemoveRecur(dpath, ddevNo);
558 * The various comparisons failed, copy it.
560 if (S_ISDIR(st1.st_mode)) {
564 logerr("%-32s/ fsmid-CHECK-FAILED\n", (dpath) ? dpath : spath);
565 if ((dir = opendir(spath)) != NULL) {
570 if (S_ISDIR(st2.st_mode) == 0) {
572 if (mkdir(dpath, st1.st_mode | 0700) != 0) {
573 logerr("%s: mkdir failed: %s\n",
574 (dpath ? dpath : spath), strerror(errno));
579 * Matt: why don't you check error codes here?
582 chown(dpath, st1.st_uid, st1.st_gid);
586 * Directory must be scanable by root for cpdup to
587 * work. We'll fix it later if the directory isn't
588 * supposed to be readable ( which is why we fixup
589 * st2.st_mode to match what we did ).
591 if ((st2.st_mode & 0700) != 0700) {
592 chmod(dpath, st2.st_mode | 0700);
596 logstd("%s\n", dpath ? dpath : spath);
600 if ((int)sdevNo >= 0 && st1.st_dev != sdevNo) {
606 if ((int)ddevNo >= 0 && st2.st_dev != ddevNo) {
613 * scan .cpignore file for files/directories
622 if (UseCpFile[0] == '/') {
623 fpath = mprintf("%s", UseCpFile);
625 fpath = mprintf("%s/%s", spath, UseCpFile);
627 AddList(&list, strrchr(fpath, '/') + 1, 1);
628 if ((fi = fopen(fpath, "r")) != NULL) {
629 while (fgets(buf, sizeof(buf), fi) != NULL) {
632 if (l && buf[l-1] == '\n')
634 if (buf[0] && buf[0] != '#')
635 AddList(&list, buf, 1);
643 * Automatically exclude MD5CacheFile that we create on the
644 * source from the copy to the destination.
646 * Automatically exclude a FSMIDCacheFile on the source that
647 * would otherwise overwrite the one we maintain on the target.
650 AddList(&list, MD5CacheFile, 1);
652 AddList(&list, FSMIDCacheFile, 1);
654 while (noLoop == 0 && (den = readdir(dir)) != NULL) {
661 if (strcmp(den->d_name, ".") == 0 ||
662 strcmp(den->d_name, "..") == 0
667 * ignore if on .cpignore list
669 if (AddList(&list, den->d_name, 0) == 1) {
672 nspath = mprintf("%s/%s", spath, den->d_name);
674 ndpath = mprintf("%s/%s", dpath, den->d_name);
689 * Remove files/directories from destination that do not appear
692 if (dpath && (dir = opendir(dpath)) != NULL) {
693 while (noLoop == 0 && (den = readdir(dir)) != NULL) {
697 if (strcmp(den->d_name, ".") == 0 ||
698 strcmp(den->d_name, "..") == 0
703 * If object does not exist in source or .cpignore
704 * then recursively remove it.
706 if (AddList(&list, den->d_name, 3) == 3) {
709 ndpath = mprintf("%s/%s", dpath, den->d_name);
710 RemoveRecur(ndpath, ddevNo);
720 st1.st_uid != st2.st_uid ||
721 st1.st_gid != st2.st_gid
723 chown(dpath, st1.st_uid, st1.st_gid);
725 if (st2Valid == 0 || st1.st_mode != st2.st_mode) {
726 chmod(dpath, st1.st_mode);
728 if (st2Valid == 0 || st1.st_flags != st2.st_flags) {
729 chflags(dpath, st1.st_flags);
733 } else if (dpath == NULL) {
735 * If dpath is NULL, we are just updating the MD5
737 if (UseMD5Opt && S_ISREG(st1.st_mode)) {
738 mres = md5_check(spath, NULL);
740 if (VerboseOpt > 1) {
742 logstd("%-32s md5-update\n", (dpath) ? dpath : spath);
744 logstd("%-32s md5-ok\n", (dpath) ? dpath : spath);
745 } else if (!QuietOpt && mres < 0) {
746 logstd("%-32s md5-update\n", (dpath) ? dpath : spath);
749 } else if (S_ISREG(st1.st_mode)) {
755 path = mprintf("%s.tmp", dpath);
758 * Handle check failure message.
761 logerr("%-32s md5-CHECK-FAILED\n", (dpath) ? dpath : spath);
763 logerr("%-32s fsmid-CHECK-FAILED\n", (dpath) ? dpath : spath);
766 * Not quite ready to do the copy yet. If UseHLPath is defined,
767 * see if we can hardlink instead.
770 if (UseHLPath && (hpath = checkHLPath(&st1, spath, dpath)) != NULL) {
771 if (link(hpath, dpath) == 0) {
773 logstd("%-32s hardlinked(-H)\n",
774 (dpath ? dpath : spath));
780 * Shucks, we may have hit a filesystem hard linking limit,
781 * we have to copy instead.
786 if ((fd1 = open(spath, O_RDONLY)) >= 0) {
787 if ((fd2 = open(path, O_WRONLY|O_CREAT|O_EXCL, 0600)) < 0) {
789 * There could be a .tmp file from a previously interrupted
790 * run, delete and retry. Fail if we still can't get at it.
794 fd2 = open(path, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600);
801 * Matt: What about holes?
804 while ((n = read(fd1, IOBuf1, sizeof(IOBuf1))) > 0) {
806 if (write(fd2, IOBuf1, n) != n)
812 struct timeval tv[2];
814 bzero(tv, sizeof(tv));
815 tv[0].tv_sec = st1.st_mtime;
816 tv[1].tv_sec = st1.st_mtime;
819 chown(path, st1.st_uid, st1.st_gid);
820 chmod(path, st1.st_mode);
821 if (xrename(path, dpath, st2.st_flags) != 0) {
822 logerr("%-32s rename-after-copy failed: %s\n",
823 (dpath ? dpath : spath), strerror(errno)
828 logstd("%-32s copy-ok\n", (dpath ? dpath : spath));
830 chflags(dpath, st1.st_flags);
832 CountReadBytes += size;
833 CountWriteBytes += size;
834 CountSourceBytes += size;
838 logerr("%-32s %s failed: %s\n",
839 (dpath ? dpath : spath), op, strerror(errno)
845 logerr("%-32s create (uid %d, euid %d) failed: %s\n",
846 (dpath ? dpath : spath), getuid(), geteuid(),
853 logerr("%-32s copy: open failed: %s\n",
854 (dpath ? dpath : spath),
863 if (!r && stat(dpath, &st2) == 0)
864 hln->dino = st2.st_ino;
868 } else if (S_ISLNK(st1.st_mode)) {
875 snprintf(path, sizeof(path), "%s.tmp", dpath);
876 n1 = readlink(spath, link1, sizeof(link1) - 1);
877 n2 = readlink(dpath, link2, sizeof(link2) - 1);
879 if (ForceOpt || n1 != n2 || bcmp(link1, link2, n1) != 0) {
883 if (symlink(link1, path) < 0) {
884 logerr("%-32s symlink (%s->%s) failed: %s\n",
885 (dpath ? dpath : spath), link1, path,
890 lchown(path, st1.st_uid, st1.st_gid);
892 * there is no lchmod() or lchflags(), we
893 * cannot chmod or chflags a softlink.
895 if (xrename(path, dpath, st2.st_flags) != 0) {
896 logerr("%-32s rename softlink (%s->%s) failed: %s\n",
897 (dpath ? dpath : spath),
898 path, dpath, strerror(errno));
899 } else if (VerboseOpt) {
900 logstd("%-32s softlink-ok\n", (dpath ? dpath : spath));
903 CountWriteBytes += n1;
908 logstd("%-32s nochange\n", (dpath ? dpath : spath));
910 CountSourceBytes += n1;
911 CountReadBytes += n1;
912 if (n2 > 0) CountReadBytes += n2;
916 logerr("%-32s softlink-failed\n", (dpath ? dpath : spath));
918 } else if (S_ISCHR(st1.st_mode) || S_ISBLK(st1.st_mode)) {
923 st1.st_mode != st2.st_mode ||
924 st1.st_rdev != st2.st_rdev ||
925 st1.st_uid != st2.st_uid ||
926 st1.st_gid != st2.st_gid
928 snprintf(path, sizeof(path), "%s.tmp", dpath);
931 if (mknod(path, st1.st_mode, st1.st_rdev) == 0) {
932 chmod(path, st1.st_mode);
933 chown(path, st1.st_uid, st1.st_gid);
935 if (xrename(path, dpath, st2.st_flags) != 0) {
936 logerr("%-32s dev-rename-after-create failed: %s\n",
937 (dpath ? dpath : spath),
940 } else if (VerboseOpt) {
941 logstd("%-32s dev-ok\n", (dpath ? dpath : spath));
946 logerr("%-32s dev failed: %s\n",
947 (dpath ? dpath : spath), strerror(errno)
952 logstd("%-32s nochange\n", (dpath ? dpath : spath));
965 RemoveRecur(const char *dpath, dev_t devNo)
969 if (lstat(dpath, &st) == 0) {
972 if (st.st_dev == devNo) {
973 if (S_ISDIR(st.st_mode)) {
976 if ((dir = opendir(dpath)) != NULL) {
978 while ((den = readdir(dir)) != NULL) {
981 if (strcmp(den->d_name, ".") == 0)
983 if (strcmp(den->d_name, "..") == 0)
985 ndpath = mprintf("%s/%s", dpath, den->d_name);
986 RemoveRecur(ndpath, devNo);
991 if (AskConfirmation && NoRemoveOpt == 0) {
993 if (rmdir(dpath) < 0) {
994 logerr("%-32s rmdir failed: %s\n",
995 dpath, strerror(errno)
1003 logstd("%-32s not-removed\n", dpath);
1004 } else if (rmdir(dpath) == 0) {
1006 logstd("%-32s rmdir-ok\n", dpath);
1007 CountRemovedItems++;
1009 logerr("%-32s rmdir failed: %s\n",
1010 dpath, strerror(errno)
1015 if (AskConfirmation && NoRemoveOpt == 0) {
1017 if (remove(dpath) < 0) {
1018 logerr("%-32s remove failed: %s\n",
1019 dpath, strerror(errno)
1022 CountRemovedItems++;
1027 logstd("%-32s not-removed\n", dpath);
1028 } else if (remove(dpath) == 0) {
1030 logstd("%-32s remove-ok\n", dpath);
1031 CountRemovedItems++;
1033 logerr("%-32s remove failed: %s\n",
1034 dpath, strerror(errno)
1044 InitList(List *list)
1046 bzero(list, sizeof(List));
1047 list->li_Node.no_Next = &list->li_Node;
1051 ResetList(List *list)
1055 while ((node = list->li_Node.no_Next) != &list->li_Node) {
1056 list->li_Node.no_Next = node->no_Next;
1063 AddList(List *list, const char *name, int n)
1071 * Scan against wildcards. Only a node value of 1 can be a wildcard
1072 * ( usually scanned from .cpignore )
1075 for (node = list->li_Hash[0]; node; node = node->no_HNext) {
1076 if (strcmp(name, node->no_Name) == 0 ||
1077 (n != 1 && node->no_Value == 1 && WildCmp(node->no_Name, name) == 0)
1079 return(node->no_Value);
1084 * Look for exact match
1087 for (node = list->li_Hash[hv]; node; node = node->no_HNext) {
1088 if (strcmp(name, node->no_Name) == 0) {
1089 return(node->no_Value);
1092 node = malloc(sizeof(Node) + strlen(name) + 1);
1094 fprintf(stderr, "out of memory\n");
1098 node->no_Next = list->li_Node.no_Next;
1099 list->li_Node.no_Next = node;
1101 node->no_HNext = list->li_Hash[hv];
1102 list->li_Hash[hv] = node;
1104 strcpy(node->no_Name, name);
1111 shash(const char *s)
1118 if (*s == '*' || *s == '?' ||
1119 *s == '{' || *s == '}' ||
1120 *s == '[' || *s == ']' ||
1125 hv = (hv << 5) ^ *s ^ (hv >> 23);
1128 return(((hv >> 16) ^ hv) & HMASK);
1132 * WildCmp() - compare wild string to sane string
1134 * Return 0 on success, -1 on failure.
1138 WildCmp(const char *w, const char *s)
1141 * skip fixed portion
1147 if (w[1] == 0) /* optimize wild* case */
1153 for (i = 0; i <= l; ++i) {
1154 if (WildCmp(w + 1, s + i) == 0)
1168 if (*w == 0) /* terminator */
1180 YesNo(const char *path)
1184 fprintf(stderr, "remove %s (Yes/No) [No]? ", path);
1187 first = ch = getchar();
1188 while (ch != '\n' && ch != EOF)
1190 return ((first == 'y' || first == 'Y'));
1194 * xrename() - rename with override
1196 * If the rename fails, attempt to override st_flags on the
1197 * destination and rename again. If that fails too, try to
1198 * set the flags back the way they were and give up.
1202 xrename(const char *src, const char *dst, u_long flags)
1208 if ((r = rename(src, dst)) < 0) {
1210 if ((r = rename(src, dst)) < 0)
1211 chflags(dst, flags);
1217 xlink(const char *src, const char *dst, u_long flags)
1223 if ((r = link(src, dst)) < 0) {
1227 chflags(src, flags);