FSDB(8) BSD System Manager's Manual FSDB(8) NNAAMMEE fsdb - file system debugger SSYYNNOOPPSSIISS ffssddbb [ooppttiioonnss] special OOPPTTIIOONNSS The options available to _f_s_d_b are: --?? display usage --oo override some error conditions --pp''ssttrriinngg'' set prompt to string --ww open for write DDEESSCCRRIIPPTTIIOONN Since _f_s_d_b reads the disk raw, it is able to circumvent normal file system security. Extreme caution is advised in determining its availability on the system. Suggested permissions are 600 and owned by bin. _F_s_d_b can be used to patch up a damaged file system after a crash. It has conversions to translate block and i- numbers into their corresponding disk addresses. Also included are mnemonic offsets to access different parts of an inode. These greatly simplify the process of correct- ing control block entries or descending the file system tree. _F_s_d_b contains several error-checking routines to verify inode and block addresses. These can be disabled if nec- essary by invoking _f_s_d_b with the _-_o option or by the use of the _o command. _F_s_d_b reads a block at a time and will therefore work with raw as well as block I/O. A buffer management routine is used to retain commonly used blocks of data in order to reduce the number of read system calls. All assignment operations result in an immediate write-through of the corresponding block. Note that in order to modify any portion of the disk, _f_s_d_b must be invoked with the _-_w option. Wherever possible, _a_d_b_-like syntax was adopted to promote the use of _f_s_d_b through familiarity. Numbers are considered hexadecimal by default. However, the user has control over how data is to be displayed or accepted. The _b_a_s_e command will display or set the input/output base. Once set, all input will default to this base and all output will be shown in this base. The base can be overriden temporarily for input by preceding hexadecimal numbers with '0x', preceding decimal numbers 4.4 Berkeley Distribution June 5, 1993 1 FSDB(8) BSD System Manager's Manual FSDB(8) with '0t', or octal numbers with '0'. Hexadecimal numbers beginning with a-f or A-F must be preceded with '0x' to distinguish them from commands. Disk addressing by _f_s_d_b is at the byte level. However, _f_s_d_b offers many commands to convert a desired inode, directory entry, block, superblock etc. to a byte address. Once the address has been calculated, _f_s_d_b will record the result in _d_o_t (see next paragraph). Several global values are maintained by _f_s_d_b: the current base (referred to as _b_a_s_e), the current address (referred to as _d_o_t), the current inode (referred to as _i_n_o_d_e), the current count (referred to as _c_o_u_n_t), and the current type (referred to as _t_y_p_e). Most commands use the preset value of _d_o_t in their execution. For example, > 2:inode will first set the value of _d_o_t to 2, ':' will alert the start of a command, and the _i_n_o_d_e command will set _i_n_o_d_e to 2. A count is specified after a ','. Once set, _c_o_u_n_t will remain at this value until a new command is encoun- tered which will then reset the value back to 1 (the default). So, if > 2000,400/X is typed, 400 hex longs are listed from 2000, and when completed, the value of _d_o_t will be 2000 + 400 * sizeof (long). If a carriage-return is then typed, the output routine will use the current values of _d_o_t, _c_o_u_n_t, and _t_y_p_e and display 400 more hex longs. A '*' will cause the entire block to be displayed. End of fragment, block and file are maintained by _f_s_d_b_. When displaying data as fragments or blocks, an error mes- sage will be displayed when the end of fragment or block is reached. When displaying data using the _d_b_, _i_b_, _d_i_r_e_c_- _t_o_r_y_, or _f_i_l_e commands an error message is displayed if the end of file is reached. This is mainly needed to avoid passing the end of a directory or file and getting unknown and unwanted results. An example showing several commands and the use of car- riage-return would be: > 2:ino; 0:dir?d or > 2:ino; 0:db:block?d The two examples are synonymous for getting to the first directory entry of the root of the file system. Once there, subsequent carriage-returns (or +, -) will advance to subsequent entries. Note that > 2:inode; :ls or 4.4 Berkeley Distribution June 5, 1993 2 FSDB(8) BSD System Manager's Manual FSDB(8) > :ls / is again synonymous. EEXXPPRREESSSSIIOONNSS The symbols recognized by _f_s_d_b are: ccaarrrriiaaggee--rreettuurrnn update the value of _d_o_t by the current value of _t_y_p_e and display using the current value of _c_o_u_n_t. ## numeric expressions may be composed of +, -, *, and % operators (evaluated left to right) and may use parentheses. Once evaluated, the value of _d_o_t is updated. ,, _c_o_u_n_t count indicator. The global value of _c_o_u_n_t will be updated to _c_o_u_n_t. The value of _c_o_u_n_t will remain until a new command is run. A count specifier of '*' will attempt to show a _b_l_o_c_k_s_'_s worth of infor- mation. The default for _c_o_u_n_t is 1. ?? _f display in structured style with format specifier _f (see FORMATTED OUTPUT section). // _f display in unstructured style with format specifier _f (see FORMATTED OUTPUT section). .. the value of _d_o_t. ++_e increment the value of _d_o_t by the expression _e_. The amount actually incremented is dependent on the size of _t_y_p_e: dot = dot + e * sizeof (type) The default for _e is 1. --_e decrement the value of _d_o_t by the expression _e (see +). **_e multiply the value of _d_o_t by the expression _e_. Multiplication and division don't use _t_y_p_e_. In the above calculation of _d_o_t, consider the sizeof ( _t_y_p_e) to be 1. %%_e divide the value of _d_o_t by the expression _e (see *). << _n_a_m_e restore an address saved in register _n_a_m_e. _n_a_m_e must be a single letter or digit. >> _n_a_m_e save an address in register _n_a_m_e. _n_a_m_e must be a 4.4 Berkeley Distribution June 5, 1993 3 FSDB(8) BSD System Manager's Manual FSDB(8) single letter or digit. == _f display indicator. If _f is a legitimate format specifier (see FORMATTED OUTPUT section), then the value of _d_o_t is displayed using format specifier _f. Otherwise, assignment is assumed (see next item). == _[_s_] _[_e_] assignment indicator. The address pointed to by _d_o_t has its contents changed to the value of the expression _e or to the _A_S_C_I_I representation of the quoted (") string _s_. This may be useful for chang- ing directory names or _A_S_C_I_I file information. ==++ _e incremental assignment. The address pointed to by _d_o_t has its contents incremented by expression _e. ==-- _e decremental assignment. The address pointed to by _d_o_t has its contents decremented by expression _e. CCOOMMMMAANNDDSS A command must be prefixed by a ':' character. Only enough letters of the command to uniquely distinguish it are needed. Multiple commands may be entered on one line by separating them by a space, tab or ';'. In order to view a potentially unmounted disk in a reason- able manner, _f_s_d_b offers the _c_d, _p_w_d, _l_s and _f_i_n_d com- mands. The functionality of these commands substantially matches those of its _U_N_I_X counterparts (see individual command for details). The '*', '?', and '[-]' wild card characters are available. bbaassee==bb display or set base. As stated above, all input and output is governed by the current _b_a_s_e. If the '=b' is left off, the current _b_a_s_e is displayed. Otherwise, the current _b_a_s_e is set to _b_. Note that this is interpreted using the old value of _b_a_s_e, so to ensure correctness use the '0', '0t', or '0x' prefix when changing the _b_a_s_e_. The default for _b_a_s_e is hexadecimal. bblloocckk convert the value of _d_o_t to a block address. ccdd ddiirr change the current directory to directory _d_i_r_. The current values of _i_n_o_d_e and _d_o_t are also updated. If no _d_i_r is specified, then change directories to inode 2 ("/"). ccgg convert the value of _d_o_t to a cylinder group. 4.4 Berkeley Distribution June 5, 1993 4 FSDB(8) BSD System Manager's Manual FSDB(8) ddiirreeccttoorryy If the current _i_n_o_d_e is a directory, then the value of _d_o_t is converted to a directory slot offset in that directory and _d_o_t now points to this entry. ffiillee the value of _d_o_t is taken as a relative block count from the beginning of the file. The value of _d_o_t is updated to the first byte of this block. ffiinndd _d_i_r _[_-_n_a_m_e _n_] _[_-_i_n_u_m _i_] find files by name or i-number. _f_i_n_d recursively searches directory _d_i_r and below for filenames whose i-number matches _i or whose name matches pat- tern _n. Note that only one of the two options (-name or -inum) may be used at one time. Also, the -print is not needed or accepted. ffiillll_=_p fill an area of disk with pattern _p_. The area of disk is delimited by _d_o_t and _c_o_u_n_t. ffrraaggmmeenntt convert the value of _d_o_t to a fragment address. The only difference between the _f_r_a_g_m_e_n_t command and the _b_l_o_c_k command is the amount that is able to be displayed. iinnooddee convert the value of _d_o_t to an inode address. If successful, the current value of _i_n_o_d_e will be updated as well as the value of _d_o_t_. As a conve- nient shorthand, if ':inode' appears at the begin- ning of the line, the value of _d_o_t is set to the current _i_n_o_d_e and that inode is displayed in inode format. llss _[_-_R_] _[_-_l_] _p_a_t_1 _p_a_t_2 _._._. list directories or files. If no file is speci- fied, the current directory is assumed. Either or both of the options may be used (but, if used, _m_u_s_t be specified before the filename specifiers). Also, as stated above, wild card characters are available and multiple arguments may be given. The long listing shows only the i-number and the name; use the _i_n_o_d_e command with '?i' to get more infor- mation. oovveerrrriiddee toggle the value of override. Some error condi- tions may be overriden if override is toggled on. pprroommpptt _p change the fsdb prompt to _p_. _p must be surrounded 4.4 Berkeley Distribution June 5, 1993 5 FSDB(8) BSD System Manager's Manual FSDB(8) by (")s. ppwwdd display the current working directory. qquuiitt quit _f_s_d_b. ssbb the value of _d_o_t is taken as a cylinder group num- ber and then converted to the address of the superblock in that cylinder group. As a shorthand, ':sb' at the beginning of a line will set the value of _d_o_t to _t_h_e superblock and display it in superblock format. !! escape to shell IINNOODDEE CCOOMMMMAANNDDSS In addition to the above commands, there are several com- mands that deal with inode fields and operate directly on the current _i_n_o_d_e (they still require the ':'). They may be used to more easily display or change the particular fields. The value of _d_o_t is only used by the ':db' and ':ib' commands. Upon completion of the command, the value of _d_o_t is changed to point to that particular field. For example, > :ln=+1 would increment the link count of the current _i_n_o_d_e and set the value of _d_o_t to the address of the link count field. aatt access time. bbss block size. cctt creation time. ddbb use the current value of _d_o_t as a direct block index, where direct blocks number from 0 - 11. In order to display the block itself, you need to 'pipe' this result into the _b_l_o_c_k or _f_r_a_g_m_e_n_t com- mand. For example, > 1:db:block,20/X would get the contents of data block field 1 from the inode and convert it to a block address. 20 longs are then displayed in hexadecimal (see FOR- MATTED OUTPUT section). ggiidd group id. iibb use the current value of _d_o_t as an indirect block index where indirect blocks number from 0 - 2. This will only get the indirect block itself (the 4.4 Berkeley Distribution June 5, 1993 6 FSDB(8) BSD System Manager's Manual FSDB(8) block containing the pointers to the actual blocks). Use the _f_i_l_e command and start at block 12 to get to the actual blocks. llnn link count. mmtt modification time. mmdd mode. mmaajj major device number. mmiinn minor device number. nnmm although listed here, this command actually oper- ates on the directory name field. Once poised at the desired directory entry (using the _d_i_r_e_c_t_o_r_y command), this command will allow you to change or display the directory name. For example, > 7:dir:nm="foo" will get the 7th directory entry of the current _i_n_o_d_e and change its name to foo. Note that names cannot be made larger than the field is set up for. If an attempt is made, the string is truncated to fit and a warning message to this effect is dis- played. sszz file size. uuiidd user id. FFOORRMMAATTTTEEDD OOUUTTPPUUTT There are two styles and many format types. The two styles are structured and unstructured. Structured output is used to display inodes, directories, superblocks and the like. Unstructured just displays raw data. The fol- lowing table shows the different ways of displaying: ?? cc display as cylinder groups ii display as inodes dd display as directories ss display as superblocks // bb display as bytes cc display as characters oo OO display as octal shorts or longs dd DD display as decimal shorts or longs xx XX display as hexadecimal shorts or longs 4.4 Berkeley Distribution June 5, 1993 7 FSDB(8) BSD System Manager's Manual FSDB(8) The format specifier immediately follows the '/' or '?' character. The values displayed by '/b' and all '?' for- mats are displayed in the current _b_a_s_e. Also, _t_y_p_e is appropriately updated upon completion. EEXXAAMMPPLLEESS > 2000+400%(20+20)=D will display 2010 in decimal (use of _f_s_d_b as a calculator for complex arithmetic). > 386:ino?i display i-number 386 in an inode format. This now becomes the current _i_n_o_d_e. > :ln=4 changes the link count for the current _i_n_o_d_e to 4. > :ln=+1 increments the link count by 1. > :ct=X display the creation time as a hexadecimal long. > :mt=t display the modification time in time for- mat. > 0:file/c displays, in _A_S_C_I_I, block zero of the file associated with the current _i_n_o_d_e. > 2:ino,*?d displays the first blocks worth of direc- tory entries for the root inode of this file system. It will stop prematurely if the eof is reached. > 5:dir:inode; 0:file,*/c changes the current inode to that associ- ated with the 5th directory entry (num- bered from zero) of the current _i_n_o_d_e_. The first logical block of the file is then displayed in _A_S_C_I_I. > :sb displays the superblock of this file sys- tem. > 1:cg?c displays cylinder group information and summary for cylinder group 1. > 2:inode; 7:dir=3 changes the i-number for the seventh directory slot in the root directory to 3. > 7:dir:nm="name" changes the name field in the directory 4.4 Berkeley Distribution June 5, 1993 8 FSDB(8) BSD System Manager's Manual FSDB(8) slot to _n_a_m_e. > 2:db:block,*?d displays the third block of the current _i_n_o_d_e as directory entries. > 3c3:fragment,20:fill=0x20 get fragment 3c3 and fill 20 _t_y_p_e elements with 0x20. > 2050=0xffff set the contents of address 2050 to 0xffffffff. 0xffffffff may be truncated depending on the current _t_y_p_e_. > 1c92434="this is some text" will place the _A_S_C_I_I for the string at 1c92434. SSEEEE AALLSSOO fsck(8), dir(4), fs(5). BBUUGGSS Extreme caution is advised in determining the availability of _f_s_d_b on the system. Suggested permissions are 600 and owned by bin. 4.4 Berkeley Distribution June 5, 1993 9