Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Apr 2000 23:42:34 -0600
From:      Warner Losh <imp@village.org>
To:        "J.D. Falk" <jdfalk@mail-abuse.org>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Corrupted disk label and related issues (fwd) 
Message-ID:  <200004200542.XAA11246@billy-club.village.org>
In-Reply-To: Your message of "Wed, 19 Apr 2000 21:48:39 PDT." <20000419214839.B13391@mail-abuse.org> 
References:  <20000419214839.B13391@mail-abuse.org>  

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20000419214839.B13391@mail-abuse.org> "J.D. Falk" writes:
: 	I sent this to freebsd-questions yesterday, and didn't get any
: 	responses...looks like Andrew had a similar situation about a
: 	month ago, and found a solution which I'm trying to adapt to
: 	my own problem.  Thing is, I can't even get to the individual
: 	partitions like he did -- I keep getting "Device not configured" 
: 	and the like.  Any advice?

Well, you might be able to use the following program, supplied on an
as is basis, to recover your disklabel.  I wrote it when I
accidentally overwrote the first 32k of my drive.  Good thing only the
disklabel and fdisk partition happened to be there :-(.  I've not
verified this program recently, so I have no clue if it will work for
you.

Oh, I dumped the disk to tape with dd before messing with it.  Backup
any critical data before you attempt to use this program (although it
doesn't actually try to write anything you never know).  You are
definitely on your own here and anything bad this program does is not
my fault, so don't whine to me if you ruin your already busted disk
with it.

Disclaimer, stolen from a darkendeavors promo spot: use only as
directed.  Side effects may include incapacitation from nausea and
incessant hiccups, sporadic nostril insect infestation, terminal
Tarzanian Foot Fungus, excessively elongated ear lobes, contagious
reptilian laughter, digit loss, hemorrhagic episodes, full frontal
nudity, and an uncontrollable passion for DOS batch files.  Pregnant
women should not skydive while listening.  Read instructions at the
website: darkendeavors.com.

Warner

#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <ufs/ffs/fs.h>
#include <err.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>

void
usage()
{
	errx(1, "reclab fn");
}

ssize_t
read_good(int fd, void *addr, size_t sz)
{
	ssize_t rv;

	rv = read(fd, addr, sz);
	if (rv < 0)
		err(1, "read_good");
	return rv;
}

int
search(int fd)
{
	char buf[SBSIZE];
	struct fs *fs = (struct fs *) buf;
	off_t i = 0;
	char ch = 'a';

	while (read_good(fd, (void *) &buf, SBSIZE) == SBSIZE) {
		if (i % 2048 == 0) {
			printf("%qd MB\r", i/2048);
			fflush(stdout);
		}
		i++;
		lseek(fd, i * 512, SEEK_SET);
		if (fs->fs_magic != FS_MAGIC)
			continue;
		printf("%c: %d %qd 4.2BSD 0 0 0 # %s %d\n", ch, fs->fs_size * 2,
		    i - 1 - 16, fs->fs_fsmnt, fs->fs_sblkno);
		ch++;
		if (ch == 'b')
			ch = 'd';
		i += 2 * fs->fs_size - 1;
		lseek(fd, i * 512, SEEK_SET);
	}
	return (1);
}

int
main(int argc, char **argv)
{
	int fd;

	if (argc != 2)
		usage();
	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		err(1, "open");
	search(fd);
	close(fd);
	return 0;
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004200542.XAA11246>