/*
 * Copyright (C) 2000-2003 ASANO Masahiro
 */

#include <unistd.h>
#include "crash.h"

PRIVATE addr_t xfs_inode();
const commandtable_t command_xfs_inode =
	{"xfs_inode", xfs_inode, "address", "[XFS] print xfs_inode_t table"};
extern addr_t print_xfs_inode();

PRIVATE addr_t xfs_bmbt_rec();
const commandtable_t command_xfs_bmbt_rec =
	{"xfs_bmbt_rec", xfs_bmbt_rec, "[-s] address", "[XFS] print xfs_bmbt_rec"};
extern addr_t print_xfs_bmbt_rec();

PRIVATE addr_t
xfs_inode()
{
	int i, c;
	addr_t addr = 0;

	while ((c = getopt(argcnt, args, "")) != EOF) {
		switch (c) {
		default:
			THROW(usage);
		}
	}

	if (argcnt > optind) {
		for (i = optind; i < argcnt; i++) {
			addr = getvalue(args[i]);
			addr = print_xfs_inode(addr, 1, 0);
		}
	} else {
		THROW(usage);
	}
	return addr;
}

PRIVATE addr_t
xfs_bmbt_rec()
{
	int c;
	addr_t addr = 0;
	int size = 16;
	int swap = 0;

	while ((c = getopt(argcnt, args, "s")) != EOF) {
		switch (c) {
		case 's':
			swap = 1;
			break;
		default:
			THROW(usage);
		}
	}

	if (argcnt == optind)
		THROW(usage);

	addr = getvalue(args[optind]);
	if (argcnt > optind + 1)
		size = (int)getvalue(args[optind + 1]);

	return print_xfs_bmbt_rec(addr, size, swap);
}
