view ffstools/tiffs-mkfs/ffsparam.c @ 851:526a8cfbbfd8

CHANGES: fc-host-tools-r16 released
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 18 Aug 2021 15:48:35 +0000
parents 178ed445021d
children
line wrap: on
line source

#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_journal_size()
{
	if (journal_size)
		return;
	/* default matching TI's code */
	journal_size = ffs_sector_size >> 4;
	if (journal_size < 1024)
		journal_size = 1024;
}

void
preen_block_files_max()
{
	unsigned local_journal_size;

	if (block_files_max)
		return;
	/* default matching TI's code */
	local_journal_size = ffs_sector_size >> 4;
	if (local_journal_size < 1024)
		local_journal_size = 1024;
	block_files_max = (local_journal_size >> 4) - 6;
}