Subject: Finding partitions after lost disklabel - solved! :)
To: (NetBSD/current-users Maillist) <current-users@NetBSD.ORG>
From: David Brownlee <email@example.com>
Date: 05/24/1997 12:43:45
I wrote this little program to help someone locate their
filesystems after they lost their disklabel. I'm sure at
least one other person has asked about something similar
in the past, so hopefully this will prove useful! At the
very least its now in the mail archives. :)
If it is useful, is there a contrib area for scripts and
misc NetBSD related code?
If not, do people want one? :)
* Copyright (c) 1997 David Brownlee (firstname.lastname@example.org). Licence at end of file.
* Attempt to find ffs filesystems in the event of a lost disklabel.
* This program itself will not modify any data on a disk, but using
* disklabel and fsck _can_ cause loss of data - you have been warned!
* Compile with 'cc -Wall -O -o ffs_find ffs_find.c'.
* To use, run 'ffs_find /dev/rXXNc' (eg rsd0c, rsd1c, or rwd0c etc), note the
* possible filesystems, disklabel appropriately and try to fsck.
* (May want to use /dev/rXXNd on i386).
* It reports possible filesystems by checking for two 'superblock like'
* blocks fs.fs_sblkno blocks apart.
* It can find false positives. (It should check more rigorously).
* It assumes 512 byte blocks.
* It assumes the first & second superblocks of a filesystem are intact,
* and at offsets of fs.fs_sblkno and fs.fs_sblkno*2 respectively.
* The 'trick' with sbplus is not particularly palatable,
* Comments/suggestions welcome!
#define BLOCKSIZE 512
#define SB_SIZE (((sizeof(struct fs)+BLOCKSIZE-1)/BLOCKSIZE)*BLOCKSIZE)
struct fs data;
int main(int argc,char **argv)
if( argc!=2 )
fputs("Usage: ffs_find special\n",stderr);
if( (fds=fopen(argv,"r"))==0 )
if( fread(&sblock.data,SB_SIZE,1,fds)==0 )
fputs("Unable to read start of partition.\n",stderr);
if( sblock.data.fs_magic == FS_MAGIC )
if( last && last==blockno-sblock.data.fs_sblkno )
printf("Possible filesystem at offset %u, size %u (%uMB).\n",
* Do not skip to end of possible filesystem, as may be
* false positive
* Copyright (c) 1997 David Brownlee (email@example.com). All rights reserved.
* This program is free software.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.---- I've been too drunk to love ----.-- I've been too drunk to remember -.
| too drunk to care | the hell of the night before |
| looked like death, felt like hell | I've been drinking myself blind |
`------ been the worse for wear ------'-- and still I'll drink some more --'