1.\" $NetBSD: fsdb.8,v 1.28 2022/11/17 06:40:38 chs Exp $ 2.\" 3.\" Copyright (c) 1996, 2017 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by John T. Kohl. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd May 29, 2021 31.Dt FSDB 8 32.Os 33.Sh NAME 34.Nm fsdb 35.Nd FFS debugging/editing tool 36.Sh SYNOPSIS 37.Nm 38.Op Fl dFnN 39.Fl f Ar fsname 40.Sh DESCRIPTION 41.Nm 42opens 43.Ar fsname 44(usually a raw disk partition) and runs a command loop 45allowing manipulation of the file system's inode data. 46You are prompted to enter a command with 47.Dq "fsdb (inum X)>" 48where 49.Va X 50is the currently selected i-number. 51The initial selected inode is the root of the filesystem (i-number 2). 52The command processor uses the 53.Xr editline 3 54library, so you can use command line editing to reduce typing if desired. 55When you exit the command loop, the file system superblock is marked 56dirty and any buffered blocks are written to the file system. 57.Pp 58The 59.Fl d 60option enables additional debugging output (which comes primarily from 61.Xr fsck 8 Ns -derived 62code). 63.Pp 64The 65.Fl F 66option indicates that 67.Ar filesystem 68is a file system image, rather than a raw character device. 69It will be accessed 70.Sq as-is , 71and no attempts will be made to read a disklabel. 72.Pp 73The 74.Fl n 75option disables writing to the device, preventing any changes from being made 76to the filesystem. 77.Pp 78The 79.Fl N 80option causes the superblock not to be marked dirty when 81.Nm 82exits. 83.Sh COMMANDS 84Besides the built-in 85.Xr editline 3 86commands, 87.Nm 88supports these commands: 89.Pp 90.Bl -tag -width indent -compact 91.It Cm help 92Print out the list of accepted commands. 93.Pp 94.It Cm inode Ar i-number 95Select inode 96.Ar i-number 97as the new current inode. 98.Pp 99.It Cm back 100Revert to the previously current inode. 101.Pp 102.It Cm clri Ar i-number 103Clear the inode 104.Ar i-number . 105.Pp 106.It Cm lookup Ar name 107.It Cm cd Ar name 108Find 109.Ar name 110in the current directory and make its inode the current inode. 111.Ar Name 112may be a multi-component name or may begin with slash to indicate that 113the root inode should be used to start the lookup. 114If some component along the pathname is not found, 115the last valid directory encountered is left as the active inode. 116.br 117This command is valid only if the starting inode is a directory. 118.Pp 119.It Cm active 120.It Cm print 121Print out the active inode. 122.Pp 123.It Cm uplink 124Increment the active inode's link count. 125.Pp 126.It Cm downlink 127Decrement the active inode's link count. 128.Pp 129.It Cm linkcount Ar number 130Set the active inode's link count to 131.Ar number . 132.Pp 133.It Cm ls 134List the current inode's directory entries. 135This command is valid only if the current inode is a directory. 136.Pp 137.It Cm blks 138List the current inode's blocks numbers. 139.Pp 140.It Cm findblk Ar disk block number ... 141Find the inode(s) owning the specified disk block(s) number(s). 142Note that these are not absolute disk blocks numbers, but offsets from the 143start of the partition. 144.Pp 145.It Cm saveblks Ar filename 146Save the current inode's data into 147.Ar filename . 148.Pp 149.It Cm rm Ar name 150.It Cm del Ar name 151Remove the entry 152.Ar name 153from the current directory inode. 154This command is valid only if the current inode is a directory. 155.Pp 156.It Cm ln Ar ino Ar name 157Create a link to inode 158.Ar ino 159under the name 160.Ar name 161in the current directory inode. 162This command is valid only if the current inode is a directory. 163.Pp 164.It Cm chinum Ar dirslot Ar inum 165Change the i-number in directory entry 166.Ar dirslot 167to 168.Ar inum . 169.Pp 170.It Cm chname Ar dirslot Ar name 171Change the name in directory entry 172.Ar dirslot 173to 174.Ar name . 175This command cannot expand a directory entry. 176You can only rename an entry if the name will fit into 177the existing directory slot. 178.Pp 179.It Cm chtype Ar type 180Change the type of the current inode to 181.Ar type . 182.Ar type 183may be one of: 184.Em file , 185.Em dir , 186.Em socket , 187or 188.Em fifo . 189.Pp 190.It Cm chmod Ar mode 191Change the mode bits of the current inode to 192.Ar mode . 193You cannot change the file type with this subcommand; use 194.Ic chtype 195to do that. 196.Pp 197.It Cm chflags Ar flags 198Change the file flags of the current inode to 199.Ar flags . 200.Pp 201.It Cm chown Ar uid 202Change the owner of the current inode to 203.Ar uid . 204.Pp 205.It Cm chgrp Ar gid 206Change the group of the current inode to 207.Ar gid . 208.Pp 209.It Cm chgen Ar gen 210Change the generation number of the current inode to 211.Ar gen . 212.Pp 213.It Cm mtime Ar time 214.It Cm ctime Ar time 215.It Cm atime Ar time 216.It Cm birthtime Ar time 217Change the modification, change, access time, or birthtime (respectively) on the 218current inode to 219.Ar time . 220.Ar Time 221should be in the format 222.Em YYYYMMDDHHMMSS[.nsec] 223where 224.Em nsec 225is an optional nanosecond specification. 226If no nanoseconds are specified, the 227.Va mtimensec , 228.Va ctimensec , 229.Va atimensec , 230or 231.Va birthtimensec 232field will be set to zero. 233The birthtime field is only available on ufs2 filesystems. 234.Pp 235.It Cm quit , Cm q , Cm exit , Aq Em EOF 236Exit the program. 237.El 238.Sh SEE ALSO 239.Xr editline 3 , 240.Xr fs 5 , 241.Xr clri 8 , 242.Xr fsck 8 243.Sh HISTORY 244.Nm 245uses the source code for 246.Xr fsck 8 247to implement most of the file system manipulation code. 248The remainder of 249.Nm 250first appeared in 251.Nx 1.1 . 252.Sh WARNING 253Use this tool with extreme caution -- you can damage an FFS file system 254beyond what 255.Xr fsck 8 256can repair. 257.Sh BUGS 258Manipulation of 259.Dq short 260symlinks doesn't work (in particular, don't 261try changing a symlink's type). 262.br 263You must specify modes as numbers rather than symbolic names. 264.br 265There are a bunch of other things that you might want to do which 266.Nm 267doesn't implement. 268