btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / btrfs / crc_table.cpp
blob09ca7c25b2ec235c32850ee877a04966f2d6167f
1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the MIT License.
4 //
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //---------------------------------------------------------------------
8 /*! \file crc_table.cpp
10 Standalone program to generate the CRC table used for calculating
11 UDF tag id CRC values.
13 This code based off of crc code in UDF-2.50 specs, as permitted.
14 See UDF-2.50 6.5 for more information.
16 Reflected version by Jéme Duval
20 #include "system_dependencies.h"
23 typedef unsigned int uint32 ;
25 uint32
26 reflect32 (uint32 b)
28 uint32 rw = 0;
30 for (int i = 0; i < 32; i++){
31 if (b & 1)
32 rw |= 1 << (31 - i);
33 b >>= 1;
35 return rw;
39 int
40 main(int argc, char* argv[]) {
41 uint32 crc, poly;
43 if (argc != 2) {
44 fprintf(stderr, "USAGE: crc_table <octal polynomial=3667067501 for btrfs>\n");
45 return 0;
48 sscanf(argv[1], "%lo", &poly);
50 printf("//! CRC 0%o table, as generated by crc_table.cpp\n", poly);
51 printf("static uint32 crc_table[256] = { \n");
52 for (int n = 0; n < 256; n++) {
53 if (n % 8 == 0)
54 printf(" ");
55 crc = reflect32(n);
56 for (int i = 0; i < 8; i++) {
57 if (crc & 0x80000000)
58 crc = (crc << 1) ^ poly;
59 else
60 crc <<= 1;
62 crc = reflect32(crc);
63 printf("0x%08x%s ", crc, (n != 255 ? "," : ""));
64 if (n % 8 == 7)
65 printf("\n");
67 printf("};\n");
68 return 0;