Whamcloud - gitweb
debugfs: teach seti and freei to free a block of inodes
[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 .I blocks filespace
161 Print the blocks used by the inode
162 .I filespec
163 to stdout.
164 .TP
165 .I 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 .I cat filespec
172 Dump the contents of the inode 
173 .I filespec
174 to stdout.
175 .TP
176 .I cd filespec
177 Change the current working directory to 
178 .IR filespec .
179 .TP
180 .I chroot filespec
181 Change the root directory to be the directory 
182 .IR filespec .
183 .TP
184 .I close [-a]
185 Close the currently open file system.  If the 
186 .I -a
187 option is specified, write out any changes to the superblock and block
188 group descriptors to all of the backup superblocks, not just to the
189 master superblock.
190 .TP
191 .I clri file
192 Clear the contents of the inode 
193 .IR file .
194 .TP
195 .I dirsearch filespec filename
196 Search the directory
197 .I filespec
198 for
199 .IR filename .
200 .TP
201 .I dump [-p] filespec out_file
202 Dump the contents of the inode 
203 .I filespec
204 to the output file 
205 .IR out_file .  
206 If the 
207 .I -p 
208 option is given set the owner, group and permissions information on 
209 .I out_file 
210 to match 
211 .IR filespec .
212 .TP
213 .I dump_mmp
214 Display the multiple-mount protection (mmp) field values.
215 .TP
216 .I dx_hash [-h hash_alg] [-s hash_seed] filename
217 Calculate the directory hash of
218 .IR filename .
219 The hash algorithm specified with
220 .I -h
221 may be "legacy" "half_md4" or "tea".
222 The hash seed specified with
223 .I -s
224 must be in UUID format.
225 .TP
226 .I dump_extents [-n] [-l] filespec
227 Dump the the extent tree of the inode
228 .IR filespec .
229 The 
230 .I -n
231 flag will cause
232 .I dump_extents
233 to only display the interior nodes in the extent tree.   The
234 .I  -l
235 flag cause
236 .I dump_extents
237 to only display the leaf nodes in the extent tree.
238 .IP
239 (Please note that the length and range of blocks for the last extent in
240 an interior node is an estimate by the extents library functions, and is
241 not stored in filesystem data structures.   Hence, the values displayed
242 may not necessarily by accurate and does not indicate a problem or 
243 corruption in the file system.)
244 .TP
245 .I expand_dir filespec
246 Expand the directory
247 .IR filespec .
248 .TP
249 .I feature [fs_feature] [-fs_feature] ...
250 Set or clear various filesystem features in the superblock.  After setting
251 or clearing any filesystem features that were requested, print the current
252 state of the filesystem feature set.
253 .TP
254 .I filefrag [-dvr] filespec
255 Print the number of contiguous extents in
256 .IR filespec .
257 If
258 .I filespec
259 is a directory and the
260 .I -d
261 option is not specified,
262 .I filefrag
263 will print the number of contiguous extents for each file in
264 the directory.  The
265 .I -v
266 option will cause
267 .I filefrag
268 print a tabular listing of the contiguous extents in the
269 file.  The
270 .I -r
271 option will cause
272 .I filefrag
273 to do a recursive listing of the directory.
274 .TP
275 .I find_free_block [count [goal]]
276 Find the first 
277 .I count
278 free blocks, starting from
279 .I goal
280 and allocate it.
281 .TP
282 .I find_free_inode [dir [mode]]
283 Find a free inode and allocate it.  If present, 
284 .I dir
285 specifies the inode number of the directory 
286 which the inode is to be located.  The second 
287 optional argument
288 .I mode
289 specifies the permissions of the new inode.  (If the directory bit is set
290 on the mode, the allocation routine will function differently.)
291 .TP
292 .I freeb block [count]
293 Mark the block number
294 .I block
295 as not allocated.
296 If the optional argument 
297 .I count 
298 is present, then 
299 .I count
300 blocks starting at block number
301 .I block
302 will be marked as not allocated.
303 .TP
304 .I freefrag [-c chunk_kb ]
305 Report free space fragmentation on the currently open file system.
306 If the
307 .I \-c
308 option is specified then the filefrag command will print how many free
309 chunks of size
310 .I chunk_kb
311 can be found in the file system.  The chunk size must be a power of two
312 and be larger than the file system block size.
313 .TP
314 .I freei filespec [num]
315 Free the inode specified by 
316 .IR filespec .
317 If
318 .I num
319 is specified, also clear num-1 inodes after the specified inode.
320 .TP
321 .I help
322 Print a list of commands understood by 
323 .BR debugfs .
324 .TP
325 .I htree_dump filespec
326 Dump the hash-indexed directory
327 .IR filespec ,
328 showing its tree structure.
329 .TP
330 .I icheck block ...
331 Print a listing of the inodes which use the one or more blocks specified
332 on the command line.
333 .TP
334 .I imap filespec
335 Print the location of the inode data structure (in the inode table) 
336 of the inode
337 .IR filespec .
338 .TP
339 .I init_filesys device blocksize
340 Create an ext2 file system on
341 .I device
342 with device size
343 .IR blocksize .
344 Note that this does not fully initialize all of the data structures; 
345 to do this, use the 
346 .BR mke2fs (8)
347 program.  This is just a call to the low-level library, which sets up
348 the superblock and block descriptors.
349 .TP
350 .I kill_file filespec
351 Deallocate the inode 
352 .I filespec
353 and its blocks.  Note that this does not remove any directory
354 entries (if any) to this inode.  See the 
355 .BR rm (1)
356 command if you wish to unlink a file.
357 .TP
358 .I lcd directory
359 Change the current working directory of the
360 .B debugfs
361 process to
362 .I directory
363 on the native filesystem.
364 .TP
365 .I ln filespec dest_file
366 Create a link named 
367 .I dest_file
368 which is a link to 
369 .IR filespec .
370 Note this does not adjust the inode reference counts.
371 .TP
372 .I logdump [-acs] [-b<block>] [-i<filespec>] [-f<journal_file>] [output_file]
373 Dump the contents of the ext3 journal.  By default, the journal inode as
374 specified in the superblock.  However, this can be overridden with the 
375 .I \-i
376 option, which uses an inode specifier to specify the journal to be
377 used.  A file containing journal data can be specified using the
378 .I \-f
379 option.   Finally, the 
380 .I \-s
381 option utilizes the backup information in the superblock to locate the
382 journal.
383 .IP
384 The 
385 .I \-a
386 option causes the 
387 .I logdump
388 program to print the contents of all of the descriptor blocks.
389 The 
390 .I \-b
391 option causes 
392 .I logdump
393 to print all journal records that are refer to the specified block. 
394 The 
395 .I \-c
396 option will print out the contents of all of the data blocks selected by
397 the 
398 .I \-a
399 and 
400 .I \-b
401 options.
402 .TP
403 .I ls [-l] [-d] [-p] filespec
404 Print a listing of the files in the directory
405 .IR filespec .
406 The 
407 .I \-l
408 flag will list files using a more verbose format.
409 The
410 .I \-d
411 flag will list deleted entries in the directory.
412 The 
413 .I \-p
414 flag will list the files in a format which is more easily parsable by
415 scripts, as well as making it more clear when there are spaces or other
416 non-printing characters at the end of filenames.
417 .TP
418 .I modify_inode filespec
419 Modify the contents of the inode structure in the inode
420 .IR filespec .
421 .TP
422 .I mkdir filespec
423 Make a directory.
424 .TP
425 .I mknod filespec [p|[[c|b] major minor]]
426 Create a special device file (a named pipe, character or block device).
427 If a character or block device is to be made, the 
428 .I major
429 and
430 .I minor
431 device numbers must be specified.
432 .TP
433 .I ncheck [-c] inode_num ...
434 Take the requested list of inode numbers, and print a listing of pathnames
435 to those inodes.  The
436 .I -c
437 flag will enable checking the file type information in the directory
438 entry to make sure it matches the inode's type.
439 .TP
440 .I open [-w] [-e] [-f] [-i] [-c] [-D] [-b blocksize] [-s superblock] device
441 Open a filesystem for editing.  The 
442 .I -f 
443 flag forces the filesystem to be opened even if there are some unknown 
444 or incompatible filesystem features which would normally 
445 prevent the filesystem from being opened.  The
446 .I -e
447 flag causes the filesystem to be opened in exclusive mode.  The
448 .IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
449 options behave the same as the command-line options to 
450 .BR debugfs .
451 .TP
452 .I punch filespec start_blk [end_blk]
453 Delete the blocks in the inode ranging from
454 .I start_blk
455 to
456 .IR end_blk .
457 If
458 .I end_blk
459 is omitted then this command will function as a truncate command; that
460 is, all of the blocks starting at
461 .I start_blk
462 through to the end of the file will be deallocated.
463 .TP
464 .I pwd
465 Print the current working directory.
466 .TP
467 .I quit
468 Quit
469 .B debugfs
470 .TP
471 .I rdump directory destination
472 Recursively dump
473 .I directory
474 and all its contents (including regular files, symbolic links, and other
475 directories) into the named
476 .I destination
477 which should be an existing directory on the native filesystem.
478 .TP
479 .I rm pathname
480 Unlink 
481 .IR pathname .
482 If this causes the inode pointed to by 
483 .I pathname
484 to have no other references, deallocate the file.  This command functions
485 as the unlink() system call.
486 .I 
487 .TP
488 .I rmdir filespec
489 Remove the directory
490 .IR filespec .
491 .TP
492 .I setb block [count]
493 Mark the block number
494 .I block
495 as allocated.
496 If the optional argument 
497 .I count 
498 is present, then 
499 .I count
500 blocks starting at block number
501 .I block
502 will be marked as allocated.
503 .TP
504 .I set_block_group bgnum field value
505 Modify the block group descriptor specified by
506 .I bgnum
507 so that the block group descriptor field
508 .I field
509 has value
510 .I value.
511 .TP
512 .I seti filespec [num]
513 Mark inode 
514 .I filespec
515 as in use in the inode bitmap.  If
516 .I num
517 is specified, also set num-1 inodes after the specified inode.
518 .TP
519 .I set_inode_field filespec field value
520 Modify the inode specified by 
521 .I filespec
522 so that the inode field
523 .I field
524 has value 
525 .I value.
526 The list of valid inode fields which can be set via this command 
527 can be displayed by using the command:
528 .B set_inode_field -l
529 .TP
530 .I set_mmp_value field value
531 Modify the multiple-mount protection (mmp) data so that the
532 mmp field
533 .I field
534 has value
535 .I value.
536 The list of valid mmp fields which can be set via this command
537 can be displayed by using the command:
538 .B set_mmp_value -l
539 .TP
540 .I set_super_value field value
541 Set the superblock field
542 .I field
543 to 
544 .I value.
545 The list of valid superblock fields which can be set via this command 
546 can be displayed by using the command:
547 .B set_super_value -l
548 .TP
549 .I show_super_stats [-h]
550 List the contents of the super block and the block group descriptors.  If the
551 .I -h
552 flag is given, only print out the superblock contents.
553 .TP
554 .I stat filespec
555 Display the contents of the inode structure of the inode
556 .IR filespec .
557 .TP
558 .I testb block [count]
559 Test if the block number
560 .I block
561 is marked as allocated in the block bitmap.
562 If the optional argument 
563 .I count 
564 is present, then 
565 .I count
566 blocks starting at block number
567 .I block
568 will be tested.
569 .TP
570 .I testi filespec
571 Test if the inode 
572 .I filespec
573 is marked as allocated in the inode bitmap.
574 .TP
575 .I undel <inode num> [pathname]
576 Undelete the specified inode number (which must be surrounded by angle
577 brackets) so that it and its blocks are marked in use, and optionally
578 link the recovered inode to the specified pathname.  The 
579 .B e2fsck
580 command should always be run after using the 
581 .B undel
582 command to recover deleted files.
583 .IP
584 Note that if you are recovering a large number of deleted files, linking
585 the inode to a directory may require the directory to be expanded, which
586 could allocate a block that had been used by one of the
587 yet-to-be-undeleted files.  So it is safer to undelete all of the 
588 inodes without specifying a destination pathname, and then in a separate
589 pass, use the debugfs
590 .B link
591 command to link the inode to the destination pathname, or use 
592 .B e2fsck
593 to check the filesystem and link all of the recovered inodes to the
594 lost+found directory.
595 .TP
596 .I unlink pathname
597 Remove the link specified by 
598 .I pathname 
599 to an inode.  Note this does not adjust the inode reference counts.
600 .TP
601 .I write source_file out_file
602 Create a file in the filesystem named
603 .IR out_file ,
604 and copy the contents of
605 .I source_file
606 into the destination file.
607 .SH ENVIRONMENT VARIABLES
608 .TP
609 .B DEBUGFS_PAGER, PAGER
610 The
611 .B debugfs
612 program always pipes the output of the some commands through a
613 pager program.  These commands include: 
614 .IR show_super_stats ,
615 .IR list_directory ,
616 .IR show_inode_info ,
617 .IR list_deleted_inodes ,
618 and
619 .IR htree_dump .
620 The specific pager can explicitly specified by the
621 .B DEBUGFS_PAGER
622 environment variable, and if it is not set, by the
623 .B PAGER
624 environment variable.  
625 .IP
626 Note that since a pager is always used, the 
627 .BR less (1)
628 pager is not particularly appropriate, since it clears the screen before
629 displaying the output of the command and clears the output the screen
630 when the pager is exited.  Many users prefer to use the 
631 .BR less (1)
632 pager for most purposes, which is why the 
633 .B DEBUGFS_PAGER 
634 environment variable is available to override the more general
635 .B PAGER
636 environment variable.
637 .SH AUTHOR
638 .B debugfs
639 was written by Theodore Ts'o <tytso@mit.edu>.
640 .SH SEE ALSO
641 .BR dumpe2fs (8),
642 .BR tune2fs (8),
643 .BR e2fsck (8),
644 .BR mke2fs (8)