Whamcloud - gitweb
debugfs: create inode_dump command to dump an inode in hex
[tools/e2fsprogs.git] / debugfs / debugfs.8.in
1 .\" -*- nroff -*-
2 .\" Copyright 1993, 1994, 1995 by Theodore Ts'o.  All Rights Reserved.
3 .\" This file may be copied under the terms of the GNU Public License.
4 .\"
5 .TH DEBUGFS 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
6 .SH NAME
7 debugfs \- ext2/ext3/ext4 file system debugger
8 .SH SYNOPSIS
9 .B debugfs
10 [
11 .B \-DVwci
12 ]
13 [
14 .B \-b
15 blocksize
16 ]
17 [
18 .B \-s
19 superblock
20 ]
21 [
22 .B \-f
23 cmd_file
24 ]
25 [
26 .B \-R
27 request
28 ]
29 [
30 .B \-d
31 data_source_device
32 ]
33 [
34 device
35 ]
36 .SH DESCRIPTION
37 The
38 .B debugfs
39 program is an interactive file system debugger. It can be used to
40 examine and change the state of an ext2, ext3, or ext4 file system.
41 .br
42 .I device
43 is the special file corresponding to the device containing the
44 file system (e.g /dev/hdXX).
45 .SH OPTIONS
46 .TP
47 .I \-w
48 Specifies that the file system should be opened in read-write mode.
49 Without this option, the file system is opened in read-only mode.
50 .TP
51 .I \-c
52 Specifies that the file system should be opened in catastrophic mode, in
53 which the inode and group bitmaps are not read initially.  This can be
54 useful for filesystems with significant corruption, but because of this,
55 catastrophic mode forces the filesystem to be opened read-only.
56 .TP
57 .I \-i
58 Specifies that
59 .I device
60 represents an ext2 image file created by the
61 .B e2image
62 program.  Since the ext2 image file only contains the superblock, block
63 group descriptor, block and inode allocation bitmaps, and
64 the inode table, many
65 .B debugfs
66 commands will not function properly.
67 .B Warning:
68 no safety checks are in place, and
69 .B debugfs
70 may fail in interesting ways if commands such as
71 .IR ls ", " dump ", "
72 etc. are tried without specifying the
73 .I data_source_device
74 using the
75 .I \-d
76 option.
77 .B debugfs
78 is a debugging tool.  It has rough edges!
79 .TP
80 .I -d data_source_device
81 Used with the
82 .I \-i
83 option, specifies that
84 .I data_source_device
85 should be used when reading blocks not found in the ext2 image file.
86 This includes data, directory, and indirect blocks.
87 .TP
88 .I -b blocksize
89 Forces the use of the given block size for the file system, rather than
90 detecting the correct block size as normal.
91 .TP
92 .I -s superblock
93 Causes the file system superblock to be read from the given block
94 number, instead of using the primary superblock (located at an offset of
95 1024 bytes from the beginning of the filesystem).  If you specify the
96 .I -s
97 option, you must also provide the blocksize of the filesystem via the
98 .I -b
99 option.
100 .TP
101 .I -f cmd_file
102 Causes
103 .B debugfs
104 to read in commands from
105 .IR cmd_file ,
106 and execute them.  When
107 .B debugfs
108 is finished executing those commands, it will exit.
109 .TP
110 .I -D
111 Causes
112 .B debugfs
113 to open the device using Direct I/O, bypassing the buffer cache.  Note
114 that some Linux devices, notably device mapper as of this writing, do
115 not support Direct I/O.
116 .TP
117 .I -R request
118 Causes
119 .B debugfs
120 to execute the single command
121 .IR request ,
122 and then exit.
123 .TP
124 .I -V
125 print the version number of
126 .B debugfs
127 and exit.
128 .SH SPECIFYING FILES
129 Many
130 .B debugfs
131 commands take a
132 .I filespec
133 as an argument to specify an inode (as opposed to a pathname)
134 in the filesystem which is currently opened by
135 .BR debugfs .
136 The
137 .I filespec
138 argument may be specified in two forms.  The first form is an inode
139 number surrounded by angle brackets, e.g.,
140 .IR <2> .
141 The second form is a pathname; if the pathname is prefixed by a forward slash
142 ('/'), then it is interpreted relative to the root of the filesystem
143 which is currently opened by
144 .BR debugfs .
145 If not, the pathname is
146 interpreted relative to the current working directory as maintained by
147 .BR debugfs .
148 This may be modified by using the
149 .B debugfs
150 command
151 .IR cd .
152 .\"
153 .\"
154 .\"
155 .SH COMMANDS
156 This is a list of the commands which
157 .B debugfs
158 supports.
159 .TP
160 .BI blocks " filespace"
161 Print the blocks used by the inode
162 .I filespec
163 to stdout.
164 .TP
165 .BI bmap " filespec logical_block"
166 Print the physical block number corresponding to the logical block number
167 .I logical_block
168 in the inode
169 .IR filespec .
170 .TP
171 .BI block_dump " [-f filespec] block_num"
172 Dump the filesystem block given by
173 .I block_num
174 in hex and ASCII format to the console.  If the
175 .I -f
176 option is specified, the block number is relative to the start of the given
177 .BR filespec .
178 .TP
179 .BI cat " filespec"
180 Dump the contents of the inode
181 .I filespec
182 to stdout.
183 .TP
184 .BI cd " filespec"
185 Change the current working directory to
186 .IR filespec .
187 .TP
188 .BI chroot " filespec"
189 Change the root directory to be the directory
190 .IR filespec .
191 .TP
192 .BI close " [-a]"
193 Close the currently open file system.  If the
194 .I -a
195 option is specified, write out any changes to the superblock and block
196 group descriptors to all of the backup superblocks, not just to the
197 master superblock.
198 .TP
199 .BI clri " filespec"
200 Clear the contents of the inode
201 .IR filespec .
202 .TP
203 .BI dirsearch " filespec filename"
204 Search the directory
205 .I filespec
206 for
207 .IR filename .
208 .TP
209 .B dirty
210 Mark the filesystem as dirty, so that the superblocks will be written on exit.
211 .TP
212 .BI dump " [-p] filespec out_file"
213 Dump the contents of the inode
214 .I filespec
215 to the output file
216 .IR out_file .
217 If the
218 .I -p
219 option is given set the owner, group and permissions information on
220 .I out_file
221 to match
222 .IR filespec .
223 .TP
224 .B dump_mmp
225 Display the multiple-mount protection (mmp) field values.
226 .TP
227 .BI dx_hash " [-h hash_alg] [-s hash_seed] filename"
228 Calculate the directory hash of
229 .IR filename .
230 The hash algorithm specified with
231 .I -h
232 may be
233 .BR legacy , " half_md4" ", or " tea .
234 The hash seed specified with
235 .I -s
236 must be in UUID format.
237 .TP
238 .BI dump_extents " [-n] [-l] filespec"
239 Dump the the extent tree of the inode
240 .IR filespec .
241 The
242 .I -n
243 flag will cause
244 .B dump_extents
245 to only display the interior nodes in the extent tree.   The
246 .I -l
247 flag will cause
248 .B dump_extents
249 to only display the leaf nodes in the extent tree.
250 .IP
251 (Please note that the length and range of blocks for the last extent in
252 an interior node is an estimate by the extents library functions, and is
253 not stored in filesystem data structures.   Hence, the values displayed
254 may not necessarily by accurate and does not indicate a problem or
255 corruption in the file system.)
256 .TP
257 .BI expand_dir " filespec"
258 Expand the directory
259 .IR filespec .
260 .TP
261 .BI feature " [fs_feature] [-fs_feature] ..."
262 Set or clear various filesystem features in the superblock.  After setting
263 or clearing any filesystem features that were requested, print the current
264 state of the filesystem feature set.
265 .TP
266 .BI filefrag " [-dvr] filespec"
267 Print the number of contiguous extents in
268 .IR filespec .
269 If
270 .I filespec
271 is a directory and the
272 .I -d
273 option is not specified,
274 .I filefrag
275 will print the number of contiguous extents for each file in
276 the directory.  The
277 .I -v
278 option will cause
279 .I filefrag
280 print a tabular listing of the contiguous extents in the
281 file.  The
282 .I -r
283 option will cause
284 .I filefrag
285 to do a recursive listing of the directory.
286 .TP
287 .BI find_free_block " [count [goal]]"
288 Find the first
289 .I count
290 free blocks, starting from
291 .I goal
292 and allocate it.  Also available as
293 .BR ffb .
294 .TP
295 .BI find_free_inode " [dir [mode]]"
296 Find a free inode and allocate it.  If present,
297 .I dir
298 specifies the inode number of the directory
299 which the inode is to be located.  The second
300 optional argument
301 .I mode
302 specifies the permissions of the new inode.  (If the directory bit is set
303 on the mode, the allocation routine will function differently.)  Also
304 available as
305 .BR ffi .
306 .TP
307 .BI freeb " block [count]"
308 Mark the block number
309 .I block
310 as not allocated.
311 If the optional argument
312 .I count
313 is present, then
314 .I count
315 blocks starting at block number
316 .I block
317 will be marked as not allocated.
318 .TP
319 .BI freefrag " [-c chunk_kb]"
320 Report free space fragmentation on the currently open file system.
321 If the
322 .I \-c
323 option is specified then the filefrag command will print how many free
324 chunks of size
325 .I chunk_kb
326 can be found in the file system.  The chunk size must be a power of two
327 and be larger than the file system block size.
328 .TP
329 .BI freei " filespec [num]"
330 Free the inode specified by
331 .IR filespec .
332 If
333 .I num
334 is specified, also clear num-1 inodes after the specified inode.
335 .TP
336 .B help
337 Print a list of commands understood by
338 .BR debugfs .
339 .TP
340 .BI htree_dump " filespec"
341 Dump the hash-indexed directory
342 .IR filespec ,
343 showing its tree structure.
344 .TP
345 .BI icheck " block ..."
346 Print a listing of the inodes which use the one or more blocks specified
347 on the command line.
348 .TP
349 .BI inode_dump " filespec"
350 Print the contents of the inode data structure in hex and ASCII format.
351 .TP
352 .BI imap " filespec"
353 Print the location of the inode data structure (in the inode table)
354 of the inode
355 .IR filespec .
356 .TP
357 .BI init_filesys " device blocksize"
358 Create an ext2 file system on
359 .I device
360 with device size
361 .IR blocksize .
362 Note that this does not fully initialize all of the data structures;
363 to do this, use the
364 .BR mke2fs (8)
365 program.  This is just a call to the low-level library, which sets up
366 the superblock and block descriptors.
367 .TP
368 .BI kill_file " filespec"
369 Deallocate the inode
370 .I filespec
371 and its blocks.  Note that this does not remove any directory
372 entries (if any) to this inode.  See the
373 .BR rm (1)
374 command if you wish to unlink a file.
375 .TP
376 .BI lcd " directory"
377 Change the current working directory of the
378 .B debugfs
379 process to
380 .I directory
381 on the native filesystem.
382 .TP
383 .BI ln " filespec dest_file"
384 Create a link named
385 .I dest_file
386 which is a hard link to
387 .IR filespec .
388 Note this does not adjust the inode reference counts.
389 .TP
390 .BI logdump " [-acs] [-b block] [-i filespec] [-f journal_file] [output_file]"
391 Dump the contents of the ext3 journal.  By default, dump the journal inode as
392 specified in the superblock.  However, this can be overridden with the
393 .I \-i
394 option, which dumps the journal from the internal inode given by
395 .IR filespec .
396 A regular file containing journal data can be specified using the
397 .I \-f
398 option.  Finally, the
399 .I \-s
400 option utilizes the backup information in the superblock to locate the
401 journal.
402 .IP
403 The
404 .I \-a
405 option causes the
406 .B logdump
407 program to print the contents of all of the descriptor blocks.
408 The
409 .I \-b
410 option causes
411 .B logdump
412 to print all journal records that are refer to the specified block.
413 The
414 .I \-c
415 option will print out the contents of all of the data blocks selected by
416 the
417 .I \-a
418 and
419 .I \-b
420 options.
421 .TP
422 .BI ls " [-d] [-l] [-p] filespec"
423 Print a listing of the files in the directory
424 .IR filespec .
425 The
426 .I \-d
427 flag will list deleted entries in the directory.
428 The
429 .I \-l
430 flag will list files using a more verbose format.
431 The
432 .I \-p
433 flag will list the files in a format which is more easily parsable by
434 scripts, as well as making it more clear when there are spaces or other
435 non-printing characters at the end of filenames.
436 .TP
437 .BI list_deleted_inodes " [limit]"
438 List deleted inodes, optionally limited to those deleted within
439 .I limit
440 seconds ago.  Also available as
441 .BR lsdel .
442 .IP
443 This command was useful for recovering from accidental file deletions
444 for ext2 file systems.  Unfortunately, it is not useful for this purpose
445 if the files were deleted using ext3 or ext4, since the inode's
446 data blocks are no longer available after the inode is released.
447 .TP
448 .BI modify_inode " filespec"
449 Modify the contents of the inode structure in the inode
450 .IR filespec .
451 Also available as
452 .BR mi .
453 .TP
454 .BI mkdir " filespec"
455 Make a directory.
456 .TP
457 .BI mknod " filespec [p|[[c|b] major minor]]"
458 Create a special device file (a named pipe, character or block device).
459 If a character or block device is to be made, the
460 .I major
461 and
462 .I minor
463 device numbers must be specified.
464 .TP
465 .BI ncheck " [-c] inode_num ..."
466 Take the requested list of inode numbers, and print a listing of pathnames
467 to those inodes.  The
468 .I -c
469 flag will enable checking the file type information in the directory
470 entry to make sure it matches the inode's type.
471 .TP
472 .BI open " [-weficD] [-b blocksize] [-s superblock] device"
473 Open a filesystem for editing.  The
474 .I -f
475 flag forces the filesystem to be opened even if there are some unknown
476 or incompatible filesystem features which would normally
477 prevent the filesystem from being opened.  The
478 .I -e
479 flag causes the filesystem to be opened in exclusive mode.  The
480 .IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
481 options behave the same as the command-line options to
482 .BR debugfs .
483 .TP
484 .BI punch " filespec start_blk [end_blk]"
485 Delete the blocks in the inode ranging from
486 .I start_blk
487 to
488 .IR end_blk .
489 If
490 .I end_blk
491 is omitted then this command will function as a truncate command; that
492 is, all of the blocks starting at
493 .I start_blk
494 through to the end of the file will be deallocated.
495 .TP
496 .BI symlink " filespec target"
497 Make a symbolic link.
498 .TP
499 .B pwd
500 Print the current working directory.
501 .TP
502 .B quit
503 Quit
504 .B debugfs
505 .TP
506 .BI rdump " directory destination"
507 Recursively dump
508 .I directory
509 and all its contents (including regular files, symbolic links, and other
510 directories) into the named
511 .I destination
512 which should be an existing directory on the native filesystem.
513 .TP
514 .BI rm " pathname"
515 Unlink
516 .IR pathname .
517 If this causes the inode pointed to by
518 .I pathname
519 to have no other references, deallocate the file.  This command functions
520 as the unlink() system call.
521 .I
522 .TP
523 .BI rmdir " filespec"
524 Remove the directory
525 .IR filespec .
526 .TP
527 .BI setb " block [count]"
528 Mark the block number
529 .I block
530 as allocated.
531 If the optional argument
532 .I count
533 is present, then
534 .I count
535 blocks starting at block number
536 .I block
537 will be marked as allocated.
538 .TP
539 .BI set_block_group " bgnum field value"
540 Modify the block group descriptor specified by
541 .I bgnum
542 so that the block group descriptor field
543 .I field
544 has value
545 .IR value .
546 Also available as
547 .BR set_bg .
548 .TP
549 .BI seti " filespec [num]"
550 Mark inode
551 .I filespec
552 as in use in the inode bitmap.  If
553 .I num
554 is specified, also set num-1 inodes after the specified inode.
555 .TP
556 .BI set_inode_field " filespec field value"
557 Modify the inode specified by
558 .I filespec
559 so that the inode field
560 .I field
561 has value
562 .I value.
563 The list of valid inode fields which can be set via this command
564 can be displayed by using the command:
565 .B set_inode_field -l
566 Also available as
567 .BR sif .
568 .TP
569 .BI set_mmp_value " field value"
570 Modify the multiple-mount protection (MMP) data so that the MMP field
571 .I field
572 has value
573 .I value.
574 The list of valid MMP fields which can be set via this command
575 can be displayed by using the command:
576 .B set_mmp_value -l
577 Also available as
578 .BR smmp .
579 .TP
580 .BI set_super_value " field value"
581 Set the superblock field
582 .I field
583 to
584 .I value.
585 The list of valid superblock fields which can be set via this command
586 can be displayed by using the command:
587 .B set_super_value -l
588 Also available as
589 .BR ssv .
590 .TP
591 .BI show_super_stats " [-h]"
592 List the contents of the super block and the block group descriptors.  If the
593 .I -h
594 flag is given, only print out the superblock contents. Also available as
595 .BR stats .
596 .TP
597 .BI stat " filespec"
598 Display the contents of the inode structure of the inode
599 .IR filespec .
600 .TP
601 .BI testb " block [count]"
602 Test if the block number
603 .I block
604 is marked as allocated in the block bitmap.
605 If the optional argument
606 .I count
607 is present, then
608 .I count
609 blocks starting at block number
610 .I block
611 will be tested.
612 .TP
613 .BI testi " filespec"
614 Test if the inode
615 .I filespec
616 is marked as allocated in the inode bitmap.
617 .TP
618 .BI undel " <inode_number> [pathname]"
619 Undelete the specified inode number (which must be surrounded by angle
620 brackets) so that it and its blocks are marked in use, and optionally
621 link the recovered inode to the specified pathname.  The
622 .B e2fsck
623 command should always be run after using the
624 .B undel
625 command to recover deleted files.
626 .IP
627 Note that if you are recovering a large number of deleted files, linking
628 the inode to a directory may require the directory to be expanded, which
629 could allocate a block that had been used by one of the
630 yet-to-be-undeleted files.  So it is safer to undelete all of the
631 inodes without specifying a destination pathname, and then in a separate
632 pass, use the debugfs
633 .B link
634 command to link the inode to the destination pathname, or use
635 .B e2fsck
636 to check the filesystem and link all of the recovered inodes to the
637 lost+found directory.
638 .TP
639 .BI unlink " pathname"
640 Remove the link specified by
641 .I pathname
642 to an inode.  Note this does not adjust the inode reference counts.
643 .TP
644 .BI write " source_file out_file"
645 Copy the contents of
646 .I source_file
647 into a newly-created file in the filesystem named
648 .IR out_file .
649 .TP
650 .BI zap_block " [-f filespec] [-o offset] [-l length] [-p pattern] block_num"
651 .TP
652 Overwrite the block specified by
653 .I block_num
654 with zero (NUL) bytes, or if
655 .I -p
656 is given use the byte specified by
657 .IR pattern .
658 If
659 .I -f
660 is given then
661 .I block_num
662 is relative to the start of the file given by
663 .IR filespec .
664 The
665 .I -o
666 and
667 .I -l
668 options limit the range of bytes to zap to the specified
669 .I offset
670 and
671 .I length
672 relative to the start of the block.
673 .TP
674 .BI zap_block " [-f filespec] [-b bit] block_num"
675 Bit-flip portions of the physical
676 .IR block_num .
677 If
678 .I -f
679 is given, then
680 .I block_num
681 is a logical block relative to the start of
682 .IR filespec .
683 .SH ENVIRONMENT VARIABLES
684 .TP
685 .B DEBUGFS_PAGER, PAGER
686 The
687 .B debugfs
688 program always pipes the output of the some commands through a
689 pager program.  These commands include:
690 .IR show_super_stats " (" stats ),
691 .IR list_directory " (" ls ),
692 .IR show_inode_info " (" stat ),
693 .IR list_deleted_inodes " (" lsdel ),
694 and
695 .IR htree_dump .
696 The specific pager can explicitly specified by the
697 .B DEBUGFS_PAGER
698 environment variable, and if it is not set, by the
699 .B PAGER
700 environment variable.
701 .IP
702 Note that since a pager is always used, the
703 .BR less (1)
704 pager is not particularly appropriate, since it clears the screen before
705 displaying the output of the command and clears the output the screen
706 when the pager is exited.  Many users prefer to use the
707 .BR less (1)
708 pager for most purposes, which is why the
709 .B DEBUGFS_PAGER
710 environment variable is available to override the more general
711 .B PAGER
712 environment variable.
713 .SH AUTHOR
714 .B debugfs
715 was written by Theodore Ts'o <tytso@mit.edu>.
716 .SH SEE ALSO
717 .BR dumpe2fs (8),
718 .BR tune2fs (8),
719 .BR e2fsck (8),
720 .BR mke2fs (8),
721 .BR ext4 (5)