[patch] sendfile in fileutils

Andrea Arcangeli (andrea@e-mind.com)
Thu, 17 Dec 1998 18:13:23 +0100 (CET)


I' ve done a little patch to fileutils to allow me to do zero copy inside
`cp` and `dd`.

Here the patch against fileutils-4.0-1 (-1 is the debian
subrevision). The patch should allow cp to run fine also in kernels
without sendfile... (but not tried yet).

I also rebuild a the debian package:

ftp://e-mind.com/pub/linux/debian/fileutils+sendfile_4.0-1_i386.deb

If you want only the `cp` sendfile capable binary and you are not using debian:

1. donwload the file
2. run `ar x fileutils+sendfile_4.0-1_i386.deb`
3. tar tzf data.tar.gz

there you' ll find the binary i386...

--- copy.c~ Mon Sep 28 18:09:18 1998
+++ copy.c Thu Dec 17 18:00:26 1998
@@ -17,6 +17,8 @@

/* Extracted from cp.c and librarified by Jim Meyering. */

+/* sys_sendfile support by Andrea Arcangeli <andrea@e-mind.com> 981217 */
+
#ifdef _AIX
#pragma alloca
#endif
@@ -34,6 +36,10 @@
#include "cp-hash.h"
#include "path-concat.h"

+#include <asm/unistd.h>
+#define __NR_sendfile 187
+_syscall4(ssize_t,sendfile,int,fdo,int,fdi,off_t*,off,size_t,size);
+
#define DO_CHOWN(Chown, File, New_uid, New_gid) \
(Chown ((File), (x->myeuid == 0 ? (New_uid) : x->myeuid), (New_gid)) \
/* If non-root uses -p, it's ok if we can't preserve ownership. \
@@ -236,6 +242,12 @@
}
#endif

+ /* I don' t know what sendfile does with holes so to be safe we revert
+ * to the old case. -arca
+ */
+ if (make_holes)
+ {
+ no_zero_copy:
/* Make a buffer with space for a sentinel at the end. */

buf = (char *) alloca (buf_size + sizeof (int));
@@ -325,7 +337,21 @@
return_val = -1;
}
}
-
+ } else /* sendfile */ {
+ off_t offset = 0;
+ int retval;
+ switch ((retval = sendfile(dest_desc, source_desc, &offset, sb.st_size)))
+ {
+ case -ENOSYS:
+ goto no_zero_copy;
+ default:
+ if (retval < 0)
+ {
+ error (0, errno, "%s", dst_path);
+ return_val = -1;
+ }
+ }
+ }
ret:
if (close (dest_desc) < 0)
{

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/