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.

100 lines
2.0 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. //
  4. // x86 version (that deals with boot.ini) as opposed to arc
  5. // version, that dceals with nvram (that routine is in the portable directory).
  6. //
  7. #ifdef _X86_
  8. BOOL
  9. FChangeBootIniTimeout(
  10. IN INT Timeout
  11. )
  12. {
  13. CHP BOOTINI[] = "C:\\boot.ini";
  14. HFILE hfile;
  15. ULONG FileSize;
  16. PUCHAR buf = NULL,p1,p2;
  17. BOOL b;
  18. CHAR TimeoutLine[256];
  19. sprintf(TimeoutLine,"timeout=%u\r\n",Timeout);
  20. //
  21. // Open and read boot.ini.
  22. //
  23. b = FALSE;
  24. hfile = _lopen(BOOTINI,OF_READ);
  25. if(hfile != HFILE_ERROR) {
  26. FileSize = _llseek(hfile,0,2);
  27. if(FileSize != (ULONG)(-1)) {
  28. if((_llseek(hfile,0,0) != -1)
  29. && (buf = SAlloc(FileSize+1))
  30. && (_lread(hfile,buf,FileSize) != (UINT)(-1)))
  31. {
  32. buf[FileSize] = 0;
  33. b = TRUE;
  34. }
  35. }
  36. _lclose(hfile);
  37. }
  38. if(!b) {
  39. if(buf) {
  40. SFree(buf);
  41. }
  42. return(FALSE);
  43. }
  44. if(!(p1 = strstr(buf,"timeout"))) {
  45. SFree(buf);
  46. return(FALSE);
  47. }
  48. if(p2 = strchr(p1,'\n')) {
  49. p2++; // skip NL.
  50. } else {
  51. p2 = buf + FileSize;
  52. }
  53. SetFileAttributes(BOOTINI,FILE_ATTRIBUTE_NORMAL);
  54. hfile = _lcreat(BOOTINI,0);
  55. if(hfile == HFILE_ERROR) {
  56. SFree(buf);
  57. return(FALSE);
  58. }
  59. //
  60. // Write:
  61. //
  62. // 1) the first part, start=buf, len=p1-buf
  63. // 2) the timeout line
  64. // 3) the last part, start=p2, len=buf+FileSize-p2
  65. //
  66. b = ((_lwrite(hfile,buf ,p1-buf ) != (UINT)(-1))
  67. && (_lwrite(hfile,TimeoutLine,strlen(TimeoutLine)) != (UINT)(-1))
  68. && (_lwrite(hfile,p2 ,buf+FileSize-p2 ) != (UINT)(-1)));
  69. _lclose(hfile);
  70. SFree(buf);
  71. //
  72. // Make boot.ini archive, read only, and system.
  73. //
  74. SetFileAttributes(
  75. BOOTINI,
  76. FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE
  77. );
  78. return(b);
  79. }
  80. #endif