Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F115730854
D26395.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D26395.diff
View Options
Index: head/bin/cp/utils.c
===================================================================
--- head/bin/cp/utils.c
+++ head/bin/cp/utils.c
@@ -74,6 +74,26 @@
*/
#define BUFSIZE_SMALL (MAXPHYS)
+static int
+copy_fallback(int from_fd, int to_fd, char *buf, size_t bufsize)
+{
+ int rcount;
+ ssize_t wresid, wcount = 0;
+ char *bufp;
+
+ rcount = read(from_fd, buf, bufsize);
+ if (rcount <= 0)
+ return (rcount);
+ for (bufp = buf, wresid = rcount; ; bufp += wcount, wresid -= wcount) {
+ wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
+ if (wcount >= (ssize_t)wresid)
+ break;
+ }
+ return (wcount < 0 ? wcount : rcount);
+}
+
int
copy_file(const FTSENT *entp, int dne)
{
@@ -88,6 +108,7 @@
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
#endif
+ int use_copy_file_range = 1;
from_fd = to_fd = -1;
if (!lflag && !sflag &&
@@ -212,9 +233,19 @@
err(1, "Not enough memory");
}
wtotal = 0;
- while ((rcount = copy_file_range(from_fd, NULL,
- to_fd, NULL, bufsize, 0)) > 0)
- {
+ do {
+ if (use_copy_file_range) {
+ rcount = copy_file_range(from_fd, NULL,
+ to_fd, NULL, bufsize, 0);
+ if (rcount < 0 && errno == EINVAL) {
+ /* Prob a non-seekable FD */
+ use_copy_file_range = 0;
+ }
+ }
+ if (!use_copy_file_range) {
+ rcount = copy_fallback(from_fd, to_fd,
+ buf, bufsize);
+ }
wtotal += rcount;
if (info) {
info = 0;
@@ -223,7 +254,7 @@
entp->fts_path, to.p_path,
cp_pct(wtotal, fs->st_size));
}
- }
+ } while (rcount > 0);
if (rcount < 0) {
warn("%s", entp->fts_path);
rval = 1;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 28, 8:01 PM (11 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17833268
Default Alt Text
D26395.diff (1 KB)
Attached To
Mode
D26395: cp: fall back to read/write if copy_file_range fails
Attached
Detach File
Event Timeline
Log In to Comment