(fwd) Re: disklabel

Andrey Gerzhov (kittle@freeland.alex-ua.com)
Sat, 11 Sep 1999 02:10:42 +0300 (EEST)

-- forwarded message --
Path: freeland.alex-ua.com!routki.ki.yurteh.net!carrier.kiev.ua!srcc!Gamma.RU!ddt.demos.su!not-for-mail
From: nospam.vadim@tversu.ru (Vadim Kolontsov)
Newsgroups: fido7.ru.unix.bsd
Subject: Re: disklabel
Date: 9 Sep 1999 17:06:35 +0400
Organization: Tver State University NOC
Lines: 128
Sender: fido7@ddt.demos.su
Approved: <gateway@fido7.ru>
Message-ID: <slrn7tfbuu.hsc.nospam.vadim@gala.tversu.ru>
References: <87iu5ojjyk.fsf@neva.vlink.ru> <87aeqwz8d8.fsf@shuttle.svib.ru>
Reply-To: nospam.vadim@tversu.ru
NNTP-Posting-Host: ddt.demos.su
Mime-Version: 1.0
Content-Type: text/plain; charset=KOI8-r
Content-Transfer-Encoding: 8bit
X-Trace: ddt.demos.su 936882397 18759 194.87.13.37 (9 Sep 1999 13:06:37 GMT)
X-Complaints-To: gatekeeper@fido7.ru
NNTP-Posting-Date: 9 Sep 1999 13:06:37 GMT
X-BeforeModerator-Path: nospam.vadim
X-Comment-To: Alex Polovotsky
User-Agent: slrn/0.9.5.6 (UNIX)
X-BeforeModerator-NNTP-Posting-Host: gala.tversu.ru
X-Original-NNTP-Posting-Host: gala.tversu.ru
X-BeforeModerator-X-Trace: 9 Sep 1999 17:02:19 +0300, gala.tversu.ru
Xref: freeland.alex-ua.com fido7.ru.unix.bsd:12542

In article <87aeqwz8d8.fsf@shuttle.svib.ru>, Alex Povolotsky wrote:
>Denis> From: Denis Shaposhnikov <dsh@neva.vlink.ru> FreeBSD 3.2, пропал
>Denis> сабж. Hи одного слайса не видно. Можно ли вытащить данные?
>Держи программу. Это наколенный хак, в работе требует головы и calc'а, но
>мне disklabel вытащил.

аналогичная программка от Niall Smart ниже. Главное отличие в том, что
пытается посоветовать disklabel entries сама. Пример работы и полное
письмо автора можно найти на

http://www.freebsd.org/cgi/getmsg.cgi?fetch=51795+58713+/usr/local/www
/db/text/1999/freebsd-hackers/19990627.freebsd-hackers

(URL одной строкой)

/*
* Copyright (c) 1999 Niall Smart. 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 Niall Smart,niall@pobox.com.
*
* THIS SOFTWARE IS PROVIDED BY NIALL SMART ``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 NIALL SMART 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 <ufs/ffs/fs.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>

int
main(int argc, char** argv)
{
int fd;
int ret;
off_t offset;
u_quad_t skip;
char* ptr;
char buf[SBSIZE];
struct fs* fs = (struct fs*)buf;

if (argc != 3) {
fprintf(stderr, "usage: %s device skip\n", argv[0]);
exit(1);
}

if ( (fd = open(argv[1], O_RDONLY)) < 0) {
perror("open");
exit(1);
}

if ( (skip = strtouq(argv[2], &ptr, 0)) == QUAD_MAX || *ptr != '\0') {
fprintf(stderr, "bad seek value: %s\n", argv[2]);
exit(1);
}

if ( (skip % SBOFF) != 0)
fprintf(stderr,
"warning: %qu is not a multiple of SBOFF (%d)\n", skip, (int)SBOFF);;

if (skip > 0) {
fprintf(stderr, "skipping %qu bytes\n", skip);
lseek(fd, skip, SEEK_SET);
}

while (1) {

ret = read(fd, buf, sizeof(buf));

if (ret < 0) {
perror("read");
exit(1);
}

/*
* based on checks in /sys/ufs/ffs/ffs_vfsops.c, line 478
*/

if (fs->fs_magic == FS_MAGIC &&
fs->fs_bsize <= MAXBSIZE &&
fs->fs_bsize >= (int32_t)sizeof(struct fs)) {

offset = lseek(fd, 0, SEEK_CUR);

printf("found superblock: offset=%qd, fs_size=%d, "
fs_fsmnt=%.*s\n", offset, fs->fs_size,
MAXMNTLEN, fs->fs_fsmnt);

printf("suggested disklabel entry:\n\n");
printf(" size offset fstype\n");
printf("%8d %8qd 4.2BSD\n\n", fs->fs_size * 2,
(offset - 16384) / 512);

}

}

printf("%d:%d\n", sizeof(struct fs), offsetof(struct fs, fs_magic));

return 0;
}

V.
-- end of forwarded message --

-- 
С тем, что не помешает никогда,
                                               Kittle