]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/block.c
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 static int ablock_f(int argc
, char **argv
);
33 static void ablock_help(void);
34 static int daddr_f(int argc
, char **argv
);
35 static void daddr_help(void);
36 static int dblock_f(int argc
, char **argv
);
37 static void dblock_help(void);
38 static int fsblock_f(int argc
, char **argv
);
39 static void fsblock_help(void);
40 static void print_rawdata(void *data
, int len
);
42 static const cmdinfo_t ablock_cmd
=
43 { "ablock", NULL
, ablock_f
, 1, 1, 1, N_("filoff"),
44 N_("set address to file offset (attr fork)"), ablock_help
};
45 static const cmdinfo_t daddr_cmd
=
46 { "daddr", NULL
, daddr_f
, 0, 1, 1, N_("[d]"),
47 N_("set address to daddr value"), daddr_help
};
48 static const cmdinfo_t dblock_cmd
=
49 { "dblock", NULL
, dblock_f
, 1, 1, 1, N_("filoff"),
50 N_("set address to file offset (data fork)"), dblock_help
};
51 static const cmdinfo_t fsblock_cmd
=
52 { "fsblock", "fsb", fsblock_f
, 0, 1, 1, N_("[fsb]"),
53 N_("set address to fsblock value"), fsblock_help
};
61 " 'ablock 23' - sets the file position to the 23rd filesystem block in\n"
62 " the inode's attribute fork. The filesystem block size is specified in\n"
63 " the superblock.\n\n"
80 bno
= (xfs_fileoff_t
)strtoull(argv
[1], &p
, 0);
82 dbprintf(_("bad block number %s\n"), argv
[1]);
86 set_cur_inode(iocur_top
->ino
);
87 haveattr
= XFS_DFORK_Q((xfs_dinode_t
*)iocur_top
->data
);
90 dbprintf(_("no attribute data for file\n"));
94 bmap(bno
, 1, XFS_ATTR_FORK
, &nex
, &bm
);
96 dbprintf(_("file attr block is unmapped\n"));
99 dfsbno
= bm
.startblock
+ (bno
- bm
.startoff
);
100 ASSERT(typtab
[TYP_ATTR
].typnm
== TYP_ATTR
);
101 set_cur(&typtab
[TYP_ATTR
], (__int64_t
)XFS_FSB_TO_DADDR(mp
, dfsbno
),
102 blkbb
, DB_RING_ADD
, NULL
);
109 add_command(&ablock_cmd
);
110 add_command(&daddr_cmd
);
111 add_command(&dblock_cmd
);
112 add_command(&fsblock_cmd
);
121 " 'daddr 102' - sets position to the 102nd absolute disk block\n"
122 " (512 byte block).\n"
135 dbprintf(_("current daddr is %lld\n"), iocur_top
->off
>> BBSHIFT
);
138 d
= (__int64_t
)strtoull(argv
[1], &p
, 0);
140 d
>= mp
->m_sb
.sb_dblocks
<< (mp
->m_sb
.sb_blocklog
- BBSHIFT
)) {
141 dbprintf(_("bad daddr %s\n"), argv
[1]);
144 ASSERT(typtab
[TYP_DATA
].typnm
== TYP_DATA
);
145 set_cur(&typtab
[TYP_DATA
], d
, 1, DB_RING_ADD
, NULL
);
155 " 'dblock 23' - sets the file position to the 23rd filesystem block in\n"
156 " the inode's data fork. The filesystem block size is specified in the\n"
169 xfs_fsblock_t dfsbno
;
175 bno
= (xfs_fileoff_t
)strtoull(argv
[1], &p
, 0);
177 dbprintf(_("bad block number %s\n"), argv
[1]);
181 set_cur_inode(iocur_top
->ino
);
182 type
= inode_next_type();
184 if (type
== TYP_NONE
) {
185 dbprintf(_("no type for file data\n"));
188 nex
= nb
= type
== TYP_DIR2
? mp
->m_dir_geo
->fsbcount
: 1;
189 bmp
= malloc(nb
* sizeof(*bmp
));
190 bmap(bno
, nb
, XFS_DATA_FORK
, &nex
, bmp
);
192 dbprintf(_("file data block is unmapped\n"));
196 dfsbno
= bmp
->startblock
+ (bno
- bmp
->startoff
);
197 ASSERT(typtab
[type
].typnm
== type
);
199 make_bbmap(&bbmap
, nex
, bmp
);
200 set_cur(&typtab
[type
], (__int64_t
)XFS_FSB_TO_DADDR(mp
, dfsbno
),
201 nb
* blkbb
, DB_RING_ADD
, nex
> 1 ? &bbmap
: NULL
);
212 " 'fsblock 1023' - sets the file position to the 1023rd filesystem block.\n"
213 " The filesystem block size is specified in the superblock and set during\n"
214 " mkfs time. Offset is absolute (not AG relative).\n\n"
229 dbprintf(_("current fsblock is %lld\n"),
230 XFS_DADDR_TO_FSB(mp
, iocur_top
->off
>> BBSHIFT
));
233 d
= strtoull(argv
[1], &p
, 0);
235 dbprintf(_("bad fsblock %s\n"), argv
[1]);
238 agno
= XFS_FSB_TO_AGNO(mp
, d
);
239 agbno
= XFS_FSB_TO_AGBNO(mp
, d
);
240 if (agno
>= mp
->m_sb
.sb_agcount
|| agbno
>= mp
->m_sb
.sb_agblocks
) {
241 dbprintf(_("bad fsblock %s\n"), argv
[1]);
244 ASSERT(typtab
[TYP_DATA
].typnm
== TYP_DATA
);
245 set_cur(&typtab
[TYP_DATA
], XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
246 blkbb
, DB_RING_ADD
, NULL
);
252 const field_t
*fields
,
256 print_rawdata(iocur_top
->data
, iocur_top
->len
);
270 lastaddr
= (len
- 1) & ~(32 - 1);
273 else if (lastaddr
< 0x100)
275 else if (lastaddr
< 0x1000)
279 for (i
= 0, p
= data
; i
< len
; i
+= 32) {
280 dbprintf("%-0*.*x:", offchars
, offchars
, i
);
281 for (j
= 0; j
< 32 && i
+ j
< len
; j
++, p
++) {
284 dbprintf("%02x", *p
);