Przeziêbienie mija...
Marcin Dalecki
dalecki w cs.net.pl
Nie, 21 Lut 1999, 22:36:33 CET
I muszê przyznawaæ siê niestety do omylon¶ci :-/
Oto poprawiona ³ata na fileutils implementuj±ca
wykorzystywanie nowego wywo³ania systemowego sendfile.
Po prostu ponownie musia³em stwierdziæ, ¿e ten syscall
nie jest zbyt "interligentny" i niedzia³a na plikach
które niedadz± siê a mmap-owaæ... Podobnie w przeciwieñstwie
do tego co my¶la³ Andrea Acrangielli ten syscall niezwraca
kodu b³edu lecz po prostu tylko -1...
Mi³ej zabawy z najszybszym cp...
¿yczy
--Marcin
-------------- nastêpna czê¶æ ---------
diff -ur fileutils-4.0/src/copy.c fileutils-4.0-new/src/copy.c
--- fileutils-4.0/src/copy.c Mon Sep 28 18:09:18 1998
+++ fileutils-4.0-new/src/copy.c Sun Feb 21 22:25:37 1999
@@ -26,6 +26,18 @@
#include <assert.h>
#include <sys/types.h>
+/*
+ * Check whatever the sendfile(2) system call is supporter on this system.
+ * Actually linux is even learning from NT :-).
+ */
+#if defined(__linux__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+#define HAS_SENDFILE
+#endif
+
+#ifdef HAS_SENDFILE
+#include <sys/sendfile.h>
+#endif
+
#include "system.h"
#include "error.h"
#include "backupfile.h"
@@ -236,6 +248,14 @@
}
#endif
+ /*
+ * If we expect to make any holes we resort to normalcopy mode.
+ * Better save then sorry...
+ */
+#ifdef HAS_SENDFILE
+ if (make_holes) {
+normal_copy:
+#endif
/* Make a buffer with space for a sentinel at the end. */
buf = (char *) alloca (buf_size + sizeof (int));
@@ -325,6 +345,25 @@
return_val = -1;
}
}
+#ifdef HAS_SENDFILE
+ } else {
+ /* No holes to be done, therefore we can safely apply sendfile(2). */
+ int val;
+ errno = 0;
+ val = sendfile(dest_desc, source_desc, NULL, sb.st_size);
+ if (val < 0)
+ switch(errno) {
+ case ENOSYS:
+ case EINVAL:
+ errno = 0;
+ goto normal_copy;
+ break;
+ default:
+ error (0, errno, "%s", dst_path);
+ return_val = -1;
+ }
+ }
+#endif
ret:
if (close (dest_desc) < 0)
Więcej informacji o liście dyskusyjnej pld-devel-pl