3
* Copyright (c) International Business Machines Corp., 2000
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13
* the GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
Displays data in a variety of formats
25
#include <jfs_xtree.h>
30
static void display_hex(char*, uint32_t, uint32_t);
33
#include <jfs_filsys.h>
34
extern uint32_t type_jfs;
35
extern void ujfs_swap_iag_t( iag_t * );
36
extern void ujfs_swap_dinode( dinode_t *, int32_t, uint32_t );
37
extern void ujfs_swap_superblock( struct superblock * );
53
token = strtok(0, " \n");
55
fputs("display: Please enter: block [offset [format [count]]]\ndisplay> ",stdout);
56
fgets(cmdline, 512, stdin);
57
token = strtok(cmdline, " \n");
62
block = strtoull(token, 0, 0);
63
if (block == 0 && errno) {
64
fputs("display: invalid block\n\n", stderr);
67
if ( (token = strtok(0, " \n")) ) {
68
offset = strtoul(token, 0, 16);
69
if (offset == 0 && errno) {
70
fputs("display: invalid offset\n\n", stderr);
74
if ( (token = strtok(0, " \n")) )
77
if ( (token = strtok(0, " \n")) ) {
78
length = strtoul(token, 0, 0);
79
if (length == 0 && errno) {
80
fputs("display: invalid length\n\n", stderr);
85
if (strtok(0, " \n")) {
86
fputs("display: Too many arguments\n\n", stderr);
97
data_size=sizeof(struct dinode);
102
data_size=sizeof(iag_t);
107
data_size=sizeof(struct superblock);
117
data_size=sizeof(xad_t);
122
fputs("display: invalid format\n\n", stderr);
126
addr = block << l2bsize;
127
len = ((length*data_size)+offset+bsize-1)&(~(bsize-1));
128
buffer = malloc(len);
130
fputs("display: error calling malloc\n\n", stderr);
134
if (ujfs_rw_diskblocks(fd, addr, len, buffer, GET)) {
135
fputs("display: ujfs_rw_diskblocks failed\n\n", stderr);
140
printf("Block: %lld Real Address 0x%llx\n", (long long)block, (long long)addr);
144
display_hex(&buffer[offset], length, offset);
149
struct dinode *inode = (struct dinode*)&buffer[offset];
150
for (i=0; i < length; i++, inode++) {
151
/* swap if on big endian machine */
152
if (type_jfs & JFS_SWAP_BYTES) {
153
ujfs_swap_dinode( inode, GET, type_jfs );
155
display_inode(inode);
164
iag_t *iag = (iag_t *)&buffer[offset];
165
for (i=0; i < length; i++, iag++) {
166
/* swap if on big endian machine */
167
if (type_jfs & JFS_SWAP_BYTES) {
168
ujfs_swap_iag_t( iag );
178
/* swap if on big endian machine */
179
if (type_jfs & JFS_SWAP_BYTES) {
180
ujfs_swap_superblock( (struct superblock *)&buffer[offset] );
182
if (display_super((struct superblock *)&buffer[offset]) == XPEEK_CHANGED) {
183
/* swap if on big endian machine */
184
if (type_jfs & JFS_SWAP_BYTES) {
185
ujfs_swap_superblock( (struct superblock *)&buffer[offset] );
187
if (ujfs_rw_diskblocks(fd, addr, len, buffer, PUT))
188
fputs("Display: Error writing superblock!\n",
194
fputs("display: specified format not yet supported\n\n", stderr);
203
* display_hex: display region in hex/ascii
205
static void display_hex( char *addr,
210
uint8_t asciitxt[17];
211
uint8_t *x = (uint8_t *)addr, x1, x2;
215
asciitxt[16] = '\0'; /* null end of string */
219
for (i=1; i<=((length+15)/16); i++) {
220
if (i>1 && ((i-1)%16) == 0)
224
/* print address/offset */
225
printf("%08x: ", offset+l);
227
/* print 16 bytes per line */
228
for (j=0, k = 0; j<16; j++, x++, l++) {
232
hextext[k++] = ((x1 = ((*x & 0xf0) >> 4)) < 10)
233
? ('0' + x1) : ('A' + x1 - 10);
234
hextext[k++] = ((x2 = (*x & 0x0f)) < 10)
235
? ('0' + x2) : ('A' + x2 - 10);
236
asciitxt[j] = ((*x < 0x20) ||
237
(*x >= 0x7f)) ? '.' : *x;
238
} else { /* byte not in range */
244
printf("%s |%s|\n", hextext, asciitxt);