1diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hr_disk.c APPLE/agent/mibgroup/host/hr_disk.c 2--- SVN/agent/mibgroup/host/hr_disk.c 3+++ APPLE/agent/mibgroup/host/hr_disk.c 4@@ -65,6 +65,19 @@ 5 #include <limits.h> 6 #endif 7 8+#ifdef darwin 9+#include <paths.h> 10+#include <CoreFoundation/CoreFoundation.h> 11+#include <IOKit/IOKitLib.h> 12+#include <IOKit/storage/IOBlockStorageDriver.h> 13+#include <IOKit/storage/IOMedia.h> 14+#include <IOKit/storage/IOBDMedia.h> 15+#include <IOKit/storage/IOStorageProtocolCharacteristics.h> 16+#include <IOKit/storage/IOStorageDeviceCharacteristics.h> 17+#include <IOKit/IOBSD.h> 18+#include <DiskArbitration/DADisk.h> 19+#endif 20+ 21 #ifdef linux 22 /* 23 * define BLKGETSIZE from <linux/fs.h>: 24@@ -79,6 +92,27 @@ 25 26 #define HRD_MONOTONICALLY_INCREASING 27 28+/************************************************************* 29+ * constants for enums for the MIB node 30+ * hrDiskStorageAccess (INTEGER / ASN_INTEGER) 31+ */ 32+#define HRDISKSTORAGEACCESS_READWRITE 1 33+#define HRDISKSTORAGEACCESS_READONLY 2 34+ 35+ 36+/************************************************************* 37+ * constants for enums for the MIB node 38+ * hrDiskStorageMedia (INTEGER / ASN_INTEGER) 39+ */ 40+#define HRDISKSTORAGEMEDIA_OTHER 1 41+#define HRDISKSTORAGEMEDIA_UNKNOWN 2 42+#define HRDISKSTORAGEMEDIA_HARDDISK 3 43+#define HRDISKSTORAGEMEDIA_FLOPPYDISK 4 44+#define HRDISKSTORAGEMEDIA_OPTICALDISKROM 5 45+#define HRDISKSTORAGEMEDIA_OPTICALDISKWORM 6 46+#define HRDISKSTORAGEMEDIA_OPTICALDISKRW 7 47+#define HRDISKSTORAGEMEDIA_RAMDISK 8 48+ 49 /********************* 50 * 51 * Kernel & interface information, 52@@ -132,6 +166,19 @@ 53 static struct disklabel HRD_info; 54 #endif 55 56+#ifdef darwin 57+static int64_t HRD_cap; 58+static int HRD_access; 59+static int HRD_type; 60+static int HRD_removable; 61+static char HRD_model[40]; 62+static int HRD_saved_access; 63+static int HRD_saved_type; 64+static int HRD_saved_removable; 65+static int _get_type_from_protocol( const char *prot ); 66+static int _get_type_value( const char *str_type ); 67+#endif 68+ 69 static void parse_disk_config(const char *, char *); 70 static void free_disk_config(void); 71 72@@ -185,6 +232,8 @@ 73 "/dev/rdsk/c%dt%dd0s0", 0, 7); 74 Add_HR_Disk_entry("/dev/rdsk/c%dd%ds%d", 0, 7, 0, 15, 75 "/dev/rdsk/c%dd%ds0", 0, 7); 76+#elif defined(darwin) 77+ Add_HR_Disk_entry("/dev/disk%ds%d", -1, -1, 0, 32, "/dev/disk%d", 1, 32); 78 #elif defined(freebsd4) || defined(freebsd5) 79 Add_HR_Disk_entry("/dev/ad%ds%d%c", 0, 1, 1, 4, "/dev/ad%ds%d", 'a', 'h'); 80 Add_HR_Disk_entry("/dev/da%ds%d%c", 0, 1, 1, 4, "/dev/da%ds%d", 'a', 'h'); 81@@ -484,6 +533,7 @@ 82 Init_HR_Disk(); 83 for (;;) { 84 disk_idx = Get_Next_HR_Disk(); 85+ DEBUGMSGTL(("host/hr_disk", "... index %d\n", disk_idx)); 86 if (disk_idx == -1) 87 break; 88 newname[HRDISK_ENTRY_NAME_LENGTH] = disk_idx; 89@@ -749,6 +799,12 @@ 90 HRD_history[iindex] = 0; 91 return ((HRDEV_DISK << HRDEV_TYPE_SHIFT) + iindex); 92 } 93+ DEBUGMSGTL(("host/hr_disk", 94+ "Get_Next_HR_Disk: can't query %s\n", string)); 95+ } 96+ else { 97+ DEBUGMSGTL(("host/hr_disk", 98+ "Get_Next_HR_Disk: can't open %s\n", string)); 99 } 100 HRD_history[iindex] = now; 101 HRD_index++; 102@@ -801,6 +857,55 @@ 103 return 0; 104 } 105 106+#ifdef darwin 107+int 108+Get_HR_Disk_Label(char *string, size_t str_len, const char *devfull) 109+{ 110+ io_service_t disk; 111+ const char *name; 112+ CFDictionaryRef desc; 113+ 114+ DEBUGMSGTL(("host/hr_disk", "Disk Label type %s\n", devfull)); 115+ 116+ if (strncmp(devfull, _PATH_DEV, strlen(_PATH_DEV))) { 117+ snmp_log(LOG_ERR, 118+ "diskmgr: devfull matches _PATH_DEV for %s, skipping\n", 119+ devfull); 120+ return -1; 121+ } 122+ 123+ disk = IOServiceGetMatchingService(kIOMasterPortDefault, IOBSDNameMatching(kIOMasterPortDefault, 0, devfull + strlen(_PATH_DEV))); 124+ if (MACH_PORT_NULL == disk) { 125+ strlcpy(string, devfull, str_len); 126+ return -1; 127+ } 128+ 129+ /** model */ 130+ desc = (CFDictionaryRef) 131+ IORegistryEntrySearchCFProperty(disk, kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kIORegistryIterateParents | kIORegistryIterateRecursively); 132+ if (desc) { 133+ CFStringRef str_ref; 134+ CFStringEncoding sys_encoding = CFStringGetSystemEncoding(); 135+ str_ref = (CFStringRef) 136+ CFDictionaryGetValue(desc, CFSTR(kIOPropertyProductNameKey)); 137+ if (str_ref) { 138+ name = 139+ CFStringGetCStringPtr(str_ref, sys_encoding); 140+ strlcpy(HRD_model, name, sizeof(HRD_model)); 141+ DEBUGMSGTL(("verbose:diskmgr:darwin", " model %s\n", HRD_model)); 142+ } 143+ CFRelease(desc); 144+ } 145+ else { 146+ strlcpy(string, devfull, str_len); 147+ } 148+ 149+ IOObjectRelease(disk); 150+ 151+ return 0; 152+} 153+#endif 154+ 155 static void 156 Save_HR_Disk_Specific(void) 157 { 158@@ -822,6 +927,13 @@ 159 #ifdef DIOCGDINFO 160 HRD_savedCapacity = HRD_info.d_secperunit / 2; 161 #endif 162+#ifdef darwin 163+ HRD_savedCapacity = HRD_cap / 1024; 164+ HRD_saved_access = HRD_access; 165+ HRD_saved_type = HRD_type; 166+ HRD_saved_removable = HRD_removable; 167+#endif 168+ 169 } 170 171 static void 172@@ -845,6 +957,11 @@ 173 sizeof(HRD_savedModel)-1); 174 HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0; 175 #endif 176+#ifdef darwin 177+ strncpy(HRD_savedModel, HRD_model, 178+ sizeof(HRD_savedModel)-1); 179+ HRD_savedModel[ sizeof(HRD_savedModel)-1 ] = 0; 180+#endif 181 } 182 183 static const char * 184@@ -900,6 +1017,121 @@ 185 result = ioctl(fd, DIOCGDINFO, &HRD_info); 186 #endif 187 188+#ifdef darwin 189+ io_service_t disk; 190+ const char *name; 191+ CFDictionaryRef desc; 192+ CFStringRef str_ref; 193+ CFNumberRef number_ref; 194+ CFBooleanRef bool_ref; 195+ CFStringEncoding sys_encoding = CFStringGetSystemEncoding(); 196+ 197+ if (strncmp(devfull, _PATH_DEV, strlen(_PATH_DEV))) { 198+ snmp_log(LOG_ERR, 199+ "diskmgr: devfull matches _PATH_DEV for %s, skipping\n", 200+ devfull); 201+ return -1; 202+ } 203+ 204+ disk = IOServiceGetMatchingService(kIOMasterPortDefault, IOBSDNameMatching(kIOMasterPortDefault, 0, devfull + strlen(_PATH_DEV))); 205+ if (MACH_PORT_NULL == disk) { 206+ snmp_log(LOG_ERR, 207+ "diskmgr: couldn't get matching service for %s, skipping\n", 208+ devfull); 209+ return -1; 210+ } 211+ 212+ number_ref = (CFNumberRef) 213+ IORegistryEntryCreateCFProperty(disk, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, 0); 214+ if (number_ref) { 215+ CFNumberGetValue(number_ref, kCFNumberSInt64Type, &HRD_cap); 216+ CFRelease(number_ref); 217+ } 218+ else 219+ HRD_cap = 0; 220+ DEBUGMSGTL(("verbose:diskmgr:darwin", " size %lld\n", HRD_cap)); 221+ 222+ /** writable? */ 223+ bool_ref = (CFBooleanRef) 224+ IORegistryEntryCreateCFProperty(disk, CFSTR(kIOMediaWritableKey), kCFAllocatorDefault, 0); 225+ if (bool_ref) { 226+ HRD_access = CFBooleanGetValue(bool_ref); 227+ CFRelease(bool_ref); 228+ } 229+ else 230+ HRD_access = 0; 231+ DEBUGMSGTL(("verbose:diskmgr:darwin", " writable %d\n", 232+ HRD_access)); 233+ 234+ /** removable? */ 235+ bool_ref = (CFBooleanRef) 236+ IORegistryEntryCreateCFProperty(disk, CFSTR(kIOMediaRemovableKey), kCFAllocatorDefault, 0); 237+ if (bool_ref) { 238+ HRD_removable = CFBooleanGetValue(bool_ref); 239+ CFRelease(bool_ref); 240+ } 241+ else 242+ HRD_removable = 0; 243+ DEBUGMSGTL(("verbose:diskmgr:darwin", " removable %d\n", 244+ HRD_removable)); 245+ 246+ /** get type */ 247+ str_ref = (CFStringRef) 248+ IORegistryEntryCreateCFProperty(disk, CFSTR(kIOBDMediaTypeKey), kCFAllocatorDefault, 0); 249+ if (str_ref) { 250+ HRD_type = _get_type_value(CFStringGetCStringPtr(str_ref, 251+ sys_encoding)); 252+ DEBUGMSGTL(("verbose:diskmgr:darwin", " type %s / %d\n", 253+ CFStringGetCStringPtr(str_ref, sys_encoding), 254+ HRD_type)); 255+ CFRelease(str_ref); 256+ } else { 257+ desc = (CFDictionaryRef) 258+ IORegistryEntrySearchCFProperty(disk, kIOServicePlane, CFSTR(kIOPropertyProtocolCharacteristicsKey), kCFAllocatorDefault, kIORegistryIterateParents | kIORegistryIterateRecursively); 259+ if (desc) { 260+ str_ref = (CFStringRef) 261+ CFDictionaryGetValue(desc, CFSTR(kIOPropertyPhysicalInterconnectTypeKey)); 262+ if (str_ref) { 263+ HRD_type = 264+ _get_type_from_protocol(CFStringGetCStringPtr(str_ref, 265+ sys_encoding)); 266+ DEBUGMSGTL(("verbose:diskmgr:darwin", " type %s / %d\n", 267+ CFStringGetCStringPtr(str_ref, sys_encoding), 268+ HRD_type)); 269+ } 270+ else { 271+ DEBUGMSGTL(("verbose:diskmgr:darwin", " could not get type from description '%s'\n", 272+ desc)); 273+ HRD_type = HRDISKSTORAGEMEDIA_UNKNOWN; 274+ } 275+ CFRelease(desc); 276+ } 277+ else { 278+ DEBUGMSGTL(("verbose:diskmgr:darwin", " could not get description to look up type\n")); 279+ HRD_type = HRDISKSTORAGEMEDIA_UNKNOWN; 280+ } 281+ } 282+ 283+ /** model */ 284+ desc = (CFDictionaryRef) 285+ IORegistryEntrySearchCFProperty(disk, kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kIORegistryIterateParents | kIORegistryIterateRecursively); 286+ if (desc) { 287+ str_ref = (CFStringRef) 288+ CFDictionaryGetValue(desc, CFSTR(kIOPropertyProductNameKey)); 289+ if (str_ref) { 290+ name = 291+ CFStringGetCStringPtr(str_ref, sys_encoding); 292+ strlcpy(HRD_model, name, sizeof(HRD_model)); 293+ DEBUGMSGTL(("verbose:diskmgr:darwin", " model %s\n", HRD_model)); 294+ } 295+ CFRelease(desc); 296+ } 297+ else 298+ HRD_model[0] = 0; 299+ IOObjectRelease(disk); 300+ result = 0; 301+#endif 302+ 303 return (result); 304 } 305 306@@ -918,6 +1150,11 @@ 307 return (2); /* read only */ 308 #endif 309 310+#ifdef darwin 311+ if (!HRD_access) 312+ return (2); 313+#endif 314+ 315 return (1); /* read-write */ 316 } 317 318@@ -990,6 +1227,9 @@ 319 } 320 #endif 321 322+#ifdef darwin 323+ return HRD_type; 324+#endif 325 326 return (2); /* Unknown */ 327 } 328@@ -1020,5 +1260,63 @@ 329 return (1); /* true */ 330 #endif 331 332+#ifdef darwin 333+ if (HRD_removable) 334+ return (1); 335+#endif 336+ 337 return (2); /* false */ 338 } 339+ 340+#ifdef darwin 341+typedef struct type_value_map_s { 342+ const char *type; 343+ uint32_t value; 344+} type_value_map; 345+ 346+static type_value_map media_type_map[] = { 347+ { "CD-ROM", HRDISKSTORAGEMEDIA_OPTICALDISKROM}, 348+ { "DVD-R", HRDISKSTORAGEMEDIA_OPTICALDISKWORM}, 349+ { "DVD+R", HRDISKSTORAGEMEDIA_OPTICALDISKWORM}, 350+}; 351+static int media_types = sizeof(media_type_map)/sizeof(media_type_map[0]); 352+ 353+static int 354+_get_type_value( const char *str_type ) 355+{ 356+ int i, len; 357+ 358+ if (NULL == str_type) 359+ return HRDISKSTORAGEMEDIA_UNKNOWN; 360+ 361+ len = strlen(str_type); 362+ for(i=0; i < media_types; ++i) { 363+ if (0 == strcmp(media_type_map[i].type, str_type)) 364+ return media_type_map[i].value; 365+ } 366+ 367+ return HRDISKSTORAGEMEDIA_UNKNOWN; 368+} 369+ 370+static type_value_map proto_map[] = { 371+ { "ATA", HRDISKSTORAGEMEDIA_HARDDISK}, 372+ { "ATAPI", HRDISKSTORAGEMEDIA_OPTICALDISKROM} 373+}; 374+static int proto_maps = sizeof(proto_map)/sizeof(proto_map[0]); 375+ 376+static int _get_type_from_protocol( const char *prot ) 377+{ 378+ int i, len; 379+ 380+ if (NULL == prot) 381+ return TV_FALSE; 382+ 383+ len = strlen(prot); 384+ for(i=0; i < proto_maps; ++i) { 385+ if (0 == strcmp(proto_map[i].type, prot)) 386+ return proto_map[i].value; 387+ } 388+ 389+ return HRDISKSTORAGEMEDIA_UNKNOWN; 390+} 391+#endif 392diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hr_filesys.c APPLE/agent/mibgroup/host/hr_filesys.c 393--- SVN/agent/mibgroup/host/hr_filesys.c 394+++ APPLE/agent/mibgroup/host/hr_filesys.c 395@@ -4,9 +4,13 @@ 396 */ 397 398 #include <net-snmp/net-snmp-config.h> 399+#include <net-snmp/net-snmp-includes.h> 400+#include <net-snmp/agent/net-snmp-agent-includes.h> 401+#include <net-snmp/agent/hardware/memory.h> 402 #include "host_res.h" 403 #include "hr_filesys.h" 404 #include "hr_storage.h" 405+#include "hr_disk.h" 406 #include <net-snmp/utilities.h> 407 408 #if HAVE_MNTENT_H 409@@ -535,7 +539,7 @@ var_hrfilesys(struct variable *vp, 410 long_return = 2; /* others probably aren't */ 411 return (u_char *) & long_return; 412 case HRFSYS_STOREIDX: 413- long_return = fsys_idx + HRS_TYPE_FIXED_MAX; 414+ long_return = fsys_idx + NETSNMP_MEM_TYPE_MAX; 415 return (u_char *) & long_return; 416 case HRFSYS_FULLDUMP: 417 return when_dumped(HRFS_entry->HRFS_name, FULL_DUMP, var_len); 418diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hr_partition.c APPLE/agent/mibgroup/host/hr_partition.c 419--- SVN/agent/mibgroup/host/hr_partition.c 420+++ APPLE/agent/mibgroup/host/hr_partition.c 421@@ -35,6 +35,9 @@ 422 static int HRP_savedDiskIndex; 423 static int HRP_savedPartIndex; 424 static char HRP_savedName[1024]; 425+#ifdef NETSNMP_CAN_GET_DISK_LABEL 426+static char HRP_savedLabel[1024]; 427+#endif 428 429 static int HRP_DiskIndex; 430 431@@ -135,6 +138,7 @@ header_hrpartition(struct variable *vp, 432 (name[HRPART_DISK_NAME_LENGTH] & 433 ((1 << HRDEV_TYPE_SHIFT) - 1)); 434 435+ DEBUGMSGTL(("host/hr_partition", "... low index %d\n", LowDiskIndex)); 436 while (HRP_DiskIndex < LowDiskIndex) { 437 Init_HR_Partition(); /* moves to next disk */ 438 if (HRP_DiskIndex == -1) 439@@ -144,6 +148,7 @@ header_hrpartition(struct variable *vp, 440 441 for (;;) { 442 part_idx = Get_Next_HR_Partition(); 443+ DEBUGMSGTL(("host/hr_partition", "... part index %d\n", part_idx)); 444 if (part_idx == 0) 445 break; 446 newname[HRPART_DISK_NAME_LENGTH] = 447@@ -225,8 +230,13 @@ var_hrpartition(struct variable * vp, 448 long_return = part_idx; 449 return (u_char *) & long_return; 450 case HRPART_LABEL: 451+#ifdef NETSNMP_CAN_GET_DISK_LABEL 452+ *var_len = strlen(HRP_savedLabel); 453+ return (u_char *) HRP_savedLabel; 454+#else 455 *var_len = strlen(HRP_savedName); 456 return (u_char *) HRP_savedName; 457+#endif 458 case HRPART_ID: /* Use the device number */ 459 sprintf(string, "0x%x", (int) stat_buf.st_rdev); 460 *var_len = strlen(string); 461@@ -259,9 +269,11 @@ static int HRP_index; 462 static void 463 Init_HR_Partition(void) 464 { 465+ DEBUGMSGTL(("host/hr_partition", "Init_HR_Partition\n")); 466 HRP_DiskIndex = Get_Next_HR_Disk(); 467 if (HRP_DiskIndex != -1) 468 HRP_DiskIndex &= ((1 << HRDEV_TYPE_SHIFT) - 1); 469+ DEBUGMSGTL(("host/hr_partition", "... %d\n",HRP_DiskIndex)); 470 471 HRP_index = -1; 472 } 473@@ -272,6 +284,7 @@ Get_Next_HR_Partition(void) 474 char string[1024]; 475 int fd; 476 477+ DEBUGMSGTL(("host/hr_partition", "Get_Next_HR_Partition %d\n",HRP_DiskIndex)); 478 if (HRP_DiskIndex == -1) { 479 return 0; 480 } 481@@ -309,4 +322,7 @@ Save_HR_Partition(int disk_idx, int part 482 HRP_savedDiskIndex = disk_idx; 483 HRP_savedPartIndex = part_idx; 484 (void) Get_Next_HR_Disk_Partition(HRP_savedName, sizeof(HRP_savedName), HRP_index); 485+#ifdef NETSNMP_CAN_GET_DISK_LABEL 486+ (void) Get_HR_Disk_Label(HRP_savedLabel, sizeof(HRP_savedLabel), HRP_savedName); 487+#endif 488 } 489diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hr_partition.h APPLE/agent/mibgroup/host/hr_partition.h 490