Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. bootini.c
  5. Abstract:
  6. Routines relating to boot.ini.
  7. Author:
  8. Ted Miller (tedm) 4-Apr-1995
  9. Revision History:
  10. --*/
  11. #include "setupp.h"
  12. #pragma hdrstop
  13. BOOL
  14. ChangeBootTimeoutBootIni(
  15. IN UINT Timeout
  16. )
  17. /*++
  18. Routine Description:
  19. Changes the boot countdown value in boot.ini.
  20. Arguments:
  21. Timeout - supplies new timeout value, in seconds.
  22. Return Value:
  23. None.
  24. --*/
  25. {
  26. HFILE hfile;
  27. ULONG FileSize;
  28. PUCHAR buf = NULL,p1,p2;
  29. BOOL b;
  30. CHAR TimeoutLine[256];
  31. CHAR szBootIni[] = "?:\\BOOT.INI";
  32. szBootIni[0] = (CHAR)x86SystemPartitionDrive;
  33. wsprintfA(TimeoutLine,"timeout=%u\r\n",Timeout);
  34. //
  35. // Open and read boot.ini.
  36. //
  37. b = FALSE;
  38. hfile = _lopen(szBootIni,OF_READ);
  39. if(hfile != HFILE_ERROR) {
  40. FileSize = _llseek(hfile,0,2);
  41. if(FileSize != (ULONG)(-1)) {
  42. if((_llseek(hfile,0,0) != -1)
  43. && (buf = MyMalloc(FileSize+1))
  44. && (_lread(hfile,buf,FileSize) != (UINT)(-1)))
  45. {
  46. buf[FileSize] = 0;
  47. b = TRUE;
  48. }
  49. }
  50. _lclose(hfile);
  51. }
  52. if(!b) {
  53. if(buf) {
  54. MyFree(buf);
  55. }
  56. return(FALSE);
  57. }
  58. if(!(p1 = strstr(buf,"timeout"))) {
  59. MyFree(buf);
  60. return(FALSE);
  61. }
  62. if(p2 = strchr(p1,'\n')) {
  63. p2++; // skip NL.
  64. } else {
  65. p2 = buf + FileSize;
  66. }
  67. SetFileAttributesA(szBootIni,FILE_ATTRIBUTE_NORMAL);
  68. hfile = _lcreat(szBootIni,0);
  69. if(hfile == HFILE_ERROR) {
  70. MyFree(buf);
  71. return(FALSE);
  72. }
  73. //
  74. // Write:
  75. //
  76. // 1) the first part, start=buf, len=p1-buf
  77. // 2) the timeout line
  78. // 3) the last part, start=p2, len=buf+FileSize-p2
  79. //
  80. b = ((_lwrite(hfile,buf ,p1-buf ) != (UINT)(-1))
  81. && (_lwrite(hfile,TimeoutLine,strlen(TimeoutLine)) != (UINT)(-1))
  82. && (_lwrite(hfile,p2 ,buf+FileSize-p2 ) != (UINT)(-1)));
  83. _lclose(hfile);
  84. MyFree(buf);
  85. //
  86. // Make boot.ini archive, read only, and system.
  87. //
  88. SetFileAttributesA(
  89. szBootIni,
  90. FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN
  91. );
  92. return(b);
  93. }