From cec572daccafa1e912cbed363df6f84687778c6f Mon Sep 17 00:00:00 2001 From: Nicholas D Steeves Date: Sat, 23 Apr 2016 00:41:30 +0100 Subject: btrfs-progs (4.4.1-1.1) unstable; urgency=medium * Non-maintainer upload. * New upstream release. * Rename package to btrfs-progs (Closes: #780081) * Update standards version to 3.9.7 (no changes needed). * debian/control: Add "Breaks" per Gianfranco Costamagna's suggestion * Change lintian override to reflect package rename * Switch from using postinst and postrm to using triggers per Christian Seiler's recommendation. # imported from the archive --- btrfs-crc.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 btrfs-crc.c (limited to 'btrfs-crc.c') diff --git a/btrfs-crc.c b/btrfs-crc.c new file mode 100644 index 00000000..723e0b7a --- /dev/null +++ b/btrfs-crc.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2013 STRATO. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include "crc32c.h" +#include "utils.h" + +void usage(void) +{ + printf("usage: btrfs-crc filename\n"); + printf(" print out the btrfs crc for \"filename\"\n"); + printf("usage: btrfs-crc filename -c crc [-s seed] [-l length]\n"); + printf(" brute force search for file names with the given crc\n"); + printf(" -s seed the random seed (default: random)\n"); + printf(" -l length the length of the file names (default: 10)\n"); + exit(1); +} + +int main(int argc, char **argv) +{ + int c; + unsigned long checksum = 0; + char *str; + char *buf; + int length = 10; + int seed = getpid() ^ getppid(); + int loop = 0; + int i; + + while ((c = getopt(argc, argv, "l:c:s:h")) != -1) { + switch (c) { + case 'l': + length = atol(optarg); + break; + case 'c': + sscanf(optarg, "%li", &checksum); + loop = 1; + break; + case 's': + seed = atol(optarg); + break; + case 'h': + usage(); + case '?': + return 255; + } + } + + set_argv0(argv); + str = argv[optind]; + + if (!loop) { + if (check_argc_min(argc - optind, 1)) + return 255; + + printf("%12u - %s\n", crc32c(~1, str, strlen(str)), str); + return 0; + } + + buf = malloc(length); + if (!buf) + return -ENOMEM; + srand(seed); + + while (1) { + for (i = 0; i < length; i++) + buf[i] = rand() % 94 + 33; + if (crc32c(~1, buf, length) == checksum) + printf("%12lu - %.*s\n", checksum, length, buf); + } + + return 0; +} -- cgit v1.2.3