Does anyone know how bad sectors are marked in FAT32 file system? I remember I learned how to do that in old DOS days, but I forgot it, and I cannot find the relevant information on the net.

My problem is: I have several bad sectors on my hard drive. I know the exact position from the start of the disk. But, scandisk cannot detect them. I want to mark them manually and also want to mark it as something not moveable by defrag.exe.

MS description of FAT32 does not seem to contain the relevant information. (I think the old day trick was to mark the cluster in FAT, but I may be incorrect.)

Any information is appreciated.
Posted on 2003-12-26 22:13:12 by Starless
Hi starless
You DON?T get bad sectors from an IDE drive (I'm asumming you had an IDE drive)
thats because the drive had *spare * sector on the disks to substitute as some sectors bacame damaged, this substitution is transparent (Oculted) to the OS, If you start geting *bad sectors* it means that the drive is runing out of spare sectors, and it *must be replaces ASAP* or you will get in trouble (i.e. Lost data), buy a new (bigger) Drive and sleep well knowing that your data is safe


Saludos from Mexico

Carlos
Posted on 2003-12-30 20:19:20 by Carlos
Don't you have to mark the whole cluster bad? I think it's just a code in both FATS. Meaning be sure to mark both. How will you mark them? Debug.exe?
Posted on 2003-12-30 21:56:01 by mrgone
I was about to give up and you guys finally replied! :) Now that I have responses, I'll describe it a bit further.

Yes, the problem machine runs win98 with single IDE drive. It has been 3 years since I bought it. And, it was OK until recently it began giving me the problem. At this point, I'm half-convinced by Carlos' explanation. What I don't understand is; I thought Carlos' description only applied to the 'factory' bad sectors. But, your explanation seems to suggest that some wear-and-tear bad sectors can be remapped. Anyhow, the machine is a notebook, and it is not easy to replace the hard disk. :(

I found the mark (== -9) in MS document after re-reading it. But, the next problem is what mrgone pointed out. I was thinking more like using dd(1) with my multipurpose OpenBSD boot floppy. First, copy the sector, then hex-edit the file, and finally copy the file to the original position. It seems to me that Win32 API does not support such an operation. If it does, can anyone give me a pointer?
Posted on 2003-12-31 04:02:18 by Starless
Dunno if there's a win32 API thingy to map bad sectors (use NTFS anyway), but you can use CreateFile with \\.\PHYSICALDRIVE or \\.\x: parameters to edit your disks... or some VXD or thunk shit on 9x.
Posted on 2003-12-31 12:30:44 by f0dder
But you can write it back to the hard disk in 98. Just use Debug.exe. The commands are:
l 100 2 "sector no." "no. sectors"

and

w (same parameters)

It's been a while and I'm on NTFS and have not studied that filing system. But there is good documentation for locating sectors and clusters on the internet. I think what Carlos was talking about is on IDE drives you need to turn off the look ahead cache before you attent to format. Otherwize it will appear as if you are formatting but when you are done, nothing will have happened.
Posted on 2003-12-31 22:47:06 by mrgone
The docs on NTFS says it automatically handles remapping bad clusters - haven't really verified it though, I don't like bad disks :)
Posted on 2004-01-01 01:13:13 by f0dder
Hi Fodder,

I had a 60GB drive running NTFS5.1 (XP) that failed. It showed no problems until the defragger started acting flaky. Shortly after that, the driver reported (in the event log) that the drive would fail soon. I replaced it pronto. I still have the drive and most of the data on it is recoverable. I believe that this would be expected behavior from NTFS journalling system automatically remapping bad spots on the drive until it couldn't remap them any more.

Charles
Posted on 2004-01-03 01:05:23 by cdquarles
mmh, perhaps.

Annoying thing is that when drives start failing today, it usually ends up with major head crash or burnt out circuitry (some of the quantum fireball disks have problems with controller chips - literally - melting). It's hard for an OS to stay failsafe if this happens :P

I wonder how windows would handle the situation when the controller dies - obviously it's hard to do much but die if system/pagefile disks die, even linux doesn't exactly handle this gracefully ;)
Posted on 2004-01-03 13:34:47 by f0dder
Hi Fodder,

I remember that the IDE controller driver reported to windows (probably via a special API) that writing to the drive wasn't reliable (probably via the change journal). When the spare sector supply dropped below a threshold (remember, this is my opinion from the behavior of my system) the event log contained messages that the drive was going to fail (and it was making grinding noises). I yanked it before it failed so that I could salvage data if necessary.

Windows would crash without a doubt if when the IDE controller dies. The only times any NT based system BSOD on me was hardware trouble (power supply, drives, fans, bad ram).

Charles
Posted on 2004-01-11 18:21:53 by cdquarles
Humm, I guess the IDE drive can report some of that stuff via S.M.A.R.T
Posted on 2004-01-11 18:42:45 by f0dder
Hi Fodder,

That sounds right to me. I have added that to my Google hunt to do list.

Charles
Posted on 2004-01-11 19:09:41 by cdquarles
Yeah you can use debug.exe in Win98 to edit the FAT.

L 100 2 0 1 command gives boot sector. That's at offset I believe 13h or 14h which will be after F8h media descriptor gives the size of each FAT. You can test this by multiplying the size word by two and adding 1 for boot sector than use same command except L 100 2 (2xFAT+1) (no. of sectors to read) to read your directory.
So The first FAT is at: L 100 2 1 1 for 1st sector of first FAT. You can edit and write back like this:
W 100 2 1 1 Be careful!!!! :)
Posted on 2004-01-15 18:33:28 by mrgone
Hi f0dder,

I am back from my Google hunt. S.M.A.R.T., which has been around for a number of years (ATA3 iirc), can do what I posted if: 1. the BIOS supports it and the motherboard implements the connections, 2. The OS supports it, and 3. The drive controller is modern and the manufacturer supplies the appropriate drivers. This should be true of any system built in the last two or three years and you are running Windows XP. I am not sure of the status of Linux support for this.

Charles
Posted on 2004-01-17 10:23:44 by cdquarles