This results in a significant decrease in syscall overhead
giving a 3% speedup to the digest utilities for example
(when processing large files from cache).
Storage is moved from the stack to the heap as some
threaded environments for example can have small stacks.
* lib/copy-file.c (copy_file_preserving): Use a 32KiB malloced buffer
* modules/copy-file: Depend on xalloc
* lib/md2.c: Likewise
* lib/md4.c: Likewise
* lib/md5.c: Likewise
* lib/sha1.c: Likewise
* lib/sha256.c: Likewise
* lib/sha512.c: Likewise
+2009-10-22 Pádraig Brady <P@draigBrady.com>
+
+ Use a better IO block size for modern systems
+ * lib/copy-file.c (copy_file_preserving): Used a 32KiB malloced buffer.
+ * lib/md2.c: Likewise.
+ * lib/md4.c: Likewise.
+ * lib/md5.c: Likewise.
+ * lib/sha1.c: Likewise.
+ * lib/sha256.c: Likewise.
+ * lib/sha512.c: Likewise.
+
2009-10-22 Eric Blake <ebb9@byu.net>
tests: avoid several compiler warnings
2009-10-22 Eric Blake <ebb9@byu.net>
tests: avoid several compiler warnings
#include "acl.h"
#include "binary-io.h"
#include "gettext.h"
#include "acl.h"
#include "binary-io.h"
#include "gettext.h"
#define _(str) gettext (str)
#define _(str) gettext (str)
+enum { IO_SIZE = 32 * 1024 };
void
copy_file_preserving (const char *src_filename, const char *dest_filename)
void
copy_file_preserving (const char *src_filename, const char *dest_filename)
struct stat statbuf;
int mode;
int dest_fd;
struct stat statbuf;
int mode;
int dest_fd;
- char buf[4096];
- const size_t buf_size = sizeof (buf);
+ char *buf = xmalloc (IO_SIZE);
src_fd = open (src_filename, O_RDONLY | O_BINARY);
if (src_fd < 0 || fstat (src_fd, &statbuf) < 0)
src_fd = open (src_filename, O_RDONLY | O_BINARY);
if (src_fd < 0 || fstat (src_fd, &statbuf) < 0)
/* Copy the file contents. */
for (;;)
{
/* Copy the file contents. */
for (;;)
{
- size_t n_read = safe_read (src_fd, buf, buf_size);
+ size_t n_read = safe_read (src_fd, buf, IO_SIZE);
if (n_read == SAFE_READ_ERROR)
error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename);
if (n_read == 0)
if (n_read == SAFE_READ_ERROR)
error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename);
if (n_read == 0)
error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename);
}
error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename);
}
#if !USE_ACL
if (close (dest_fd) < 0)
error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename);
#if !USE_ACL
if (close (dest_fd) < 0)
error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename);
#include <string.h>
#include <sys/types.h>
#include <string.h>
#include <sys/types.h>
# include "unlocked-io.h"
#endif
# include "unlocked-io.h"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
md2_stream (FILE *stream, void *resblock)
{
struct md2_ctx ctx;
md2_stream (FILE *stream, void *resblock)
{
struct md2_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
md2_init_ctx (&ctx);
/* Initialize the computation context. */
md2_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
md2_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
md2_finish_ctx (&ctx, resblock);
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <string.h>
#include <sys/types.h>
# define SWAP(n) (n)
#endif
# define SWAP(n) (n)
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
md4_stream (FILE * stream, void *resblock)
{
struct md4_ctx ctx;
md4_stream (FILE * stream, void *resblock)
{
struct md4_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
md4_init_ctx (&ctx);
/* Initialize the computation context. */
md4_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
md4_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
md4_finish_ctx (&ctx, resblock);
# define SWAP(n) (n)
#endif
# define SWAP(n) (n)
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
md5_stream (FILE *stream, void *resblock)
{
struct md5_ctx ctx;
md5_stream (FILE *stream, void *resblock)
{
struct md5_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
md5_init_ctx (&ctx);
/* Initialize the computation context. */
md5_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
md5_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
md5_finish_ctx (&ctx, resblock);
#include "sha1.h"
#include <stddef.h>
#include "sha1.h"
#include <stddef.h>
#include <string.h>
#if USE_UNLOCKED_IO
#include <string.h>
#if USE_UNLOCKED_IO
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#endif
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
sha1_stream (FILE *stream, void *resblock)
{
struct sha1_ctx ctx;
sha1_stream (FILE *stream, void *resblock)
{
struct sha1_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
sha1_init_ctx (&ctx);
/* Initialize the computation context. */
sha1_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
sha1_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
sha1_finish_ctx (&ctx, resblock);
#include "sha256.h"
#include <stddef.h>
#include "sha256.h"
#include <stddef.h>
#include <string.h>
#if USE_UNLOCKED_IO
#include <string.h>
#if USE_UNLOCKED_IO
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#endif
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 64 != 0
# error "invalid BLOCKSIZE"
#endif
sha256_stream (FILE *stream, void *resblock)
{
struct sha256_ctx ctx;
sha256_stream (FILE *stream, void *resblock)
{
struct sha256_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
sha256_init_ctx (&ctx);
/* Initialize the computation context. */
sha256_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
sha256_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
sha256_finish_ctx (&ctx, resblock);
sha224_stream (FILE *stream, void *resblock)
{
struct sha256_ctx ctx;
sha224_stream (FILE *stream, void *resblock)
{
struct sha256_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
sha224_init_ctx (&ctx);
/* Initialize the computation context. */
sha224_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
sha224_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
sha224_finish_ctx (&ctx, resblock);
#include "sha512.h"
#include <stddef.h>
#include "sha512.h"
#include <stddef.h>
#include <string.h>
#if USE_UNLOCKED_IO
#include <string.h>
#if USE_UNLOCKED_IO
#if BLOCKSIZE % 128 != 0
# error "invalid BLOCKSIZE"
#endif
#if BLOCKSIZE % 128 != 0
# error "invalid BLOCKSIZE"
#endif
sha512_stream (FILE *stream, void *resblock)
{
struct sha512_ctx ctx;
sha512_stream (FILE *stream, void *resblock)
{
struct sha512_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
sha512_init_ctx (&ctx);
/* Initialize the computation context. */
sha512_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
sha512_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
sha512_finish_ctx (&ctx, resblock);
sha384_stream (FILE *stream, void *resblock)
{
struct sha512_ctx ctx;
sha384_stream (FILE *stream, void *resblock)
{
struct sha512_ctx ctx;
- char buffer[BLOCKSIZE + 72];
+ char *buffer = malloc (BLOCKSIZE + 72);
+ if (!buffer)
+ return 1;
+
/* Initialize the computation context. */
sha384_init_ctx (&ctx);
/* Initialize the computation context. */
sha384_init_ctx (&ctx);
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
exit the loop after a partial read due to e.g., EAGAIN
or EWOULDBLOCK. */
if (ferror (stream))
+ {
+ free (buffer);
+ return 1;
+ }
goto process_partial_block;
}
goto process_partial_block;
}
/* Construct result in desired memory. */
sha384_finish_ctx (&ctx, resblock);
/* Construct result in desired memory. */
sha384_finish_ctx (&ctx, resblock);
configure.ac:
gl_COPY_FILE
configure.ac:
gl_COPY_FILE