1.\" $OpenBSD: badsect.8,v 1.17 2007/08/06 19:16:05 sobrado Exp $ 2.\" $NetBSD: badsect.8,v 1.8 1995/03/18 14:54:27 cgd Exp $ 3.\" 4.\" Copyright (c) 1985, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)badsect.8 8.1 (Berkeley) 6/5/93 32.\" 33.Dd $Mdocdate: August 6 2007 $ 34.Dt BADSECT 8 35.Os 36.Sh NAME 37.Nm badsect 38.Nd create files to contain bad sectors 39.Sh SYNOPSIS 40.Nm badsect 41.Ar bbdir sector ... 42.Sh DESCRIPTION 43.Nm 44makes a file to contain a bad sector. 45Normally, bad sectors 46are made inaccessible by the standard formatter, which provides 47a forwarding table for bad sectors to the driver. 48If a driver supports the bad blocking standard, it is much more preferable 49to use that method to isolate bad blocks, since the bad block forwarding 50makes the pack appear perfect, and such packs can then be copied with 51.Xr dd 1 . 52The technique used by this program is also less general than 53bad block forwarding, as 54.Nm 55can't make amends for 56bad blocks in the i-list of file systems or in swap areas. 57.Pp 58On some disks, 59adding a sector which is suddenly bad to the bad sector table 60currently requires the running of the standard 61.Tn DEC 62formatter. 63Thus to deal with a newly bad block 64or on disks where the drivers 65do not support the bad-blocking standard 66.Nm 67may be used to good effect. 68.Pp 69.Nm 70is used on a quiet file system in the following way: 71First mount the file system, and change to its root directory. 72Make a directory 73.Li BAD 74there. 75Run 76.Nm badsect , 77giving as argument the 78.Ar BAD 79directory followed by 80all the bad sectors you wish to add. 81(The sector numbers must be relative to the beginning of 82the file system, but this is not hard as the system reports 83relative sector numbers in its console error messages.) 84Then change back to the root directory, unmount the file system 85and run 86.Xr fsck 8 87on the file system. 88The bad sectors should show up in two files 89or in the bad sector files and the free list. 90Have 91.Em fsck 92remove files containing the offending bad sectors, but 93.Em do not 94have it remove the 95.Pa BAD/ Ns Em nnnnn 96files. 97This will leave the bad sectors in only the 98.Li BAD 99files. 100.Pp 101.Nm 102works by giving the specified sector numbers in a 103.Xr mknod 2 104system call, 105creating an illegal file whose first block address is the block containing 106the bad sector, and whose name is the bad sector number. 107When it is discovered by 108.Em fsck 109it will ask 110.Dq Li "HOLD BAD BLOCK?" 111A positive response will cause 112.Em fsck 113to convert the inode to a regular file containing the bad block. 114.Sh DIAGNOSTICS 115.Nm 116refuses to attach a block that 117resides in a critical area or is out of range of the file system. 118A warning is issued if the block is already in use. 119.Sh SEE ALSO 120.Xr fsck 8 121.Sh HISTORY 122The 123.Nm 124command appeared in 125.Bx 4.1 . 126.Sh BUGS 127If more than one sector which comprises a file system fragment is bad, 128you should specify only one of them to 129.Nm badsect , 130as the blocks in the bad sector files actually cover all the sectors in a 131file system fragment. 132