How does bad sector reallocation work?

Hello,

I would like to know briefly how the process of reallocating bad sectors works.

Does an hard drive identify (and reallocate) bad sectors directly during write operations, or is a previous read operation required to determine that the sector is bad?

Does it happen like this:
Read operation > if the sector is bad it is marked as “pending” (in SMART) > the next time the pending sector is written, it gets reallocated.

I was curious to know what happens when data is written to unused space: if a sector is bad, should data get reallocated at once, or will the hard drive not recognize the bad sector, and thus the written data will be corrupt?

Thanks.

Hello, as far as I know sectors only get relocated when a write operation fails, most of the time a read operation will only give a I/O Error. If the data is to be written in a bad sector, the sector should be reallocated, however as you mentioned if a sector with data gets damaged the information will be corrupted.