Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 1996 01:19:46 +1000 (EST)
From:      Darren Reed <avalon@coombs.anu.edu.au>
To:        rhwang@mail.io.com
Cc:        hackers@freebsd.org
Subject:   Re: rebuilding trashed disklabel
Message-ID:  <199609101520.IAA21924@freefall.freebsd.org>
In-Reply-To: <199609092010.QAA02289@megazone.bigpanda.com> from "Richard Hwang" at Sep 9, 96 04:10:11 pm

next in thread | previous in thread | raw e-mail | index | archive | help
In some mail from Richard Hwang, sie said:
> 
> I have a drive here (western digital 32500 2.5G ide) on a Dell P6 system with
> 80M RAM which had FreeBSD on it.  (The whole drive was allocated to FreeBSD;
> no multiple boot to other operating systems.)  When I rebooted the system, it
> failed to boot, claiming that I should insert bootable media.  When I checked
> out the disklabel, it looked something like this:

I found the program I wrote, written for SunOS4 so you
may have to do some work before it works under FreeBSD.

You should probably run it across your entire disk (c partition or
whatever that is) so you know where all possible super blocks are.

Sometimes daatSometimes data in progarms can throw it, but there are a few
sanity checks to keep it on track.
Well, I just compiled it on 2.1.5, by changing "stand/param.h" to
"sys/param.h" and "ufs/fs.h" to "ufs/ffs/fs.h"

that done, it compiles (1 warning) with a simple cc and away you go.

Sorry, this is an RTFS for docs, etc.
Was an emergency quick hack :-)
Maybe some more smarts could be gotten from the disklabel as it needs
help in knowing about disk geometry.

Darren

#include <stdio.h>
#include <stand/param.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <ufs/fs.h>

#define	BLKSIZ	512	/* size of cyliner in longs */
#define	NTRACK	16
#define	NSECT	63

extern	char	*optarg;
extern	int	optind;


main(argc, argv)
int argc;
char *argv[];
{
	int	fd, nsect = NSECT, ntrack = NTRACK;
	int	search = 0;
	u_long	*block, blksiz;
	u_long	*u, cyl = 0, o;
	char	*part = "/dev/rsd0c", c;
	struct	fs	*fs;

	while ((c = getopt(argc, argv, "h:p:Ss:t:V")) != -1)
		switch (c)
		{
		case 's' :
			nsect = atoi(optarg);
			break;
		case 'S' :
			search |= 1;
			break;
		case 't' :
			ntrack = atoi(optarg);
			break;
		case 'h' :
			ntrack = atoi(optarg);
			break;
		case 'p' :
			part = optarg;
			break;
		case 'V' :
			search |= 2;
			break;
		}

	blksiz = BLKSIZ * ntrack * nsect;
	block = (u_long)malloc(blksiz);
	if ((fd = open(part, O_RDONLY)) == -1) {
		fprintf(stderr, "%s ", part);
		perror("open");
		exit(-1);
	}

	while (read(fd, block, blksiz) == blksiz) {
		for (u = block, o = blksiz/4 - sizeof(*fs)/4; o; o--, u++) {
			fs = (struct fs *)u;
			if (fs->fs_magic == 0x011954)
				printsuperblock(block, u, cyl, fs, search);
		}
		cyl++;
		printf("%d\r", cyl);
		fflush(stdout);
	}
}

printsuperblock(bs, u, cyl, fs, opts)
u_long *bs, *u, cyl;
struct fs *fs;
int opts;
{
	if ((int)fs->fs_rps < 0 || !fs->fs_ncyl ||
	    (0 > fs->fs_minfree || fs->fs_minfree > 100))
		return;
	if (!fs->fs_fsmnt[0] && !(opts & 2))
		return;
	printf("Superblock %#x for mnt [%s] @%d/%d size %d at %s",
		fs->fs_magic, fs->fs_fsmnt, cyl, (u - bs)>>9,
		fs->fs_ncyl, ctime(&fs->fs_time));
	printf("\tSuperblock addr %d size %d\n",
		fs->fs_sblkno, fs->fs_sbsize);
	printf("\tclean %d modified %d read-only %d unused %d\n",
		fs->fs_clean, fs->fs_fmod, fs->fs_ronly, fs->fs_flags);
	printf("\tSizes: Partition %d (block %dB) = %dMB, frags %d * %d\n",
		fs->fs_dsize, fs->fs_bsize, fs->fs_dsize / 0x400,
		fs->fs_frag, fs->fs_fsize);
	if (opts & 1)
		return;
	printf("Disk geometry: %d/%d = %d s/c, %drpm minfree %d delay %d\n",
		fs->fs_ntrak, fs->fs_nsect, fs->fs_spc,
		fs->fs_rps * 60, fs->fs_minfree, fs->fs_rotdelay);
	printf("\tInterleave %d skew %d\n",
		fs->fs_interleave, fs->fs_trackskew);
	printf("Cylinders: cyl-block offset %d group offset in cyl. %d\n",
		fs->fs_cblkno, fs->fs_cgoffset);
	printf("\tMax Contiguous blocks %d per cylinder %d\n",
		fs->fs_maxcontig, fs->fs_maxbpg);
	printf("\tNINDIR %d INOPB %d NSPF %d\n",
		fs->fs_nindir, fs->fs_inopb, fs->fs_nspf);
	printf("Per-Group: Inodes %d cylinders %d blocks %d\n",
		fs->fs_ipg, fs->fs_cpg, fs->fs_fpg);
	printf("\tOptimize by %s\n", fs->fs_optim ? "space" : "time");
	printf("# Directories %d, free: blocks %d inodes %d frags %d\n",
		fs->fs_cstotal.cs_ndir, fs->fs_cstotal.cs_nbfree,
		fs->fs_cstotal.cs_nifree, fs->fs_cstotal.cs_nffree);
}




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