Subject: Re: disklabel lost (ARGH)
To: None <l.raiser@deathsdoor.com>
From: William S. Morgart <morgarws@molbio.sbphrd.com>
List: port-i386
Date: 09/14/2000 10:53:07
I had the same thing happen several years ago and found this short program 
that searches the disk for the superblocks of the filesystems. It was 
orginally written for the Sun and then ported to FreeBSD ... I ported it to 
NetBSd plus added some modifications to allow me to specify where to start 
looking (so that I could skip an already discovered filesystem) ...

Good Luck YMMV
Bill Morgart
wsm@morgart.com

here is the source 

-------------------------------------> find_super.c 
<---------------------------------------------
/* Hunt for file system superblocks on disk.
 * Andrew Heybey, ath@niksun.com
 * Modified by: William Morgart, wsm@morgartcom
 *
 * This code is placed in the public domain.  No warantee.
 *
 * $Id: find_super.c,v 1.2 1998/03/23 21:28:48 ath Exp $
 */

#include <sys/param.h>
#include <stdio.h>
#include <sys/types.h>
#define ufs_daddr_t daddr_t
#include <fcntl.h>
#include <ufs/ffs/fs.h>

#define BUFSIZE (512*1024)

main(argc, argv)
  int argc;
  char *argv[];
{
    char *dev = argv[1];
    int fd;
    int res;
    FILE *out = stdout;
    u_long sect = 0;
    char buf[BUFSIZE];
    int cnt, limit;
    struct fs *fs;
    
    if (argc == 3) {
      /* have a starting sector */
      sect = atoi(argv[2]);
    }
    fd = open (dev, O_RDONLY);
    if (fd < 0)  {
        perror ("open");
        exit (1);
    }

    for (;;)  {
        res = read (fd, buf, sizeof (buf));
        if (res != sizeof (buf))
            break;
        for (cnt = 0; cnt < BUFSIZE; cnt += 512, sect++)  {
            fs = (struct fs *)&buf[cnt];

            if (fs->fs_magic != FS_MAGIC)
                continue;

            fprintf (out, "Found possible superblock at sector %u:\n", sect);

            fprintf (out, "size %ld, bsize %ld, fsize %ld\n",
                     fs->fs_size, fs->fs_bsize, fs->fs_fsize);
        }
    }

    if (res < 0)  {
        perror ("read");
    }

    close (fd);
}

---------------------------------> end of find_super.c 
<---------------------------------------