Leaked source code of windows server 2003
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.

142 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. LogSize.c
  5. Abstract:
  6. This file contains RxpEstimateLogSize().
  7. Author:
  8. John Rogers (JohnRo) 20-Jul-1992
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 20-Jul-1992 JohnRo
  14. Created as part of fix for RAID 9933: ALIGN_WORST should be 8 for x86
  15. builds.
  16. --*/
  17. // These must be included first:
  18. #include <windef.h> // IN, DWORD, etc.
  19. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  20. // These may be included in any order:
  21. #include <align.h> // ALIGN_ROUND_UP(), etc.
  22. #include <netdebug.h> // NetpAssert().
  23. #include <rxp.h> // My prototype.
  24. #include <winerror.h> // NO_ERROR and ERROR_ equates.
  25. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  26. //
  27. // Estimate bytes needed for an audit log or error log array.
  28. //
  29. NET_API_STATUS
  30. RxpEstimateLogSize(
  31. IN DWORD DownlevelFixedEntrySize,
  32. IN DWORD InputArraySize, // input (downlevel) array size in bytes.
  33. IN BOOL DoingErrorLog, // TRUE for error log, FALSE for audit log
  34. OUT LPDWORD OutputArraySizePtr
  35. )
  36. {
  37. DWORD MaxEntries;
  38. DWORD OutputArraySize;
  39. DWORD PerEntryAdditionalSize;
  40. //
  41. // Error check the caller.
  42. //
  43. if (OutputArraySizePtr == NULL) {
  44. return (ERROR_INVALID_PARAMETER);
  45. } else if (DownlevelFixedEntrySize == 0) {
  46. return (ERROR_INVALID_PARAMETER);
  47. } else if (InputArraySize == 0) {
  48. return (ERROR_INVALID_PARAMETER);
  49. }
  50. //
  51. // Compute an initial size needed for output buffer, taking into account
  52. // per field expansion:
  53. // WORDs expand into DWORDs
  54. // ANSI strings expand into UNICODE
  55. //
  56. #define WORD_EXPANSION_FACTOR ( sizeof(DWORD) / sizeof(WORD) )
  57. #define CHAR_EXPANSION_FACTOR ( sizeof(TCHAR) / sizeof(CHAR) )
  58. #define PER_FIELD_EXPANSION_FACTOR \
  59. MAX( WORD_EXPANSION_FACTOR, CHAR_EXPANSION_FACTOR )
  60. OutputArraySize = InputArraySize * PER_FIELD_EXPANSION_FACTOR;
  61. //
  62. // There are several "per entry" expansions, so let's figure-out
  63. // the maximum number of entries we might have.
  64. //
  65. MaxEntries = ( (InputArraySize+DownlevelFixedEntrySize-1)
  66. / DownlevelFixedEntrySize );
  67. NetpAssert( MaxEntries > 0 );
  68. //
  69. // Compute per-entry expansion specific to the kind of entry:
  70. //
  71. // each audit entry gets:
  72. //
  73. // DWORD ae_data_size
  74. //
  75. // each error log entry gets:
  76. //
  77. // LPTSTR el_name
  78. // LPTSTR el_text
  79. // LPBYTE el_data
  80. // DWORD el_data_size
  81. //
  82. if (DoingErrorLog) {
  83. PerEntryAdditionalSize =
  84. sizeof(LPTSTR) + sizeof(LPTSTR) + sizeof(LPBYTE) + sizeof(DWORD);
  85. } else {
  86. PerEntryAdditionalSize = sizeof(DWORD);
  87. }
  88. OutputArraySize += (MaxEntries * PerEntryAdditionalSize);
  89. //
  90. // Compute per-entry expansion due to alignment requirements.
  91. //
  92. NetpAssert( ALIGN_WORST != 0 );
  93. OutputArraySize += ( MaxEntries * (ALIGN_WORST-1) );
  94. //
  95. // Double-check what we've done and tell caller.
  96. //
  97. NetpAssert( OutputArraySize > 0 );
  98. NetpAssert( OutputArraySize > InputArraySize );
  99. NetpAssert( OutputArraySize > MaxEntries );
  100. *OutputArraySizePtr = OutputArraySize;
  101. return (NO_ERROR);
  102. }