Guest User

Lba to CHS

a guest
Sep 12th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4.  
  5. int main (int argc, char** argv) {
  6.  
  7.    
  8.     int LBA, S , H; //LBA, Sectors on track, Heads count
  9.    
  10.     //verefy for valid block
  11.    
  12.     //
  13.     LBA = atoll ( argv [1] );
  14.       S = atoi ( argv[2] );
  15.       H = atoi ( argv [3] );
  16.    
  17.  
  18.     printf ( "\n LBA = %lld, Sectors = %d, Headers = %d\n", LBA, S, H );
  19.  
  20.     int sec_num = ( LBA % S ) + 1 ;
  21.  
  22.     int num_head = ( ( LBA - ( sec_num - 1 ) ) / S ) % H ;
  23.  
  24.     int c_num = ( LBA - ( s - 1 ) - h * S ) / ( H * S ) ;  
  25.    
  26.     printf ("\ncyl = %d, num_head = %d, sec_num = %d\n", c_num, num_head, sec_num);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment