From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: fs corruption recovery?
Date: 8 Jan 2002 21:20:31 -0800 [thread overview]
Message-ID: <a1gjuv$eak$1@cesium.transmeta.com> (raw)
In-Reply-To: <3C3BB082.8020204@fit.edu> <20020108200705.S769@lynx.adilger.int> <3C3BC0FC.30403@fit.edu>
Followup to: <3C3BC0FC.30403@fit.edu>
By author: Kervin Pierre <kpierre@fit.edu>
In newsgroup: linux.dev.kernel
>
> Thanks for the reply,
>
> >Try "e2fsck -B 4096 -b 32768 <device>" instead.
> >
>
> e2fsck -B 4096 -b 32768 /dev/hdc1
>
> e2fsck 1.25 (20-Sep-2001)
> e2fsck: Attempt to read block from filesystem resulted in short read
> while trying to open /dev/hdc1
> Could this be a zero-length partition?
>
> Does ext keep a backup of that backup? :)
>
> Are there any other options?
>
You have bad media. You need to read the disk sector by sector, save
it elsewhere, write it to another drive, and then try to fsck it --
HOWEVER, DON'T FSCK THE ORIGINAL. Fsck can actually cause serious
damage if it guesses wrong.
The following is a small C program that I just threw together to read
sector by sector and dump the data on stdout. No guarantees
whatsoever:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#define SECTORSIZE 512
int read_sector(int fd, void *buf)
{
char *p = buf;
int bytes = SECTORSIZE;
int rv;
while ( bytes ) {
if ( (rv = read(fd, p, bytes)) <= 0 ) {
if ( rv < 0 || errno == EINTR )
continue; /* Happens... */
return 0; /* Error */
}
p += rv;
bytes -= rv;
}
return 1; /* Success */
}
int main(int argc, char *argv[])
{
unsigned long long count;
unsigned long long n;
int fd;
char buffer[SECTORSIZE];
if ( argc != 3 ) {
fprintf(stderr, "Usage: %s device sectors\n", argv[0]);
exit(1);
}
count = strtoull(argv[2], NULL, 0);
fd = open(argv[1], O_RDONLY);
if ( fd < 0 ) {
perror(argv[1]);
exit(1);
}
n = 0;
while ( count-- ) {
if ( !read_sector(fd, buffer) ) {
fprintf(stderr, "Sector %llu: %s\n", n, strerror(errno));
memset(buffer, 0, SECTORSIZE);
}
if ( fwrite(buffer, 1, SECTORSIZE, stdout) != SECTORSIZE ) {
fprintf(stderr, "Sector %llu: output error: %s\n", n, strerror(errno));
exit(1);
}
n++;
}
return 0;
}
-hpa
--
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt <amsp@zytor.com>
next prev parent reply other threads:[~2002-01-09 5:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-09 2:52 fs corruption recovery? Kervin Pierre
2002-01-09 3:07 ` Andreas Dilger
2002-01-09 3:26 ` Richard Gooch
2002-01-09 4:14 ` Kervin Pierre
2002-01-09 5:29 ` Richard Gooch
2002-01-09 11:10 ` Walter Hofmann
2002-01-10 15:50 ` Ralf Baechle
2002-01-09 10:24 ` Helge Hafting
2002-01-09 15:12 ` Richard Gooch
2002-01-09 15:22 ` Roy Sigurd Karlsbakk
2002-01-09 12:26 ` Bjorn Wesen
2002-01-09 20:29 ` Alex Bligh - linux-kernel
2002-01-09 4:03 ` Kervin Pierre
2002-01-09 5:20 ` H. Peter Anvin [this message]
2002-01-09 9:28 ` Thomas Capricelli
2002-01-09 10:43 ` Andreas Dilger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='a1gjuv$eak$1@cesium.transmeta.com' \
--to=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox