We help IT Professionals succeed at work.

Code to make bad sector

skanade
skanade asked
on
I found the following code for a DOS program that marks a sector bad on a floppy.

Questions:
1) It only works first time. Later, one has to reboot the system for a second floppy. Why?

2) Can there be an equivalent Windows code from win32? I don't mind if it only works on Win9X.

#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <conio.h>

int main (void)
{
     char buffer[512];
     int x;

     for (x = 0; x < 18; x++)
     {
          buffer[x * 4 + 0] = 40;
          buffer[x * 4 + 1] = 0;
          buffer[x * 4 + 2] = x + 1;
          buffer[x * 4 + 3] = 2;
     }
     buffer[0] = 0xFF;
     buffer[1] = 0xFF;
     buffer[2] = 0xFF;
     buffer[3] = 0xFF;
     buffer[4] = 0xFF;
     buffer[5] = 0xFF;
     buffer[6] = 0xFF;
     buffer[7] = 0xFF;

     printf ("Insert a formatted disk. Press a key to continue...");
     getch();
     printf ("\n");
     biosdisk (_DISK_RESET, 0, 0, 41, 1, 1, NULL);
     biosdisk (_DISK_RESET, 0, 0, 41, 1, 1, NULL);
     biosdisk (_DISK_RESET, 0, 0, 41, 1, 1, NULL);

     if (biosdisk (_DISK_FORMAT, 0, 0, 40, 1, 1, buffer) != 0)
          printf ("Format error.\n");

     printf ("Remove the disk, and re-insert it. Press a key to continue...");
     getch();
     printf ("\n");

     if (absread (0, 1, 1440, buffer) == -1)
          printf ("OK. Sector is bad.\n");
     else
          printf ("Sorry... the Sector was read.\n");

     return 0;
}
Comment
Watch Question

Commented:
listening..

Commented:
Make it more clear:

One can read/write a floppy sectors from Win32,
but to change a sector size can be done only from DOS.

It is usually done only for copy protection.
It is also possible to hide your code in this sector
of different size and inject it into your program.

Author

Commented:
I want to use it for copy protection only. Can you
see why a reboot is required for marking the next
floppy? Thanks.
Commented:
Hi skanade,

Quote:
------------------------------------------
if (absread (0, 1, 1440, buffer) == -1)
printf ("OK. Sector is bad.\n");
------------------------------------------

You are trying to read bad sector which leaves
your drive unstable.

Try to reset it again.

BTW You asking the user:
Insert a formatted disk. Press a key to continue...");
and then you reformat whole floppy again.
Wouldn't be much easier just to format one track
and mark it as bad.
Or just change a first byte in FAT to 0x0FF.

Regards forge1
Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20197490.html
http://www.experts-exchange.com/questions/Q.20267396.html


PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

Commented:
No more discusion, no more comment,
nothing to say.

forge

Author

Commented:
"3. Ask Community Support to help split points between participating experts, or just comment here with
details and we'll respond with the process."

I would prefer to do that.

Thanks,
Sanjay

Commented:
What ever you do I'm happy.

Thanks
forge
Thank you, I have finalized this for you.  This is being awarded to the one Expert who provided you the guidance, the other expert was only "listening".

Item completed.

Moondancer - EE Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.