]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/jerasure/Examples/jerasure_01.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / jerasure / jerasure / Examples / jerasure_01.c
1 /* *
2 * Copyright (c) 2014, James S. Plank and Kevin Greenan
3 * All rights reserved.
4 *
5 * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
6 * Coding Techniques
7 *
8 * Revision 2.0: Galois Field backend now links to GF-Complete
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * - Neither the name of the University of Tennessee nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /* Jerasure's authors:
41
42 Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
43 Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
44 Revision 1.0 - 2007: James S. Plank.
45 */
46
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include "jerasure.h"
50
51 #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
52
53 usage(char *s)
54 {
55 fprintf(stderr, "usage: jerasure_01 r c w - creates and prints out a matrix in GF(2^w).\n\n");
56 fprintf(stderr, " Element i,j is equal to 2^(i*c+j)\n");
57 fprintf(stderr, " \n");
58 fprintf(stderr, "This demonstrates jerasure_print_matrix().\n");
59 if (s != NULL) fprintf(stderr, "%s\n", s);
60 exit(1);
61 }
62
63 int main(int argc, char **argv)
64 {
65 int r, c, w, i, n;
66 int *matrix;
67
68 if (argc != 4) usage(NULL);
69 if (sscanf(argv[1], "%d", &r) == 0 || r <= 0) usage("Bad r");
70 if (sscanf(argv[2], "%d", &c) == 0 || c <= 0) usage("Bad c");
71 if (sscanf(argv[3], "%d", &w) == 0 || w <= 0) usage("Bad w");
72
73 matrix = talloc(int, r*c);
74
75 n = 1;
76 for (i = 0; i < r*c; i++) {
77 matrix[i] = n;
78 n = galois_single_multiply(n, 2, w);
79 }
80
81 printf("<HTML><TITLE>jerasure_01");
82 for (i = 1; i < argc; i++) printf(" %s", argv[i]);
83 printf("</TITLE>\n");
84 printf("<h3>jerasure_01");
85 for (i = 1; i < argc; i++) printf(" %s", argv[i]);
86 printf("</h3>\n");
87 printf("<pre>\n");
88
89 jerasure_print_matrix(matrix, r, c, w);
90 return 0;
91 }
92