From owner-freebsd-hackers Tue Feb 27 11:20:27 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id LAA14569 for hackers-outgoing; Tue, 27 Feb 1996 11:20:27 -0800 (PST) Received: from gilberto.physik.rwth-aachen.de (gilberto.physik.rwth-aachen.de [137.226.31.2]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id LAA14556 for ; Tue, 27 Feb 1996 11:20:19 -0800 (PST) Received: (from kuku@localhost) by gilberto.physik.rwth-aachen.de (8.6.11/8.6.9) id UAA07342 for freebsd-hackers@freefall.cdrom.com; Tue, 27 Feb 1996 20:22:29 +0100 Date: Tue, 27 Feb 1996 20:22:29 +0100 From: "Christoph P. Kukulies" Message-Id: <199602271922.UAA07342@gilberto.physik.rwth-aachen.de> To: freebsd-hackers@freefall.FreeBSD.org Subject: Re: help needed in recovering a disk Sender: owner-hackers@FreeBSD.ORG Precedence: bulk Here is the program to scan the disk: Originally I used 512 byte reads to scan for disklabel. I had to change it to 2048 ti read in a whole struct fs. ======= disk.c====== #include #include #include #include #include #define DKTYPENAMES #include #include /* */ #define DISKMAGIC ((u_long) 0x82564557) /* The disk magic number */ main(argc,argv) int argc; char **argv; { int i; char *dev; struct fs *f; struct disklabel *dl; struct stat sb; off_t lseek(); off_t block=0; char buf[2048]; off_t end; u_long *l; off_t offset = (off_t) 0; off_t newoffset; int fd, vd, n; if(argc==2) dev=argv[1]; else dev="/dev/rwd0"; printf("sizeof struct fs=%d\n",sizeof(struct fs)); l = (u_long *) buf; f = (struct fs *) buf; dl = (struct disklabel *) buf; if ((fd = open(dev, O_RDONLY, 0)) == -1) fprintf(stderr,"error opening %s\n",dev),exit(1); while(read(fd, buf, 2048)>0) { block+=2048; printf("\r%qd",block);fflush(stdout); if (*l == DISKMAGIC) { printf("\ndisklabel found at offset %qd (%qd MB/%qd)\n", block-2048, (block-2048)/ (off_t) (1024), (block-2048) / 2048); printf("d_type=%d\n%s\nd_npartitions=%d\n", dl->d_type, dl->d_typename, dl->d_npartitions); for (i = 0; i < dl->d_npartitions; i++) { printf("\t%d\t%d\t%d\t%s\n", dl->d_partitions[i].p_size, dl->d_partitions[i].p_offset, dl->d_partitions[i].p_fsize, fstypenames[dl->d_partitions[i].p_fstype]); } } if(f->fs_magic == FS_MAGIC ) printf("\nfs at block # %qd last mounted on %s f->fs_ncyl=%ld\n",(block-2048)/512, f->fs_fsmnt,f->fs_ncyl); } } --Chris Christoph P. U. Kukulies kuku@gil.physik.rwth-aachen.de