test_rel.c revision 19c78dc07fce2d6f39b5e541562afc3ca1ea38ff
119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * test_rel.c
319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1997 Theodore Ts'o.
519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header%
719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * This file may be redistributed under the terms of the GNU Public
819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * License.
919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header%
1019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
1119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
1219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdio.h>
1319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <stdlib.h>
1419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <string.h>
1519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <unistd.h>
1619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#ifdef HAVE_GETOPT_H
1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <getopt.h>
1819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#endif
1919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <fcntl.h>
2019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <linux/ext2_fs.h>
2219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <et/com_err.h>
2419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <ss/ss.h>
2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <ext2fs/ext2fs.h>
2619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <ext2fs/irel.h>
2719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include <ext2fs/brel.h>
2819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include "test_rel.h"
3019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oextern ss_request_table test_cmds;
3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oext2_irel irel = NULL;
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'oext2_brel brel = NULL;
3519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which parses an inode number.
3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
3919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic int parse_inode(const char *request, const char *desc,
4019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       const char *str, ino_t *ino)
4119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
4219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char *tmp;
4319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	*ino = strtoul(str, &tmp, 0);
4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (*tmp) {
4619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(request, 0, "Bad %s - %s", desc, str);
4719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return 1;
4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 0;
5019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
5319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which parses a block number.
5419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
5519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic int parse_block(const char *request, const char *desc,
5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       const char *str, blk_t *blk)
5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
5819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char *tmp;
5919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	*blk = strtoul(str, &tmp, 0);
6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (*tmp) {
6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(request, 0, "Bad %s - %s", desc, str);
6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return 1;
6419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
6519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 0;
6619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
6719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
6919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which assures that a brel table is open
7019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
7119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic int check_brel(char *request)
7219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
7319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (brel)
7419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return 0;
7519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	com_err(request, 0, "A block relocation table must be open.");
7619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 1;
7719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
7819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
7919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which assures that an irel table is open
8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic int check_irel(char *request)
8319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
8419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (irel)
8519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return 0;
8619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	com_err(request, 0, "An inode relocation table must be open.");
8719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return 1;
8819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
8919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
9019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
9119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which displays a brel entry
9219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
9319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic void display_brel_entry(blk_t old,
9419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       struct ext2_block_relocate_entry *ent)
9519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
9619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	printf("Old= %u, New= %u, Owner= %u:%u\n", old, ent->new,
9719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	       ent->owner.block_ref, ent->offset);
9819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
9919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
10019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
10119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Helper function which displays an irel entry
10219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
10319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic void display_irel_entry(ino_t old,
10419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       struct ext2_inode_relocate_entry *ent,
10519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			       int do_refs)
10619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
10719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_reference ref;
10819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval;
10919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		first = 1;
11019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
11119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	printf("Old= %lu, New= %lu, Original=%lu, Max_refs=%u\n", old,
11219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	       ent->new, ent->orig, ent->max_refs);
11319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (!do_refs)
11419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
11519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
11619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_start_iter_ref(irel, old);
11719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
11819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("\tCouldn't get references: %s\n",
11919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		       error_message(retval));
12019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
12119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
12219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	while (1) {
12319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ext2fs_irel_next_ref(irel, &ref);
12419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval) {
12519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			printf("(%s) ", error_message(retval));
12619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
12719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
12819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (ref.block == 0)
12919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
13019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (first) {
13119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			fputc('\t', stdout);
13219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			first = 0;
13319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		} else
13419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			printf(", ");
13519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("%u:%u", ref.block, ref.offset);
13619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
13719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (!first)
13819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		fputc('\n', stdout);
13919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
14019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
14119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
14219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * These are the actual command table procedures
14319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
14419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_ma_create(int argc, char **argv)
14519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
14619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "Usage: %s name max_blocks\n";
14719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval;
14819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t		max_blk;
14919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
15019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 3) {
15119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
15219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
15319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
15419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "max_blocks", argv[2], &max_blk))
15519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
15619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_memarray_create(argv[1], max_blk, &brel);
15719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
15819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while opening memarray brel");
15919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
16019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
16119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
16219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
16319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
16419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_free(int argc, char **argv)
16519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
16619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
16719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
16819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ext2fs_brel_free(brel);
16919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	brel = NULL;
17019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
17119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
17219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
17319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_put(int argc, char **argv)
17419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
17519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "usage: %s old_block new_block [owner] [offset]";
17619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
17719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_block_relocate_entry ent;
17819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	old, new, offset=0, owner=0;
17919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
18119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
18219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
18319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 3) {
18419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
18519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
18619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
18719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "old block", argv[1], &old))
18819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
18919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "new block", argv[2], &new))
19019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
19119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc > 3 &&
19219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	    parse_block(argv[0], "owner block", argv[3], &owner))
19319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
19419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc > 4 &&
19519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	    parse_block(argv[0], "offset", argv[4], &offset))
19619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
19719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (offset > 65535) {
19819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Offset too large.\n");
19919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
20019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
20119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.new = new;
20219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.offset = (__u16) offset;
20319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.flags = 0;
20419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.owner.block_ref = owner;
20519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
20619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_put(brel, old, &ent);
20719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
20819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_put");
20919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
21019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
21119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
21219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
21319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
21419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_get(int argc, char **argv)
21519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
21619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s block";
21719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
21819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_block_relocate_entry ent;
21919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	blk;
22019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
22119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
22219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
22319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
22419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
22519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
22619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
22719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "block", argv[1], &blk))
22819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
22919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_get(brel, blk, &ent);
23019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
23119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_get");
23219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
23319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
23419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	display_brel_entry(blk, &ent);
23519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
23619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
23719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
23819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_start_iter(int argc, char **argv)
23919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
24019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
24119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
24219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
24319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
24419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
24519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_start_iter(brel);
24619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
24719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_start_iter");
24819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
24919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
25019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
25119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
25219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
25319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_next(int argc, char **argv)
25419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
25519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
25619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_block_relocate_entry ent;
25719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	blk;
25819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
25919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
26019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
26119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
26219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_next(brel, &blk, &ent);
26319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
26419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_next");
26519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
26619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
26719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (blk == 0) {
26819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("No more entries!\n");
26919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
27019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
27119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	display_brel_entry(blk, &ent);
27219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
27319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
27419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
27519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_dump(int argc, char **argv)
27619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
27719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
27819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_block_relocate_entry ent;
27919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	blk;
28019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
28119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
28219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
28319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
28419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_start_iter(brel);
28519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
28619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_start_iter");
28719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
28819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
28919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
29019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	while (1) {
29119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ext2fs_brel_next(brel, &blk, &ent);
29219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval) {
29319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			com_err(argv[0], retval, "while calling ext2fs_brel_next");
29419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			return;
29519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
29619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (blk == 0)
29719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
29819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
29919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		display_brel_entry(blk, &ent);
30019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
30119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
30219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
30319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
30419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_move(int argc, char **argv)
30519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
30619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s old_block new_block";
30719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
30819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	old, new;
30919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
31019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
31119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
31219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
31319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
31419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
31519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
31619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "old block", argv[1], &old))
31719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
31819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "new block", argv[2], &new))
31919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
32019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
32119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_move(brel, old, new);
32219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
32319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_move");
32419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
32519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
32619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
32719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
32819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
32919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_brel_delete(int argc, char **argv)
33019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
33119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s block";
33219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
33319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	blk;
33419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
33519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_brel(argv[0]))
33619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
33719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
33819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
33919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
34019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
34119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "block", argv[1], &blk))
34219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
34319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
34419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_brel_delete(brel, blk);
34519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
34619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_brel_delete");
34719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
34819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
34919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
35019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
35119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_ma_create(int argc, char **argv)
35219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
35319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "Usage: %s name max_inode\n";
35419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	retval;
35519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t		max_ino;
35619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
35719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 3) {
35819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
35919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
36019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
36119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "max_inodes", argv[2], &max_ino))
36219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
36319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_memarray_create(argv[1], max_ino, &irel);
36419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
36519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while opening memarray irel");
36619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
36719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
36819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
36919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
37019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
37119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_free(int argc, char **argv)
37219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
37319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
37419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
37519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
37619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ext2fs_irel_free(irel);
37719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	irel = NULL;
37819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
37919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
38019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
38119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_put(int argc, char **argv)
38219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
38319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s old new max_refs";
38419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_relocate_entry ent;
38519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
38619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	old, new, max_refs;
38719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
38819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
38919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
39019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
39119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 4) {
39219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
39319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
39419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
39519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "old inode", argv[1], &old))
39619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
39719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "new inode", argv[2], &new))
39819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
39919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "max_refs", argv[3], &max_refs))
40019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
40119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (max_refs > 65535) {
40219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("max_refs too big\n");
40319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
40419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
40519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.new = new;
40619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.max_refs = (__u16) max_refs;
40719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ent.flags = 0;
40819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
40919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_put(irel, old, &ent);
41019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
41119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_put");
41219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
41319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
41419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
41519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
41619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
41719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_get(int argc, char **argv)
41819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
41919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s inode";
42019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_relocate_entry ent;
42119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
42219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	old;
42319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
42419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
42519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
42619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
42719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
42819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
42919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
43019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
43119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "inode", argv[1], &old))
43219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
43319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
43419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_get(irel, old, &ent);
43519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
43619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_get");
43719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
43819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
43919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	display_irel_entry(old, &ent, 1);
44019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
44119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
44219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
44319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_get_by_orig(int argc, char **argv)
44419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
44519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s orig_inode";
44619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
44719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_relocate_entry ent;
44819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	orig, old;
44919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
45019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
45119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
45219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
45319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
45419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
45519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
45619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
45719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "original inode", argv[1], &orig))
45819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
45919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
46019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_get_by_orig(irel, orig, &old, &ent);
46119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
46219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_get_by_orig");
46319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
46419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
46519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	display_irel_entry(old, &ent, 1);
46619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
46719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
46819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
46919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_start_iter(int argc, char **argv)
47019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
47119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
47219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
47319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
47419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
47519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
47619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_start_iter(irel);
47719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
47819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_start_iter");
47919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
48019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
48119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
48219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
48319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
48419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_next(int argc, char **argv)
48519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
48619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
48719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_relocate_entry ent;
48819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	old;
48919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
49019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
49119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
49219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
49319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_next(irel, &old, &ent);
49419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
49519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_next");
49619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
49719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
49819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (old == 0) {
49919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("No more entries!\n");
50019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
50119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
50219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	display_irel_entry(old, &ent, 1);
50319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
50419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
50519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
50619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_dump(int argc, char **argv)
50719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
50819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
50919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_relocate_entry ent;
51019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	ino;
51119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
51219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
51319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
51419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
51519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_start_iter(irel);
51619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
51719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_start_iter");
51819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
51919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
52019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
52119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	while (1) {
52219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ext2fs_irel_next(irel, &ino, &ent);
52319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval) {
52419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			com_err(argv[0], retval, "while calling ext2fs_irel_next");
52519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			return;
52619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
52719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (ino == 0)
52819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
52919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
53019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		display_irel_entry(ino, &ent, 1);
53119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
53219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
53319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
53419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
53519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_add_ref(int argc, char **argv)
53619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
53719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s inode block offset";
53819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
53919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_reference ref;
54019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	blk_t	block, offset;
54119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	ino;
54219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
54319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
54419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
54519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
54619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
54719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 4) {
54819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
54919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
55019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
55119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "inode", argv[1], &ino))
55219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
55319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "block", argv[2], &block))
55419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
55519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_block(argv[0], "offset", argv[3], &offset))
55619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
55719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (offset > 65535) {
55819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf("Offset too big.\n");
55919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
56019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
56119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ref.block = block;
56219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ref.offset = offset;
56319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
56419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_add_ref(irel, ino, &ref);
56519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
56619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_add_ref");
56719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
56819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
56919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
57019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
57119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
57219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_start_iter_ref(int argc, char **argv)
57319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
57419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s inode";
57519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
57619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	ino;
57719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
57819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
57919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
58019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
58119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
58219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
58319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
58419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
58519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
58619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "inode", argv[1], &ino))
58719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
58819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_start_iter_ref(irel, ino);
58919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
59019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_start_iter_ref");
59119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
59219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
59319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
59419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
59519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
59619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_next_ref(int argc, char **argv)
59719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
59819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	struct ext2_inode_reference ref;
59919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
60019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
60119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
60219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
60319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
60419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_next_ref(irel, &ref);
60519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
60619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_next_ref");
60719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
60819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
60919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	printf("Inode reference: %u:%u\n", ref.block, ref.offset);
61019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
61119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
61219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
61319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_move(int argc, char **argv)
61419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
61519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s old new";
61619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
61719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	old, new;
61819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
61919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
62019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
62119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
62219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 3) {
62319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
62419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
62519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
62619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "old inode", argv[1], &old))
62719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
62819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "new inode", argv[2], &new))
62919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
63019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
63119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_move(irel, old, new);
63219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
63319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_move");
63419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
63519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
63619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
63719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
63819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
63919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid do_irel_delete(int argc, char **argv)
64019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
64119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char *usage = "%s inode";
64219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t retval;
64319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ino_t	ino;
64419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
64519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (check_irel(argv[0]))
64619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
64719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
64819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (argc < 2) {
64919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		printf(usage, argv[0]);
65019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
65119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
65219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (parse_inode(argv[0], "inode", argv[1], &ino))
65319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
65419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
65519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	retval = ext2fs_irel_delete(irel, ino);
65619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
65719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		com_err(argv[0], retval, "while calling ext2fs_irel_delete");
65819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		return;
65919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
66019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return;
66119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
66219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
66319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostatic int source_file(const char *cmd_file, int sci_idx)
66419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
66519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	FILE		*f;
66619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		buf[256];
66719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		*cp;
66819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		exit_status = 0;
66919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		retval;
67019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int 		noecho;
67119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
67219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (strcmp(cmd_file, "-") == 0)
67319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		f = stdin;
67419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	else {
67519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		f = fopen(cmd_file, "r");
67619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (!f) {
67719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			perror(cmd_file);
67819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			exit(1);
67919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
68019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
68119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	setbuf(stdout, NULL);
68219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	setbuf(stderr, NULL);
68319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	while (!feof(f)) {
68419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (fgets(buf, sizeof(buf), f) == NULL)
68519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
68619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (buf[0] == '#')
68719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			continue;
68819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		noecho = 0;
68919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (buf[0] == '-') {
69019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			noecho = 1;
69119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			buf[0] = ' ';
69219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
69319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		cp = strchr(buf, '\n');
69419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (cp)
69519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			*cp = 0;
69619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		cp = strchr(buf, '\r');
69719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (cp)
69819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			*cp = 0;
69919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (!noecho)
70019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			printf("test_rel: %s\n", buf);
70119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ss_execute_line(sci_idx, buf);
70219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval) {
70319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			ss_perror(sci_idx, retval, buf);
70419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			exit_status++;
70519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
70619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
70719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	return exit_status;
70819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
70919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
71019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
71119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
71219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ovoid main(int argc, char **argv)
71319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o{
71419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		retval;
71519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		sci_idx;
71619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	const char	*usage = "Usage: test_rel [-R request] [-f cmd_file]";
71719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		c;
71819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		*request = 0;
71919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		exit_status = 0;
72019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		*cmd_file = 0;
72119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
72219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	initialize_ext2_error_table();
72319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
72419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	while ((c = getopt (argc, argv, "wR:f:")) != EOF) {
72519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		switch (c) {
72619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		case 'R':
72719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			request = optarg;
72819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
72919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		case 'f':
73019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			cmd_file = optarg;
73119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			break;
73219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		default:
73319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			com_err(argv[0], 0, usage);
73419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			return;
73519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
73619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
73719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	sci_idx = ss_create_invocation("test_rel", "0.0", (char *) NULL,
73819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o				       &test_cmds, &retval);
73919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
74019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		ss_perror(sci_idx, retval, "creating invocation");
74119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		exit(1);
74219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
74319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
74419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	(void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval);
74519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (retval) {
74619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		ss_perror(sci_idx, retval, "adding standard requests");
74719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		exit (1);
74819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
74919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	if (request) {
75019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = 0;
75119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		retval = ss_execute_line(sci_idx, request);
75219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		if (retval) {
75319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			ss_perror(sci_idx, retval, request);
75419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			exit_status++;
75519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		}
75619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	} else if (cmd_file) {
75719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		exit_status = source_file(cmd_file, sci_idx);
75819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	} else {
75919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		ss_listen(sci_idx);
76019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	}
76119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
76219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	exit(exit_status);
76319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o}
76419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
765