Subject: Re: Partition table on x86 trashed. Any ideas?
To: Gerald Heinig <Gerald.Heinig@post.rwth-aachen.de>
From: Giles Lean <giles@nemeton.com.au>
List: netbsd-users
Date: 09/09/2001 06:57:23
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <10757.999982471.1@nemeton.com.au>

> My question is: how do I resurrect my partition table?

I've not had to do that precisely, but I have had to locate
filesystems within a NetBSD partition which I did by looking for
blocks with FS_MAGIC at the right offset.

Perhaps you could work out a suitable partition table by working out
where the filesystems are?  For what it's worth, findsb.c is below.

Good luck,

Giles


------- =_aaaaaaaaaa0
Content-Type: text/plain; name="findsb.c"; charset="us-ascii"
Content-ID: <10757.999982471.2@nemeton.com.au>

/*
 * Find superblocks on a BSD FFS filesystem.
 */

#include <sys/param.h>
#include <sys/types.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>

#include <fcntl.h>
#include <stdio.h>

/*
 * If this is smaller than the filesystem block size expect
 * more false matches.
 */
#define BLOCKSIZE (4 * 1024)

int
main(int argc, char *argv[])
{
	char            block[BLOCKSIZE];
	int             fd;
	struct fs      *filesys;
	int             n;
	int             blockno;

	blockno = 0;
	filesys = (struct fs *) block;

	if (argc != 2) {
		fprintf(stderr, "usage: findsb raw_device\n");
		exit(1);
	}

	if ((fd = open(argv[1], O_RDONLY)) < 0) {
		perror(argv[1]);
		exit(1);
	}

	while ((n = read(fd, block, BLOCKSIZE)) == BLOCKSIZE) {
		if (filesys->fs_magic == FS_MAGIC)
			printf("%d\n", blockno * (BLOCKSIZE / 512));
		blockno++;
	}
}

------- =_aaaaaaaaaa0--