home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  4.1 KB  |  168 lines

  1. #include <exec/types.h>
  2. #include <string.h>
  3. #include "defs.h"
  4.  
  5. #define AT_LEAST_3_3 ((CurrentConfig.Version > 3) || \
  6.                      (CurrentConfig.Version == 3 && CurrentConfig.Revision >= 3))
  7.  
  8. static char rcsid [] = "$Id: config.c,v 3.6 95/12/16 18:36:55 Martin_Apel Exp $";
  9.  
  10. /************************************************************************/
  11.  
  12. PRIVATE int ReadOldTaskEntry (BPTR cfg_file)
  13.  
  14. {
  15. struct OldTaskEntryInFile old_te;
  16.  
  17. if (Read (cfg_file, &old_te, sizeof (struct OldTaskEntryInFile)) != 
  18.     sizeof (struct OldTaskEntryInFile))
  19.   return (ERR_CORRUPT_CFG_FILE);
  20.  
  21. return (EnterTask (old_te.TaskName, old_te.MinPublic, old_te.MinNonPublic, 
  22.         old_te.CodePaging, INSERT_BACK));
  23. }
  24.  
  25. /************************************************************************/
  26.  
  27. PRIVATE int ReadNewTaskEntry (BPTR cfg_file)
  28.  
  29. {
  30. struct TaskEntryInFile teif;
  31. char *name_buf;
  32. int rc;
  33.  
  34. if (Read (cfg_file, &teif, sizeof (struct TaskEntryInFile)) != 
  35.     sizeof (struct TaskEntryInFile))
  36.   return (ERR_CORRUPT_CFG_FILE);
  37.  
  38. if ((name_buf = AllocMem ((ULONG)teif.NameLen, MEMF_PUBLIC)) == NULL)
  39.   return (ERR_NOT_ENOUGH_MEM);
  40.  
  41. if (Read (cfg_file, name_buf, (ULONG)teif.NameLen) != teif.NameLen)
  42.   {
  43.   FreeMem (name_buf, (ULONG)teif.NameLen);
  44.   return (ERR_CORRUPT_CFG_FILE);
  45.   }
  46.  
  47. rc = EnterTask (name_buf, teif.MinPublic, teif.MinNonPublic, teif.CodePaging,
  48.                 INSERT_BACK);
  49.  
  50. FreeMem (name_buf, (ULONG)teif.NameLen);
  51. return (rc);
  52. }
  53.  
  54. /************************************************************************/
  55.  
  56. int ReadConfigFile (char *name)
  57.  
  58. {
  59. int i;
  60. PRIVATE BOOL FirstTime = TRUE;
  61. UWORD OldPageDev;
  62. ULONG OldFileSize;
  63. char OldPartOrFileName [80];
  64. int rc;
  65. BPTR cfg_file;
  66.  
  67. DISABLE_VM;
  68.  
  69. if ((cfg_file = Open (name, MODE_OLDFILE)) == NULL)
  70.   {
  71.   PRINT_DEB ("Couldn't find config file", 0L);
  72.   ENABLE_VM;
  73.   return (ERR_NO_CONFIG_FILE);
  74.   }
  75.  
  76. if (!FirstTime)
  77.   {
  78.   OldPageDev = CurrentConfig.PageDev;  
  79.   OldFileSize = CurrentConfig.FileSize;
  80.   strcpy (OldPartOrFileName, CurrentConfig.PartOrFileName);
  81.   }
  82.  
  83. if ((Read (cfg_file, &CurrentConfig, sizeof (struct VMMConfig)) !=
  84.      sizeof (struct VMMConfig)) || (CurrentConfig.CfgMagic != CFG_MAGIC))
  85.   {
  86.   Close (cfg_file);
  87.   ENABLE_VM;
  88.   return (ERR_CORRUPT_CFG_FILE);
  89.   }
  90.  
  91. if (!FirstTime && 
  92.     ((OldPageDev != CurrentConfig.PageDev) ||
  93.      (OldFileSize != CurrentConfig.FileSize) ||
  94.      (strcmp (OldPartOrFileName, CurrentConfig.PartOrFileName) != 0)))
  95.   {
  96.   ReportError (GetVMMString (msgPageDevChanged), ERR_NOERROR);
  97.   CurrentConfig.PageDev = OldPageDev;
  98.   CurrentConfig.FileSize = OldFileSize;
  99.   strcpy (CurrentConfig.PartOrFileName, OldPartOrFileName);
  100.   }
  101.  
  102. /* Adjust some of the values to legal ones */
  103. if (CurrentConfig.MinMem < MAX_FAULTS * PAGESIZE)
  104.   CurrentConfig.MinMem = MAX_FAULTS * PAGESIZE;
  105. CurrentConfig.MinMem = ALIGN_DOWN (CurrentConfig.MinMem, PAGESIZE);
  106.  
  107. if (CurrentConfig.MaxMem < MAX_FAULTS * PAGESIZE)
  108.   CurrentConfig.MaxMem = MAX_FAULTS * PAGESIZE;
  109. CurrentConfig.MaxMem = ALIGN_DOWN (CurrentConfig.MaxMem, PAGESIZE);
  110.  
  111. /* The following two assignments are done for performance only */
  112. MinVMAlloc = CurrentConfig.MinVMAlloc;
  113. MemTracking = CurrentConfig.MemTracking;
  114.  
  115. if (CurrentConfig.PageDev == PD_PART)
  116.   {
  117.   strcpy (PartWithColon, CurrentConfig.PartOrFileName);
  118.   strcpy (PartitionName, PartWithColon);
  119.   *(PartitionName + strlen (PartitionName) - 1) = 0;
  120.   }
  121. else
  122.   {
  123.   if (!GetPartName (PartitionName, CurrentConfig.PartOrFileName))
  124.     {
  125.     Close (cfg_file);
  126.     ENABLE_VM;
  127.     return (ERR_VOLUME_NOT_FOUND);
  128.     }
  129.   strcpy (PartWithColon, PartitionName);
  130.   strcat (PartWithColon, ":");
  131.   }
  132.  
  133.  
  134. if (AT_LEAST_3_3)
  135.   {
  136.   PRINT_DEB ("Reading config file for V3.3 or later", 0L);
  137.  
  138.   for (i = 0; i < CurrentConfig.NumTaskEntries; i++)
  139.     {
  140.     if ((rc = ReadNewTaskEntry (cfg_file)) != SUCCESS)    
  141.       {
  142.       Close (cfg_file);
  143.       ENABLE_VM;
  144.       return (rc);
  145.       }
  146.     }
  147.   }
  148. else
  149.   {
  150.   PRINT_DEB ("Reading pre-V3.3 config file", 0L);
  151.  
  152.   for (i = 0; i < CurrentConfig.NumTaskEntries; i++)
  153.     {
  154.     if ((rc = ReadOldTaskEntry (cfg_file)) != SUCCESS)    
  155.       {
  156.       Close (cfg_file);
  157.       ENABLE_VM;
  158.       return (rc);
  159.       }
  160.     }
  161.   }
  162.  
  163. Close (cfg_file);
  164. ENABLE_VM;
  165. FirstTime = FALSE;
  166. return (SUCCESS);
  167. }
  168.