Re: scan_ffs for UFS2

2003-02-24 Thread Hiten Pandya
Michael Ranner (Sun, Feb 23, 2003 at 03:40:20PM +0100) wrote:
 Am Freitag, 21. Februar 2003 22:38 schrieben Sie:
  At 10:20 PM +0100 2/19/03, Michael Ranner wrote:
 
  For what it's worth, we (FreeBSD) have a simple SuperBlock recovery
  program in /usr/src/tools/tools/find-sb.  I picked up some updates
  from Dave Cross for that, and have a few more of my own.  I just
  have to sit down and get them all together into a single version.
  I don't know how find-sb compares to the program you're talking
  about, but they sound kind of similar.
 
 Scan_ffs can print the lost disklabel for use with disklabel(8).
 Find-sb, that version from cvs, seems only to print info about
 the superblocks of each file system and you have to rebuild the
 lost disklabel for your self. I was on the search for a simple
 tool for everybody, and found scan_ffs several months ago
 in the OpenBSD distribution (so it seems find-sb was like
 reinventing the wheel) and Robert Watson suggested in a posting
 december last year to adopt scan_ffs for UFS2. IMHO we should
 reuse a already written program with existing man pages, so
 we have the same sounding tools for the same tasks.
 
 I don't know what find-sb could do with your patches applied.
 If it's superior to scan_ffs, we can forget scan_ffs.

FWIW, I did make scan_ffs work with UFS2 at one point in time, but I
lost my stuff in a disk crash.  It's a pretty good utility with good
documentation.  The only thing you need to worry about in the scan_ffs
code is the opendisk() routine, or something like that, but it shouldn't
be hard.

-- 
Hiten Pandya ([EMAIL PROTECTED], [EMAIL PROTECTED])
http://www.unixdaemons.com/~hiten/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message


Re: scan_ffs for UFS2

2003-02-23 Thread Michael Ranner
Am Freitag, 21. Februar 2003 22:38 schrieben Sie:
 At 10:20 PM +0100 2/19/03, Michael Ranner wrote:

 For what it's worth, we (FreeBSD) have a simple SuperBlock recovery
 program in /usr/src/tools/tools/find-sb.  I picked up some updates
 from Dave Cross for that, and have a few more of my own.  I just
 have to sit down and get them all together into a single version.
 I don't know how find-sb compares to the program you're talking
 about, but they sound kind of similar.

Scan_ffs can print the lost disklabel for use with disklabel(8).
Find-sb, that version from cvs, seems only to print info about
the superblocks of each file system and you have to rebuild the
lost disklabel for your self. I was on the search for a simple
tool for everybody, and found scan_ffs several months ago
in the OpenBSD distribution (so it seems find-sb was like
reinventing the wheel) and Robert Watson suggested in a posting
december last year to adopt scan_ffs for UFS2. IMHO we should
reuse a already written program with existing man pages, so
we have the same sounding tools for the same tasks.

I don't know what find-sb could do with your patches applied.
If it's superior to scan_ffs, we can forget scan_ffs.

-- 
/\/\ichael Ranner

[EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED]
--
JAWA Management Software GmbH - http://www.jawa.at/
  Liebenauer Hauptstrasse 2oo - A-8041 Graz
Tel +43 316 403274 21 - Fax +43 316 403274 10
--
 Mariazell Online - http://www.mariazell.at/
--

-BEGIN GEEK CODE BLOCK-
GIT/CS/AT dx(-) s+:(++:) a- C++ UBLVS$ P+$ L-(+)$ E---
W+++$ N+(++) o-- K- w--()$ O-(--) M V-(--) PS+++ PE(-) Y+ PGP(-)
t+ 5+ X+++() R* tv++ b+(++) DI++ D-(--) G- e h--(*) r++ y?
--END GEEK CODE BLOCK--


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message


Re: scan_ffs for UFS2

2003-02-23 Thread Garance A Drosihn
At 3:40 PM +0100 2/23/03, Michael Ranner wrote:
Am Freitag, 21. Februar 2003 Garance wrote:
 
  I don't know how find-sb compares to the program you're
  talking about, but they sound kind of similar.
Scan_ffs can print the lost disklabel for use with disklabel(8).
Find-sb, that version from cvs, seems only to print info about
the superblocks of each file system and you have to rebuild the
lost disklabel for your self. [...]
I don't know what find-sb could do with your patches applied.
If it's superior to scan_ffs, we can forget scan_ffs.
It sounds like you should go with scan_ffs, and when I have the
time to sort out my updates I'll see how they apply to that.
--
Garance Alistair Drosehn=   [EMAIL PROTECTED]
Senior Systems Programmer   or  [EMAIL PROTECTED]
Rensselaer Polytechnic Instituteor  [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message


Re: scan_ffs for UFS2

2003-02-21 Thread Garance A Drosihn
At 10:20 PM +0100 2/19/03, Michael Ranner wrote:
Hello!

I am trying to learn scan_ffs (original from OpenBSD, ported to
FreeBSD by Robert Watson) about UFS2 on 5-CURRENT, but it will
not find the Superblock and I dont understand exactly both for
loops, especially that 512 byte increment.
Scan_ffs is a system tool from OpenBSD to recover erased disklabels
from your hard drive.
Thanks for your input.
For what it's worth, we (FreeBSD) have a simple SuperBlock recovery
program in /usr/src/tools/tools/find-sb.  I picked up some updates
from Dave Cross for that, and have a few more of my own.  I just
have to sit down and get them all together into a single version.
I don't know how find-sb compares to the program you're talking
about, but they sound kind of similar.
--
Garance Alistair Drosehn=   [EMAIL PROTECTED]
Senior Systems Programmer   or  [EMAIL PROTECTED]
Rensselaer Polytechnic Instituteor  [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message


scan_ffs for UFS2

2003-02-19 Thread Michael Ranner

Hello!

I am trying to learn scan_ffs (original from OpenBSD, ported to FreeBSD
by Robert Watson) about UFS2 on 5-CURRENT, but it will not find the
Superblock and I dont understand exactly both for loops, especially
that 512 byte increment.

Scan_ffs is a system tool from OpenBSD to recover erased disklabels
from your hard drive.

Thanks for your input.

-- 
/\/\ichael Ranner

[EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED]
--
JAWA Management Software GmbH - http://www.jawa.at/
  Liebenauer Hauptstrasse 2oo - A-8041 Graz
Tel +43 316 403274 21 - Fax +43 316 403274 10
--
 Mariazell Online - http://www.mariazell.at/
--

-BEGIN GEEK CODE BLOCK-
GIT/CS/AT dx(-) s+:(++:) a- C++ UBLVS$ P+$ L-(+)$ E---
W+++$ N+(++) o-- K- w--()$ O-(--) M@ V-(--) PS+++ PE(-) Y+ PGP(-)
t+ 5+ X+++() R* tv++ b+(++) DI++ D-(--) G- e h--(*) r++ y?
--END GEEK CODE BLOCK--

/*	$OpenBSD: scan_ffs.c,v 1.8 2002/07/03 22:32:33 deraadt Exp $	*/

/*
 * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *must display the following acknowledgement:
 *This product includes software developed by Tobias Weingartner.
 * 4. The name of the author may not be used to endorse or promote products
 *derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include sys/types.h
#include sys/param.h
#include sys/fcntl.h
#ifdef __FreeBSD__
#include ufs/ufs/dinode.h
#endif
#include ufs/ffs/fs.h
#include unistd.h
#include stdlib.h
#include stdio.h
#include string.h
#include time.h
#include err.h
#if 0
#include util.h
#endif

#ifdef __FreeBSD__
#define SBSIZE SBLOCKSIZE
#endif
#define SBCOUNT 64		/* XXX - Should be configurable */

/* Flags to control ourselves... */
#define FLAG_VERBOSE		1
#define FLAG_SMART		2
#define FLAG_LABELS		4

int
ufsscan(int fd, daddr_t beg, daddr_t end, int flags)
{
	static char lastmount[MAXMNTLEN];
	static u_int8_t buf[SBSIZE * SBCOUNT];
	struct fs *sb;
	daddr_t blk, lastblk;
	int n;

	lastblk = -1;
	memset(lastmount, 0, MAXMNTLEN);

	for (blk = beg; blk = ((end0)?blk:end); blk += (SBCOUNT*SBSIZE/512)){
		memset(buf, 0, SBSIZE * SBCOUNT);
		if (lseek(fd, (off_t)blk * 512, SEEK_SET)  0)
		err(1, lseek);
		if (read(fd, buf, SBSIZE * SBCOUNT)  0)
			err(1, read);

		for (n = 0; n  (SBSIZE * SBCOUNT); n += 512){
			sb = (struct fs*)(buf[n]);
			if ((sb-fs_magic == FS_UFS1_MAGIC) ||
			(sb-fs_magic == FS_UFS2_MAGIC)) {
if (flags  FLAG_VERBOSE)
	printf(block %d id %x,%x size %d\n,
	blk + (n/512), sb-fs_id[0],
	sb-fs_id[1], sb-fs_size);

if (((blk+(n/512)) - lastblk) == (SBSIZE/512)) {
	if (flags  FLAG_LABELS ) {
#ifdef __FreeBSD__
		printf(X: %lld %lld 4.2BSD %ld %ld %ld # %s\n,
#else
		printf(X: %d %d 4.2BSD %d %d %d # %s\n,
#endif
		(daddr_t)((off_t)sb-fs_size *
		sb-fs_fsize / 512),
		blk+(n/512)-(2*SBSIZE/512),
		sb-fs_fsize, sb-fs_bsize,
		sb-fs_old_cpg, lastmount);
	} else {
#ifdef __FreeBSD__
		printf(ufs1 at %lld size %lld mount %s time %s\n,
#else
		printf(ffs1 at %d size %lld mount %s time %s\n,
#endif
		  blk+(n/512)-(2*SBSIZE/512),
	(long long)(off_t)sb-fs_size *
			sb-fs_fsize,
		lastmount, ctime((time_t *)sb-fs_time));
	}

	if (flags  FLAG_SMART) {
		off_t size = (off_t)sb-fs_size *
		sb-fs_fsize;

		if ((n + size)  (SBSIZE * SBCOUNT))
			n += 

Re: scan_ffs for UFS2

2003-02-19 Thread Michael Ranner
Am Mittwoch, 19. Februar 2003 22:20 schrieb Michael Ranner:
 Hello!

 I am trying to learn scan_ffs (original from OpenBSD, ported to FreeBSD
 by Robert Watson) about UFS2 on 5-CURRENT, but it will not find the
 Superblock and I dont understand exactly both for loops, especially
 that 512 byte increment.


Ok, now scan_ffs can detect a UFS2 filesystem, but scan_ffs does
not calculate the correct offset for the disklabel. Further I do
not unterstand the smart feature of scan_ffs fully at the moment.

Where to I find CPG in an UFS2 superblock? How can I detect, if
scan_ffs should display fs_old_cpg or the new cpg value. Which
fields hold the new cpg value in the superblock?

Regards,

-- 
/\/\ichael Ranner

[EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED]
--
JAWA Management Software GmbH - http://www.jawa.at/
  Liebenauer Hauptstrasse 2oo - A-8041 Graz
Tel +43 316 403274 21 - Fax +43 316 403274 10
--
 Mariazell Online - http://www.mariazell.at/
--

-BEGIN GEEK CODE BLOCK-
GIT/CS/AT dx(-) s+:(++:) a- C++ UBLVS$ P+$ L-(+)$ E---
W+++$ N+(++) o-- K- w--()$ O-(--) M@ V-(--) PS+++ PE(-) Y+ PGP(-)
t+ 5+ X+++() R* tv++ b+(++) DI++ D-(--) G- e h--(*) r++ y?
--END GEEK CODE BLOCK--



/*	$OpenBSD: scan_ffs.c,v 1.8 2002/07/03 22:32:33 deraadt Exp $	*/

/*
 * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *must display the following acknowledgement:
 *This product includes software developed by Tobias Weingartner.
 * 4. The name of the author may not be used to endorse or promote products
 *derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include sys/types.h
#include sys/param.h
#include sys/fcntl.h
#ifdef __FreeBSD__
#include ufs/ufs/dinode.h
#endif
#include ufs/ffs/fs.h
#include unistd.h
#include stdlib.h
#include stdio.h
#include string.h
#include time.h
#include err.h
#if 0
#include util.h
#endif

#ifdef __FreeBSD__
#define SBSIZE SBLOCKSIZE
#endif
#define SBCOUNT 64		/* XXX - Should be configurable */

/* Flags to control ourselves... */
#define FLAG_VERBOSE		1
#define FLAG_SMART		2
#define FLAG_LABELS		4

int
ufsscan(int fd, daddr_t beg, daddr_t end, int flags)
{
	static char lastmount[MAXMNTLEN];
	static u_int8_t buf[SBSIZE * SBCOUNT];
	struct fs *sb;
	daddr_t blk, lastblk;
	int n;
#ifdef __FreeBSD__
	int ufs;
#endif

	lastblk = -1;
	memset(lastmount, 0, MAXMNTLEN);

	for (blk = beg; blk = ((end0)?blk:end); blk += (SBCOUNT*SBSIZE/512)){
		memset(buf, 0, SBSIZE * SBCOUNT);
		if (lseek(fd, (off_t)blk * 512, SEEK_SET)  0)
		err(1, lseek);
		if (read(fd, buf, SBSIZE * SBCOUNT)  0)
			err(1, read);

		for (n = 0; n  (SBSIZE * SBCOUNT); n += 512){
#ifdef __FreeBSD__
			ufs = 0;
#endif
			sb = (struct fs*)(buf[n]);

#ifdef __FreeBSD__
			if (sb-fs_magic == FS_UFS1_MAGIC)
ufs = 1;
			if (sb-fs_magic == FS_UFS2_MAGIC)
ufs = 2;

			if (ufs  0) {
#else
			if (sb-fs_magic == FS_MAGIC)
#endif
if (flags  FLAG_VERBOSE)
	printf(block %d id %x,%x size %d\n,
	blk + (n/512), sb-fs_id[0],
	sb-fs_id[1], sb-fs_size);

#ifdef __FreeBSD__
if (((blk+(n/512)) - lastblk) == (SBSIZE*ufs/512)) {
#else
if (((blk+(n/512)) - lastblk) == (SBSIZE/512)) {
#endif
	if (flags  FLAG_LABELS ) {
#ifdef __FreeBSD__
		printf(X: %lld %lld 4.2BSD %ld %ld %ld # %s\n,
#else
		printf(X: %d %d 4.2BSD %d %d %d # %s\n,
#endif
		(daddr_t)((off_t)sb-fs_size

Re: scan_ffs for UFS2

2003-02-19 Thread Brandon D. Valentine
[ Originally crossposted to -hackers and -fs.  This reply Bcc'd to
-hackers, followups to -fs. ]

On Wed, Feb 19, 2003 at 10:20:12PM +0100, Michael Ranner wrote:
 Scan_ffs is a system tool from OpenBSD to recover erased disklabels
 from your hard drive.

Forgive me if I'm being dense, but what features does scan_ffs provide
that are not a subset of the features provided by gpart[0]?

Seems like a duplicate wheel to me.

[0] - http://www.stud.uni-hannover.de/user/76201/gpart/ or [1]
[1] - ports/sysutils/gpart

Brandon D. Valentine
-- 
[EMAIL PROTECTED] http://www.geekpunk.net

We've been raised on replicas of fake and winding roads, and day after day up
on this beautiful stage we've been playing tambourine for minimum wage, but we
are real; I know we are real.  -- David Berman

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message