comparison ffstools/tiffs-mkfs/ffsparam.c @ 705:12ae93940467

tiffs-mkfs program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 20 May 2020 06:55:58 +0000
parents
children 178ed445021d
comparison
equal deleted inserted replaced
704:dacd9fdc392a 705:12ae93940467
1 #include <sys/types.h>
2 #include <sys/param.h>
3 #include <ctype.h>
4 #include <stdio.h>
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <strings.h>
9 #include "struct.h"
10 #include "globals.h"
11
12 void
13 parse_org_arg(arg)
14 char *arg;
15 {
16 char *cp;
17
18 cp = index(arg, 'x');
19 if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) {
20 fprintf(stderr,
21 "error: TIFFS organization argument \"%s\" is invalid\n", arg);
22 exit(1);
23 }
24 *cp++ = '\0';
25 if (!strcmp(arg, "8"))
26 ffs_sector_size = 0x2000;
27 else if (!strcmp(arg, "16"))
28 ffs_sector_size = 0x4000;
29 else if (!strcmp(arg, "32"))
30 ffs_sector_size = 0x8000;
31 else if (!strcmp(arg, "64"))
32 ffs_sector_size = 0x10000;
33 else if (!strcmp(arg, "128"))
34 ffs_sector_size = 0x20000;
35 else if (!strcmp(arg, "256"))
36 ffs_sector_size = 0x40000;
37 else {
38 fprintf(stderr,
39 "error: \"%s\" is not a recognized flash sector size\n",
40 arg);
41 exit(1);
42 }
43 ffs_nsectors = atoi(cp);
44 if (ffs_nsectors < 3 || ffs_nsectors > 128) {
45 fprintf(stderr,
46 "error: \"%s\" is not a reasonable number of FFS sectors\n",
47 cp);
48 exit(1);
49 }
50 }
51
52 void
53 preen_chunk_size_max()
54 {
55 if (chunk_size_max) {
56 if (chunk_size_max > ffs_sector_size / 2) {
57 fprintf(stderr,
58 "error: max chunk size specified with -c is too large\n");
59 exit(1);
60 }
61 return;
62 }
63 /* default matching TI's code */
64 if (ffs_sector_size * ffs_nsectors > 1024*1024)
65 chunk_size_max = 8192;
66 else if (ffs_sector_size / 8 < 2048)
67 chunk_size_max = ffs_sector_size / 8;
68 else
69 chunk_size_max = 2048;
70 }
71
72 void
73 preen_block_files_max()
74 {
75 unsigned journal_size;
76
77 if (block_files_max)
78 return;
79 /* default matching TI's code */
80 journal_size = ffs_sector_size >> 4;
81 if (journal_size < 1024)
82 journal_size = 1024;
83 block_files_max = (journal_size >> 4) - 6;
84 }