view ffstools/tiffs-rd/main.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents d68275d47a32
children
line wrap: on
line source

/*
 * This C module contains the main() function for the tiffs utility,
 * dispatching control to different operation commands.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "types.h"
#include "globals.h"

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"))
		eraseblk_size = 0x2000;
	else if (!strcmp(arg, "16"))
		eraseblk_size = 0x4000;
	else if (!strcmp(arg, "32"))
		eraseblk_size = 0x8000;
	else if (!strcmp(arg, "64"))
		eraseblk_size = 0x10000;
	else if (!strcmp(arg, "128"))
		eraseblk_size = 0x20000;
	else if (!strcmp(arg, "256"))
		eraseblk_size = 0x40000;
	else {
		fprintf(stderr,
			"error: \"%s\" is not a recognized flash sector size\n",
			arg);
		exit(1);
	}
	total_blocks = atoi(cp);
	if (total_blocks < 1 || total_blocks > 128) {
		fprintf(stderr,
		"error: \"%s\" is not a reasonable number of FFS sectors\n",
			cp);
		exit(1);
	}
	total_ffs_size = eraseblk_size * total_blocks;
	inode_limit = eraseblk_size >> 4;
}

extern int cmd_blkhdr();
extern int cmd_cat();
extern int cmd_catino();
extern int cmd_decode();
extern int cmd_fsinfo();
extern int cmd_ls();
extern int cmd_lsino();
extern int cmd_xtr();

static struct cmdtab {
	char *cmd;
	int (*func)();
} cmdtab[] = {
	{"blkhdr", cmd_blkhdr},
	{"cat", cmd_cat},
	{"catino", cmd_catino},
	{"decode", cmd_decode},
	{"fsck", NULL},
	{"fsinfo", cmd_fsinfo},
	{"ls", cmd_ls},
	{"lsino", cmd_lsino},
	{"xtr", cmd_xtr},
	{NULL, NULL}
};

main(argc, argv)
	char **argv;
{
	extern int optind;
	extern char *optarg;
	int c;
	char *cmd;
	struct cmdtab *tp;

	while ((c = getopt(argc, argv, "+a:o:Or:v")) != EOF)
		switch (c) {
		case 'a':
			index_blk_num = atoi(optarg);
			continue;
		case 'o':
			imgfile_offset = strtoul(optarg, 0, 0);
			continue;
		case 'O':
			old_16bit_location = 1;
			continue;
		case 'r':
			root_inode = strtoul(optarg, 0, 16);
			continue;
		case 'v':
			verbose++;
			continue;
		default:
usage:			fprintf(stderr,
			"usage: %s [global-options] <imgfile> <org> <op> ...\n",
				argv[0]);
			exit(1);
		}
	if (argc - optind < 3)
		goto usage;
	imgfile = argv[optind];
	parse_org_arg(argv[optind+1]);
	cmd = argv[optind+2];

	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, cmd))
			break;
	if (!tp->func) {
		fprintf(stderr,
			"%s: operation \"%s\" is unknown or unimplemented\n",
			argv[0], cmd);
		exit(1);
	}
	optind += 2;
	return tp->func(argc - optind, argv + optind);
}