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