home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / LOGDR_ST.CPP < prev    next >
C/C++ Source or Header  |  1995-08-22  |  5KB  |  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.4 1995/01/19 00:00:54 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 boot sector                           */
  37. /* ----------------------------------------------------------------------- */
  38.  
  39. void bios_parameter_block::get (boot_sector *boot_sector)
  40. {
  41.     byte *bp = boot_sector->data;
  42.  
  43.     memcpy (jump_instruction,bp,3);
  44.     memcpy (oem_name,bp+3,8);
  45.     oem_name[8]=0;
  46.     bytes_per_sector = *(bp+0xb) | (*(bp+0xc) << 8);
  47.     sectors_per_cluster = *(bp+0xd);
  48.     reserved_sectors = *(bp+0xe) | (*(bp+0xf) << 8);
  49.     no_of_fats = *(bp+0x10);
  50.     no_of_rootdir_entries = *(bp+0x11) | (*(bp+0x12) << 8);
  51.     no_of_sectors = *(bp+0x13) | (*(bp+0x14) << 8);
  52.     media_descriptor = *(bp+0x15);
  53.     sectors_per_fat = *(bp+0x16) | (*(bp+0x17) << 8);
  54.     sectors_per_track = *(bp+0x18) | (*(bp+0x19) << 8);
  55.     drive_heads = *(bp+0x1a) | (*(bp+0x1b) << 8);
  56.     hidden_sectors = (dword) *(bp+0x1c) | ((dword) *(bp+0x1d) << 8) | ((dword) *(bp+0x1e) << 16) | ((dword) *(bp+0x1f) << 24);
  57.     no_of_sectors_long = (dword) *(bp+0x20) | ((dword) *(bp+0x21) << 8) | ((dword) *(bp+0x22) << 16) | ((dword) *(bp+0x23) << 24);
  58.     phys_drive_no = *(bp+0x24);
  59.     signature = *(bp+0x26);
  60.     serial_number = (dword) *(bp+0x27) | ((dword) *(bp+0x28) << 8) | ((dword) *(bp+0x29) << 16) | ((dword) *(bp+0x2a) << 24);
  61.     memcpy (volume_label,bp+0x2b,11);
  62.     volume_label[11] = 0;
  63.     memcpy (file_system_id,bp+0x36,8);
  64.     file_system_id[8] = 0;
  65. }
  66.  
  67. /* ----------------------------------------------------------------------- */
  68. /* Write Bios Parameter Block back into boot sector                        */
  69. /* ----------------------------------------------------------------------- */
  70.  
  71. void bios_parameter_block::put (boot_sector *boot_sector)
  72. {
  73.     byte *bp = boot_sector->data;
  74.  
  75.     memcpy (bp,jump_instruction,3);
  76.     memcpy (bp+3,oem_name,8);
  77.     *(bp+0xb) = bytes_per_sector & 0xff;
  78.     *(bp+0xc) = (bytes_per_sector >> 8) & 0xff;
  79.     *(bp+0xd) = sectors_per_cluster;
  80.     *(bp+0xe) = reserved_sectors & 0xff;
  81.     *(bp+0xf) = (reserved_sectors >> 8) & 0xff;
  82.     *(bp+0x10) = no_of_fats;
  83.     *(bp+0x11) = no_of_rootdir_entries & 0xff;
  84.     *(bp+0x12) = (no_of_rootdir_entries >> 8) & 0xff;
  85.     *(bp+0x13) = no_of_sectors & 0xff;
  86.     *(bp+0x14) = (no_of_sectors >> 8) & 0xff;
  87.     *(bp+0x15) = media_descriptor;
  88.     *(bp+0x16) = sectors_per_fat & 0xff;
  89.     *(bp+0x17) = (sectors_per_fat >> 8) & 0xff;
  90.     *(bp+0x18) = sectors_per_track & 0xff;
  91.     *(bp+0x19) = (sectors_per_track >> 8) & 0xff;
  92.     *(bp+0x1a) = drive_heads & 0xff;
  93.     *(bp+0x1b) = (drive_heads >> 8) & 0xff;
  94.     *(bp+0x1c) = hidden_sectors & 0xff;
  95.     *(bp+0x1d) = (hidden_sectors >> 8) & 0xff;
  96.     *(bp+0x1e) = (hidden_sectors >> 16) & 0xff;
  97.     *(bp+0x1f) = (hidden_sectors >> 24) & 0xff;
  98.     *(bp+0x20) = no_of_sectors_long & 0xff;
  99.     *(bp+0x21) = (no_of_sectors_long >> 8) & 0xff;
  100.     *(bp+0x22) = (no_of_sectors_long >> 16) & 0xff;
  101.     *(bp+0x23) = (no_of_sectors_long >> 24) & 0xff;
  102.     *(bp+0x24) = phys_drive_no;
  103.     *(bp+0x26) = signature;
  104.     *(bp+0x27) = serial_number & 0xff;
  105.     *(bp+0x28) = (serial_number >> 8) & 0xff;
  106.     *(bp+0x29) = (serial_number >> 16) & 0xff;
  107.     *(bp+0x2a) = (serial_number >> 24) & 0xff;
  108.     memcpy (bp+0x2b,volume_label,11);
  109.     memcpy (bp+0x36,file_system_id,8);
  110. }
  111.  
  112. /* ----------------------------------------------------------------------- */
  113. /* Extract some misc. drive parameters from BPB                            */
  114. /* ----------------------------------------------------------------------- */
  115.  
  116. void logical_drive_info::get (const bios_parameter_block &bpb)
  117. {
  118.     start_fat1 = bpb.reserved_sectors;
  119.     start_fat2 = start_fat1 + bpb.sectors_per_fat;
  120.     start_rootdir = start_fat2 + bpb.sectors_per_fat;
  121.     if (bpb.no_of_rootdir_entries == 0) start_data = start_rootdir;
  122.     else start_data = start_rootdir + (bpb.no_of_rootdir_entries - 1) / 16 + 1;
  123.     if (bpb.sectors_per_cluster == 0) no_of_clusters = 0;
  124.     else no_of_clusters = ((bpb.no_of_sectors ? bpb.no_of_sectors : bpb.no_of_sectors_long) - start_data) / bpb.sectors_per_cluster;
  125. };
  126.  
  127.