1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) Linux Test Project, 2001-2023
* Copyright (c) International Business Machines Corp., 2001
*/
/*\
* [Description]
*
* Tool to generate data for testing file locking.
* Used in nfslock01.sh.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i, j, k, nlines, nchars, ctype;
char c, buf[BUFSIZ];
FILE *fp;
if (argc != 5) {
fprintf(stderr, "usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n");
exit(2);
}
fp = fopen(argv[1], "w");
nchars = atoi(argv[2]);
nlines = atoi(argv[3]);
ctype = atoi(argv[4]);
if (nchars > BUFSIZ) {
fprintf(stderr, "Exceeded the maximum limit of the buffer (%d)\n", BUFSIZ);
exit(3);
}
if (nchars < 1) {
fprintf(stderr, "<char/line> must be > 0\n");
exit(3);
}
if (nlines < 1) {
fprintf(stderr, "<lines> must be > 0\n");
exit(3);
}
k = 0;
for (i = 1; i <= nlines; i++) {
if (ctype)
c = ((i % 2) ? '1' : '0');
else
c = 'A' + k;
for (j = 0; j < nchars - 1; j++)
buf[j] = c;
fprintf(fp, "%s\n", buf);
if (!ctype) {
if (i != 1 && i % 26 == 0)
k = 0;
else
k++;
}
}
fclose(fp);
return 0;
}
|