From owner-freebsd-hackers Mon Mar 23 13:35:33 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA15140 for freebsd-hackers-outgoing; Mon, 23 Mar 1998 13:35:33 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from arjun.niksun.com (gw.niksun.com [206.20.52.122]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA14595 for ; Mon, 23 Mar 1998 13:33:50 -0800 (PST) (envelope-from ath@niksun.com) Received: from stiegl.niksun.com (stiegl.niksun.com [10.0.0.44]) by arjun.niksun.com (8.8.8/8.8.7) with ESMTP id QAA14299; Mon, 23 Mar 1998 16:30:20 -0500 (EST) (envelope-from ath@stiegl.niksun.com) Received: (from ath@localhost) by stiegl.niksun.com (8.8.7/8.8.7) id QAA22215; Mon, 23 Mar 1998 16:33:40 -0500 (EST) (envelope-from ath) To: Narvi cc: FreeBSD-Hackers@FreeBSD.ORG Subject: Re: Finding an FS on the disk References: From: Andrew Heybey Date: 23 Mar 1998 16:33:40 -0500 In-Reply-To: Narvi's message of Mon, 23 Mar 1998 22:48:07 +0200 (EET) Message-ID: <85afahf5xn.fsf@stiegl.niksun.com> Lines: 84 X-Mailer: Gnus v5.3/Emacs 19.34 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Here is some code I wrote when I had a similar problem under SunOS. I just modified it to compile and (apparently) work under FreeBSD. Do something like: ./find_super /dev/rwd0c and it will print something like: Found possible superblock at sector 16: size 65536, bsize 8192, fsize 1024 Found possible superblock at sector 32: size 65536, bsize 8192, fsize 1024 ... superblocks (& backups) from /var, /usr, etc. You have to figure out a) whether you just got unlucky and there happened to be an FS_MAGIC at the beggining of a sector of otherwise random data (which is why my program prints out size, bsize & fsize for sanity checking), b) which superblock is the one at the beginning of the file system you care about and c) how to recover your data once you have passed a) and b). Good luck. andrew ==================== cut here (MIME? what's that?) ================== /* Hunt for file system superblocks on disk. * Andrew Heybey, ath@niksun.com * * 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 #include #include #include #include #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; 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); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message