lfn
serial
ticket/834-toolchain-update
topic/msim-upgrade
topic/simplify-dev-export
Last change
on this file since db9aa04 was b9060a83, checked in by Oleg Romanenko <romanenko.oleg@…>, 14 years ago |
Fix bug in fat_get_cluster_fat12 and fat_set_cluster_fat12:
offset should not be larger than size of sector
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 |
|
---|
2 | /** @addtogroup filecheck
|
---|
3 | * @{
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * @file filecrc.c
|
---|
8 | * @brief Tool for generating file with random data
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 |
|
---|
13 | #include <unistd.h>
|
---|
14 | #include <stdio.h>
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <sys/types.h>
|
---|
17 | #include <fcntl.h>
|
---|
18 | #include <errno.h>
|
---|
19 | #include <sys/time.h>
|
---|
20 | #include "crc32.h"
|
---|
21 |
|
---|
22 | #define NAME "filegen"
|
---|
23 | #define VERSION "0.0.1"
|
---|
24 |
|
---|
25 | #define BUFFERSIZE 256
|
---|
26 |
|
---|
27 |
|
---|
28 | static void print_help(void);
|
---|
29 |
|
---|
30 |
|
---|
31 | int main(int argc, char **argv) {
|
---|
32 | int rc;
|
---|
33 | uint64_t size = 0;
|
---|
34 |
|
---|
35 | if (argc < 3) {
|
---|
36 | print_help();
|
---|
37 | return 0;
|
---|
38 | }
|
---|
39 |
|
---|
40 | int fd = open(argv[1], O_WRONLY | O_CREAT);
|
---|
41 | if (fd < 0) {
|
---|
42 | printf("Unable to open %s for writing\n", argv[1]);
|
---|
43 | return 1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | rc = str_uint64(argv[2], NULL, 10, true, &size);
|
---|
47 | if (rc != EOK) {
|
---|
48 | printf("Cannot convert size to number\n");
|
---|
49 | return 1;
|
---|
50 | }
|
---|
51 |
|
---|
52 | struct timeval tv;
|
---|
53 | gettimeofday(&tv, NULL);
|
---|
54 | srandom(tv.tv_sec + tv.tv_usec / 100000);
|
---|
55 |
|
---|
56 | uint64_t i=0, pbuf=0;
|
---|
57 | uint32_t crc=~0;
|
---|
58 | char buf[BUFFERSIZE];
|
---|
59 |
|
---|
60 | while (i<size) {
|
---|
61 | pbuf=0;
|
---|
62 | while (i<size && pbuf<BUFFERSIZE) {
|
---|
63 | buf[pbuf] = rand() % 255;
|
---|
64 | i++;
|
---|
65 | pbuf++;
|
---|
66 | }
|
---|
67 | if (pbuf) {
|
---|
68 | crc32(buf, pbuf, &crc);
|
---|
69 | write(fd, buf, pbuf);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | close(fd);
|
---|
74 | crc = ~crc;
|
---|
75 | printf("%s : %x\n", argv[1], crc);
|
---|
76 |
|
---|
77 | return 0;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | /* Displays help for filegen */
|
---|
82 | static void print_help(void)
|
---|
83 | {
|
---|
84 | printf(
|
---|
85 | "Usage: %s <file> <size in bytes>\n",
|
---|
86 | NAME);
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * @}
|
---|
92 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.