changes for dynamic file system;
[unix-history] / usr / src / sbin / fsdb / fsdb.8
CommitLineData
ba8cfc9e
KM
1.\" Copyright (c) 1988 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This program is derived from software contributed to Berkeley by
5.\" Computer Consoles Inc.
6.\"
7.\" Redistribution and use in source and binary forms are permitted
8.\" provided that this notice is preserved and that due credit is given
9.\" to the University of California at Berkeley. The name of the University
10.\" may not be used to endorse or promote products derived from this
11.\" software without specific prior written permission. This software
12.\" is provided ``as is'' without express or implied warranty.
13.\"
14.\" @(#)fsdb.8 6.1 (Berkeley) %G%
15.\"
16.TH FSDB 8 ""
17.UC 7
18.SH NAME
19fsdb \- file system debugger
20.SH SYNOPSIS
21.B /etc/fsdb
22.RB [ options ]
23special
24.SH OPTIONS
25The options available to
26.I fsdb\^
27are:
28.RS
29.PD 0
30.TP 13
31.B -?
32display usage
33.TP 13
34.B -o
35override some error conditions
36.TP 13
37.B "-p'string'\^"
38set prompt to string
39.TP 13
40.B -w
41open for write
42.PD
43.RE
44.SH DESCRIPTION
45Since
46.I fsdb
47reads the disk raw,
48it is able to circumvent normal
49file system security.
50Extreme caution is advised
51in determining its availability
52on the system.
53Suggested permissions are 600
54and owned by bin.
55.PP
56.I Fsdb\^
57can be used
58to patch up
59a damaged file system
60after a crash.
61It has conversions
62to translate block and i-numbers
63into their corresponding disk addresses.
64Also included are mnemonic offsets
65to access different parts
66of an inode.
67These greatly simplify the process
68of correcting control block entries
69or descending the file system tree.
70.PP
71.I Fsdb\^
72contains several error-checking routines
73to verify inode and block addresses.
74These can be disabled if necessary
75by invoking
76.I fsdb\^
77with the
78.IR \-o
79option
80or by the use of the
81.IR o
82command.
83.PP
84.I Fsdb\^
85reads a block at a time
86and will therefore work with raw as well as block
87I/O.
88A buffer management routine
89is used to retain commonly used
90blocks of data
91in order to reduce the number of read system calls.
92All assignment operations result
93in an immediate write-through
94of the corresponding block.
95Note that in order to modify
96any portion of the disk,
97.IR fsdb
98must be invoked with the
99.IR -w
100option.
101.PP
102Wherever possible,
103.IR adb- like
104syntax was adopted
105to promote the use
106of
107.IR fsdb
108through familiarity.
109.PP
110Numbers are considered hexadecimal by default.
111However, the user has control over how data is
112to be displayed
113or accepted.
114The
115.IR base
116command will display
117or set the input/output base.
118Once set,
119all input will default to this base
120and all output will be shown in this base.
121The base can be overriden temporarily for input by
122preceding hexadecimal numbers with '0x', preceding
123decimal numbers with '0t', or
124octal numbers with '0'.
125Hexadecimal numbers beginning with a-f or A-F must
126be preceded with '0x'
127to distinguish them from commands.
128.PP
129Disk addressing by
130.IR fsdb
131is at the byte level.
132However,
133.IR fsdb
134offers many commands to convert
135a desired inode, directory entry,
136block, superblock etc. to a
137byte address.
138Once the address has been calculated,
139.IR fsdb
140will record the result in
141.IR dot
142(see next paragraph).
143.PP
144Several global values are maintained by
145.IR fsdb :
146the current base (referred to as
147.IR base ),
148the current address (referred to as
149.IR dot ),
150the current inode (referred to as
151.IR inode ),
152the current count (referred to as
153.IR count ),
154and the current type (referred to as
155.IR type ).
156Most commands use the preset value of
157.IR dot
158in
159their execution.
160For example,
161.RS
162.PD 0
163.TP 7.2n
164> 2:inode
165.PD
166.RE
167will first set the value of
168.IR dot
169to 2, ':' will alert the start of a command,
170and the
171.IR inode
172command will set
173.IR inode
174to 2.
175A count is specified after a ','.
176Once set,
177.IR count
178will remain at this value
179until a new command is encountered
180which will then reset the value back to 1 (the default).
181So, if
182.RS
183.PD 0
184.TP 7.2n
185> 2000,400/X
186.PD
187.RE
188is typed,
189400 hex longs are listed
190from 2000,
191and when completed,
192the value of
193.IR dot
194will be 2000 + 400 * sizeof (long).
195If a carriage-return is then typed,
196the output routine will use the
197current values of
198.IR dot ,
199.IR count ,
200and
201.IR type
202and display 400 more hex longs.
203A '*' will cause the entire block to
204be displayed.
205.PP
206End of fragment, block and file are maintained by
207.IR fsdb.
208When displaying data as fragments or blocks,
209an error message will be displayed when the end of fragment
210or block is reached.
211When displaying data using the
212.IR db,
213.IR ib,
214.IR directory,
215or
216.IR file
217commands an error message is displayed if the
218end of file is reached.
219This is mainly needed
220to avoid passing the
221end of a directory or file
222and getting unknown and unwanted results.
223.PP
224An example showing several commands and
225the use of carriage-return would be:
226.RS
227.PD 0
228.TP 7.2n
229> 2:ino; 0:dir?d
230.br
231or
232.PD
233.RE
234.RS
235.PD 0
236.TP 7.2n
237> 2:ino; 0:db:block?d
238.PD
239.RE
240The two examples are synonymous for getting to the first
241directory entry of the root of the file system.
242Once there,
243subsequent carriage-returns (or +, -) will advance to subsequent
244entries.
245Note that
246.RS
247.PD 0
248.TP 7.2n
249> 2:inode; :ls
250.br
251or
252.PD
253.RE
254.RS
255.PD 0
256.TP 7.2n
257> :ls /
258.PD
259.RE
260is again synonymous.
261.SH EXPRESSIONS
262.PP
263The symbols recognized by
264.I fsdb\^
265are:
266.TP 7.2n
267.B carriage-return
268update the value of
269.IR dot
270by the current value of
271.IR type
272and display using the current value of
273.IR count .
274.TP 7.2n
275.B #
276numeric expressions may be composed of +, -, *, and % operators
277(evaluated left to right) and may use parentheses. Once evaluated,
278the value of
279.IR dot
280is updated.
281.TP 7.2n
282.BI , " count"\^
283count indicator. The global value of
284.IR count
285will be updated to
286.IR count .
287The value of
288.IR count
289will remain until a new command is run.
290A count specifier of '*' will attempt to show a
291.IR blocks's
292worth of information.
293The default for
294.IR count
295is 1.
296.TP 7.2n
297.BI ? " f\^"
298display in structured style with format
299specifier
300.IR f
301(see FORMATTED OUTPUT section).
302.TP 7.2n
303.BI / " f\^"
304display in unstructured style with format
305specifier
306.IR f
307(see FORMATTED OUTPUT section).
308.TP 7.2n
309.B .
310the value of
311.IR dot .
312.TP 7.2n
313.BI + "e\^"
314increment the value of
315.IR dot
316by the expression
317.IR e.
318The amount actually incremented is dependent
319on the size of
320.IR type :
321.br
322.nf
323 dot = dot + e * sizeof (type)
324.fi
325The default for
326.IR e
327is 1.
328.TP 7.2n
329.BI - "e\^"
330decrement the value of
331.IR dot
332by the expression
333.IR e
334(see +).
335.TP 7.2n
336.BI * "e\^"
337multiply the value of
338.IR dot
339by the expression
340.IR e.
341Multiplication and division don't
342use
343.IR type.
344In the above calculation of
345.IR dot ,
346consider the
347sizeof (
348.IR type )
349to be 1.
350.TP 7.2n
351.BI % "e\^"
352divide the value of
353.IR dot
354by the expression
355.IR e
356(see *).
357.TP 7.2n
358.BI < " name\^"
359restore an address saved in register
360.IR name .
361.IR name
362must be a single letter or digit.
363.TP 7.2n
364.BI > " name\^"
365save an address in register
366.IR name .
367.IR name
368must be a single letter or digit.
369.TP 7.2n
370.BI = " f"
371display indicator.
372If
373.IR f
374is a legitimate format specifier
375(see FORMATTED OUTPUT
376section),
377then the value of
378.IR dot
379is displayed using
380format specifier
381.IR f .
382Otherwise,
383assignment is assumed
384(see next item).
385.TP 7.2n
386.BI = " [s] [e]\^"
387assignment indicator.
388The address pointed to by
389.IR dot
390has its contents changed to the value of the
391expression
392.IR e
393or to the
394.IR ASCII
395representation of the
396quoted (") string
397.IR s.
398This may be useful for changing
399directory names or
400.IR ASCII
401file information.
402.TP 7.2n
403.BI =+ " e\^"
404incremental assignment.
405The address pointed to by
406.IR dot
407has its contents incremented by expression
408.IR e .
409.TP 7.2n
410.BI =- " e\^"
411decremental assignment.
412The address pointed to by
413.IR dot
414has its contents decremented by expression
415.IR e .
416.SH COMMANDS
417.PP
418A command must be prefixed by a ':' character.
419Only enough letters of the command
420to uniquely
421distinguish it are needed.
422Multiple commands may be entered
423on one line by separating
424them by a space, tab or ';'.
425.PP
426In order to view a potentially
427unmounted disk in a reasonable
428manner,
429.I fsdb\^
430offers the
431.IR cd ,
432.IR pwd ,
433.IR ls
434and
435.IR find
436commands.
437The functionality of these
438commands substantially matches those of
439its
440.IR UNIX
441counterparts
442(see individual command for details).
443The '*', '?', and '[-]' wild card
444characters are available.
445.TP 7.2n
446.BI base=b
447display or set base. As stated above,
448all input and output is governed by
449the current
450.IR base .
451If the '=b' is left off,
452the current
453.IR base
454is displayed.
455Otherwise, the current
456.IR base
457is set
458to
459.IR b.
460Note that this is interpreted
461using the old value of
462.IR base ,
463so to ensure correctness use the '0', '0t', or '0x'
464prefix when changing the
465.IR base.
466The default for
467.IR base
468is hexadecimal.
469.TP 7.2n
470.B block
471convert the value of
472.IR dot
473to a block address.
474.TP 7.2n
475.B cd dir
476change the current directory
477to directory
478.IR dir.
479The current values of
480.IR inode
481and
482.IR dot
483are also updated.
484If no
485.IR dir
486is specified,
487then change directories to
488inode 2 ("/").
489.TP 7.2n
490.B cg
491convert the value of
492.IR dot
493to a cylinder group.
494.TP 7.2n
495.B directory
496If the current
497.IR inode
498is a directory,
499then the value of
500.IR dot
501is converted to a directory
502slot offset in that directory
503and
504.IR dot
505now points to
506this entry.
507.TP 7.2n
508.B file
509the value of
510.IR dot
511is taken as
512a relative block count from the
513beginning of the file.
514The value of
515.IR dot
516is updated to the first byte
517of this block.
518.IR
519.TP 7.2n
520.BI find " dir [-name n] [-inum i]\^"
521find files by name or i-number.
522.IR find
523recursively searches
524directory
525.IR dir
526and below for filenames whose
527i-number matches
528.IR i
529or whose name
530matches pattern
531.IR n .
532Note that only one of the two options
533(-name or -inum)
534may be used at one time.
535Also, the -print is not needed or
536accepted.
537.TP 7.2n
538.BI fill "=p\^"
539fill an area of disk with pattern
540.IR p.
541The area of disk
542is delimited by
543.IR dot
544and
545.IR count .
546.TP 7.2n
547.B fragment
548convert the value of
549.IR dot
550to
551a fragment address.
552The only difference between the
553.IR fragment
554command and the
555.IR block
556command is the amount that
557is able to be displayed.
558.TP 7.2n
559.B inode
560convert the value of
561.IR dot
562to an inode address.
563If successful,
564the current value of
565.IR inode
566will be updated as well as
567the value of
568.IR dot.
569As a convenient shorthand,
570if ':inode' appears at the
571beginning of the line,
572the value of
573.IR dot
574is set to the current
575.IR inode
576and that inode is displayed
577in inode format.
578.TP 7.2n
579.BI ls " [-R] [-l] pat1 pat2 ...\^"
580list directories or files.
581If no file is specified,
582the current directory is assumed.
583Either or both of the
584options may be used (but, if used,
585.IR must
586be specified before the
587filename specifiers).
588Also, as stated above,
589wild card characters are
590available and multiple
591arguments may be given.
592The long listing shows only
593the i-number and the name;
594use the
595.IR inode
596command with '?i'
597to get more information.
598.TP 7.2n
599.B override
600toggle the value of override.
601Some error conditions may be
602overriden
603if override is toggled on.
604.TP 7.2n
605.BI prompt " p\^"
606change the fsdb prompt to
607.IR p.
608.IR p
609must be surrounded by (")s.
610.TP 7.2n
611.B pwd
612display the current working directory.
613.TP 7.2n
614.B quit
615quit
616.IR fsdb .
617.TP 7.2n
618.B sb
619the value of
620.IR dot
621is taken as a cylinder group
622number and then converted to
623the address of the superblock
624in that cylinder group.
625As a shorthand, ':sb' at
626the beginning of a line
627will set the value of
628.IR dot
629to
630.IR the
631superblock and display it
632in superblock format.
633.TP 7.2n
634.B !
635escape to shell
636.SH INODE COMMANDS
637In addition to the above commands,
638there are several commands that deal with inode
639fields and operate directly on the current
640.IR inode
641(they still require the ':').
642They may be used to more easily display
643or change the particular fields.
644The value of
645.IR dot
646is only used by the ':db'
647and ':ib' commands.
648Upon completion of the command,
649the value of
650.IR dot
651is changed to point to
652that particular field.
653For example,
654.RS
655.PD 0
656.TP 7.2n
657> :ln=+1
658.PD
659.RE
660would
661increment the link count of the current
662.IR inode
663and set the value of
664.IR dot
665to the address of the link
666count field.
667.TP 7.2n
668.B at
669access time.
670.TP 7.2n
671.B bs
672block size.
673.TP 7.2n
674.B ct
675creation time.
676.TP 7.2n
677.B db
678use the current value of
679.IR dot
680as a direct block index,
681where direct blocks number from
6820 - 11.
683In order to display the block
684itself, you need to 'pipe' this
685result into the
686.IR block
687or
688.IR fragment
689command.
690For example,
691.br
692.nf
693 > 1:db:block,20/X
694.fi
695would get the contents of
696data block field 1 from the inode and
697convert it to a block address.
69820 longs are then displayed in hexadecimal
699(see FORMATTED OUTPUT section).
700.TP 7.2n
701.B gid
702group id.
703.TP 7.2n
704.B ib
705use the current value of
706.IR dot
707as an indirect block index
708where indirect blocks number from
7090 - 2.
710This will only get the indirect block itself
711(the block containing the pointers to the actual blocks).
712Use the
713.IR file
714command and start at block 12 to get to the actual
715blocks.
716.TP 7.2n
717.B ln
718link count.
719.TP 7.2n
720.B mt
721modification time.
722.TP 7.2n
723.B md
724mode.
725.TP 7.2n
726.B maj
727major device number.
728.TP 7.2n
729.B min
730minor device number.
731.TP 7.2n
732.B nm
733although listed here,
734this command actually
735operates on the directory
736name field.
737Once poised at the desired
738directory entry (using the
739.IR directory
740command),
741this command will allow
742you to change or display
743the directory name.
744For example,
745.br
746.nf
747 > 7:dir:nm="foo"
748.fi
749will get the 7th directory
750entry of the current
751.IR inode
752and change its name to foo.
753Note that names
754cannot be made larger than the
755field is set up for.
756If an attempt is made,
757the string is truncated to fit
758and a warning message to this
759effect is displayed.
760.TP 7.2n
761.B sz
762file size.
763.TP 7.2n
764.B uid
765user id.
766.SH FORMATTED OUTPUT
767.PP
768There are two styles
769and many format types.
770The two styles are structured and
771unstructured.
772Structured output is used to display
773inodes, directories, superblocks and the
774like.
775Unstructured just displays
776raw data.
777The following table shows the
778different ways of displaying:
779.TP 7.2n
780.B ?
781.RS
782.PD 0
783.TP 13
784.B c
785display as cylinder groups
786.TP 13
787.B i
788display as inodes
789.TP 13
790.B d
791display as directories
792.TP 13
793.B s
794display as superblocks
795.PD
796.RE
797.TP 7.2n
798.B /
799.RS
800.PD 0
801.TP 13
802.B b
803display as bytes
804.TP 13
805.B c
806display as characters
807.TP 13
808.B o O
809display as octal shorts or longs
810.TP 13
811.B d D
812display as decimal shorts or longs
813.TP 13
814.B x X
815display as hexadecimal shorts or longs
816.PD
817.RE
818.PP
819The format specifier immediately follows
820the '/' or '?' character.
821The values displayed by '/b' and all '?'
822formats are displayed in the current
823.IR base .
824Also,
825.IR type
826is appropriately updated
827upon completion.
828.SH EXAMPLES
829.TP 16
830> 2000+400%(20+20)=D
831will display 2010 in decimal (use of
832.IR fsdb
833as a calculator
834for complex arithmetic).
835.TP 16
836> 386:ino?i
837display i-number 386 in an inode format.
838This now becomes the current
839.IR inode .
840.TP 16
841> :ln=4
842changes the link count for the
843current
844.IR inode
845to 4.
846.TP 16
847> :ln=+1
848increments the link count by 1.
849.TP 16
850> :ct=X
851display the creation time as a hexadecimal long.
852.TP 16
853> :mt=t
854display the modification time in time format.
855.TP 16
856> 0:file/c
857displays, in
858.IR ASCII ,
859block zero of the file associated
860with the
861current
862.IR inode .
863.TP 16
864> 2:ino,*?d
865displays the first blocks worth of directory entries for
866the root inode of this file system.
867It will stop prematurely if the eof is reached.
868.TP 16
869> 5:dir:inode; 0:file,*/c
870changes the current inode to that
871associated with the 5th directory entry
872(numbered from zero)
873of the current
874.IR inode.
875The first logical block of the file
876is then displayed in
877.IR ASCII .
878.TP 16
879> :sb
880displays the superblock of this file system.
881.TP 16
882> 1:cg?c
883displays cylinder group information and summary
884for cylinder group 1.
885.TP 16
886> 2:inode; 7:dir=3
887changes the i-number for the
888seventh directory slot in the root directory to 3.
889.TP 16
890> 7:dir:nm="name"
891changes the name field
892in the directory slot to
893.IR name .
894.TP 16
895> 2:db:block,*?d
896displays the third block of the current
897.IR inode
898as directory entries.
899.TP 16
900> 3c3:fragment,20:fill=0x20
901get fragment 3c3 and fill 20
902.IR type
903elements
904with 0x20.
905.TP 16
906> 2050=0xffff
907set the contents of address 2050 to 0xffffffff.
9080xffffffff may be truncated depending on the current
909.IR type.
910.TP 16
911> 1c92434="this is some text"
912will place the
913.IR ASCII
914for the string at
9151c92434.
916.SH SEE ALSO
917fsck(8), dir(4), fs(5).
918.SH BUGS
919.PP
920Extreme caution is advised in
921determining the availability
922of
923.IR fsdb
924on the system.
925Suggested permissions are 600 and
926owned by bin.