10 void copy(char *from, char *to, int todir);
11 int copy1(int fdf, int fdt, char *from, char *to);
12 void worker(int fdf, int fdt, char *from, char *to);
14 void failure(void *, char *note);
20 main(int argc, char *argv[])
43 dirb = dirstat(argv[argc-1]);
44 if(dirb!=nil && (dirb->mode&DMDIR))
47 fprint(2, "fcp: %s not a directory\n", argv[argc-1]);
50 for(i=0; i<argc-1; i++)
51 copy(argv[i], argv[argc-1], todir);
57 fprint(2, "usage:\tfcp [-gux] fromfile tofile\n");
58 fprint(2, "\tfcp [-x] fromfile ... todir\n");
63 samefile(Dir *a, char *an, char *bn)
71 if(b->qid.type==a->qid.type)
72 if(b->qid.path==a->qid.path)
73 if(b->qid.vers==a->qid.vers)
76 fprint(2, "fcp: %s and %s are the same file\n", an, bn);
84 copy(char *from, char *to, int todir)
96 sprint(name, "%s/%s", to, elem);
100 if((dirb=dirstat(from))==nil){
101 fprint(2,"fcp: can't stat %s: %r\n", from);
107 fprint(2, "fcp: %s is a directory\n", from);
112 if(samefile(dirb, from, to)){
118 fdf=open(from, OREAD);
120 fprint(2, "fcp: can't open %s: %r\n", from);
125 fdt=create(to, OWRITE, mode);
127 fprint(2, "fcp: can't create %s: %r\n", to);
133 if(copy1(fdf, fdt, from, to)==0 && (xflag || gflag || uflag)){
136 dirt.mtime = dirb->mtime;
137 dirt.mode = dirb->mode;
140 dirt.uid = dirb->uid;
142 dirt.gid = dirb->gid;
143 if(dirfwstat(fdt, &dirt) < 0)
144 fprint(2, "fcp: warning: can't wstat %s: %r\n", to);
152 copy1(int fdf, int fdt, char *from, char *to)
154 int i, n, rv, pid[Nwork];
159 for(i=0; i<Nwork; i++){
160 switch(pid[n] = rfork(RFPROC|RFMEM)){
163 worker(fdf, fdt, from, to);
172 fprint(2, "fcp: rfork: %r\n");
178 while((w = wait()) != nil){
184 postnote(PNPROC, pid[i], "failure");
192 worker(int fdf, int fdt, char *from, char *to)
202 while(n = pread(fdf, bp, len, o)){
204 fprint(2, "reading %s at %lld: %r\n", from, o);
207 if(pwrite(fdt, buf, n, o) != n){
208 fprint(2, "writing %s: %r\n", to);
237 failure(void*, char *note)
239 if(strcmp(note, "failure") == 0)