projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a fsck symlink to btrfsck
[platform/upstream/btrfs-progs.git]
/
btrfs-crc.c
diff --git
a/btrfs-crc.c
b/btrfs-crc.c
index
6e21a0e
..
c3e4774
100644
(file)
--- a/
btrfs-crc.c
+++ b/
btrfs-crc.c
@@
-20,26
+20,29
@@
#include <stdlib.h>
#include <unistd.h>
#include "crc32c.h"
#include <stdlib.h>
#include <unistd.h>
#include "crc32c.h"
+#include "utils.h"
-void
usage(void
)
+void
print_usage(int status
)
{
printf("usage: btrfs-crc filename\n");
printf(" print out the btrfs crc for \"filename\"\n");
{
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("usage: btrfs-crc -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");
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);
+ printf("usage: btrfs-crc -h\n");
+ printf(" print this message\n");
+ exit(status);
}
int main(int argc, char **argv)
{
}
int main(int argc, char **argv)
{
-
char
c;
+
int
c;
unsigned long checksum = 0;
char *str;
char *buf;
int length = 10;
unsigned long checksum = 0;
char *str;
char *buf;
int length = 10;
-
int seed = getpid() ^ getppid()
;
+
u64 seed = 0
;
int loop = 0;
int i;
int loop = 0;
int i;
@@
-49,38
+52,41
@@
int main(int argc, char **argv)
length = atol(optarg);
break;
case 'c':
length = atol(optarg);
break;
case 'c':
-
checksum = atol(optarg
);
+
sscanf(optarg, "%li", &checksum
);
loop = 1;
break;
case 's':
loop = 1;
break;
case 's':
- seed = atol(optarg);
+ seed = atol
l
(optarg);
break;
case 'h':
break;
case 'h':
-
usage(
);
+
print_usage(1
);
case '?':
case '?':
-
return 255
;
+
print_usage(255)
;
}
}
}
}
+ set_argv0(argv);
str = argv[optind];
if (!loop) {
str = argv[optind];
if (!loop) {
- if (optind >= argc) {
- fprintf(stderr, "not enough arguments\n");
- return 255;
- }
+ if (check_argc_exact(argc - optind, 1))
+ print_usage(255);
+
printf("%12u - %s\n", crc32c(~1, str, strlen(str)), str);
return 0;
}
printf("%12u - %s\n", crc32c(~1, str, strlen(str)), str);
return 0;
}
+ if (check_argc_exact(argc - optind, 0))
+ print_usage(255);
buf = malloc(length);
if (!buf)
return -ENOMEM;
buf = malloc(length);
if (!buf)
return -ENOMEM;
- srand(seed);
+ if (seed)
+ init_rand_seed(seed);
while (1) {
for (i = 0; i < length; i++)
while (1) {
for (i = 0; i < length; i++)
- buf[i] = rand
() % 94
+ 33;
+ buf[i] = rand
_range(94)
+ 33;
if (crc32c(~1, buf, length) == checksum)
printf("%12lu - %.*s\n", checksum, length, buf);
}
if (crc32c(~1, buf, length) == checksum)
printf("%12lu - %.*s\n", checksum, length, buf);
}