home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / install / fips / source / logdr_st.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-25  |  5.1 KB  |  127 lines

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module logdr_st.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/logdr_str.cpp 1.4 1995/01/19 00:00:54 schaefer Exp schaefer $
  14.  
  15.  
  16.  
  17.     Copyright (C) 1993 Arno Schaefer
  18.  
  19.  
  20.  
  21.     This program is free software; you can redistribute it and/or modify
  22.  
  23.     it under the terms of the GNU General Public License as published by
  24.  
  25.     the Free Software Foundation; either version 2 of the License, or
  26.  
  27.     (at your option) any later version.
  28.  
  29.  
  30.  
  31.     This program is distributed in the hope that it will be useful,
  32.  
  33.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.  
  35.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  
  37.     GNU General Public License for more details.
  38.  
  39.  
  40.  
  41.     You should have received a copy of the GNU General Public License
  42.  
  43.     along with this program; if not, write to the Free Software
  44.  
  45.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     Report problems and direct all questions to:
  52.  
  53.  
  54.  
  55.     schaefer@rbg.informatik.th-darmstadt.de
  56.  
  57. */
  58.  
  59.  
  60.  
  61. #include <string.h>
  62.  
  63. #include "types.h"
  64.  
  65. #include "logdr_st.h"
  66.  
  67.  
  68.  
  69. /* ----------------------------------------------------------------------- */
  70.  
  71. /* Extract Bios Parameter Block from boot sector                           */
  72.  
  73. /* ----------------------------------------------------------------------- */
  74.  
  75.  
  76.  
  77. void bios_parameter_block::get (boot_sector *boot_sector)
  78.  
  79. {
  80.  
  81.     byte *bp = boot_sector->data;
  82.  
  83.  
  84.  
  85.     memcpy (jump_instruction,bp,3);
  86.  
  87.     memcpy (oem_name,bp+3,8);
  88.  
  89.     oem_name[8]=0;
  90.  
  91.     bytes_per_sector = *(bp+0xb) | (*(bp+0xc) << 8);
  92.  
  93.     sectors_per_cluster = *(bp+0xd);
  94.  
  95.     reserved_sectors = *(bp+0xe) | (*(bp+0xf) << 8);
  96.  
  97.     no_of_fats = *(bp+0x10);
  98.  
  99.     no_of_rootdir_entries = *(bp+0x11) | (*(bp+0x12) << 8);
  100.  
  101.     no_of_sectors = *(bp+0x13) | (*(bp+0x14) << 8);
  102.  
  103.     media_descriptor = *(bp+0x15);
  104.  
  105.     sectors_per_fat = *(bp+0x16) | (*(bp+0x17) << 8);
  106.  
  107.     sectors_per_track = *(bp+0x18) | (*(bp+0x19) << 8);
  108.  
  109.     drive_heads = *(bp+0x1a) | (*(bp+0x1b) << 8);
  110.  
  111.     hidden_sectors = (dword) *(bp+0x1c) | ((dword) *(bp+0x1d) << 8) | ((dword) *(bp+0x1e) << 16) | ((dword) *(bp+0x1f) << 24);
  112.  
  113.     no_of_sectors_long = (dword) *(bp+0x20) | ((dword) *(bp+0x21) << 8) | ((dword) *(bp+0x22) << 16) | ((dword) *(bp+0x23) << 24);
  114.  
  115.     phys_drive_no = *(bp+0x24);
  116.  
  117.     signature = *(bp+0x26);
  118.  
  119.     serial_number = (dword) *(bp+0x27) | ((dword) *(bp+0x28) << 8) | ((dword) *(bp+0x29) << 16) | ((dword) *(bp+0x2a) << 24);
  120.  
  121.     memcpy (volume_label,bp+0x2b,11);
  122.  
  123.     volume_label[11] = 0;
  124.  
  125.     memcpy (file_system_id,bp+0x36,8);
  126.  
  127.     file_system_id[8] = 0;
  128.  
  129. }
  130.  
  131.  
  132.  
  133. /* ----------------------------------------------------------------------- */
  134.  
  135. /* Write Bios Parameter Block back into boot sector                        */
  136.  
  137. /* ----------------------------------------------------------------------- */
  138.  
  139.  
  140.  
  141. void bios_parameter_block::put (boot_sector *boot_sector)
  142.  
  143. {
  144.  
  145.     byte *bp = boot_sector->data;
  146.  
  147.  
  148.  
  149.     memcpy (bp,jump_instruction,3);
  150.  
  151.     memcpy (bp+3,oem_name,8);
  152.  
  153.     *(bp+0xb) = bytes_per_sector & 0xff;
  154.  
  155.     *(bp+0xc) = (bytes_per_sector >> 8) & 0xff;
  156.  
  157.     *(bp+0xd) = sectors_per_cluster;
  158.  
  159.     *(bp+0xe) = reserved_sectors & 0xff;
  160.  
  161.     *(bp+0xf) = (reserved_sectors >> 8) & 0xff;
  162.  
  163.     *(bp+0x10) = no_of_fats;
  164.  
  165.     *(bp+0x11) = no_of_rootdir_entries & 0xff;
  166.  
  167.     *(bp+0x12) = (no_of_rootdir_entries >> 8) & 0xff;
  168.  
  169.     *(bp+0x13) = no_of_sectors & 0xff;
  170.  
  171.     *(bp+0x14) = (no_of_sectors >> 8) & 0xff;
  172.  
  173.     *(bp+0x15) = media_descriptor;
  174.  
  175.     *(bp+0x16) = sectors_per_fat & 0xff;
  176.  
  177.     *(bp+0x17) = (sectors_per_fat >> 8) & 0xff;
  178.  
  179.     *(bp+0x18) = sectors_per_track & 0xff;
  180.  
  181.     *(bp+0x19) = (sectors_per_track >> 8) & 0xff;
  182.  
  183.     *(bp+0x1a) = drive_heads & 0xff;
  184.  
  185.     *(bp+0x1b) = (drive_heads >> 8) & 0xff;
  186.  
  187.     *(bp+0x1c) = hidden_sectors & 0xff;
  188.  
  189.     *(bp+0x1d) = (hidden_sectors >> 8) & 0xff;
  190.  
  191.     *(bp+0x1e) = (hidden_sectors >> 16) & 0xff;
  192.  
  193.     *(bp+0x1f) = (hidden_sectors >> 24) & 0xff;
  194.  
  195.     *(bp+0x20) = no_of_sectors_long & 0xff;
  196.  
  197.     *(bp+0x21) = (no_of_sectors_long >> 8) & 0xff;
  198.  
  199.     *(bp+0x22) = (no_of_sectors_long >> 16) & 0xff;
  200.  
  201.     *(bp+0x23) = (no_of_sectors_long >> 24) & 0xff;
  202.  
  203.     *(bp+0x24) = phys_drive_no;
  204.  
  205.     *(bp+0x26) = signature;
  206.  
  207.     *(bp+0x27) = serial_number & 0xff;
  208.  
  209.     *(bp+0x28) = (serial_number >> 8) & 0xff;
  210.  
  211.     *(bp+0x29) = (serial_number >> 16) & 0xff;
  212.  
  213.     *(bp+0x2a) = (serial_number >> 24) & 0xff;
  214.  
  215.     memcpy (bp+0x2b,volume_label,11);
  216.  
  217.     memcpy (bp+0x36,file_system_id,8);
  218.  
  219. }
  220.  
  221.  
  222.  
  223. /* ----------------------------------------------------------------------- */
  224.  
  225. /* Extract some misc. drive parameters from BPB                            */
  226.  
  227. /* ----------------------------------------------------------------------- */
  228.  
  229.  
  230.  
  231. void logical_drive_info::get (const bios_parameter_block &bpb)
  232.  
  233. {
  234.  
  235.     start_fat1 = bpb.reserved_sectors;
  236.  
  237.     start_fat2 = start_fat1 + bpb.sectors_per_fat;
  238.  
  239.     start_rootdir = start_fat2 + bpb.sectors_per_fat;
  240.  
  241.     if (bpb.no_of_rootdir_entries == 0) start_data = start_rootdir;
  242.  
  243.     else start_data = start_rootdir + (bpb.no_of_rootdir_entries - 1) / 16 + 1;
  244.  
  245.     if (bpb.sectors_per_cluster == 0) no_of_clusters = 0;
  246.  
  247.     else no_of_clusters = ((bpb.no_of_sectors ? bpb.no_of_sectors : bpb.no_of_sectors_long) - start_data) / bpb.sectors_per_cluster;
  248.  
  249. };
  250.  
  251.  
  252.  
  253.