version.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. version.c
  9. Abstract:
  10. This module implements support for returning the loader system version
  11. information.
  12. Author:
  13. Evan Green 19-Nov-2013
  14. Environment:
  15. Boot
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. #include <minoca/kernel/kernel.h>
  21. #include "version.h"
  22. //
  23. // --------------------------------------------------------------------- Macros
  24. //
  25. //
  26. // ---------------------------------------------------------------- Definitions
  27. //
  28. //
  29. // Define the system version information.
  30. //
  31. #define PRODUCT_NAME "Minoca Boot App"
  32. #ifndef VERSION_RELEASE
  33. #define VERSION_RELEASE SystemReleaseDevelopment
  34. #endif
  35. #ifdef DEBUG
  36. #define VERSION_DEBUG SystemBuildDebug
  37. #else
  38. #define VERSION_DEBUG SystemBuildRelease
  39. #endif
  40. #ifndef VERSION_MAJOR
  41. #define VERSION_MAJOR 0
  42. #define VERSION_MINOR 0
  43. #define VERSION_REVISION 0
  44. #endif
  45. #ifndef VERSION_SERIAL
  46. #define VERSION_SERIAL 0
  47. #endif
  48. #ifndef VERSION_BUILD_TIME
  49. #define VERSION_BUILD_TIME 0
  50. #endif
  51. #ifndef VERSION_BUILD_STRING
  52. #define VERSION_BUILD_STRING ""
  53. #endif
  54. //
  55. // ------------------------------------------------------ Data Type Definitions
  56. //
  57. //
  58. // ----------------------------------------------- Internal Function Prototypes
  59. //
  60. //
  61. // -------------------------------------------------------------------- Globals
  62. //
  63. //
  64. // Store the version information jammed into a packed format.
  65. //
  66. ULONG BoEncodedVersion = ENCODE_VERSION_INFORMATION(VERSION_MAJOR,
  67. VERSION_MINOR,
  68. VERSION_REVISION,
  69. VERSION_RELEASE,
  70. VERSION_DEBUG);
  71. ULONG BoVersionSerial = VERSION_SERIAL;
  72. ULONG BoBuildTime = VERSION_BUILD_TIME;
  73. PSTR BoBuildString = VERSION_BUILD_STRING;
  74. PSTR BoProductName = PRODUCT_NAME;
  75. //
  76. // ------------------------------------------------------------------ Functions
  77. //
  78. KSTATUS
  79. KeGetSystemVersion (
  80. PSYSTEM_VERSION_INFORMATION VersionInformation,
  81. PVOID Buffer,
  82. PULONG BufferSize
  83. )
  84. /*++
  85. Routine Description:
  86. This routine gets the system version information.
  87. Arguments:
  88. VersionInformation - Supplies a pointer where the system version
  89. information will be returned.
  90. Buffer - Supplies an optional pointer to the buffer to use for the
  91. product name and build string.
  92. BufferSize - Supplies an optional pointer that on input contains the size
  93. of the supplied string buffer in bytes. On output, returns the needed
  94. size of the build string buffer in bytes including the null terminator
  95. characters.
  96. Return Value:
  97. STATUS_SUCCESS on success.
  98. STATUS_BUFFER_TOO_SMALL if the supplied buffer was not big enough to hold
  99. both strings.
  100. --*/
  101. {
  102. ULONG BuildStringSize;
  103. ULONG ProductNameSize;
  104. KSTATUS Status;
  105. Status = STATUS_SUCCESS;
  106. VersionInformation->MajorVersion = DECODE_MAJOR_VERSION(BoEncodedVersion);
  107. VersionInformation->MinorVersion = DECODE_MINOR_VERSION(BoEncodedVersion);
  108. VersionInformation->Revision = DECODE_VERSION_REVISION(BoEncodedVersion);
  109. VersionInformation->SerialVersion = BoVersionSerial;
  110. VersionInformation->ReleaseLevel = DECODE_VERSION_RELEASE(BoEncodedVersion);
  111. VersionInformation->DebugLevel = DECODE_VERSION_DEBUG(BoEncodedVersion);
  112. VersionInformation->BuildTime.Seconds = BoBuildTime;
  113. VersionInformation->BuildTime.Nanoseconds = 0;
  114. VersionInformation->ProductName = NULL;
  115. VersionInformation->BuildString = NULL;
  116. BuildStringSize = RtlStringLength(BoBuildString);
  117. if (BuildStringSize != 0) {
  118. BuildStringSize += 1;
  119. }
  120. ProductNameSize = RtlStringLength(BoProductName) + 1;
  121. if ((BufferSize != NULL) && (Buffer != NULL)) {
  122. if (*BufferSize < BuildStringSize + ProductNameSize) {
  123. Status = STATUS_BUFFER_TOO_SMALL;
  124. } else {
  125. RtlCopyMemory(Buffer, BoProductName, ProductNameSize);
  126. VersionInformation->ProductName = Buffer;
  127. if (BuildStringSize != 0) {
  128. VersionInformation->BuildString = Buffer + ProductNameSize;
  129. RtlCopyMemory(VersionInformation->BuildString,
  130. BoBuildString,
  131. BuildStringSize);
  132. }
  133. }
  134. }
  135. if (BufferSize != NULL) {
  136. *BufferSize = BuildStringSize + ProductNameSize;
  137. }
  138. return Status;
  139. }
  140. //
  141. // --------------------------------------------------------- Internal Functions
  142. //