diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/tiffs-mkfs/ffsparam.c	Wed May 20 06:55:58 2020 +0000
@@ -0,0 +1,84 @@
+#include <sys/types.h>
+#include <sys/param.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "struct.h"
+#include "globals.h"
+
+void
+parse_org_arg(arg)
+	char *arg;
+{
+	char *cp;
+
+	cp = index(arg, 'x');
+	if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) {
+		fprintf(stderr,
+		"error: TIFFS organization argument \"%s\" is invalid\n", arg);
+		exit(1);
+	}
+	*cp++ = '\0';
+	if (!strcmp(arg, "8"))
+		ffs_sector_size = 0x2000;
+	else if (!strcmp(arg, "16"))
+		ffs_sector_size = 0x4000;
+	else if (!strcmp(arg, "32"))
+		ffs_sector_size = 0x8000;
+	else if (!strcmp(arg, "64"))
+		ffs_sector_size = 0x10000;
+	else if (!strcmp(arg, "128"))
+		ffs_sector_size = 0x20000;
+	else if (!strcmp(arg, "256"))
+		ffs_sector_size = 0x40000;
+	else {
+		fprintf(stderr,
+			"error: \"%s\" is not a recognized flash sector size\n",
+			arg);
+		exit(1);
+	}
+	ffs_nsectors = atoi(cp);
+	if (ffs_nsectors < 3 || ffs_nsectors > 128) {
+		fprintf(stderr,
+		"error: \"%s\" is not a reasonable number of FFS sectors\n",
+			cp);
+		exit(1);
+	}
+}
+
+void
+preen_chunk_size_max()
+{
+	if (chunk_size_max) {
+		if (chunk_size_max > ffs_sector_size / 2) {
+			fprintf(stderr,
+		"error: max chunk size specified with -c is too large\n");
+			exit(1);
+		}
+		return;
+	}
+	/* default matching TI's code */
+	if (ffs_sector_size * ffs_nsectors > 1024*1024)
+		chunk_size_max = 8192;
+	else if (ffs_sector_size / 8 < 2048)
+		chunk_size_max = ffs_sector_size / 8;
+	else
+		chunk_size_max = 2048;
+}
+
+void
+preen_block_files_max()
+{
+	unsigned journal_size;
+
+	if (block_files_max)
+		return;
+	/* default matching TI's code */
+	journal_size = ffs_sector_size >> 4;
+	if (journal_size < 1024)
+		journal_size = 1024;
+	block_files_max = (journal_size >> 4) - 6;
+}