]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
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 | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
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. | |
dfc130f3 | 13 | * |
da23017d NS |
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 | |
2bd0ea18 NS |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
2bd0ea18 | 20 | #include "command.h" |
2bd0ea18 NS |
21 | #include "type.h" |
22 | #include "faddr.h" | |
23 | #include "fprint.h" | |
24 | #include "field.h" | |
25 | #include "inode.h" | |
26 | #include "io.h" | |
27 | #include "output.h" | |
4ca431fc | 28 | #include "init.h" |
2bd0ea18 | 29 | #include "malloc.h" |
b64af2c4 | 30 | #include "crc.h" |
2bd0ea18 NS |
31 | |
32 | static int pop_f(int argc, char **argv); | |
33 | static void pop_help(void); | |
34 | static int push_f(int argc, char **argv); | |
35 | static void push_help(void); | |
36 | static int stack_f(int argc, char **argv); | |
37 | static void stack_help(void); | |
38 | static int forward_f(int argc, char **argv); | |
39 | static void forward_help(void); | |
40 | static int back_f(int argc, char **argv); | |
41 | static void back_help(void); | |
42 | static int ring_f(int argc, char **argv); | |
43 | static void ring_help(void); | |
44 | ||
45 | static const cmdinfo_t pop_cmd = | |
46 | { "pop", NULL, pop_f, 0, 0, 0, NULL, | |
9ee7055c | 47 | N_("pop location from the stack"), pop_help }; |
2bd0ea18 | 48 | static const cmdinfo_t push_cmd = |
9ee7055c AM |
49 | { "push", NULL, push_f, 0, 2, 0, N_("[command]"), |
50 | N_("push location to the stack"), push_help }; | |
2bd0ea18 NS |
51 | static const cmdinfo_t stack_cmd = |
52 | { "stack", NULL, stack_f, 0, 0, 0, NULL, | |
9ee7055c | 53 | N_("view the location stack"), stack_help }; |
dfc130f3 | 54 | static const cmdinfo_t forward_cmd = |
2bd0ea18 | 55 | { "forward", "f", forward_f, 0, 0, 0, NULL, |
9ee7055c | 56 | N_("move forward to next entry in the position ring"), forward_help }; |
dfc130f3 | 57 | static const cmdinfo_t back_cmd = |
2bd0ea18 | 58 | { "back", "b", back_f, 0, 0, 0, NULL, |
9ee7055c | 59 | N_("move to the previous location in the position ring"), back_help }; |
dfc130f3 | 60 | static const cmdinfo_t ring_cmd = |
2bd0ea18 | 61 | { "ring", NULL, ring_f, 0, 1, 0, NULL, |
9ee7055c | 62 | N_("show position ring or move to a specific entry"), ring_help }; |
2bd0ea18 NS |
63 | |
64 | iocur_t *iocur_base; | |
65 | iocur_t *iocur_top; | |
66 | int iocur_sp = -1; | |
67 | int iocur_len; | |
68 | ||
69 | #define RING_ENTRIES 20 | |
70 | static iocur_t iocur_ring[RING_ENTRIES]; | |
71 | static int ring_head = -1; | |
72 | static int ring_tail = -1; | |
73 | static int ring_current = -1; | |
74 | ||
75 | void | |
76 | io_init(void) | |
77 | { | |
78 | add_command(&pop_cmd); | |
79 | add_command(&push_cmd); | |
80 | add_command(&stack_cmd); | |
81 | add_command(&forward_cmd); | |
82 | add_command(&back_cmd); | |
83 | add_command(&ring_cmd); | |
84 | } | |
85 | ||
86 | void | |
87 | off_cur( | |
88 | int off, | |
89 | int len) | |
90 | { | |
91 | if (iocur_top == NULL || off + len > BBTOB(iocur_top->blen)) | |
9ee7055c | 92 | dbprintf(_("can't set block offset to %d\n"), off); |
2bd0ea18 NS |
93 | else { |
94 | iocur_top->boff = off; | |
95 | iocur_top->off = ((xfs_off_t)iocur_top->bb << BBSHIFT) + off; | |
96 | iocur_top->len = len; | |
97 | iocur_top->data = (void *)((char *)iocur_top->buf + off); | |
98 | } | |
99 | } | |
100 | ||
101 | void | |
102 | pop_cur(void) | |
103 | { | |
104 | if (iocur_sp < 0) { | |
9ee7055c | 105 | dbprintf(_("can't pop anything from I/O stack\n")); |
2bd0ea18 NS |
106 | return; |
107 | } | |
72298d16 DC |
108 | if (iocur_top->bp) { |
109 | libxfs_putbuf(iocur_top->bp); | |
110 | iocur_top->bp = NULL; | |
111 | } | |
112 | if (iocur_top->bbmap) { | |
113 | free(iocur_top->bbmap); | |
114 | iocur_top->bbmap = NULL; | |
115 | } | |
2bd0ea18 NS |
116 | if (--iocur_sp >= 0) { |
117 | iocur_top = iocur_base + iocur_sp; | |
118 | cur_typ = iocur_top->typ; | |
119 | } else { | |
120 | iocur_top = iocur_base; | |
121 | iocur_sp = 0; | |
122 | } | |
123 | } | |
124 | ||
125 | /*ARGSUSED*/ | |
126 | static int | |
127 | pop_f( | |
128 | int argc, | |
129 | char **argv) | |
130 | { | |
131 | pop_cur(); | |
132 | return 0; | |
133 | } | |
134 | ||
135 | static void | |
136 | pop_help(void) | |
137 | { | |
9ee7055c | 138 | dbprintf(_( |
2bd0ea18 NS |
139 | "\n" |
140 | " Changes the address and data type to the first entry on the stack.\n" | |
141 | "\n" | |
9ee7055c | 142 | )); |
2bd0ea18 NS |
143 | } |
144 | ||
145 | void | |
146 | print_iocur( | |
147 | char *tag, | |
148 | iocur_t *ioc) | |
149 | { | |
150 | int i; | |
151 | ||
152 | dbprintf("%s\n", tag); | |
9ee7055c AM |
153 | dbprintf(_("\tbyte offset %lld, length %d\n"), ioc->off, ioc->len); |
154 | dbprintf(_("\tbuffer block %lld (fsbno %lld), %d bb%s\n"), ioc->bb, | |
5a35bf2c | 155 | (xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb), ioc->blen, |
2bd0ea18 | 156 | ioc->blen == 1 ? "" : "s"); |
72298d16 | 157 | if (ioc->bbmap) { |
9ee7055c | 158 | dbprintf(_("\tblock map")); |
72298d16 DC |
159 | for (i = 0; i < ioc->bbmap->nmaps; i++) |
160 | dbprintf(" %lld:%d", ioc->bbmap->b[i].bm_bn, | |
161 | ioc->bbmap->b[i].bm_len); | |
2bd0ea18 NS |
162 | dbprintf("\n"); |
163 | } | |
9ee7055c AM |
164 | dbprintf(_("\tinode %lld, dir inode %lld, type %s\n"), ioc->ino, |
165 | ioc->dirino, ioc->typ == NULL ? _("none") : ioc->typ->name); | |
2bd0ea18 NS |
166 | } |
167 | ||
168 | void | |
169 | print_ring(void) | |
170 | { | |
171 | int i; | |
172 | iocur_t *ioc; | |
173 | ||
174 | if (ring_current == -1) { | |
9ee7055c | 175 | dbprintf(_("no entries in location ring.\n")); |
2bd0ea18 NS |
176 | return; |
177 | } | |
178 | ||
9ee7055c | 179 | dbprintf(_(" type bblock bblen fsbno inode\n")); |
2bd0ea18 NS |
180 | |
181 | i = ring_head; | |
182 | for (;;) { | |
183 | ioc = &iocur_ring[i]; | |
184 | if (i == ring_current) | |
185 | printf("*%2d: ", i); | |
186 | else | |
187 | printf(" %2d: ", i); | |
188 | ||
189 | dbprintf("%-7.7s %8lld %5d %8lld %9lld\n", | |
190 | ioc->typ == NULL ? "none" : ioc->typ->name, | |
191 | ioc->bb, | |
192 | ioc->blen, | |
5a35bf2c | 193 | (xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb), |
2bd0ea18 NS |
194 | ioc->ino |
195 | ); | |
196 | ||
197 | if (i == ring_tail) | |
198 | break; | |
199 | ||
200 | i = (i+(RING_ENTRIES-1))%RING_ENTRIES; | |
201 | } | |
202 | } | |
203 | ||
204 | ||
205 | void | |
206 | push_cur(void) | |
207 | { | |
208 | if (iocur_sp + 1 >= iocur_len) { | |
209 | iocur_base = xrealloc(iocur_base, | |
210 | sizeof(*iocur_base) * (iocur_len + 1)); | |
211 | iocur_len++; | |
212 | } | |
213 | iocur_sp++; | |
214 | iocur_top = iocur_base + iocur_sp; | |
215 | memset(iocur_top, 0, sizeof(*iocur_base)); | |
216 | iocur_top->ino = iocur_sp > 0 ? iocur_top[-1].ino : NULLFSINO; | |
217 | iocur_top->dirino = iocur_sp > 0 ? iocur_top[-1].dirino : NULLFSINO; | |
218 | iocur_top->mode = iocur_sp > 0 ? iocur_top[-1].mode : 0; | |
219 | cur_typ = NULL; | |
220 | } | |
221 | ||
222 | static int | |
223 | push_f( | |
224 | int argc, | |
225 | char **argv) | |
226 | { | |
227 | const cmdinfo_t *ct; | |
228 | ||
229 | if (argc > 1) { | |
dfc130f3 RC |
230 | /* check we can execute command */ |
231 | ct = find_command(argv[1]); | |
232 | if (ct == NULL) { | |
9ee7055c | 233 | dbprintf(_("no such command %s\n"), argv[1]); |
dfc130f3 RC |
234 | return 0; |
235 | } | |
236 | if (!ct->canpush) { | |
9ee7055c | 237 | dbprintf(_("no push form allowed for %s\n"), argv[1]); |
dfc130f3 RC |
238 | return 0; |
239 | } | |
240 | } | |
241 | ||
242 | /* save current state */ | |
243 | push_cur(); | |
2bd0ea18 NS |
244 | if (iocur_top[-1].typ && iocur_top[-1].typ->typnm == TYP_INODE) |
245 | set_cur_inode(iocur_top[-1].ino); | |
246 | else | |
247 | set_cur(iocur_top[-1].typ, iocur_top[-1].bb, | |
dfc130f3 | 248 | iocur_top[-1].blen, DB_RING_IGN, |
72298d16 | 249 | iocur_top[-1].bbmap); |
2bd0ea18 | 250 | |
dfc130f3 RC |
251 | /* run requested command */ |
252 | if (argc>1) | |
253 | (void)command(argc-1, argv+1); | |
2bd0ea18 NS |
254 | return 0; |
255 | } | |
256 | ||
257 | static void | |
258 | push_help(void) | |
259 | { | |
9ee7055c | 260 | dbprintf(_( |
2bd0ea18 NS |
261 | "\n" |
262 | " Allows you to push the current address and data type on the stack for\n" | |
263 | " later return. 'push' also accepts an additional command to execute after\n" | |
264 | " storing the current address (ex: 'push a rootino' from the superblock).\n" | |
265 | "\n" | |
9ee7055c | 266 | )); |
2bd0ea18 NS |
267 | } |
268 | ||
269 | /* move forward through the ring */ | |
270 | /* ARGSUSED */ | |
271 | static int | |
272 | forward_f( | |
273 | int argc, | |
274 | char **argv) | |
275 | { | |
276 | if (ring_current == -1) { | |
9ee7055c | 277 | dbprintf(_("ring is empty\n")); |
2bd0ea18 NS |
278 | return 0; |
279 | } | |
280 | if (ring_current == ring_head) { | |
9ee7055c | 281 | dbprintf(_("no further entries\n")); |
2bd0ea18 NS |
282 | return 0; |
283 | } | |
284 | ||
285 | ring_current = (ring_current+1)%RING_ENTRIES; | |
286 | ||
287 | set_cur(iocur_ring[ring_current].typ, | |
288 | iocur_ring[ring_current].bb, | |
289 | iocur_ring[ring_current].blen, | |
290 | DB_RING_IGN, | |
72298d16 | 291 | iocur_ring[ring_current].bbmap); |
2bd0ea18 NS |
292 | |
293 | return 0; | |
294 | } | |
295 | ||
296 | static void | |
297 | forward_help(void) | |
298 | { | |
9ee7055c | 299 | dbprintf(_( |
2bd0ea18 NS |
300 | "\n" |
301 | " The 'forward' ('f') command moves to the next location in the position\n" | |
302 | " ring, updating the current position and data type. If the current location\n" | |
303 | " is the top entry in the ring, then the 'forward' command will have\n" | |
304 | " no effect.\n" | |
305 | "\n" | |
9ee7055c | 306 | )); |
2bd0ea18 NS |
307 | } |
308 | ||
309 | /* move backwards through the ring */ | |
310 | /* ARGSUSED */ | |
311 | static int | |
312 | back_f( | |
313 | int argc, | |
314 | char **argv) | |
315 | { | |
316 | if (ring_current == -1) { | |
9ee7055c | 317 | dbprintf(_("ring is empty\n")); |
2bd0ea18 NS |
318 | return 0; |
319 | } | |
320 | if (ring_current == ring_tail) { | |
9ee7055c | 321 | dbprintf(_("no previous entries\n")); |
2bd0ea18 NS |
322 | return 0; |
323 | } | |
324 | ||
325 | ring_current = (ring_current+(RING_ENTRIES-1))%RING_ENTRIES; | |
326 | ||
327 | set_cur(iocur_ring[ring_current].typ, | |
328 | iocur_ring[ring_current].bb, | |
329 | iocur_ring[ring_current].blen, | |
330 | DB_RING_IGN, | |
72298d16 | 331 | iocur_ring[ring_current].bbmap); |
2bd0ea18 NS |
332 | |
333 | return 0; | |
334 | } | |
335 | ||
336 | static void | |
337 | back_help(void) | |
338 | { | |
9ee7055c | 339 | dbprintf(_( |
2bd0ea18 NS |
340 | "\n" |
341 | " The 'back' ('b') command moves to the previous location in the position\n" | |
342 | " ring, updating the current position and data type. If the current location\n" | |
343 | " is the last entry in the ring, then the 'back' command will have no effect.\n" | |
344 | "\n" | |
9ee7055c | 345 | )); |
2bd0ea18 NS |
346 | } |
347 | ||
348 | /* show or go to specific point in ring */ | |
349 | static int | |
350 | ring_f( | |
351 | int argc, | |
352 | char **argv) | |
353 | { | |
354 | int index; | |
355 | ||
356 | if (argc == 1) { | |
357 | print_ring(); | |
358 | return 0; | |
359 | } | |
360 | ||
b3d6b800 | 361 | index = (int)strtoul(argv[1], NULL, 0); |
d15f7cfb | 362 | if (index < 0 || index >= RING_ENTRIES) { |
9ee7055c | 363 | dbprintf(_("invalid entry: %d\n"), index); |
d15f7cfb ES |
364 | return 0; |
365 | } | |
2bd0ea18 NS |
366 | |
367 | ring_current = index; | |
368 | ||
369 | set_cur(iocur_ring[index].typ, | |
370 | iocur_ring[index].bb, | |
371 | iocur_ring[index].blen, | |
372 | DB_RING_IGN, | |
72298d16 | 373 | iocur_ring[index].bbmap); |
2bd0ea18 NS |
374 | |
375 | return 0; | |
376 | } | |
377 | ||
378 | static void | |
379 | ring_help(void) | |
380 | { | |
9ee7055c | 381 | dbprintf(_( |
2bd0ea18 NS |
382 | "\n" |
383 | " The position ring automatically keeps track of each disk location and\n" | |
384 | " structure type for each change of position you make during your xfs_db\n" | |
385 | " session. The last %d most recent entries are kept in the ring.\n" | |
386 | "\n" | |
387 | " To display the current list of ring entries type 'ring' by itself on\n" | |
388 | " the command line. The entry highlighted by an asterisk ('*') is the\n" | |
389 | " current entry.\n" | |
390 | "\n" | |
391 | " To move to another entry in the ring type 'ring <num>' where <num> is\n" | |
392 | " your desired entry from the ring position list.\n" | |
393 | "\n" | |
394 | " You may also use the 'forward' ('f') or 'back' ('b') commands to move\n" | |
395 | " to the previous or next entry in the ring, respectively.\n" | |
396 | "\n" | |
397 | " Note: Unlike the 'stack', 'push' and 'pop' commands, the ring tracks your\n" | |
398 | " location implicitly. Use the 'push' and 'pop' commands if you wish to\n" | |
399 | " store a specific location explicitly for later return.\n" | |
9ee7055c | 400 | "\n"), |
2bd0ea18 NS |
401 | RING_ENTRIES); |
402 | } | |
403 | ||
404 | ||
405 | void | |
406 | ring_add(void) | |
407 | { | |
408 | if (ring_head == -1) { | |
409 | /* only get here right after startup */ | |
410 | ring_head = 0; | |
411 | ring_tail = 0; | |
412 | ring_current = 0; | |
413 | iocur_ring[0] = *iocur_top; | |
414 | } else { | |
415 | if (ring_current == ring_head) { | |
416 | ring_head = (ring_head+1)%RING_ENTRIES; | |
417 | iocur_ring[ring_head] = *iocur_top; | |
418 | if (ring_head == ring_tail) | |
419 | ring_tail = (ring_tail+1)%RING_ENTRIES; | |
420 | ring_current = ring_head; | |
421 | } else { | |
422 | ring_current = (ring_current+1)%RING_ENTRIES; | |
423 | iocur_ring[ring_current] = *iocur_top; | |
424 | } | |
425 | } | |
426 | } | |
427 | ||
2a8b3fdf DC |
428 | static void |
429 | write_cur_buf(void) | |
430 | { | |
431 | int ret; | |
432 | ||
12b53197 | 433 | ret = -libxfs_writebufr(iocur_top->bp); |
72298d16 | 434 | if (ret != 0) |
2a8b3fdf DC |
435 | dbprintf(_("write error: %s\n"), strerror(ret)); |
436 | ||
437 | /* re-read buffer from disk */ | |
12b53197 | 438 | ret = -libxfs_readbufr(mp->m_ddev_targp, iocur_top->bb, iocur_top->bp, |
72298d16 DC |
439 | iocur_top->blen, 0); |
440 | if (ret != 0) | |
2a8b3fdf DC |
441 | dbprintf(_("read error: %s\n"), strerror(ret)); |
442 | } | |
443 | ||
2a8b3fdf DC |
444 | static void |
445 | write_cur_bbs(void) | |
2bd0ea18 NS |
446 | { |
447 | int ret; | |
448 | ||
12b53197 | 449 | ret = -libxfs_writebufr(iocur_top->bp); |
72298d16 | 450 | if (ret != 0) |
9ee7055c | 451 | dbprintf(_("write error: %s\n"), strerror(ret)); |
2a8b3fdf | 452 | |
72298d16 | 453 | |
2bd0ea18 | 454 | /* re-read buffer from disk */ |
12b53197 | 455 | ret = -libxfs_readbufr_map(mp->m_ddev_targp, iocur_top->bp, 0); |
72298d16 | 456 | if (ret != 0) |
9ee7055c | 457 | dbprintf(_("read error: %s\n"), strerror(ret)); |
2bd0ea18 NS |
458 | } |
459 | ||
c9f5e3db ES |
460 | void |
461 | xfs_dummy_verify( | |
462 | struct xfs_buf *bp) | |
463 | { | |
464 | return; | |
465 | } | |
466 | ||
6f7f8928 DW |
467 | void |
468 | xfs_verify_recalc_inode_crc( | |
469 | struct xfs_buf *bp) | |
470 | { | |
471 | ASSERT(iocur_top->ino_buf); | |
472 | ASSERT(iocur_top->bp == bp); | |
473 | ||
474 | libxfs_dinode_calc_crc(mp, iocur_top->data); | |
475 | iocur_top->ino_crc_ok = 1; | |
476 | } | |
477 | ||
86769b32 DC |
478 | void |
479 | xfs_verify_recalc_crc( | |
480 | struct xfs_buf *bp) | |
481 | { | |
482 | xfs_buf_update_cksum(bp, iocur_top->typ->crc_off); | |
483 | } | |
484 | ||
2a8b3fdf DC |
485 | void |
486 | write_cur(void) | |
487 | { | |
b64af2c4 ES |
488 | bool skip_crc = false; |
489 | ||
2a8b3fdf DC |
490 | if (iocur_sp < 0) { |
491 | dbprintf(_("nothing to write\n")); | |
492 | return; | |
493 | } | |
494 | ||
b64af2c4 ES |
495 | if (!xfs_sb_version_hascrc(&mp->m_sb) || |
496 | !iocur_top->bp->b_ops || | |
497 | iocur_top->bp->b_ops->verify_write == xfs_dummy_verify) | |
498 | skip_crc = true; | |
499 | ||
500 | if (!skip_crc) { | |
501 | if (iocur_top->ino_buf) { | |
502 | libxfs_dinode_calc_crc(mp, iocur_top->data); | |
503 | iocur_top->ino_crc_ok = 1; | |
504 | } else if (iocur_top->dquot_buf) { | |
505 | xfs_update_cksum(iocur_top->data, | |
506 | sizeof(struct xfs_dqblk), | |
507 | XFS_DQUOT_CRC_OFF); | |
508 | } | |
b335ecb5 | 509 | } |
72298d16 | 510 | if (iocur_top->bbmap) |
2a8b3fdf DC |
511 | write_cur_bbs(); |
512 | else | |
513 | write_cur_buf(); | |
b64af2c4 ES |
514 | |
515 | /* If we didn't write the crc automatically, re-check inode validity */ | |
516 | if (xfs_sb_version_hascrc(&mp->m_sb) && | |
517 | skip_crc && iocur_top->ino_buf) { | |
3c73a9a1 | 518 | iocur_top->ino_crc_ok = libxfs_verify_cksum(iocur_top->data, |
b64af2c4 ES |
519 | mp->m_sb.sb_inodesize, |
520 | XFS_DINODE_CRC_OFF); | |
521 | } | |
522 | ||
2a8b3fdf DC |
523 | } |
524 | ||
2bd0ea18 NS |
525 | void |
526 | set_cur( | |
527 | const typ_t *t, | |
dfc130f3 | 528 | __int64_t d, |
2bd0ea18 | 529 | int c, |
b64af2c4 | 530 | int ring_flag, |
2bd0ea18 NS |
531 | bbmap_t *bbmap) |
532 | { | |
72298d16 | 533 | struct xfs_buf *bp; |
2bd0ea18 NS |
534 | xfs_ino_t dirino; |
535 | xfs_ino_t ino; | |
536 | __uint16_t mode; | |
6fea8f83 | 537 | const struct xfs_buf_ops *ops = t ? t->bops : NULL; |
2bd0ea18 NS |
538 | |
539 | if (iocur_sp < 0) { | |
9ee7055c | 540 | dbprintf(_("set_cur no stack element to set\n")); |
2bd0ea18 NS |
541 | return; |
542 | } | |
543 | ||
6fea8f83 | 544 | |
2bd0ea18 NS |
545 | ino = iocur_top->ino; |
546 | dirino = iocur_top->dirino; | |
547 | mode = iocur_top->mode; | |
548 | pop_cur(); | |
549 | push_cur(); | |
2a8b3fdf DC |
550 | |
551 | if (bbmap) { | |
857592d2 | 552 | #ifdef DEBUG_BBMAP |
72298d16 | 553 | int i; |
2a8b3fdf | 554 | printf(_("xfs_db got a bbmap for %lld\n"), (long long)d); |
72298d16 DC |
555 | printf(_("\tblock map")); |
556 | for (i = 0; i < bbmap->nmaps; i++) | |
557 | printf(" %lld:%d", (long long)bbmap->b[i].bm_bn, | |
558 | bbmap->b[i].bm_len); | |
559 | printf("\n"); | |
2a8b3fdf | 560 | #endif |
72298d16 DC |
561 | iocur_top->bbmap = malloc(sizeof(struct bbmap)); |
562 | if (!iocur_top->bbmap) | |
2a8b3fdf | 563 | return; |
72298d16 DC |
564 | memcpy(iocur_top->bbmap, bbmap, sizeof(struct bbmap)); |
565 | bp = libxfs_readbuf_map(mp->m_ddev_targp, bbmap->b, | |
6fea8f83 | 566 | bbmap->nmaps, 0, ops); |
2a8b3fdf | 567 | } else { |
6fea8f83 | 568 | bp = libxfs_readbuf(mp->m_ddev_targp, d, c, 0, ops); |
72298d16 | 569 | iocur_top->bbmap = NULL; |
2a8b3fdf | 570 | } |
6fea8f83 DC |
571 | |
572 | /* | |
9c0a86ed | 573 | * Keep the buffer even if the verifier says it is corrupted. |
6fea8f83 DC |
574 | * We're a diagnostic tool, after all. |
575 | */ | |
66fc04e0 DW |
576 | if (!bp || (bp->b_error && bp->b_error != -EFSCORRUPTED && |
577 | bp->b_error != -EFSBADCRC)) | |
72298d16 DC |
578 | return; |
579 | iocur_top->buf = bp->b_addr; | |
580 | iocur_top->bp = bp; | |
b511ff41 DC |
581 | if (!ops) |
582 | bp->b_flags |= LIBXFS_B_UNCHECKED; | |
2a8b3fdf | 583 | |
2bd0ea18 NS |
584 | iocur_top->bb = d; |
585 | iocur_top->blen = c; | |
586 | iocur_top->boff = 0; | |
587 | iocur_top->data = iocur_top->buf; | |
588 | iocur_top->len = BBTOB(c); | |
589 | iocur_top->off = d << BBSHIFT; | |
590 | iocur_top->typ = cur_typ = t; | |
591 | iocur_top->ino = ino; | |
592 | iocur_top->dirino = dirino; | |
593 | iocur_top->mode = mode; | |
a73b88f2 | 594 | iocur_top->ino_buf = 0; |
66a40d02 | 595 | iocur_top->dquot_buf = 0; |
2bd0ea18 NS |
596 | |
597 | /* store location in ring */ | |
598 | if (ring_flag) | |
599 | ring_add(); | |
600 | } | |
601 | ||
9ba69ce2 DC |
602 | void |
603 | set_iocur_type( | |
604 | const typ_t *t) | |
605 | { | |
606 | struct xfs_buf *bp = iocur_top->bp; | |
607 | ||
608 | iocur_top->typ = t; | |
609 | ||
610 | /* verify the buffer if the type has one. */ | |
611 | if (!bp) | |
612 | return; | |
613 | if (!t->bops) { | |
614 | bp->b_ops = NULL; | |
615 | bp->b_flags |= LIBXFS_B_UNCHECKED; | |
616 | return; | |
617 | } | |
618 | if (!(bp->b_flags & LIBXFS_B_UPTODATE)) | |
619 | return; | |
620 | bp->b_error = 0; | |
621 | bp->b_ops = t->bops; | |
622 | bp->b_ops->verify_read(bp); | |
623 | bp->b_flags &= ~LIBXFS_B_UNCHECKED; | |
624 | } | |
625 | ||
2bd0ea18 NS |
626 | static void |
627 | stack_help(void) | |
628 | { | |
9ee7055c | 629 | dbprintf(_( |
2bd0ea18 NS |
630 | "\n" |
631 | " The stack is used to explicitly store your location and data type\n" | |
632 | " for later return. The 'push' operation stores the current address\n" | |
633 | " and type on the stack, the 'pop' operation returns you to the\n" | |
634 | " position and datatype of the top entry on the stack.\n" | |
635 | "\n" | |
636 | " The 'stack' allows explicit location saves, see 'ring' for implicit\n" | |
637 | " position tracking.\n" | |
638 | "\n" | |
9ee7055c | 639 | )); |
2bd0ea18 NS |
640 | } |
641 | ||
642 | /*ARGSUSED*/ | |
643 | static int | |
644 | stack_f( | |
645 | int argc, | |
646 | char **argv) | |
647 | { | |
648 | int i; | |
649 | char tagbuf[8]; | |
650 | ||
2d9475a4 NS |
651 | for (i = iocur_sp; i > 0; i--) { |
652 | snprintf(tagbuf, sizeof(tagbuf), "%d: ", i); | |
2bd0ea18 NS |
653 | print_iocur(tagbuf, &iocur_base[i]); |
654 | } | |
655 | return 0; | |
656 | } |