- int rc;
- int opt;
- int blocksize = 4096;
- int keysize = 8;
- int recsize = 8;
- int ptrsize = 4;
- int verbose = 0;
- void *buf;
- char *fmtstr = "lfix";
- enum iam_fmt_t fmt;
-
- do {
- opt = getopt(argc, argv, "hb:k:r:p:vf:");
- switch (opt) {
- case 'v':
- verbose++;
- case -1:
- break;
- case 'b':
- blocksize = atoi(optarg);
- break;
- case 'k':
- keysize = atoi(optarg);
- break;
- case 'r':
- recsize = atoi(optarg);
- break;
- case 'p':
- ptrsize = atoi(optarg);
- break;
- case 'f':
- fmtstr = optarg;
- break;
- case '?':
- default:
- fprintf(stderr, "Unable to parse options.");
- case 'h':
- usage();
- return 0;
- }
- } while (opt != -1);
-
- if (ptrsize != 4 && ptrsize != 8) {
- fprintf(stderr, "Invalid ptrsize (%i). "
- "Only 4 and 8 are supported\n", ptrsize);
- return 1;
- }
-
- if (blocksize <= 100 || keysize < 1 || recsize < 0) {
- fprintf(stderr, "Too small record, key or block block\n");
- return 1;
- }
-
- if (keysize + recsize + sizeof(struct iam_leaf_head) > blocksize / 3) {
- fprintf(stderr, "Too large (record, key) or too small block\n");
- return 1;
- }
-
- if (!strcmp(fmtstr, "lfix"))
- fmt = FMT_LFIX;
- else if (!strcmp(fmtstr, "lvar"))
- fmt = FMT_LVAR;
- else {
- fprintf(stderr, "Wrong format `%s'\n", fmtstr);
- return 1;
- }
-
- if (verbose > 0) {
- fprintf(stderr,
- "fmt: %s, key: %i, rec: %i, ptr: %i, block: %i\n",
- fmtstr, keysize, recsize, ptrsize, blocksize);
- }
- buf = malloc(blocksize);
- if (buf == NULL) {
- fprintf(stderr, "Unable to allocate %i bytes\n", blocksize);
- return 1;
- }
-
- memset(buf, 0, blocksize);
-
- if (fmt == FMT_LFIX)
- lfix_root(buf, blocksize, keysize, ptrsize, recsize);
- else
- lvar_root(buf, blocksize, keysize, ptrsize, recsize);
-
- rc = write(1, buf, blocksize);
- if (rc != blocksize) {
- fprintf(stderr, "Unable to write root node: %m (%i)\n", rc);
- free(buf);
- return 1;
- }
-
- /* form leaf */
- memset(buf, 0, blocksize);
-
- if (fmt == FMT_LFIX)
- lfix_leaf(buf, blocksize, keysize, ptrsize, recsize);
- else
- lvar_leaf(buf, blocksize, keysize, ptrsize, recsize);
-
- rc = write(1, buf, blocksize);
- free(buf);
- if (rc != blocksize) {
- fprintf(stderr, "Unable to write leaf node: %m (%i)\n", rc);
- return 1;
- }
- if (verbose > 0)
- fprintf(stderr, "Don't forget to umount/mount "
- "before accessing iam from the kernel!\n");
- return 0;
+ int rc;
+ int opt;
+ int blocksize = 4096;
+ int keysize = 8;
+ int recsize = 8;
+ int ptrsize = 4;
+ int verbose = 0;
+ void *buf;
+ char *fmtstr = "lfix";
+ enum iam_fmt_t fmt;
+
+ do {
+ opt = getopt(argc, argv, "hb:k:r:p:vf:");
+ switch (opt) {
+ case 'v':
+ verbose++;
+ case -1:
+ break;
+ case 'b':
+ blocksize = atoi(optarg);
+ break;
+ case 'k':
+ keysize = atoi(optarg);
+ break;
+ case 'r':
+ recsize = atoi(optarg);
+ break;
+ case 'p':
+ ptrsize = atoi(optarg);
+ break;
+ case 'f':
+ fmtstr = optarg;
+ break;
+ case '?':
+ default:
+ fprintf(stderr, "Unable to parse options.");
+ case 'h':
+ usage();
+ return 0;
+ }
+ } while (opt != -1);
+
+ if (ptrsize != 4 && ptrsize != 8) {
+ fprintf(stderr,
+ "Invalid ptrsize (%i). Only 4 and 8 are supported\n",
+ ptrsize);
+ return 1;
+ }
+
+ if (blocksize <= 100 || keysize < 1 || recsize < 0) {
+ fprintf(stderr, "Too small record, key or block block\n");
+ return 1;
+ }
+
+ if (keysize + recsize + sizeof(struct iam_leaf_head) > blocksize / 3) {
+ fprintf(stderr, "Too large (record, key) or too small block\n");
+ return 1;
+ }
+
+ if (!strcmp(fmtstr, "lfix")) {
+ fmt = FMT_LFIX;
+ } else if (!strcmp(fmtstr, "lvar")) {
+ fmt = FMT_LVAR;
+ } else {
+ fprintf(stderr, "Wrong format `%s'\n", fmtstr);
+ return 1;
+ }
+
+ if (verbose > 0) {
+ fprintf(stderr,
+ "fmt: %s, key: %i, rec: %i, ptr: %i, block: %i\n",
+ fmtstr, keysize, recsize, ptrsize, blocksize);
+ }
+ buf = malloc(blocksize);
+ if (!buf) {
+ fprintf(stderr, "Unable to allocate %i bytes\n", blocksize);
+ return 1;
+ }
+
+ memset(buf, 0, blocksize);
+
+ if (fmt == FMT_LFIX)
+ lfix_root(buf, blocksize, keysize, ptrsize, recsize);
+ else
+ lvar_root(buf, blocksize, keysize, ptrsize, recsize);
+
+ rc = write(1, buf, blocksize);
+ if (rc != blocksize) {
+ fprintf(stderr, "Unable to write root node: %m (%i)\n", rc);
+ free(buf);
+ return 1;
+ }
+
+ /* form leaf */
+ memset(buf, 0, blocksize);
+
+ if (fmt == FMT_LFIX)
+ lfix_leaf(buf, blocksize, keysize, ptrsize, recsize);
+ else
+ lvar_leaf(buf, blocksize, keysize, ptrsize, recsize);
+
+ rc = write(1, buf, blocksize);
+ free(buf);
+ if (rc != blocksize) {
+ fprintf(stderr, "Unable to write leaf node: %m (%i)\n", rc);
+ return 1;
+ }
+ if (verbose > 0)
+ fprintf(stderr,
+ "Don't forget to umount/mount before accessing iam from the kernel!\n");
+ return 0;