int argc,
char **argv)
{
- return crc32c_test() != 0;
+ return crc32c_test(0) != 0;
}
static const cmdinfo_t crc32cselftest_cmd = {
printf("CRC_LE_BITS = %d\n", CRC_LE_BITS);
- errors = crc32c_test();
+ errors = crc32c_test(0);
return errors != 0;
}
{0xb18a0319, 0x00000026, 0x000007db, 0x9dc0bb48},
};
+/* Don't print anything to stdout. */
+#define CRC32CTEST_QUIET (1U << 0)
+
static int
-crc32c_test(void)
+crc32c_test(
+ unsigned int flags)
{
- int i;
- int errors = 0;
- int bytes = 0;
- struct timeval start, stop;
- uint64_t usec;
+ int i;
+ int errors = 0;
+ int bytes = 0;
+ struct timeval start, stop;
+ uint64_t usec;
/* keep static to prevent cache warming code from
* getting eliminated by the compiler */
- static uint32_t crc;
+ static uint32_t crc;
/* pre-warm the cache */
for (i = 0; i < 100; i++) {
usec = stop.tv_usec - start.tv_usec +
1000000 * (stop.tv_sec - start.tv_sec);
+ if (flags & CRC32CTEST_QUIET)
+ return errors;
+
if (errors)
printf("crc32c: %d self tests failed\n", errors);
else {
.PP
Many feature options allow an optional argument of 0 or 1, to explicitly
disable or enable the functionality.
+
+The correctness of the crc32c checksum implementation will be tested
+before formatting the filesystem.
+If the test fails, the format will abort.
.SH OPTIONS
Options may be specified either on the command line or in a configuration file.
Not all command line options can be specified in configuration files; only the
.B \-V
Prints the version number and exits.
.SS Checks Performed
+The correctness of the crc32c checksum implementation will be tested
+before examining the filesystem.
+If the test fails, the program will abort.
+
Inconsistencies corrected include the following:
.IP 1.
Inode and inode blockmap (addressing) checks:
#include "libxcmd.h"
#include "libfrog/fsgeom.h"
#include "libfrog/convert.h"
+#include "libfrog/crc32cselftest.h"
#include "proto.h"
#include <ini.h>
exit(0);
}
+ /* Make sure our checksum algorithm really works. */
+ if (crc32c_test(CRC32CTEST_QUIET) != 0) {
+ fprintf(stderr,
+ _("crc32c self-test failed, will not create a filesystem here.\n"));
+ return 1;
+ }
+
/*
* All values have been validated, discard the old device layout.
*/
#include "bmap.h"
#include "incore.h"
#include "prefetch.h"
+#include "libfrog/crc32cselftest.h"
#include <sys/resource.h>
static void
ts_create();
increase_rlimit();
pftrace_init();
+
+ if (crc32c_test(CRC32CTEST_QUIET) != 0)
+ do_error(
+ _("crc32c self-test failed, will not examine filesystem.\n"));
}