]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/block.c
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
46 static int ablock_f(int argc
, char **argv
);
47 static void ablock_help(void);
48 static int daddr_f(int argc
, char **argv
);
49 static void daddr_help(void);
50 static int dblock_f(int argc
, char **argv
);
51 static void dblock_help(void);
52 static int fsblock_f(int argc
, char **argv
);
53 static void fsblock_help(void);
54 static void print_rawdata(void *data
, int len
);
56 static const cmdinfo_t ablock_cmd
=
57 { "ablock", NULL
, ablock_f
, 1, 1, 1, "filoff",
58 "set address to file offset (attr fork)", ablock_help
};
59 static const cmdinfo_t daddr_cmd
=
60 { "daddr", NULL
, daddr_f
, 0, 1, 1, "[d]",
61 "set address to daddr value", daddr_help
};
62 static const cmdinfo_t dblock_cmd
=
63 { "dblock", NULL
, dblock_f
, 1, 1, 1, "filoff",
64 "set address to file offset (data fork)", dblock_help
};
65 static const cmdinfo_t fsblock_cmd
=
66 { "fsblock", "fsb", fsblock_f
, 0, 1, 1, "[fsb]",
67 "set address to fsblock value", fsblock_help
};
75 " 'ablock 23' - sets the file position to the 23rd filesystem block in\n"
76 " the inode's attribute fork. The filesystem block size is specified in\n"
77 " the superblock.\n\n"
94 bno
= (xfs_dfiloff_t
)strtoull(argv
[1], &p
, 0);
96 dbprintf("bad block number %s\n", argv
[1]);
100 set_cur_inode(iocur_top
->ino
);
101 haveattr
= XFS_DFORK_Q((xfs_dinode_t
*)iocur_top
->data
);
104 dbprintf("no attribute data for file\n");
108 bmap(bno
, 1, XFS_ATTR_FORK
, &nex
, &bm
);
110 dbprintf("file attr block is unmapped\n");
113 dfsbno
= bm
.startblock
+ (bno
- bm
.startoff
);
114 ASSERT(typtab
[TYP_ATTR
].typnm
== TYP_ATTR
);
115 set_cur(&typtab
[TYP_ATTR
], (__int64_t
)XFS_FSB_TO_DADDR(mp
, dfsbno
),
116 blkbb
, DB_RING_ADD
, NULL
);
123 add_command(&ablock_cmd
);
124 add_command(&daddr_cmd
);
125 add_command(&dblock_cmd
);
126 add_command(&fsblock_cmd
);
135 " 'daddr 102' - sets position to the 102nd absolute disk block\n"
136 " (512 byte block).\n"
149 dbprintf("current daddr is %lld\n", iocur_top
->off
>> BBSHIFT
);
152 d
= (__int64_t
)strtoull(argv
[1], &p
, 0);
154 d
>= mp
->m_sb
.sb_dblocks
<< (mp
->m_sb
.sb_blocklog
- BBSHIFT
)) {
155 dbprintf("bad daddr %s\n", argv
[1]);
158 ASSERT(typtab
[TYP_DATA
].typnm
== TYP_DATA
);
159 set_cur(&typtab
[TYP_DATA
], d
, 1, DB_RING_ADD
, NULL
);
169 " 'dblock 23' - sets the file position to the 23rd filesystem block in\n"
170 " the inode's data fork. The filesystem block size is specified in the\n"
189 bno
= (xfs_dfiloff_t
)strtoull(argv
[1], &p
, 0);
191 dbprintf("bad block number %s\n", argv
[1]);
195 set_cur_inode(iocur_top
->ino
);
196 type
= inode_next_type();
198 if (type
== TYP_NONE
) {
199 dbprintf("no type for file data\n");
202 nex
= nb
= type
== TYP_DIR2
? mp
->m_dirblkfsbs
: 1;
203 bmp
= malloc(nb
* sizeof(*bmp
));
204 bmap(bno
, nb
, XFS_DATA_FORK
, &nex
, bmp
);
206 dbprintf("file data block is unmapped\n");
210 dfsbno
= bmp
->startblock
+ (bno
- bmp
->startoff
);
211 ASSERT(typtab
[type
].typnm
== type
);
213 make_bbmap(&bbmap
, nex
, bmp
);
214 set_cur(&typtab
[type
], (__int64_t
)XFS_FSB_TO_DADDR(mp
, dfsbno
),
215 nb
* blkbb
, DB_RING_ADD
, nex
> 1 ? &bbmap
: NULL
);
226 " 'fsblock 1023' - sets the file position to the 1023rd filesystem block.\n"
227 " The filesystem block size is specified in the superblock and set during\n"
228 " mkfs time. Offset is absolute (not AG relative).\n\n"
243 dbprintf("current fsblock is %lld\n",
244 XFS_DADDR_TO_FSB(mp
, iocur_top
->off
>> BBSHIFT
));
247 d
= strtoull(argv
[1], &p
, 0);
249 dbprintf("bad fsblock %s\n", argv
[1]);
252 agno
= XFS_FSB_TO_AGNO(mp
, d
);
253 agbno
= XFS_FSB_TO_AGBNO(mp
, d
);
254 if (agno
>= mp
->m_sb
.sb_agcount
|| agbno
>= mp
->m_sb
.sb_agblocks
) {
255 dbprintf("bad fsblock %s\n", argv
[1]);
258 ASSERT(typtab
[TYP_DATA
].typnm
== TYP_DATA
);
259 set_cur(&typtab
[TYP_DATA
], XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
260 blkbb
, DB_RING_ADD
, NULL
);
266 const field_t
*fields
,
270 print_rawdata(iocur_top
->data
, iocur_top
->len
);
284 lastaddr
= (len
- 1) & ~(32 - 1);
287 else if (lastaddr
< 0x100)
289 else if (lastaddr
< 0x1000)
293 for (i
= 0, p
= data
; i
< len
; i
+= 32) {
294 dbprintf("%-0*.*x:", offchars
, offchars
, i
);
295 for (j
= 0; j
< 32 && i
+ j
< len
; j
++, p
++) {
298 dbprintf("%02x", *p
);