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.

1222 lines
42 KiB

  1. /*
  2. * HrPartitionEntry.c v0.10
  3. * Generated in conjunction with Management Factory scripts:
  4. * script version: SNMPv1, 0.16, Apr 25, 1996
  5. * project: D:\TEMP\EXAMPLE\HOSTMIB
  6. ****************************************************************************
  7. * *
  8. * (C) Copyright 1995 DIGITAL EQUIPMENT CORPORATION *
  9. * *
  10. * This software is an unpublished work protected under the *
  11. * the copyright laws of the United States of America, all *
  12. * rights reserved. *
  13. * *
  14. * In the event this software is licensed for use by the United *
  15. * States Government, all use, duplication or disclosure by the *
  16. * United States Government is subject to restrictions as set *
  17. * forth in either subparagraph (c)(1)(ii) of the Rights in *
  18. * Technical Data And Computer Software Clause at DFARS *
  19. * 252.227-7013, or the Commercial Computer Software Restricted *
  20. * Rights Clause at FAR 52.221-19, whichever is applicable. *
  21. * *
  22. ****************************************************************************
  23. *
  24. * Facility:
  25. *
  26. * Windows NT SNMP Extension Agent
  27. *
  28. * Abstract:
  29. *
  30. * This module contains the code for dealing with the get, set, and
  31. * instance name routines for the HrPartitionEntry. Actual instrumentation code is
  32. * supplied by the developer.
  33. *
  34. * Functions:
  35. *
  36. * A get and set routine for each attribute in the class.
  37. *
  38. * The routines for instances within the class.
  39. *
  40. * Author:
  41. *
  42. * D. D. Burns @ Webenable Inc
  43. *
  44. * Revision History:
  45. *
  46. * V1.00 - 04/28/97 D. D. Burns Genned: Thu Nov 07 16:43:52 1996
  47. *
  48. |
  49. | The approach envisioned for generating the contents of this table consists
  50. | of walking all physical drives (using CreateFile and the "physical drive"
  51. | naming convention) and acquiring the partition information for each drive
  52. | using Win32 API functions DeviceIoControl (IOCTL_DISK_GET_DRIVE_LAYOUT).
  53. |
  54. */
  55. #include <windows.h>
  56. #include <malloc.h>
  57. #include <snmp.h>
  58. #include "mib.h"
  59. #include "smint.h"
  60. #include "hostmsmi.h"
  61. #include "user.h" /* Developer supplied include file */
  62. #include "HMCACHE.H" /* Cache-related definitions */
  63. #include "HRDEVENT.H" /* HrDevice Table-related definitions */
  64. /*
  65. |==============================================================================
  66. | A word about the cache for this sub-table.
  67. |
  68. | This is a unique sub-table within the hrDevice table in that it is doubly
  69. | indexed.
  70. |
  71. | As a consequence, there are multiple instances of the cache-head,
  72. | one for each simple instance of this table. Consequently there is no
  73. | single, static instance of a cache-head to be found (as is typically the
  74. | case for sub-tables of hrDevice) here at the start of the module.
  75. |
  76. | The "value" of the "hidden-context" attribute for a hrDevice table
  77. | row for this sub-table has as its value a pointer to a slug of malloced
  78. | memory containing the cache-head for that instance of this sub-table.
  79. | (See "HMCACHE.C" for storage picture).
  80. |
  81. | Initialization of this sub-table occurs as part of the initialization
  82. | of the HrDiskStorage sub-table (HRDISKST.C) in function "ProcessPartitions".
  83. */
  84. /*
  85. |==============================================================================
  86. | Function Prototypes for this module.
  87. */
  88. /* RollToNextFixedDisk - Helper Routine for HrPartitionEntryFindNextInstance */
  89. static UINT
  90. RollToNextFixedDisk (
  91. UINT *dev_tmp_instance , /* ->Device Table Instance Arc ("1st") */
  92. UINT *part_tmp_instance , /* ->Partition Table Instance Arc ("2nd") */
  93. CACHEROW **dev_row, /* ->> Entry in hrDevice Table */
  94. CACHEHEAD **part_cache /* ->> Cache-Header for Partition */
  95. );
  96. /*
  97. * GetHrPartitionIndex
  98. * A unique value for each partition on this long term storage device. The
  99. * value for each long-term storage device must remain con
  100. *
  101. * Gets the value for HrPartitionIndex.
  102. *
  103. * Arguments:
  104. *
  105. * outvalue address to return variable value
  106. * accesss Reserved for future security use
  107. * instance address of instance name as ordered native
  108. * data type(s)
  109. *
  110. * Return Codes:
  111. *
  112. * Standard PDU error codes.
  113. *
  114. * SNMP_ERRORSTATUS_NOERROR Successful get
  115. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  116. * mibtget.c v0.10
  117. *
  118. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  119. | hrPartitionIndex
  120. |
  121. | ACCESS SYNTAX
  122. | read-only INTEGER (1..2147483647)
  123. |
  124. | "A unique value for each partition on this long- term storage device. The
  125. | value for each long-term storage device must remain constant at least from one
  126. | re-initialization of the agent to the next re- initialization."
  127. |
  128. | DISCUSSION:
  129. |
  130. | (See discussion above for the table as a whole).
  131. |
  132. |============================================================================
  133. | 1.3.6.1.2.1.25.3.7.1.1.<dev-instance>.<partition-instance>
  134. | | | | |
  135. | | | | *-hrPartitionIndex
  136. | | | *-hrPartitionEntry
  137. | | *-hrPartitionTable
  138. | *-hrDevice
  139. */
  140. UINT
  141. GetHrPartitionIndex(
  142. OUT Integer *outvalue ,
  143. IN Access_Credential *access ,
  144. IN InstanceName *instance )
  145. {
  146. ULONG disk_index; /* As fetched from instance structure */
  147. ULONG part_index; /* As fetched from instance structure */
  148. CACHEROW *disk_row; /* Row entry fetched from Disk cache */
  149. CACHEROW *part_row; /* Row entry fetched from Part. cache */
  150. CACHEHEAD *part_cache; /* HrPartition Table cache to search */
  151. /*
  152. | Grab the instance information
  153. */
  154. disk_index = GET_INSTANCE(0);
  155. part_index = GET_INSTANCE(1);
  156. /*
  157. |===========
  158. | Index 1
  159. | Use Disk-Index to find the right Disk-row entry in the hrDevice cache
  160. */
  161. if ((disk_row = FindTableRow(disk_index, &hrDevice_cache)) == NULL) {
  162. return SNMP_ERRORSTATUS_GENERR;
  163. }
  164. /* Grab a pointer to the hrPartition cache for this disk */
  165. part_cache = disk_row->attrib_list[HIDDEN_CTX].u.cache;
  166. /*
  167. |===========
  168. | Index 2
  169. | Use Partition-Index to find the right row entry in the hrPartition cache
  170. */
  171. if ((part_row = FindTableRow(part_index, part_cache)) == NULL) {
  172. return SNMP_ERRORSTATUS_GENERR;
  173. }
  174. *outvalue = part_row->attrib_list[HRPT_INDEX].u.unumber_value;
  175. return SNMP_ERRORSTATUS_NOERROR ;
  176. } /* end of GetHrPartitionIndex() */
  177. /*
  178. * GetHrPartitionLabel
  179. * A textual description of this partition.
  180. *
  181. * Gets the value for HrPartitionLabel.
  182. *
  183. * Arguments:
  184. *
  185. * outvalue address to return variable value
  186. * accesss Reserved for future security use
  187. * instance address of instance name as ordered native
  188. * data type(s)
  189. *
  190. * Return Codes:
  191. *
  192. * Standard PDU error codes.
  193. *
  194. * SNMP_ERRORSTATUS_NOERROR Successful get
  195. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  196. * mibtget.c v0.10
  197. *
  198. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  199. | hrPartitionLabel
  200. |
  201. | ACCESS SYNTAX
  202. | read-only InternationalDisplayString (SIZE (0..128))
  203. |
  204. | "A textual description of this partition."
  205. |
  206. | DISCUSSION:
  207. |
  208. | This information for the entire drive is obtained using Win32 API CreateFile
  209. | to open the device and DeviceIoControl to retrieve the needed information.
  210. |
  211. |============================================================================
  212. | 1.3.6.1.2.1.25.3.7.1.2.<dev-instance>.<partition-instance>
  213. | | | | |
  214. | | | | *-hrPartitionLabel
  215. | | | *-hrPartitionEntry
  216. | | *-hrPartitionTable
  217. | *-hrDevice
  218. */
  219. UINT
  220. GetHrPartitionLabel(
  221. OUT InternationalDisplayString *outvalue ,
  222. IN Access_Credential *access ,
  223. IN InstanceName *instance )
  224. {
  225. ULONG disk_index; /* As fetched from instance structure */
  226. ULONG part_index; /* As fetched from instance structure */
  227. CACHEROW *disk_row; /* Row entry fetched from Disk cache */
  228. CACHEROW *part_row; /* Row entry fetched from Part. cache */
  229. CACHEHEAD *part_cache; /* HrPartition Table cache to search */
  230. /*
  231. | Grab the instance information
  232. */
  233. disk_index = GET_INSTANCE(0);
  234. part_index = GET_INSTANCE(1);
  235. /*
  236. |===========
  237. | Index 1
  238. | Use Disk-Index to find the right Disk-row entry in the hrDevice cache
  239. */
  240. if ((disk_row = FindTableRow(disk_index, &hrDevice_cache)) == NULL) {
  241. return SNMP_ERRORSTATUS_GENERR;
  242. }
  243. /* Grab a pointer to the hrPartition cache for this disk */
  244. part_cache = disk_row->attrib_list[HIDDEN_CTX].u.cache;
  245. /*
  246. |===========
  247. | Index 2
  248. | Use Partition-Index to find the right row entry in the hrPartition cache
  249. */
  250. if ((part_row = FindTableRow(part_index, part_cache)) == NULL) {
  251. return SNMP_ERRORSTATUS_GENERR;
  252. }
  253. outvalue->string = part_row->attrib_list[HRPT_LABEL].u.string_value;
  254. if (outvalue->string == NULL) {
  255. outvalue->length = 0;
  256. }
  257. else {
  258. outvalue->length = strlen(outvalue->string);
  259. /* "Truncate" here to meet RFC as needed*/
  260. if (outvalue->length > 128) {
  261. outvalue->length = 128;
  262. }
  263. }
  264. return SNMP_ERRORSTATUS_NOERROR ;
  265. } /* end of GetHrPartitionLabel() */
  266. /*
  267. * GetHrPartitionID
  268. * A descriptor which uniquely represents this partition to the responsible
  269. * operating system. On some systems, this might take on
  270. *
  271. * Gets the value for HrPartitionID.
  272. *
  273. * Arguments:
  274. *
  275. * outvalue address to return variable value
  276. * accesss Reserved for future security use
  277. * instance address of instance name as ordered native
  278. * data type(s)
  279. *
  280. * Return Codes:
  281. *
  282. * Standard PDU error codes.
  283. *
  284. * SNMP_ERRORSTATUS_NOERROR Successful get
  285. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  286. * mibtget.c v0.10
  287. *
  288. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  289. | hrPartitionID
  290. |
  291. | ACCESS SYNTAX
  292. | read-only OCTET STRING
  293. |
  294. | "A descriptor which uniquely represents this partition to the responsible
  295. | operating system. On some systems, this might take on a binary
  296. | representation."
  297. |
  298. | DISCUSSION:
  299. |
  300. | This information for the entire drive is obtained using Win32 API CreateFile
  301. | to open the device and DeviceIoControl to retrieve the needed information.
  302. |
  303. |
  304. |============================================================================
  305. | 1.3.6.1.2.1.25.3.7.1.3.<dev-instance>.<partition-instance>
  306. | | | | |
  307. | | | | *-hrPartitionID
  308. | | | *-hrPartitionEntry
  309. | | *-hrPartitionTable
  310. | *-hrDevice
  311. */
  312. UINT
  313. GetHrPartitionID(
  314. OUT OctetString *outvalue ,
  315. IN Access_Credential *access ,
  316. IN InstanceName *instance )
  317. {
  318. ULONG disk_index; /* As fetched from instance structure */
  319. ULONG part_index; /* As fetched from instance structure */
  320. CACHEROW *disk_row; /* Row entry fetched from Disk cache */
  321. CACHEROW *part_row; /* Row entry fetched from Part. cache */
  322. CACHEHEAD *part_cache; /* HrPartition Table cache to search */
  323. /*
  324. | Grab the instance information
  325. */
  326. disk_index = GET_INSTANCE(0);
  327. part_index = GET_INSTANCE(1);
  328. /*
  329. |===========
  330. | Index 1
  331. | Use Disk-Index to find the right Disk-row entry in the hrDevice cache
  332. */
  333. if ((disk_row = FindTableRow(disk_index, &hrDevice_cache)) == NULL) {
  334. return SNMP_ERRORSTATUS_GENERR;
  335. }
  336. /* Grab a pointer to the hrPartition cache for this disk */
  337. part_cache = disk_row->attrib_list[HIDDEN_CTX].u.cache;
  338. /*
  339. |===========
  340. | Index 2
  341. | Use Partition-Index to find the right row entry in the hrPartition cache
  342. */
  343. if ((part_row = FindTableRow(part_index, part_cache)) == NULL) {
  344. return SNMP_ERRORSTATUS_GENERR;
  345. }
  346. outvalue->string = (char *) &(part_row->attrib_list[HRPT_ID].u.unumber_value);
  347. outvalue->length = 4;
  348. return SNMP_ERRORSTATUS_NOERROR ;
  349. } /* end of GetHrPartitionID() */
  350. /*
  351. * GetHrPartitionSize
  352. * The size of this partition.
  353. *
  354. * Gets the value for HrPartitionSize.
  355. *
  356. * Arguments:
  357. *
  358. * outvalue address to return variable value
  359. * accesss Reserved for future security use
  360. * instance address of instance name as ordered native
  361. * data type(s)
  362. *
  363. * Return Codes:
  364. *
  365. * Standard PDU error codes.
  366. *
  367. * SNMP_ERRORSTATUS_NOERROR Successful get
  368. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  369. * mibtget.c v0.10
  370. *
  371. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  372. | hrPartitionSize
  373. |
  374. | ACCESS SYNTAX
  375. | read-only KBytes
  376. |
  377. | "The size of this partition."
  378. |
  379. | DISCUSSION:
  380. |
  381. | This information for the entire drive is obtained using Win32 API CreateFile
  382. | to open the device and DeviceIoControl to retrieve the needed information.
  383. |
  384. |============================================================================
  385. | 1.3.6.1.2.1.25.3.7.1.4.<dev-instance>.<partition-instance>
  386. | | | | |
  387. | | | | *-hrPartitionSize
  388. | | | *-hrPartitionEntry
  389. | | *-hrPartitionTable
  390. | *-hrDevice
  391. */
  392. UINT
  393. GetHrPartitionSize(
  394. OUT KBytes *outvalue ,
  395. IN Access_Credential *access ,
  396. IN InstanceName *instance )
  397. {
  398. ULONG disk_index; /* As fetched from instance structure */
  399. ULONG part_index; /* As fetched from instance structure */
  400. CACHEROW *disk_row; /* Row entry fetched from Disk cache */
  401. CACHEROW *part_row; /* Row entry fetched from Part. cache */
  402. CACHEHEAD *part_cache; /* HrPartition Table cache to search */
  403. /*
  404. | Grab the instance information
  405. */
  406. disk_index = GET_INSTANCE(0);
  407. part_index = GET_INSTANCE(1);
  408. /*
  409. |===========
  410. | Index 1
  411. | Use Disk-Index to find the right Disk-row entry in the hrDevice cache
  412. */
  413. if ((disk_row = FindTableRow(disk_index, &hrDevice_cache)) == NULL) {
  414. return SNMP_ERRORSTATUS_GENERR;
  415. }
  416. /* Grab a pointer to the hrPartition cache for this disk */
  417. part_cache = disk_row->attrib_list[HIDDEN_CTX].u.cache;
  418. /*
  419. |===========
  420. | Index 2
  421. | Use Partition-Index to find the right row entry in the hrPartition cache
  422. */
  423. if ((part_row = FindTableRow(part_index, part_cache)) == NULL) {
  424. return SNMP_ERRORSTATUS_GENERR;
  425. }
  426. *outvalue = part_row->attrib_list[HRPT_SIZE].u.unumber_value;
  427. return SNMP_ERRORSTATUS_NOERROR ;
  428. } /* end of GetHrPartitionSize() */
  429. /*
  430. * GetHrPartitionFSIndex
  431. * The index of the file system mounted on this partition. If no file
  432. * system is mounted on this partition, then this value shall b
  433. *
  434. * Gets the value for HrPartitionFSIndex.
  435. *
  436. * Arguments:
  437. *
  438. * outvalue address to return variable value
  439. * accesss Reserved for future security use
  440. * instance address of instance name as ordered native
  441. * data type(s)
  442. *
  443. * Return Codes:
  444. *
  445. * Standard PDU error codes.
  446. *
  447. * SNMP_ERRORSTATUS_NOERROR Successful get
  448. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  449. * mibtget.c v0.10
  450. *
  451. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  452. | hrPartitionFSIndex
  453. |
  454. | ACCESS SYNTAX
  455. | read-only INTEGER (0..2147483647)
  456. |
  457. | "The index of the file system mounted on this partition. If no file system is
  458. | mounted on this partition, then this value shall be zero. Note that multiple
  459. | partitions may point to one file system, denoting that that file system
  460. | resides on those partitions. Multiple file systems may not reside on one
  461. | partition."
  462. |
  463. | DISCUSSION:
  464. |
  465. | This information for the entire drive is obtained using Win32 API CreateFile
  466. | to open the device and DeviceIoControl to retrieve the needed information.
  467. |
  468. |============================================================================
  469. | 1.3.6.1.2.1.25.3.7.1.5.<dev-instance>.<partition-instance>
  470. | | | | |
  471. | | | | *-hrPartitionFSIndex
  472. | | | *-hrPartitionEntry
  473. | | *-hrPartitionTable
  474. | *-hrDevice
  475. */
  476. UINT
  477. GetHrPartitionFSIndex(
  478. OUT Integer *outvalue ,
  479. IN Access_Credential *access ,
  480. IN InstanceName *instance )
  481. {
  482. ULONG disk_index; /* As fetched from instance structure */
  483. ULONG part_index; /* As fetched from instance structure */
  484. CACHEROW *disk_row; /* Row entry fetched from Disk cache */
  485. CACHEROW *part_row; /* Row entry fetched from Part. cache */
  486. CACHEHEAD *part_cache; /* HrPartition Table cache to search */
  487. /*
  488. | Grab the instance information
  489. */
  490. disk_index = GET_INSTANCE(0);
  491. part_index = GET_INSTANCE(1);
  492. /*
  493. |===========
  494. | Index 1
  495. | Use Disk-Index to find the right Disk-row entry in the hrDevice cache
  496. */
  497. if ((disk_row = FindTableRow(disk_index, &hrDevice_cache)) == NULL) {
  498. return SNMP_ERRORSTATUS_GENERR;
  499. }
  500. /* Grab a pointer to the hrPartition cache for this disk */
  501. part_cache = disk_row->attrib_list[HIDDEN_CTX].u.cache;
  502. /*
  503. |===========
  504. | Index 2
  505. | Use Partition-Index to find the right row entry in the hrPartition cache
  506. */
  507. if ((part_row = FindTableRow(part_index, part_cache)) == NULL) {
  508. return SNMP_ERRORSTATUS_GENERR;
  509. }
  510. *outvalue = part_row->attrib_list[HRPT_FSINDEX].u.unumber_value;
  511. return SNMP_ERRORSTATUS_NOERROR ;
  512. } /* end of GetHrPartitionFSIndex() */
  513. /*
  514. * HrPartitionEntryFindInstance
  515. *
  516. * This routine is used to verify that the specified instance is
  517. * valid.
  518. *
  519. * Arguments:
  520. *
  521. * FullOid Address for the full oid - group, variable,
  522. * and instance information
  523. * instance Address for instance specification as an oid
  524. *
  525. * Return Codes:
  526. *
  527. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  528. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  529. *
  530. */
  531. UINT
  532. HrPartitionEntryFindInstance( IN ObjectIdentifier *FullOid ,
  533. IN OUT ObjectIdentifier *instance )
  534. {
  535. UINT dev_tmp_instance ; /* Device Table Instance Arc */
  536. UINT part_tmp_instance ; /* Partition Table Instance Arc */
  537. CACHEROW *dev_row; /* --> Entry in hrDevice Table */
  538. CACHEHEAD *part_cache; /* --> Cache-Header for Partition*/
  539. //
  540. // Developer instrumentation code to find appropriate instance goes here.
  541. // For non-tables, it is not necessary to modify this routine. However, if
  542. // there is any context that needs to be set, it can be done here.
  543. //
  544. if ( FullOid->idLength <= HRPARTITIONENTRY_VAR_INDEX )
  545. // No instance was specified
  546. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  547. // Instance is 2 arcs for this table:
  548. else if ( FullOid->idLength != HRPARTITIONENTRY_VAR_INDEX + 2 )
  549. // Instance length is more than 2, or 1 exactly, either way: error
  550. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  551. else
  552. // The only valid instance for a non-table are instance 0. If this
  553. // is a non-table, the following code validates the instances. If this
  554. // is a table, developer modification is necessary below.
  555. /*
  556. | Check the first of two instance arcs here. The first should
  557. | select a valid entry in hrDiskStorage cache. This guarantees
  558. | that a disk is being selected. If a valid entry is present in
  559. | hrDiskStorage cache, then a corresponding row should be in the
  560. | main hrDevice table (and having checked hrDiskStorage first, we
  561. | don't have to verify the type of the entry in hrDevice).
  562. |
  563. | The corresponding hrDevice row entry should have a hidden-context
  564. | that is a non-NULL pointer to a CACHEHEAD **if** the first instance
  565. | arc is truly selecting a Fixed-Disk (which is the only kind of disk
  566. | for which HrPartition sub-tables are constructed).
  567. */
  568. dev_tmp_instance = FullOid->ids[ HRPARTITIONENTRY_VAR_INDEX ] ;
  569. if ( FindTableRow(dev_tmp_instance, &hrDiskStorage_cache) == NULL ) {
  570. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  571. }
  572. /*
  573. | Ok, there is an entry in hrDiskStorage, now go get the corresponding
  574. | hrDevice entry... it **will be** for a Disk.
  575. */
  576. if ( (dev_row = FindTableRow(dev_tmp_instance, &hrDevice_cache))
  577. == NULL ) {
  578. return SNMP_ERRORSTATUS_GENERR ;
  579. }
  580. /*
  581. | Check to be sure there is a cache tucked into the hidden-context,
  582. | this assures us it is a Fixed Disk and that there is something to
  583. | search given the second instance arc. (The cache header may be
  584. | for an empty cache, but it will support a search).
  585. */
  586. if (dev_row->attrib_list[HIDDEN_CTX].attrib_type != CA_CACHE ||
  587. (part_cache = dev_row->attrib_list[HIDDEN_CTX].u.cache) == NULL) {
  588. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  589. }
  590. /*
  591. | First instance arc ("dev_tmp_instance") is kosher... check the second,
  592. | ("part_tmp_instance") it should select a valid entry in the cache
  593. | whose header pointer is in HIDDEN_CTX.
  594. */
  595. part_tmp_instance = FullOid->ids[ HRPARTITIONENTRY_VAR_INDEX + 1] ;
  596. if ( FindTableRow(part_tmp_instance, part_cache) == NULL ) {
  597. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  598. }
  599. else
  600. {
  601. // the both instances are valid. Create the instance portion of
  602. // the OID to be returned from this call.
  603. instance->ids[ 0 ] = dev_tmp_instance ;
  604. instance->ids[ 1 ] = part_tmp_instance ;
  605. instance->idLength = 2 ;
  606. }
  607. return SNMP_ERRORSTATUS_NOERROR ;
  608. } /* end of HrPartitionEntryFindInstance() */
  609. /*
  610. * HrPartitionEntryFindNextInstance
  611. *
  612. * This routine is called to get the next instance. If no instance
  613. * was passed than return the first instance (1).
  614. *
  615. * Arguments:
  616. *
  617. * FullOid Address for the full oid - group, variable,
  618. * and instance information
  619. * instance Address for instance specification as an oid
  620. *
  621. * Return Codes:
  622. *
  623. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  624. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  625. *
  626. */
  627. UINT
  628. HrPartitionEntryFindNextInstance( IN ObjectIdentifier *FullOid ,
  629. IN OUT ObjectIdentifier *instance )
  630. {
  631. UINT dev_tmp_instance=0; /* Device Table Instance Arc ("1st") */
  632. UINT part_tmp_instance=0; /* Partition Table Instance Arc ("2nd")*/
  633. CACHEROW *hrDevice_row; /* Looked-up row in hrDevice table */
  634. CACHEROW *dev_row = NULL; /* --> Entry in hrDiskStorage Table */
  635. CACHEROW *part_row = NULL; /* --> Entry in hrPartition Table */
  636. CACHEHEAD *part_cache=NULL; /* --> Cache-Header for Partition */
  637. UINT ret_status; /* Status to be returned by this func */
  638. //
  639. // Developer supplied code to find the next instance of class goes here.
  640. // If this is a class with cardinality 1, no modification of this routine
  641. // is necessary unless additional context needs to be set.
  642. // If the FullOid does not specify an instance, then the only instance
  643. // of the class is returned. If this is a table, the first row of the
  644. // table is returned.
  645. //
  646. // If an instance is specified and this is a non-table class, then NOSUCHNAME
  647. // is returned so that correct MIB rollover processing occurs. If this is
  648. // a table, then the next instance is the one following the current instance.
  649. // If there are no more instances in the table, return NOSUCHNAME.
  650. //
  651. /*
  652. | With two numeric indices to deal with on this table, we're attempting
  653. | to cover the following situations:
  654. |
  655. | 1) No instance arcs provided at all. In this case, we need to look up
  656. | and return the instance arcs that select the first fixed-disk and
  657. | the first partition within that disk. We cover this case as a
  658. | "standalone" case.
  659. |
  660. | 2) Only the hrdevice ("disk selecting") first instance arc is provided.
  661. | In this case, we'll "assume" an initial partition-selecting instance
  662. | arc of "0", and continue processing with the code that covers case 3.
  663. |
  664. | 3) Two or more instance arcs are provided, in which case we just use the
  665. | first of two arcs as the hrdevice ("disk selecting") "first" instance
  666. | arc and the second arc as the hrPartition ("partition selecting")
  667. | "second" instance arc, ignoring any remaining arcs.
  668. |
  669. | The "Party Line" on this logic is that it works even if the "fixed-disk"
  670. | entries don't have monotonically increasing indices the way the
  671. | cache-population code currently creates them and even if the partition
  672. | cache (table) has no entries for a particular disk (it must, however
  673. | have a cache).
  674. */
  675. if ( FullOid->idLength <= HRPARTITIONENTRY_VAR_INDEX ) {
  676. /* CASE 1
  677. |
  678. | No instance arcs were provided, so we want to setup local instance
  679. | arcs that select the first hrDevice table "Fixed Disk" entry and the
  680. | first "Partition" entry within that disk (if any disk and if any
  681. | partitions within that disk).
  682. |
  683. | Entry into "RollToNextFixedDisk()" is special for this case as
  684. | "dev_row" is NULL, so it'll roll to the first legal Fixed-Disk.
  685. */
  686. ret_status =
  687. RollToNextFixedDisk(&dev_tmp_instance, // hrDiskStorage arc
  688. &part_tmp_instance, // hrPartition arc
  689. &dev_row, // row in hrDiskStorage
  690. &part_cache // cache for hrPartition
  691. );
  692. /* If we got a no-good return status */
  693. if (ret_status != SNMP_ERRORSTATUS_NOERROR) {
  694. return ( ret_status );
  695. }
  696. /*
  697. | Ok, all we need to do is roll into the hrPartition table using the
  698. | second instance arc returned above (which will be zero) to find
  699. | the true first entry in the hrPartition table cache so we can return
  700. | it's index as the second instance arc, (or keep rolling if the
  701. | partition table (cache) is empty (which it really shouldn't be, but
  702. | we have it covered if it is)).
  703. |
  704. | All this is performed by the "General Roll" code below.
  705. */
  706. }
  707. else { /* Some instance arcs provided */
  708. if ( FullOid->idLength == HRPARTITIONENTRY_VAR_INDEX + 1 ) {
  709. /* CASE 2
  710. |
  711. | Exactly one instance arc is provided,
  712. | so use it and assume the second arc is 0.
  713. */
  714. dev_tmp_instance = FullOid->ids[ HRPARTITIONENTRY_VAR_INDEX ] ;
  715. part_tmp_instance = 0;
  716. }
  717. else {
  718. /* CASE 3
  719. |
  720. | Two or more instance arcs are provided,
  721. | so use the first two arcs and ignore the rest.
  722. */
  723. dev_tmp_instance = FullOid->ids[ HRPARTITIONENTRY_VAR_INDEX ] ;
  724. part_tmp_instance = FullOid->ids[ HRPARTITIONENTRY_VAR_INDEX + 1] ;
  725. }
  726. /* Show "No HrPartition Cache Selected Yet" (at entry time: NULL) */
  727. /*
  728. | At this point, we need to know whether the first instance arc
  729. | actually selects a Fixed-Disk entry in hrDevice (and hrDiskStorage)
  730. | that has an hrPartition table that we can "roll" thru.
  731. |
  732. | Attempt a direct ("non-rolling") lookup on the hrDiskStorage table
  733. | cache with the first instance arc.
  734. */
  735. dev_row = FindTableRow(dev_tmp_instance, &hrDiskStorage_cache);
  736. /*
  737. | If (an entry is found)
  738. */
  739. if ( dev_row != NULL) {
  740. /* If (the entry is for a "Fixed-Disk") */
  741. if ( dev_row->attrib_list[HRDS_REMOVABLE].u.unumber_value
  742. == FALSE) {
  743. /*
  744. | Perform "FindTableRow" on hrdevice cache using first
  745. | instance arc.
  746. */
  747. hrDevice_row = FindTableRow(dev_tmp_instance, &hrDevice_cache);
  748. /*
  749. | If (no hrdevice entry was found)
  750. */
  751. if ( hrDevice_row == NULL) {
  752. return SNMP_ERRORSTATUS_GENERR ;
  753. }
  754. /*
  755. | If the hrdevice entry DOES NOT have a
  756. | cache associated with it . . .
  757. */
  758. if ( (hrDevice_row->attrib_list[HIDDEN_CTX].attrib_type
  759. != CA_CACHE) ||
  760. (hrDevice_row->attrib_list[HIDDEN_CTX].u.cache
  761. == NULL)) {
  762. return SNMP_ERRORSTATUS_GENERR ;
  763. }
  764. /*
  765. | Select the cache from the hrdevice disk entry as the
  766. | HrPartition table cache to be searched in the following
  767. | logic.
  768. */
  769. part_cache = hrDevice_row->attrib_list[HIDDEN_CTX].u.cache;
  770. } /* if entry was fixed-disk */
  771. } /* if entry was found */
  772. /*
  773. | At this point, if a hrpartition cache has been selected (!NULL),
  774. | the first instance arc has selected a fixed-disk entry
  775. | and there is no need to "roll" on the first index.
  776. |
  777. | Otherwise we've got to "reset" the second instance arc
  778. | to "0" and do a rolling lookup on the first arc for
  779. | another Fixed-disk entry (that should have a partition-cache).
  780. */
  781. /* if (an hrpartition cache has NOT been selected) */
  782. if (part_cache == NULL) {
  783. /* Perform "RollToNextFixedDisk" processing */
  784. ret_status =
  785. RollToNextFixedDisk(&dev_tmp_instance, // hrDiskStorage arc
  786. &part_tmp_instance, // hrPartition arc
  787. &dev_row, // row in hrDiskStorage
  788. &part_cache // hrPartition cache
  789. );
  790. /* If we got a no-good return status */
  791. if (ret_status != SNMP_ERRORSTATUS_NOERROR) {
  792. return ( ret_status ); // (either NOSUCH or GENERR)
  793. }
  794. }
  795. } /* else Some instance arcs provided */
  796. /*
  797. | At this point, we have:
  798. |
  799. | + a valid hrPartition cache to search,
  800. | + the second instance arc to search it with (by "rolling"),
  801. | + the first instance arc that is valid, (but may need to be
  802. | rolled again if there are no valid partitions found).
  803. |
  804. | We can now do a "General Roll" to land on the proper Partition entry.
  805. */
  806. while (1) { /* "General Roll" */
  807. /*
  808. | Do a "FindNextTableRow" (rolling) lookup on the hrpartition
  809. | cache with the current value of the second instance arc.
  810. |
  811. | if (an entry was found)
  812. */
  813. if ((part_row = FindNextTableRow(part_tmp_instance, part_cache))
  814. != NULL ) {
  815. /*
  816. | Return the current first arc and the index from the returned
  817. | entry as the second instance arc and signal NOERROR.
  818. */
  819. instance->ids[ 0 ] = dev_tmp_instance ;
  820. instance->ids[ 1 ] = part_row->index;
  821. instance->idLength = 2 ;
  822. return SNMP_ERRORSTATUS_NOERROR ;
  823. }
  824. /*
  825. | Fell off the end of the current hrPartition cache, must
  826. | go get another hrPartition cache from the next fixed-disk entry.
  827. |
  828. | Perform "RollToNextFixedDisk" processing
  829. */
  830. ret_status =
  831. RollToNextFixedDisk(&dev_tmp_instance, // hrDiskStorage arc
  832. &part_tmp_instance, // hrPartition arc
  833. &dev_row, // row in hrDiskStorage
  834. &part_cache // hrPartition cache
  835. );
  836. if (ret_status != SNMP_ERRORSTATUS_NOERROR) {
  837. return ( ret_status ); // (either NOSUCH or GENERR)
  838. }
  839. } /* while */
  840. } /* end of HrPartitionEntryFindNextInstance() */
  841. /* RollToNextFixedDisk - Helper Routine for HrPartitionEntryFindNextInstance */
  842. /* RollToNextFixedDisk - Helper Routine for HrPartitionEntryFindNextInstance */
  843. /* RollToNextFixedDisk - Helper Routine for HrPartitionEntryFindNextInstance */
  844. static UINT
  845. RollToNextFixedDisk (
  846. /* Index */
  847. UINT *dev_tmp_instance, /* ->Device Table Instance Arc ("1st") */
  848. UINT *part_tmp_instance, /* ->Partition Table Instance Arc ("2nd") */
  849. CACHEROW **dev_row, /* ->> Entry in hrDevice Table */
  850. CACHEHEAD **part_cache /* ->> Cache-Header for Partition */
  851. )
  852. /*
  853. | EXPLICIT INPUTS:
  854. |
  855. | "dev_tmp_instance" & "part_tmp_instance" are pointers to the "current"
  856. | instance arcs for the hrDevice and hrPartition table respectively.
  857. |
  858. | Note that "*dev_tmp_instance" is also implicitly the index into the
  859. | hrDiskStorage table as well.
  860. |
  861. | "dev_row" - is a pointer to the pointer to the hrDiskStorage
  862. | row currently selected by "*dev_tmp_instance". It is the
  863. | case that "*dev_row" might be null, indicating that no row
  864. | has been selected yet.
  865. |
  866. | "part_cache" is a pointer to the pointer to any selected hrPartition
  867. | table (ie a cache taken from an hrDevice row for a fixed-disk). If
  868. | no such partition cache has been selected yet, then "*part_cache" is
  869. | NULL.
  870. |
  871. | IMPLICIT INPUTS:
  872. |
  873. | "HrDiskStorage_cache" may be referenced if "*dev_row" is NULL.
  874. |
  875. | OUTPUTS:
  876. |
  877. | On Success:
  878. | Function returns SNMP_ERRORSTATUS_NOERROR when the roll to the next
  879. | Fixed-Disk hrDiskStorage entry has succeeded. New "first" and "second"
  880. | instance arcs are returned as well as the cache for the hrPartition
  881. | table that needs to be searched using the "second" arc.
  882. |
  883. | On any Failure:
  884. | Function returns SNMP_ERRORSTATUS_GENERR if it bumps into what it
  885. | thinks should be a Fixed-Disk entry in hrDevice but the entry does
  886. | not have an hrPartition table cache as it should.
  887. |
  888. | Function returns SNMP_ERRORSTATUS_NOSUCHNAME if it can't find another
  889. | hrDevice entry for a Fixed-Disk.
  890. |
  891. | THE BIG PICTURE:
  892. |
  893. | This function takes care of the details of "rolling" to the next
  894. | Fixed-Disk entry in hrDevice (& HrDiskStorage) on behalf of
  895. | "HrPartitionEntryFindNextInstance()".
  896. |
  897. | OTHER THINGS TO KNOW:
  898. |
  899. | Because we rolling at the device "level", we reset the "instance"
  900. | arc for the partition level back to zero so that a FindNextTableRow
  901. | using zero will select the first entry in the selected hrPartition
  902. | Table (cache) being returned by this function.
  903. */
  904. {
  905. CACHEROW *hrDevice_row; /* Looked-up row in hrDevice table */
  906. /* Reset the second instance arc to "0" */
  907. *part_tmp_instance = 0;
  908. while (1) { /* Forever . . . */
  909. /*
  910. | Try to get the "next" hrDiskStorage row
  911. | given our pointer to the current row.
  912. |
  913. | If no "current" row, start with the first in hrDiskStorage
  914. | and riffle upward until we get the row "after" the row that
  915. | the current device instance arc would have selected.
  916. */
  917. /* if (there is no current hrDiskStorage row) */
  918. if (*dev_row == NULL) {
  919. /* If the cache is empty . . . */
  920. if ( (*dev_row =
  921. FindNextTableRow(*dev_tmp_instance, &hrDiskStorage_cache))
  922. == NULL) {
  923. return SNMP_ERRORSTATUS_NOSUCHNAME;
  924. }
  925. }
  926. else {
  927. /*
  928. | Perform "GetNextTableRow" on current hrdiskstorage entry
  929. |
  930. | if (processing returned no-next-entry)
  931. */
  932. if ( (*dev_row = GetNextTableRow((*dev_row))) == NULL) {
  933. return SNMP_ERRORSTATUS_NOSUCHNAME;
  934. }
  935. }
  936. /*
  937. | Ok, we've got a "next" row in hrDiskStorage. If it isn't for a fixed
  938. | disk, we've got to go around again in hopes of finding one that is.
  939. */
  940. /* if (entry is not for Fixed-Disk (skip Removables)) */
  941. if ( (*dev_row)->attrib_list[HRDS_REMOVABLE].u.unumber_value == TRUE) {
  942. continue; /* Skippity doo-dah */
  943. }
  944. /*
  945. | Set current first instance arc value to index of current entry:
  946. | it is the "next" row following the row for which the original
  947. | device instance arc selected.
  948. */
  949. *dev_tmp_instance = (*dev_row)->index;
  950. /*
  951. | Ok, now we've got to go over to the big hrDevice table and hope to
  952. | find the corresponding hrDevice row given the row index we're on in
  953. | hrDiskStorage. As this is coded, I realize that we could have put
  954. | the HIDDEN_CTX attribute in the hrDiskStorage entry rather than
  955. | the hrDevice entry and saved this lookup, but it matters little.
  956. */
  957. /*
  958. | Do "FindTableRow" on hrdevice cache using first instance arc
  959. |
  960. | if (no hrdevice entry was found) */
  961. if ( (hrDevice_row = FindTableRow(*dev_tmp_instance, &hrDevice_cache))
  962. == NULL) {
  963. /*
  964. | There should be an hrDevice table entry for every entry in
  965. | hrDiskStorage. This seems not to be the case for some reason.
  966. */
  967. return SNMP_ERRORSTATUS_GENERR ;
  968. }
  969. /* If (the hrdevice entry DOES NOT have a cache associated with it) */
  970. if ( (hrDevice_row->attrib_list[HIDDEN_CTX].attrib_type != CA_CACHE) ||
  971. (hrDevice_row->attrib_list[HIDDEN_CTX].u.cache == NULL) ) {
  972. /*
  973. | There should be a cache in the HIDDEN_CTX attribute for all fixed
  974. | disks.
  975. */
  976. return SNMP_ERRORSTATUS_GENERR ;
  977. }
  978. /*
  979. | Select and return the cache from the hrDevice fixed-disk row entry as
  980. | the HrPartition table cache to be searched on return.
  981. */
  982. *part_cache = hrDevice_row->attrib_list[HIDDEN_CTX].u.cache;
  983. return SNMP_ERRORSTATUS_NOERROR;
  984. }
  985. }
  986. /*
  987. * HrPartitionEntryConvertInstance
  988. *
  989. * This routine is used to convert the object id specification of an
  990. * instance into an ordered native representation. The object id format
  991. * is that object identifier that is returned from the Find Instance
  992. * or Find Next Instance routines. It is NOT the full object identifier
  993. * that contains the group and variable object ids as well. The native
  994. * representation is an argc/argv-like structure that contains the
  995. * ordered variables that define the instance. This is specified by
  996. * the MIB's INDEX clause. See RFC 1212 for information about the INDEX
  997. * clause.
  998. *
  999. *
  1000. * Arguments:
  1001. *
  1002. * oid_spec Address of the object id instance specification
  1003. * native_spec Address to return the ordered native instance
  1004. * specification
  1005. *
  1006. * Return Codes:
  1007. *
  1008. * SUCCESS Conversion complete successfully
  1009. * FAILURE Unable to convert object id into native format
  1010. *
  1011. */
  1012. UINT
  1013. HrPartitionEntryConvertInstance( IN ObjectIdentifier *oid_spec ,
  1014. IN OUT InstanceName *native_spec )
  1015. {
  1016. static char *array[2];/* The address of this (char *) is passed back */
  1017. /* as an array of pointers to instance arc numbers */
  1018. static ULONG inst1, /* The addresses of these ULONGs are passed back */
  1019. inst2; /* (Obviously, no "free()" action is needed) */
  1020. /* We expect the two arcs in "oid_spec" */
  1021. inst1 = oid_spec->ids[0];
  1022. array[0] = (char *) &inst1;
  1023. inst2 = oid_spec->ids[1];
  1024. array[1] = (char *) &inst2;
  1025. native_spec->count = 2;
  1026. native_spec->array = array;
  1027. return SUCCESS ;
  1028. } /* end of HrPartitionEntryConvertInstance() */
  1029. /*
  1030. * HrPartitionEntryFreeInstance
  1031. *
  1032. * This routine is used to free an ordered native representation of an
  1033. * instance name.
  1034. *
  1035. * Arguments:
  1036. *
  1037. * instance Address to return the ordered native instance
  1038. * specification
  1039. *
  1040. * Return Codes:
  1041. *
  1042. *
  1043. */
  1044. void
  1045. HrPartitionEntryFreeInstance( IN OUT InstanceName *instance )
  1046. {
  1047. //
  1048. // Developer supplied code to free native representation of instance name goes here.
  1049. //
  1050. } /* end of HrPartitionEntryFreeInstance() */