home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / logdr_st.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  5.0 KB  |  127 lines

  1. /* 
  2.     FIPS - the First nondestructive Interactive Partition Splitting program 
  3.  
  4.     Module logdr_st.cpp 
  5.  
  6.     RCS - Header: 
  7.     $Header: c:/daten/fips/source/main/RCS/logdr_str.cpp 1.1 1994/05/25 22:20:01 schaefer Exp schaefer $ 
  8.  
  9.     Copyright (C) 1993 Arno Schaefer 
  10.  
  11.     This program is free software; you can redistribute it and/or modify 
  12.     it under the terms of the GNU General Public License as published by 
  13.     the Free Software Foundation; either version 2 of the License, or 
  14.     (at your option) any later version. 
  15.  
  16.     This program is distributed in the hope that it will be useful, 
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  19.     GNU General Public License for more details. 
  20.  
  21.     You should have received a copy of the GNU General Public License 
  22.     along with this program; if not, write to the Free Software 
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  24.  
  25.  
  26.     Report problems and direct all questions to: 
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de 
  29. */ 
  30.  
  31. #include <string.h> 
  32. #include "types.h" 
  33. #include "logdr_st.h" 
  34.  
  35. /* ----------------------------------------------------------------------- */ 
  36. /* Extract Bios Parameter Block from bootsector                            */ 
  37. /* ----------------------------------------------------------------------- */ 
  38.  
  39. void bios_parameter_block::get (bootsector *bootsector) 
  40.     byte *bp = bootsector->data; 
  41.  
  42.     memcpy (jump_instruction,bp,3); 
  43.     memcpy (oem_name,bp+3,8); 
  44.     oem_name[8]=0; 
  45.     bytes_per_sector = *(bp+0xb) | (*(bp+0xc) << 8); 
  46.     sectors_per_cluster = *(bp+0xd); 
  47.     reserved_sectors = *(bp+0xe) | (*(bp+0xf) << 8); 
  48.     no_of_fats = *(bp+0x10); 
  49.     no_of_rootdir_entries = *(bp+0x11) | (*(bp+0x12) << 8); 
  50.     no_of_sectors = *(bp+0x13) | (*(bp+0x14) << 8); 
  51.     media_descriptor = *(bp+0x15); 
  52.     sectors_per_fat = *(bp+0x16) | (*(bp+0x17) << 8); 
  53.     sectors_per_track = *(bp+0x18) | (*(bp+0x19) << 8); 
  54.     drive_heads = *(bp+0x1a) | (*(bp+0x1b) << 8); 
  55.     hidden_sectors = (dword) *(bp+0x1c) | ((dword) *(bp+0x1d) << 8) | ((dword) *(bp+0x1e) << 16) | ((dword) *(bp+0x1f) << 24); 
  56.     no_of_sectors_long = (dword) *(bp+0x20) | ((dword) *(bp+0x21) << 8) | ((dword) *(bp+0x22) << 16) | ((dword) *(bp+0x23) << 24); 
  57.     phys_drive_no = *(bp+0x24); 
  58.     signature = *(bp+0x26); 
  59.     serial_number = (dword) *(bp+0x27) | ((dword) *(bp+0x28) << 8) | ((dword) *(bp+0x29) << 16) | ((dword) *(bp+0x2a) << 24); 
  60.     memcpy (volume_label,bp+0x2b,11); 
  61.     volume_label[11] = 0; 
  62.     memcpy (file_system_id,bp+0x36,8); 
  63.     file_system_id[8] = 0; 
  64.  
  65. /* ----------------------------------------------------------------------- */ 
  66. /* Write Bios Parameter Block back into bootsector                         */ 
  67. /* ----------------------------------------------------------------------- */ 
  68.  
  69. void bios_parameter_block::put (bootsector *bootsector) 
  70.     byte *bp = bootsector->data; 
  71.  
  72.     memcpy (bp,jump_instruction,3); 
  73.     memcpy (bp+3,oem_name,8); 
  74.     *(bp+0xb) = bytes_per_sector & 0xff; 
  75.     *(bp+0xc) = (bytes_per_sector >> 8) & 0xff; 
  76.     *(bp+0xd) = sectors_per_cluster; 
  77.     *(bp+0xe) = reserved_sectors & 0xff; 
  78.     *(bp+0xf) = (reserved_sectors >> 8) & 0xff; 
  79.     *(bp+0x10) = no_of_fats; 
  80.     *(bp+0x11) = no_of_rootdir_entries & 0xff; 
  81.     *(bp+0x12) = (no_of_rootdir_entries >> 8) & 0xff; 
  82.     *(bp+0x13) = no_of_sectors & 0xff; 
  83.     *(bp+0x14) = (no_of_sectors >> 8) & 0xff; 
  84.     *(bp+0x15) = media_descriptor; 
  85.     *(bp+0x16) = sectors_per_fat & 0xff; 
  86.     *(bp+0x17) = (sectors_per_fat >> 8) & 0xff; 
  87.     *(bp+0x18) = sectors_per_track & 0xff; 
  88.     *(bp+0x19) = (sectors_per_track >> 8) & 0xff; 
  89.     *(bp+0x1a) = drive_heads & 0xff; 
  90.     *(bp+0x1b) = (drive_heads >> 8) & 0xff; 
  91.     *(bp+0x1c) = hidden_sectors & 0xff; 
  92.     *(bp+0x1d) = (hidden_sectors >> 8) & 0xff; 
  93.     *(bp+0x1e) = (hidden_sectors >> 16) & 0xff; 
  94.     *(bp+0x1f) = (hidden_sectors >> 24) & 0xff; 
  95.     *(bp+0x20) = no_of_sectors_long & 0xff; 
  96.     *(bp+0x21) = (no_of_sectors_long >> 8) & 0xff; 
  97.     *(bp+0x22) = (no_of_sectors_long >> 16) & 0xff; 
  98.     *(bp+0x23) = (no_of_sectors_long >> 24) & 0xff; 
  99.     *(bp+0x24) = phys_drive_no; 
  100.     *(bp+0x26) = signature; 
  101.     *(bp+0x27) = serial_number & 0xff; 
  102.     *(bp+0x28) = (serial_number >> 8) & 0xff; 
  103.     *(bp+0x29) = (serial_number >> 16) & 0xff; 
  104.     *(bp+0x2a) = (serial_number >> 24) & 0xff; 
  105.     memcpy (bp+0x2b,volume_label,11); 
  106.     memcpy (bp+0x36,file_system_id,8); 
  107.  
  108. /* ----------------------------------------------------------------------- */ 
  109. /* Extract some misc. drive parameters from BPB                            */ 
  110. /* ----------------------------------------------------------------------- */ 
  111.  
  112. void logical_drive_info::get (const bios_parameter_block &bpb) 
  113.     start_fat1 = bpb.reserved_sectors; 
  114.     start_fat2 = start_fat1 + bpb.sectors_per_fat; 
  115.     start_rootdir = start_fat2 + bpb.sectors_per_fat; 
  116.     if (bpb.no_of_rootdir_entries == 0) start_data = start_rootdir; 
  117.     else start_data = start_rootdir + (bpb.no_of_rootdir_entries - 1) / 16 + 1; 
  118.     if (bpb.sectors_per_cluster == 0) no_of_clusters = 0; 
  119.     else no_of_clusters = ((bpb.no_of_sectors ? bpb.no_of_sectors : bpb.no_of_sectors_long) - start_data) / bpb.sectors_per_cluster; 
  120. }; 
  121.  
  122.