FIPSSPEC.CPP
资源名称:os_source.zip [点击查看]
上传用户:datang2001
上传日期:2007-02-01
资源大小:53269k
文件大小:7k
源码类别:
操作系统开发
开发平台:
C/C++
- /*
- FIPS - the First nondestructive Interactive Partition Splitting program
- Module fipsspec.cpp
- RCS - Header:
- $Header: c:/daten/fips/source/main/RCS/fipsspec.cpp 1.4 1995/01/19 00:00:53 schaefer Exp schaefer $
- Copyright (C) 1993 Arno Schaefer
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- Report problems and direct all questions to:
- schaefer@rbg.informatik.th-darmstadt.de
- */
- #include <dos.h>
- #include "fipsspec.h"
- #include "global.h"
- #include "input.h"
- #define FIRST_CHECK false
- #define FINAL_CHECK true
- #define DISK_INT 0x13
- #define RESET_DISK 0
- #define GET_DRIVE_PARAMS 8
- void fips_bpb::print (void)
- {
- printx ("Bytes per sector: %un",bytes_per_sector);
- printx ("Sectors per cluster: %un",sectors_per_cluster);
- printx ("Reserved sectors: %un",reserved_sectors);
- printx ("Number of FATs: %un",no_of_fats);
- printx ("Number of rootdirectory entries: %un",no_of_rootdir_entries);
- printx ("Number of sectors (short): %un",no_of_sectors);
- printx ("Media descriptor byte: %02Xhn",media_descriptor);
- printx ("Sectors per FAT: %un",sectors_per_fat);
- printx ("Sectors per track: %un",sectors_per_track);
- printx ("Drive heads: %un",drive_heads);
- printx ("Hidden sectors: %lun",hidden_sectors);
- printx ("Number of sectors (long): %lun",no_of_sectors_long);
- printx ("Physical drive number: %02Xhn",phys_drive_no);
- printx ("Signature: %02Xhnn",signature);
- }
- void fips_partition_table::print (void)
- {
- printx (" | | Start | | End | Start |Number of|n");
- printx ("Part.|bootable|Head Cyl. Sector|System|Head Cyl. Sector| Sector |Sectors | MBn");
- printx ("-----+--------+----------------+------+----------------+--------+---------+----n");
- for (int i=0;i<4;i++)
- {
- printx ("%u | %s |%4u %4u %4u| %02Xh|%4u %4u %4u|%8lu| %8lu|%4lun",i+1,
- partition_info[i].bootable ? "yes" : " no",
- partition_info[i].start_head,partition_info[i].start_cylinder,partition_info[i].start_sector,
- partition_info[i].system,partition_info[i].end_head,partition_info[i].end_cylinder,partition_info[i].end_sector,
- partition_info[i].start_sector_abs,partition_info[i].no_of_sectors_abs,partition_info[i].no_of_sectors_abs / 2048);
- }
- }
- void fips_harddrive::get_geometry (void)
- {
- union REGS regs;
- regs.h.ah = GET_DRIVE_PARAMS;
- regs.h.dl = number;
- int86 (DISK_INT,®s,®s);
- if (global.debug_mode)
- {
- fprintf (global.debugfile,"nRegisters after call to int 13h 08h (drive %02Xh):nn",number);
- fprintf (global.debugfile," 00 sc/cl hdn");
- fprintf (global.debugfile,"al ah bl bh cl ch dl dh si di cflgs flagsn");
- hexwrite ((byte *) ®s,16,global.debugfile);
- }
- if ((errorcode = regs.h.ah) != 0) return;
- geometry.heads = (dword) regs.h.dh + 1;
- geometry.sectors = (dword) regs.h.cl & 0x3f;
- geometry.cylinders = ((dword) regs.h.ch | (((dword) regs.h.cl << 2) & 0x300)) + 1;
- if (global.debug_mode)
- {
- fprintf (global.debugfile, "nGeometry reported by BIOS:n");
- fprintf
- (
- global.debugfile,
- "%ld cylinders, %ld heads, %ld sectorsn",
- geometry.cylinders,
- geometry.heads,
- geometry.sectors
- );
- }
- }
- void fips_harddrive::reset (void)
- {
- union REGS regs;
- regs.h.ah = RESET_DISK;
- regs.h.dl = number;
- int86 (DISK_INT,®s,®s);
- if (global.debug_mode)
- {
- fprintf (global.debugfile,"nRegisters after call to int 13h 00h (drive %02Xh):nn",number);
- fprintf (global.debugfile,"al ah bl bh cl ch dl dh si di cflgs flagsn");
- hexwrite ((byte *) ®s,16,global.debugfile);
- }
- errorcode = regs.h.ah;
- }
- void fips_logdrive_info::put_debug_info (void)
- {
- fprintf (global.debugfile,"Calculated Partition Characteristica:nn");
- fprintf (global.debugfile,"Start of FAT 1: %lun",start_fat1);
- fprintf (global.debugfile,"Start of FAT 2: %lun",start_fat2);
- fprintf (global.debugfile,"Start of Rootdirectory: %lun",start_rootdir);
- fprintf (global.debugfile,"Start of Data: %lun",start_data);
- fprintf (global.debugfile,"Number of Clusters: %lun",no_of_clusters);
- }
- dword fips_partition::min_cylinder (fat16 fat, drive_geometry geometry)
- {
- dword new_part_min_sector =
- info().start_data
- + (dword) 4085
- * bpb().sectors_per_cluster;
- dword new_part_min_cylinder =
- (
- new_part_min_sector
- + partition_info->start_sector_abs
- - 1
- )
- / (geometry.heads * geometry.sectors)
- + 1;
- if (new_part_min_cylinder > partition_info->end_cylinder)
- error ("Partition too small - can't split");
- dword min_free_cluster = fat.min_free_cluster ();
- dword min_free_sector =
- info().start_data
- + (min_free_cluster - 2)
- * (dword) bpb().sectors_per_cluster;
- dword min_free_cylinder =
- (
- min_free_sector
- + partition_info->start_sector_abs
- - 1
- )
- / (geometry.heads * geometry.sectors)
- + 1;
- if (min_free_cylinder > partition_info->end_cylinder)
- error ("Last cylinder is not free");
- if (new_part_min_cylinder < min_free_cylinder)
- new_part_min_cylinder = min_free_cylinder;
- return (new_part_min_cylinder);
- }
- boolean fips_partition::split (fips_harddrive hd)
- {
- if (read_boot_sector ())
- error ("Error reading boot sector");
- if (global.debug_mode)
- {
- fprintf
- (
- global.debugfile,
- "nBoot sector drive %02Xh, partition %u:nn",
- hd.number,
- number + 1
- );
- hexwrite
- (
- boot_sector->data,
- 512,
- global.debugfile
- );
- }
- get_bpb ();
- printx ("nBoot sector:nn");
- print_bpb ();
- get_info ();
- if (global.debug_mode)
- write_info_debugfile ();
- check ();
- fat16 fat1 (this,1);
- fat16 fat2 (this,2);
- fat1.check_against (&fat2);
- dword new_part_min_cylinder =
- min_cylinder (fat2, hd.geometry);
- if (ask_if_save()) save_root_and_boot(&hd,this);
- dword new_start_cylinder =
- ask_for_new_start_cylinder
- (
- partition_info->start_cylinder,
- new_part_min_cylinder,
- partition_info->end_cylinder,
- hd.geometry.heads * hd.geometry.sectors
- );
- fat2.check_empty
- (
- new_start_cylinder
- * hd.geometry.heads
- * hd.geometry.sectors
- - partition_info->start_sector_abs
- );
- hd.calculate_new_root (new_start_cylinder, this);
- hd.put_partition_table();
- hd.get_partition_table();
- printx ("nNew partition table:nn");
- hd.print_partition_table ();
- hd.check (FINAL_CHECK);
- if (ask_if_continue () == false)
- {
- return (false);
- }
- calculate_new_boot ();
- put_bpb ();
- get_bpb ();
- printx ("nNew boot sector:nn");
- print_bpb ();
- get_info ();
- if (global.debug_mode)
- write_info_debugfile ();
- check();
- if (!global.test_mode)
- {
- ask_for_write_permission ();
- if (hd.write_root_sector ())
- error ("Error writing root sector");
- if (write_boot_sector ())
- error ("Error writing boot sector");
- printx ("Repartitioning completen");
- }
- return (true);
- }