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.

412 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991-2000 Microsoft Corporation
  3. Module Name:
  4. error.hxx
  5. Abstract:
  6. This module contains ERROR class.
  7. Environment:
  8. ULIB, User Mode
  9. Notes:
  10. --*/
  11. /*
  12. Defining error code:
  13. */
  14. #define ERROR_USER_DEFINED_BASE 0xFF00
  15. #define ERR_ERRSTK_STACK_OVERFLOW ERROR_USER_DEFINED_BASE + 1
  16. #define NEW_ALLOC_FAILED ERROR_USER_DEFINED_BASE + 2
  17. #define ERROR_NLS_STRING_BASE 0xFF10
  18. #define ERR_NLS_ALLOC_FAILED ERROR_NLS_STRING_BASE + 1
  19. #define ERR_NLS_INVALID_PSZ ERROR_NLS_STRING_BASE + 2
  20. #define ERR_NLS_INVALID_STRING ERROR_NLS_STRING_BASE + 3
  21. #define ERR_NLS_FIXED_SIZE_BUF ERROR_NLS_STRING_BASE + 4
  22. #define ERR_NLS_NOT_FOUND ERROR_NLS_STRING_BASE + 5
  23. #define ERR_NLS_BAD_DATE ERROR_NLS_STRING_BASE + 6
  24. #define ERR_NLS_BAD_TIME ERROR_NLS_STRING_BASE + 7
  25. #define ERR_BAD_SUBSTRING ERROR_NLS_STRING_BASE + 8
  26. #define ERROR_ARG_BASE 0xFF20
  27. #define ERR_UNKNOWN_ARG_STRING ERROR_ARG_BASE + 1
  28. #define ERR_INVALID_COMMAND_LINE ERROR_ARG_BASE + 2
  29. #define ERROR_ARRAYLIST_BASE 0xFF30
  30. #define ERR_REALLOC_SIZE_FAILED ERROR_ARRAYLIST_BASE + 1
  31. #define ERROR_STR_BUF_BASE 0xFF40
  32. #define ERR_FILE_TOO_LARGE ERROR_STR_BUF_BASE + 1
  33. #define ERR_MEMORY_UNAVAILABLE ERROR_STR_BUF_BASE + 2
  34. #define ERR_FILE_READ_ERROR ERROR_STR_BUF_BASE + 3
  35. #define ERR_NO_STRINGS_IN_BUFFER ERROR_STR_BUF_BASE + 4
  36. #define ERR_INVALID_FILE_NAME ERROR_STR_BUF_BASE + 4
  37. #define ERROR_MB_STRING_BASE 0xFF50
  38. #define ERR_COLLATE_FAILURE ERROR_MB_STRING_BASE + 1
  39. #define ERROR_VOLUME_BASE 0xFF60
  40. #define ERR_CANNOT_OPEN_VOL ERROR_VOLUME_BASE + 1
  41. #define ERR_CANNOT_GET_VOL ERROR_VOLUME_BASE + 2
  42. #define ERR_PARITION_TOOBIG ERROR_VOLUME_BASE + 3
  43. #define ERR_NO_S_SWITCH ERROR_VOLUME_BASE + 4
  44. #define ERR_INVALID_PARM ERROR_VOLUME_BASE + 5
  45. #define ERR_VOL_NOTOPEN ERROR_VOLUME_BASE + 6
  46. #define ERR_VOL_NOHELPERS ERROR_VOLUME_BASE + 7
  47. #define ERR_VOL_NETDRIVE ERROR_VOLUME_BASE + 8
  48. #define ERR_VOL_BUSYDRIVE ERROR_VOLUME_BASE + 9
  49. #define ERR_VOL_INVALIDLABEL ERROR_VOLUME_BASE + 0xA
  50. #define ERROR_FMT_BASE 0xFFFF0070
  51. #define ERR_FMT_NOTSUPPORTED ERROR_FMT_BASE + 1
  52. #define ERR_FMT_UNEXPECTEDERR ERROR_FMT_BASE + 2
  53. #define ERR_FMT_BADPARM ERROR_FMT_BASE + 3
  54. #define ERR_FMT_INCOMPATPARM ERROR_FMT_BASE + 4
  55. #define ERR_FMT_INCOMPATDISK ERROR_FMT_BASE + 5
  56. #define ERR_FMT_ONCEONLY ERROR_FMT_BASE + 6
  57. #define ERR_FMT_VOLTOOBIG ERROR_FMT_BASE + 7
  58. #define ERR_FMT_BADVOLID ERROR_FMT_BASE + 8
  59. #define ERR_FMT_EXECFAIL ERROR_FMT_BASE + 9
  60. #define ERR_FMT_BADCMMFUNC ERROR_FMT_BASE + 0xA
  61. #define ERR_FMT_INVALIDMEDIA ERROR_FMT_BASE + 0xB
  62. #define ERR_FMT_BADOS ERROR_FMT_BASE + 0xC
  63. #define ERR_FMT_GENERALFAIL ERROR_FMT_BASE + 0xD
  64. #define ERR_FMT_NOSPARM ERROR_FMT_BASE + 0xE
  65. #define ERR_FMT_INVALIDNAME ERROR_FMT_BASE + 0xF
  66. #define ERR_FMT_NOWRITEBOOT ERROR_FMT_BASE + 0x10
  67. #define ERR_FMT_BADLABEL ERROR_FMT_BASE + 0x11
  68. #define ERR_FMT_FATERR ERROR_FMT_BASE + 0x12
  69. #define ERR_FMT_DIRWRITE ERROR_FMT_BASE + 0x13
  70. #define ERR_FMT_DRIVELETTER ERROR_FMT_BASE + 0x14
  71. #define ERR_FMT_UNSUPP_PARMS ERROR_FMT_BASE + 0x15
  72. #define ERR_FMT_STOPIFDISK ERROR_FMT_BASE + 0x16
  73. #define ERR_FMT_NODRIVESPEC ERROR_FMT_BASE + 0x17
  74. #define ERROR_IOBUF_BASE 0xFF90
  75. #define ERR_ALLOC_FAILURE ERROR_IOBUF_BASE + 1
  76. #define ERR_REALLOC_FAILURE ERROR_IOBUF_BASE + 2
  77. #define ERR_BUFFER_OVERFLOW ERROR_IOBUF_BASE + 3
  78. #define ERR_BUFFER_NOT_LOCAL ERROR_IOBUF_BASE + 4
  79. #define ERROR_FS_MGR_BASE 0xff95
  80. #define ERROR_DRV_BASE 0xff96
  81. #define ERR_DRV_NOT_SET ERROR_DRV_BASE + 1
  82. #define ERR_DRV_INVALID_ARG ERROR_DRV_BASE + 2
  83. #define ERROR_FS_REF_BASE 0xff99
  84. #define ERROR_FS_REF_SETPROPERTY ERROR_FS_REF_BASE + 1
  85. #define ERROR_FILE_BASE 0xffa0
  86. #define ERROR_DIRECTORY_BASE 0xffb0
  87. #define ERROR_MSG_BASE 0xffc0
  88. #define ERROR_MBR_BASE 0xFFd0
  89. #define ERR_INVALID_PARITION ERROR_MBR_BASE + 1
  90. #define ERR_INVALID_SYSTEM_ID ERROR_MBR_BASE + 2
  91. #define ERROR_BPB_BASE 0xFFe0
  92. #define ERR_BPB_NOMEM ERROR_BPB_BASE + 1
  93. #define ERR_INVALID_DEVICE ERROR_BPB_BASE + 2
  94. #define ERR_NO_BPB ERROR_BPB_BASE + 3
  95. #define ERR_NO_MBR ERROR_BPB_BASE + 4
  96. #define ERROR_FAT_BASE 0xFFf0
  97. #define ERR_BAD_CLUS_NUM ERROR_FAT_BASE + 1
  98. #define ERROR_FATFMT_BASE 0xFFf5
  99. #define ERR_NOMULTITRACK ERROR_FATFMT_BASE + 1
  100. #define ERR_BADAREAS ERROR_FATFMT_BASE + 2
  101. #define ERROR_BMIND_BASE 0xFFFF0000
  102. #define ERR_BMIND_PARAMETER ERROR_BMIND_BASE + 1
  103. #define ERR_BMIND_INITIALIZATION ERROR_BMIND_BASE + 2
  104. #define ERROR_BITMAP_BASE 0xFFFF0010
  105. #define ERR_BM_PARAMETER ERROR_BITMAP_BASE + 1
  106. #define ERR_BM_FULL ERROR_BITMAP_BASE + 2
  107. #define ERROR_BADBLK_BASE 0xFFFF0020
  108. #define ERR_BB_PARAMETER ERROR_BADBLK_BASE + 1
  109. #define ERROR_HOTFIX_BASE 0xFFFF0030
  110. #define ERR_HF_PARAMETER ERROR_HOTFIX_BASE + 1
  111. #define ERROR_FNODE_BASE 0xFFFF0040
  112. #define ERR_FN_PARAMETER ERROR_FNODE_BASE + 1
  113. #define ERROR_SUPER_BASE 0xFFFF0050
  114. #define ERR_SB_PARAMETER ERROR_SUPER_BASE + 1
  115. #define ERROR_SPARE_BASE 0xFFFF0060
  116. #define ERR_SP_PARAMETER ERROR_SPARE_BASE + 1
  117. #define ERROR_HPFSVOL_BASE 0xFFFF0070
  118. #define ERR_HV_PARAMETER ERROR_HPFSVOL_BASE + 1
  119. #define ERR_HV_BAD_SA ERROR_HPFSVOL_BASE + 2
  120. #define ERROR_DIRMAP_BASE 0xFFFF0080
  121. #define ERR_DM_PARAMETER ERROR_DIRMAP_BASE + 1
  122. #define ERR_DM_FULL ERROR_DIRMAP_BASE + 2
  123. #define ERROR_DIRBLK_BASE 0xFFFF0090
  124. #define ERR_DB_PARAMETER ERROR_DIRBLK_BASE + 1
  125. #define ERROR_HP_SUPER_AREA_BASE 0xFFFF00A0
  126. #define ERR_HPSA_PARAMETER ERROR_HP_SUPER_AREA_BASE + 1
  127. #define ERR_HPSA_NOT_READ ERROR_HP_SUPER_AREA_BASE + 2
  128. #define ERR_HPSA_BAD_SA ERROR_HP_SUPER_AREA_BASE + 3
  129. #define ERROR_CHKDSK_BASE 0xFFFF00B0
  130. #define ERR_CHKDSK_NOTSUPPORTED ERROR_CHKDSK_BASE + 1
  131. #define ERR_CHKDSK_UNEXPECTEDERR ERROR_CHKDSK_BASE + 2
  132. #define ERR_CHKDSK_BADPARM ERROR_CHKDSK_BASE + 3
  133. #define ERR_CHKDSK_INCOMPATPARM ERROR_CHKDSK_BASE + 4
  134. #define ERR_CHKDSK_INCOMPATDISK ERROR_CHKDSK_BASE + 5
  135. #define ERR_CHKDSK_BADVOLID ERROR_CHKDSK_BASE + 6
  136. #define ERR_CHKDSK_EXECFAIL ERROR_CHKDSK_BASE + 7
  137. #define ERR_CHKDSK_BADCMMFUNC ERROR_CHKDSK_BASE + 8
  138. #define ERR_CHKDSK_INVALIDMEDIA ERROR_CHKDSK_BASE + 9
  139. #define ERR_CHKDSK_BADOS ERROR_CHKDSK_BASE + 0xA
  140. #define ERR_CHKDSK_GENERALFAIL ERROR_CHKDSK_BASE + 0xB
  141. #define ERR_CHKDSK_INVALIDNAME ERROR_CHKDSK_BASE + 0xC
  142. #define ERR_CHKDSK_NOWRITEBOOT ERROR_CHKDSK_BASE + 0xD
  143. #define ERR_CHKDSK_BADLABEL ERROR_CHKDSK_BASE + 0xE
  144. #define ERR_CHKDSK_FATERR ERROR_CHKDSK_BASE + 0xF
  145. #define ERR_CHKDSK_DIRWRITE ERROR_CHKDSK_BASE + 0x10
  146. #define ERR_CHKDSK_DRIVELETTER ERROR_CHKDSK_BASE + 0x11
  147. #define ERR_CHKDSK_UNSUPP_PARMS ERROR_CHKDSK_BASE + 0x12
  148. #define ERR_CHKDSK_NODRIVESPEC ERROR_CHKDSK_BASE + 0x13
  149. #define ERR_CHKDSK_INVALID_FSTYPE ERROR_CHKDSK_BASE + 0x14
  150. #define ERR_CHKDSK_NO_FIX_SECTOR0 ERROR_CHKDSK_BASE + 0x15
  151. #define ERR_NOT_INIT 0xFFFF00D0
  152. #define ERR_NOT_READ 0xFFFF00E0
  153. #define ERROR_MEM_BASE 0xFFFF00F0
  154. #define ERR_CMEM_NO_MEM ERROR_MEM_BASE + 1
  155. #define ERR_HMEM_NO_MEM ERROR_MEM_BASE + 2
  156. #define ERRSTK_DEFAULT_SIZE 20
  157. typedef ULONG ERRCODE; // errco
  158. #if !defined( ERRSTACK_DEFN )
  159. #define ERRSTACK_DEFN
  160. // this has to be defined in the .exe and has to use this name.
  161. class ERRSTACK;
  162. typedef ERRSTACK* PERRSTACK;
  163. extern ERRSTACK *perrstk;
  164. class ERRSTACK {
  165. public:
  166. void push (ERRCODE errIn, CLASS_ID idIn)
  167. { (void)(errIn); (void)(idIn); (void)(this); };
  168. };
  169. #define PUSH_ERR( x ) perrstk->push( x, QueryClassId() );
  170. #endif // !defined ERRSTACK_DEFN
  171. #if 0 // BUGBUG fix
  172. /***************************************************************************\
  173. CLASS: ERROR
  174. PURPOSE: Class to hold an error code.
  175. INTERFACE: ERROR constructs and init error with class id and error code
  176. SetErr Sets the error code
  177. QueryErr returns current error code
  178. SetId Set id used to identify class that had error.
  179. QueryClassId returns current class id
  180. SetMsg Sets pointer to message object
  181. QueryMsg Returns pointer to message object
  182. SetIdErrMsg Sets err, id and message at same time
  183. NOTES: Any error that is to be passed up the stack should be put into
  184. an error object and put in the ERRSTK object. All references
  185. to ERRSTK are through the ulib defined global perrstk. All
  186. users of ERRSTK should declare:
  187. #include "error.hxx";
  188. extern ERRSTK * perrstk;
  189. The ERROR object contains the error code, the class id (see
  190. object.hxx) and an optional pointer to a MESSAGE object.
  191. Error codes are defined with error.hxx. These are the error codes
  192. specific to the utility objects. All error codes generated from
  193. outside of OS/2 need to be mapped to this set of error codes.
  194. Specifically the C runtime error codes will have to be mapped
  195. to an error code defined in error.hxx. An error code returned
  196. from an OS/2 call is put directly into the ERROR object. An
  197. error code from the C runtime has to be mapped to some error
  198. code defined in error.hxx.
  199. The class id is defined in object.hxx. Each class has a unique
  200. class id. This can be found be using the QueryClassId method on any
  201. object. If the error does not occur within an object then use
  202. ID_NOT_AN_OBJECT. This is a generic class id defined for this
  203. purpose. If a more specific location is needed and the error
  204. is not in an object then define a new class id substracting
  205. from ID_BASE as shown in object.hxx with the ID_NOT_AN_OBJECT
  206. example.
  207. The optional pointer to a MESSAGE object can be used latter
  208. to process the ERROR and recover context specific information
  209. about the ERROR. There will need to be a message id defined
  210. for the error.
  211. HISTORY: 4-1-90
  212. KEYWORDS: ERROR CLASS_ID
  213. SEEALSO: ERRSTK
  214. \***************************************************************************/
  215. #if !defined (ERROR_DEFN)
  216. #define ERROR_DEFN
  217. class MESSAGE;
  218. class ERROR : public OBJECT { // err
  219. private:
  220. ERRCODE err;
  221. CLASS_ID id;
  222. // const MESSAGE * pmsg;
  223. public:
  224. ERROR ();
  225. // ERROR (ERRCODE errIn, CLASS_ID idIn, const MESSAGE *pmsgIn = (MESSAGE *)NULL);
  226. ~ERROR ();
  227. ERROR & operator= (ERROR & );
  228. BOOL SetErr (ERRCODE errIn) {return(err = errIn);}
  229. ERRCODE QueryErr () {return(err);}
  230. BOOL SetId (CLASS_ID idIn) {return(id = idIn); }
  231. CLASS_ID QueryClassId () {return(id); }
  232. // ERROR * PutIdErrMsg (CLASS_ID idIn, ERRCODE errIn, const MESSAGE * pmsgIn = (const MESSAGE *)NULL) {id = idIn; pmsg = pmsgIn; err = errIn; return(this); }
  233. // const MESSAGE * PutMsg (MESSAGE * pmsgIn) { return(pmsg = pmsgIn); }
  234. // const MESSAGE * GetMsg () { return(pmsg); }
  235. #if defined (DEBUG)
  236. BOOL print ();
  237. #endif
  238. };
  239. #if defined( DEBUG_STOP_PUSHERR )
  240. #define PUSH_ERR( x ) DebugPrintAbort( "PUSH_ERR called" );
  241. #else
  242. #define PUSH_ERR( x ) (void)*perrstk->push( x, QueryClassId() );
  243. #endif // DEBUG
  244. #endif // ERROR_DEFN
  245. /***************************************************************************\
  246. CLASS: ERRSTACK
  247. PURPOSE: Hold a stack of error objects
  248. INTERFACE: ERRSTACK creates an array of error obj. pointers
  249. ~ERRSTACK deletes array of errors. (calls ~ERROR on each)
  250. push push an error object onto the stack. There are
  251. two signatures one for pointer to error objectg
  252. the other for error code, class id and message
  253. pop pop the top error object off the stack
  254. QueryCount Query number of errors on the stack
  255. QueryTop Query Top index to stack.
  256. QuerySize Query size in pointer of stack
  257. ClearStack Clear all error from stack (deletes error objects)
  258. NOTES: Each exe should declare with global scope an object of type
  259. ERRSTK. If you include error.hxx a pointer called perrstk will
  260. be declared. perrstk = NEW ERRSTK should be done at the start
  261. of the program. The default size for the error stack will be
  262. ERRSTK_DEFAULT_SIZE. If the error stack cannot be constructed the
  263. the program should abort.
  264. One slot is always reserved in the stack to hold an overflow
  265. error. If ERRSTK_DEFAULT_SIZE stack is allocated then the
  266. actual size of the stack is ERRSTK_DEFAULT_SIZE + 1. The overflow
  267. error will also occur at index 0. Index ERRSTK_DEFAULT_SIZE - 1
  268. is the bottom of the stack. Unless an overflow has occured the
  269. stack index will not go below 1. Note that QuerySize will
  270. return the original size passed in plus 1. QueryCountError will
  271. include a stack overflow error.
  272. The ERROR object passed to the stack is copied before it is
  273. pushed. The caller is responsible for deleting the object.
  274. HISTORY: 3-6-90
  275. KEYWORDS: ERRSTK
  276. SEEALSO: ERROR CLASS_ID
  277. \***************************************************************************/
  278. #if !defined (ERRSTK_DEFN)
  279. #define ERRSTK_DEFN
  280. class ERRSTACK : public OBJECT { // errstk
  281. public:
  282. ERRSTACK (ULONG cpoInitIn = ERRSTK_DEFAULT_SIZE, ULONG cpoIncIn = 0);
  283. ~ERRSTACK ();
  284. ERROR * push (const ERROR * );
  285. ERROR * push (ERRCODE errIn, CLASS_ID idIn);
  286. ERROR * pop ();
  287. ULONG QueryCount () { return(ipoCur); }
  288. ULONG QueryTop () { return(ipoCur); }
  289. ULONG QuerySize () { return(cpoMax); }
  290. ULONG ClearStack ();
  291. #ifdef DEBUG
  292. ULONG print ();
  293. #endif
  294. private:
  295. ERROR * AllocError();
  296. ULONG ipoCur; // index to top of stack
  297. ULONG cpoMax; // index to bottom of stack
  298. ULONG cpoInc; // bytes to add for each realloc
  299. ULONG cpoInit; // initial alloc. (used by ClearStack
  300. ERROR ** papo; // pointer to stack bottom
  301. };
  302. #endif // ERRSTK_DEFN
  303. #endif // BUGBUG