1*87ba0e2aSchs.\" $NetBSD: fsdb.8,v 1.28 2022/11/17 06:40:38 chs Exp $ 2e727d216Sthorpej.\" 39cb0f8bdSmrg.\" Copyright (c) 1996, 2017 The NetBSD Foundation, Inc. 43f7621c1Sthorpej.\" All rights reserved. 53f7621c1Sthorpej.\" 68bd51c47Sjtc.\" This code is derived from software contributed to The NetBSD Foundation 78bd51c47Sjtc.\" by John T. Kohl. 88bd51c47Sjtc.\" 93f7621c1Sthorpej.\" Redistribution and use in source and binary forms, with or without 103f7621c1Sthorpej.\" modification, are permitted provided that the following conditions 113f7621c1Sthorpej.\" are met: 123f7621c1Sthorpej.\" 1. Redistributions of source code must retain the above copyright 133f7621c1Sthorpej.\" notice, this list of conditions and the following disclaimer. 143f7621c1Sthorpej.\" 2. Redistributions in binary form must reproduce the above copyright 153f7621c1Sthorpej.\" notice, this list of conditions and the following disclaimer in the 163f7621c1Sthorpej.\" documentation and/or other materials provided with the distribution. 173f7621c1Sthorpej.\" 188bd51c47Sjtc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 198bd51c47Sjtc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 208bd51c47Sjtc.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21fb0208bcSjtc.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22fb0208bcSjtc.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 238bd51c47Sjtc.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 248bd51c47Sjtc.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 258bd51c47Sjtc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 268bd51c47Sjtc.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 278bd51c47Sjtc.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283f7621c1Sthorpej.\" POSSIBILITY OF SUCH DAMAGE. 293f7621c1Sthorpej.\" 3081d30165Schristos.Dd May 29, 2021 313f7621c1Sthorpej.Dt FSDB 8 3273f545bbSwiz.Os 333f7621c1Sthorpej.Sh NAME 343f7621c1Sthorpej.Nm fsdb 353f7621c1Sthorpej.Nd FFS debugging/editing tool 363f7621c1Sthorpej.Sh SYNOPSIS 373f7621c1Sthorpej.Nm 38*87ba0e2aSchs.Op Fl dFnN 393f7621c1Sthorpej.Fl f Ar fsname 403f7621c1Sthorpej.Sh DESCRIPTION 413f7621c1Sthorpej.Nm 423f7621c1Sthorpejopens 433f7621c1Sthorpej.Ar fsname 443f7621c1Sthorpej(usually a raw disk partition) and runs a command loop 452fb4b1dbSwizallowing manipulation of the file system's inode data. 462fb4b1dbSwizYou are prompted to enter a command with 4701869ca4Swiz.Dq "fsdb (inum X)>" 483f7621c1Sthorpejwhere 493f7621c1Sthorpej.Va X 502fb4b1dbSwizis the currently selected i-number. 512fb4b1dbSwizThe initial selected inode is the root of the filesystem (i-number 2). 523f7621c1SthorpejThe command processor uses the 535c9d30ebSlukem.Xr editline 3 543f7621c1Sthorpejlibrary, so you can use command line editing to reduce typing if desired. 553f7621c1SthorpejWhen you exit the command loop, the file system superblock is marked 563f7621c1Sthorpejdirty and any buffered blocks are written to the file system. 573f7621c1Sthorpej.Pp 583f7621c1SthorpejThe 593f7621c1Sthorpej.Fl d 603f7621c1Sthorpejoption enables additional debugging output (which comes primarily from 616dd6d12dSwiz.Xr fsck 8 Ns -derived 623f7621c1Sthorpejcode). 634656cdfbSbouyer.Pp 644656cdfbSbouyerThe 65efbd5db6Sdbj.Fl F 66efbd5db6Sdbjoption indicates that 67efbd5db6Sdbj.Ar filesystem 68efbd5db6Sdbjis a file system image, rather than a raw character device. 69efbd5db6SdbjIt will be accessed 70efbd5db6Sdbj.Sq as-is , 71efbd5db6Sdbjand no attempts will be made to read a disklabel. 72efbd5db6Sdbj.Pp 73efbd5db6SdbjThe 744656cdfbSbouyer.Fl n 751a2d0da7Ssnjoption disables writing to the device, preventing any changes from being made 764656cdfbSbouyerto the filesystem. 77*87ba0e2aSchs.Pp 78*87ba0e2aSchsThe 79*87ba0e2aSchs.Fl N 80*87ba0e2aSchsoption causes the superblock not to be marked dirty when 81*87ba0e2aSchs.Nm 82*87ba0e2aSchsexits. 833f7621c1Sthorpej.Sh COMMANDS 843f7621c1SthorpejBesides the built-in 855c9d30ebSlukem.Xr editline 3 863f7621c1Sthorpejcommands, 873f7621c1Sthorpej.Nm 883f7621c1Sthorpejsupports these commands: 893f7621c1Sthorpej.Pp 903f7621c1Sthorpej.Bl -tag -width indent -compact 913f7621c1Sthorpej.It Cm help 923f7621c1SthorpejPrint out the list of accepted commands. 933f7621c1Sthorpej.Pp 943f7621c1Sthorpej.It Cm inode Ar i-number 953f7621c1SthorpejSelect inode 963f7621c1Sthorpej.Ar i-number 973f7621c1Sthorpejas the new current inode. 983f7621c1Sthorpej.Pp 993f7621c1Sthorpej.It Cm back 1003f7621c1SthorpejRevert to the previously current inode. 1013f7621c1Sthorpej.Pp 102473e93d0Sblymn.It Cm clri Ar i-number 103473e93d0SblymnClear the inode 104473e93d0Sblymn.Ar i-number . 1053f7621c1Sthorpej.Pp 1063f7621c1Sthorpej.It Cm lookup Ar name 1073f7621c1Sthorpej.It Cm cd Ar name 1083f7621c1SthorpejFind 1093f7621c1Sthorpej.Ar name 1103f7621c1Sthorpejin the current directory and make its inode the current inode. 1113f7621c1Sthorpej.Ar Name 1123f7621c1Sthorpejmay be a multi-component name or may begin with slash to indicate that 1132fb4b1dbSwizthe root inode should be used to start the lookup. 1142fb4b1dbSwizIf some component along the pathname is not found, 1152fb4b1dbSwizthe last valid directory encountered is left as the active inode. 1163f7621c1Sthorpej.br 1173f7621c1SthorpejThis command is valid only if the starting inode is a directory. 1183f7621c1Sthorpej.Pp 1193f7621c1Sthorpej.It Cm active 1203f7621c1Sthorpej.It Cm print 1213f7621c1SthorpejPrint out the active inode. 1223f7621c1Sthorpej.Pp 1233f7621c1Sthorpej.It Cm uplink 1243f7621c1SthorpejIncrement the active inode's link count. 1253f7621c1Sthorpej.Pp 1263f7621c1Sthorpej.It Cm downlink 1273f7621c1SthorpejDecrement the active inode's link count. 1283f7621c1Sthorpej.Pp 1293f7621c1Sthorpej.It Cm linkcount Ar number 1303f7621c1SthorpejSet the active inode's link count to 1313f7621c1Sthorpej.Ar number . 1323f7621c1Sthorpej.Pp 1333f7621c1Sthorpej.It Cm ls 1342fb4b1dbSwizList the current inode's directory entries. 1352fb4b1dbSwizThis command is valid only if the current inode is a directory. 1363f7621c1Sthorpej.Pp 1374656cdfbSbouyer.It Cm blks 1384656cdfbSbouyerList the current inode's blocks numbers. 1394656cdfbSbouyer.Pp 140e43e5360Sbouyer.It Cm findblk Ar disk block number ... 1411a2d0da7SsnjFind the inode(s) owning the specified disk block(s) number(s). 142e43e5360SbouyerNote that these are not absolute disk blocks numbers, but offsets from the 143c9bb642dSjmcstart of the partition. 144e43e5360Sbouyer.Pp 1459cb0f8bdSmrg.It Cm saveblks Ar filename 1469cb0f8bdSmrgSave the current inode's data into 1479cb0f8bdSmrg.Ar filename . 1489cb0f8bdSmrg.Pp 1493f7621c1Sthorpej.It Cm rm Ar name 1503f7621c1Sthorpej.It Cm del Ar name 1513f7621c1SthorpejRemove the entry 1523f7621c1Sthorpej.Ar name 1532fb4b1dbSwizfrom the current directory inode. 1542fb4b1dbSwizThis command is valid only if the current inode is a directory. 1553f7621c1Sthorpej.Pp 1563f7621c1Sthorpej.It Cm ln Ar ino Ar name 1573f7621c1SthorpejCreate a link to inode 1583f7621c1Sthorpej.Ar ino 1593f7621c1Sthorpejunder the name 1603f7621c1Sthorpej.Ar name 1612fb4b1dbSwizin the current directory inode. 1622fb4b1dbSwizThis command is valid only if the current inode is a directory. 1633f7621c1Sthorpej.Pp 1643f7621c1Sthorpej.It Cm chinum Ar dirslot Ar inum 1653f7621c1SthorpejChange the i-number in directory entry 1663f7621c1Sthorpej.Ar dirslot 1673f7621c1Sthorpejto 1683f7621c1Sthorpej.Ar inum . 1693f7621c1Sthorpej.Pp 1703f7621c1Sthorpej.It Cm chname Ar dirslot Ar name 1713f7621c1SthorpejChange the name in directory entry 1723f7621c1Sthorpej.Ar dirslot 1733f7621c1Sthorpejto 1743f7621c1Sthorpej.Ar name . 1752fb4b1dbSwizThis command cannot expand a directory entry. 1762fb4b1dbSwizYou can only rename an entry if the name will fit into 1772fb4b1dbSwizthe existing directory slot. 1783f7621c1Sthorpej.Pp 1793f7621c1Sthorpej.It Cm chtype Ar type 1803f7621c1SthorpejChange the type of the current inode to 1813f7621c1Sthorpej.Ar type . 1823f7621c1Sthorpej.Ar type 1833f7621c1Sthorpejmay be one of: 1843f7621c1Sthorpej.Em file , 1853f7621c1Sthorpej.Em dir , 1863f7621c1Sthorpej.Em socket , 1873f7621c1Sthorpejor 1883f7621c1Sthorpej.Em fifo . 1893f7621c1Sthorpej.Pp 1903f7621c1Sthorpej.It Cm chmod Ar mode 1913f7621c1SthorpejChange the mode bits of the current inode to 1923f7621c1Sthorpej.Ar mode . 1933f7621c1SthorpejYou cannot change the file type with this subcommand; use 1943f7621c1Sthorpej.Ic chtype 1953f7621c1Sthorpejto do that. 1963f7621c1Sthorpej.Pp 1973f7621c1Sthorpej.It Cm chflags Ar flags 1983f7621c1SthorpejChange the file flags of the current inode to 1993f7621c1Sthorpej.Ar flags . 2003f7621c1Sthorpej.Pp 2013f7621c1Sthorpej.It Cm chown Ar uid 2023f7621c1SthorpejChange the owner of the current inode to 2033f7621c1Sthorpej.Ar uid . 2043f7621c1Sthorpej.Pp 2053f7621c1Sthorpej.It Cm chgrp Ar gid 2063f7621c1SthorpejChange the group of the current inode to 2073f7621c1Sthorpej.Ar gid . 2083f7621c1Sthorpej.Pp 2093f7621c1Sthorpej.It Cm chgen Ar gen 2103f7621c1SthorpejChange the generation number of the current inode to 2113f7621c1Sthorpej.Ar gen . 2123f7621c1Sthorpej.Pp 2133f7621c1Sthorpej.It Cm mtime Ar time 2143f7621c1Sthorpej.It Cm ctime Ar time 2153f7621c1Sthorpej.It Cm atime Ar time 21681d30165Schristos.It Cm birthtime Ar time 21781d30165SchristosChange the modification, change, access time, or birthtime (respectively) on the 2183f7621c1Sthorpejcurrent inode to 2193f7621c1Sthorpej.Ar time . 2203f7621c1Sthorpej.Ar Time 2213f7621c1Sthorpejshould be in the format 2223f7621c1Sthorpej.Em YYYYMMDDHHMMSS[.nsec] 2233f7621c1Sthorpejwhere 2243f7621c1Sthorpej.Em nsec 2252fb4b1dbSwizis an optional nanosecond specification. 2262fb4b1dbSwizIf no nanoseconds are specified, the 2273f7621c1Sthorpej.Va mtimensec , 2283f7621c1Sthorpej.Va ctimensec , 22981d30165Schristos.Va atimensec , 2303f7621c1Sthorpejor 23181d30165Schristos.Va birthtimensec 2323f7621c1Sthorpejfield will be set to zero. 23381d30165SchristosThe birthtime field is only available on ufs2 filesystems. 2343f7621c1Sthorpej.Pp 23585e66d6bSwiz.It Cm quit , Cm q , Cm exit , Aq Em EOF 2363f7621c1SthorpejExit the program. 2373f7621c1Sthorpej.El 2383f7621c1Sthorpej.Sh SEE ALSO 2395c9d30ebSlukem.Xr editline 3 , 2403f7621c1Sthorpej.Xr fs 5 , 241f8c66df3Smsaitoh.Xr clri 8 , 242f8c66df3Smsaitoh.Xr fsck 8 2433f7621c1Sthorpej.Sh HISTORY 2443f7621c1Sthorpej.Nm 2453f7621c1Sthorpejuses the source code for 2463f7621c1Sthorpej.Xr fsck 8 2472fb4b1dbSwizto implement most of the file system manipulation code. 2482fb4b1dbSwizThe remainder of 2493f7621c1Sthorpej.Nm 250e114a31bSjtcfirst appeared in 251e114a31bSjtc.Nx 1.1 . 2523f7621c1Sthorpej.Sh WARNING 2533f7621c1SthorpejUse this tool with extreme caution -- you can damage an FFS file system 2543f7621c1Sthorpejbeyond what 2553f7621c1Sthorpej.Xr fsck 8 2563f7621c1Sthorpejcan repair. 25780d1ff49Swiz.Sh BUGS 2581a2d0da7SsnjManipulation of 2591a2d0da7Ssnj.Dq short 2601a2d0da7Ssnjsymlinks doesn't work (in particular, don't 26180d1ff49Swiztry changing a symlink's type). 26280d1ff49Swiz.br 26380d1ff49SwizYou must specify modes as numbers rather than symbolic names. 26480d1ff49Swiz.br 26580d1ff49SwizThere are a bunch of other things that you might want to do which 26680d1ff49Swiz.Nm 26780d1ff49Swizdoesn't implement. 268