home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / SAVE.CPP < prev    next >
C/C++ Source or Header  |  1995-08-22  |  2KB  |  69 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module save.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/save.cpp 1.4 1995/01/19 00:01:24 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 <stdio.h>
  32. #include <io.h>
  33. #include "global.h"
  34. #include "hdstruct.h"
  35.  
  36. /* ----------------------------------------------------------------------- */
  37. /* Save root- and boot sector to floppy disk                               */
  38. /* ----------------------------------------------------------------------- */
  39.  
  40. void save_root_and_boot (harddrive *drive,partition *partition)
  41. {
  42.     FILE *save_file;
  43.  
  44.     char *filename = "a:\\rootboot.000";
  45.  
  46.     while (access (filename,0) == 0)
  47.     {
  48.         if (++filename[14] > '9')
  49.             error ("Too many save files on disk");
  50.     }
  51.  
  52.     if ((save_file = fopen (filename,"wb")) == NULL)
  53.         error ("Can't open file: %s",filename);
  54.  
  55.     printx ("\nWriting file %s\n", filename);
  56.  
  57.     if (fwrite (drive->root_sector->data,1,512,save_file) != 512)
  58.         error ("Error writing file: %s",filename);
  59.     if (fwrite (partition->boot_sector->data,1,512,save_file) != 512)
  60.         error ("Error writing file: %s",filename);
  61.     if (fputc (drive->number,save_file) != drive->number)
  62.         error ("Error writing file: %s",filename);
  63.     if (fputc (partition->number,save_file) != partition->number)
  64.         error ("Error writing file: %s",filename);
  65.  
  66.     if (fclose (save_file))
  67.         error ("Error closing file: %s",filename);
  68. }
  69.