On 2022-11-08, Laurence Perkins <lperk...@openeye.net> wrote:
>>>
>>>> What happens when the bad block is _already_allocated_ to a file?
>>
>>> [...]
>>
>>Thanks. I guess I should have been more specific in my question.
>>
>>What does e2fsck -c do to the filesystem structure when it discovers
>>a bad block that is already allocated to an existing inode?
>>
>>Is the inode's chain of block groups left as is -- still containing
>>the bad block that (according to the man page) "has been added to
>>the bad block inode"?  Presumably not, since a block can't be
>>allocated to two different inodes.
>>
>>Is the "broken" file split into two chunks (before/after the bad
>>block) and moved to the lost-and-found?
>>
>>Is the man page's description only correct when the bad block is
>>currently unallocated?
>
> If I recall correctly, it will add any unreadable blocks to its
> internal list of bad sectors, which it will then refuse to allocate
> in the future.

I'm asking what happens to the file containing the bad block. Perphaps
nothing. The man page says the block is added to the "bad block
inode". If that block was already allocated, is the bad block is now
allocated to two different inodes?

> I don't believe it will attempt to move the file to elsewhere until
> it is written since:
>
> A)  what would you then put in that block? You don't know the contents.

You wouldn't put anything in that block.

One solution that comes to mind would be to truncate the file
immediately before the bad block (we'll call that truncated file the
"head"). Then you allocate a new inode to which you assign all of the
blocks after the bad block (we'll call that the "tail"). The bad block
is then moved to the "bad blocks inode" and the head/tail files are
moved into the lost+found.

> B) Moving the file around would make attempts to recover the data
>    from that bad sector significantly more difficult.

Yes, probably. Any manipulation of a filesystem (like adding the block
to the bad block inode) on a failing disk seems like a bad idea.

--
Grant





Reply via email to