[prev in list] [next in list] [prev in thread] [next in thread]
List: netbsd-port-i386
Subject: Re: Direct disk editing & regenerating partition info.
From: Giles Lean <giles () nemeton ! com ! au>
Date: 2002-05-24 11:44:30
[Download RAW message or body]
Hisashi T Fujinaka wrote:
> I've deleted my NetBSD partition info. I really need to find the data in
> the last partition, which is /dev/wd1e on my disk.
Last time I did something like that some years ago, I fixed it by
locating the filesystem super blocks which let me manually calculate
what the partitions should be, and I then carefully re-labelled the
disk.
The program below was what I used to find the super blocks. The
suggestions already provided about locating a backup disklabel are
easier, but this works even when a backup disklabel is not found.
Regards,
Giles
/*
* Find superblocks on a BSD FFS filesystem.
*
* On NetBSD, need only to check for FS_MAGIC. HP-UX has about three
* flavours of FS_MAGIC. You'll need something else for a Veritas
* file system.
*/
#include <sys/param.h>
#include <sys/types.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <fcntl.h>
#include <stdio.h>
/*
* Usually larger on HP-UX -- too small will only result in the odd
* false match.
*/
#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++;
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic