424,303 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,303 IT Pros & Developers. It's quick & easy.

using c how to read the boot sctor of floppy disk

P: 2
how to read the boot sector of a floppy disk
Dec 31 '18 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 983
Untested code found by Googling for "c code read boot sector":

source: https://stackoverflow.com/questions/...-c-on-windows8
Expand|Select|Wrap|Line Numbers
  1. int lire_secteur(int num_sect,unsigned char* buf)
  2. {
  3. int retCode = 0;
  4. unsigned char secteur[512];
  5. char disque[10]   ;
  6. char partition ;
  7. FILE* device ;
  8. do
  9. {
  10.     disque[0]='\0'  ;       
  11.     scanf("%c",&partition) ;
  12.     if (partition=='0')
  13.     {
  14.         strcpy(disque,"\\\\.\\PHYSICALDRIVE0") ;
  15.     }
  16.     else
  17.     {
  18.         sprintf(disque,"\\\\.\\%c:",partition) ;
  19.     }
  20.     device = fopen(disque, "rb+");
  21. }
  22.  
  23. while (device == NULL) ;
  24. fseek( device,num_sect*512 , SEEK_SET );
  25. if (fread (secteur, 512,1, device) < 1)
  26. {
  27.     printf("erreur\n");
  28.     return 1 ;
  29. }
  30. else
  31. {
  32.     memcpy(buf,secteur, 512);
  33.     retCode=0;
  34. }
  35. return retCode;
  36. }
Dec 31 '18 #2

Expert 100+
P: 983
But 'floppy disk', what's that? 😒😒
It's almost 2019 😊😊

And floppies are soo 1980's.... 😉
Dec 31 '18 #3

P: 2
That's as maybe. But i find them very handy for storing specific data and programs. Also they are a totally secure way of passing information (by post) to like minded people.

Thank you for your solution - I look forward to trying it.

Best wihes, dks
Dec 31 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.