Gentoo Archives: gentoo-user

From: Grant Edwards <grant.b.edwards@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file?
Date: Wed, 09 Nov 2022 23:31:49
Message-Id: tkhd8l$4oa$1@ciao.gmane.io
In Reply to: RE: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file? by Laurence Perkins
1 On 2022-11-08, Laurence Perkins <lperkins@×××××××.net> wrote:
2 >>>
3 >>>> What happens when the bad block is _already_allocated_ to a file?
4 >>
5 >>> [...]
6 >>
7 >>Thanks. I guess I should have been more specific in my question.
8 >>
9 >>What does e2fsck -c do to the filesystem structure when it discovers
10 >>a bad block that is already allocated to an existing inode?
11 >>
12 >>Is the inode's chain of block groups left as is -- still containing
13 >>the bad block that (according to the man page) "has been added to
14 >>the bad block inode"? Presumably not, since a block can't be
15 >>allocated to two different inodes.
16 >>
17 >>Is the "broken" file split into two chunks (before/after the bad
18 >>block) and moved to the lost-and-found?
19 >>
20 >>Is the man page's description only correct when the bad block is
21 >>currently unallocated?
22 >
23 > If I recall correctly, it will add any unreadable blocks to its
24 > internal list of bad sectors, which it will then refuse to allocate
25 > in the future.
26
27 I'm asking what happens to the file containing the bad block. Perphaps
28 nothing. The man page says the block is added to the "bad block
29 inode". If that block was already allocated, is the bad block is now
30 allocated to two different inodes?
31
32 > I don't believe it will attempt to move the file to elsewhere until
33 > it is written since:
34 >
35 > A) what would you then put in that block? You don't know the contents.
36
37 You wouldn't put anything in that block.
38
39 One solution that comes to mind would be to truncate the file
40 immediately before the bad block (we'll call that truncated file the
41 "head"). Then you allocate a new inode to which you assign all of the
42 blocks after the bad block (we'll call that the "tail"). The bad block
43 is then moved to the "bad blocks inode" and the head/tail files are
44 moved into the lost+found.
45
46 > B) Moving the file around would make attempts to recover the data
47 > from that bad sector significantly more difficult.
48
49 Yes, probably. Any manipulation of a filesystem (like adding the block
50 to the bad block inode) on a failing disk seems like a bad idea.
51
52 --
53 Grant

Replies

Subject Author
Re: [gentoo-user] Re: e2fsck -c when bad blocks are in existing file? Wol <antlists@××××××××××××.uk>