446 char components[MAXPATHLEN];
447
448 i_hp_dprintf("hp_path: node=%p, path=%p, connection=%p\n", (void *)node,
449 (void *)path, (void *)connection);
450
451 if ((node == NULL) || (path == NULL) || (connection == NULL)) {
452 i_hp_dprintf("hp_path: invalid arguments.\n");
453 return (EINVAL);
454 }
455
456 (void) memset(path, 0, MAXPATHLEN);
457 (void) memset(connection, 0, MAXPATHLEN);
458 (void) memset(components, 0, MAXPATHLEN);
459
460 /* Set 'connection' only for connectors and ports */
461 if ((node->hp_type == HP_NODE_CONNECTOR) ||
462 (node->hp_type == HP_NODE_PORT))
463 (void) strlcpy(connection, node->hp_name, MAXPATHLEN);
464
465 /* Trace back to the root node, accumulating components */
466 for (parent = node; parent != NULL; parent = parent->hp_parent) {
467 if (parent->hp_type == HP_NODE_DEVICE) {
468 (void) strlcat(components, "/", MAXPATHLEN);
469 (void) strlcat(components, parent->hp_name, MAXPATHLEN);
470 }
471 if (parent->hp_parent == NULL)
472 root = parent;
473 }
474
475 /* Ensure the snapshot actually contains a base path */
476 if (root->hp_basepath == NULL) {
477 i_hp_dprintf("hp_path: missing base pathname.\n");
478 return (EFAULT);
479 }
480
481 /*
482 * Construct the path. Start with the base path from the root
483 * node, then append the accumulated components in reverse order.
484 */
485 if (strcmp(root->hp_basepath, "/") != 0) {
486 (void) strlcat(path, root->hp_basepath, MAXPATHLEN);
487 if ((root->hp_type == HP_NODE_DEVICE) &&
488 ((s = strrchr(path, '/')) != NULL))
489 *s = '\0';
490 }
491 for (i = strlen(components) - 1; i >= 0; i--) {
492 if (components[i] == '/') {
|
446 char components[MAXPATHLEN];
447
448 i_hp_dprintf("hp_path: node=%p, path=%p, connection=%p\n", (void *)node,
449 (void *)path, (void *)connection);
450
451 if ((node == NULL) || (path == NULL) || (connection == NULL)) {
452 i_hp_dprintf("hp_path: invalid arguments.\n");
453 return (EINVAL);
454 }
455
456 (void) memset(path, 0, MAXPATHLEN);
457 (void) memset(connection, 0, MAXPATHLEN);
458 (void) memset(components, 0, MAXPATHLEN);
459
460 /* Set 'connection' only for connectors and ports */
461 if ((node->hp_type == HP_NODE_CONNECTOR) ||
462 (node->hp_type == HP_NODE_PORT))
463 (void) strlcpy(connection, node->hp_name, MAXPATHLEN);
464
465 /* Trace back to the root node, accumulating components */
466 for (parent = node, root = parent; parent != NULL;
467 root = parent, parent = parent->hp_parent) {
468 if (parent->hp_type == HP_NODE_DEVICE) {
469 (void) strlcat(components, "/", MAXPATHLEN);
470 (void) strlcat(components, parent->hp_name, MAXPATHLEN);
471 }
472 }
473
474 /* Ensure the snapshot actually contains a base path */
475 if (root->hp_basepath == NULL) {
476 i_hp_dprintf("hp_path: missing base pathname.\n");
477 return (EFAULT);
478 }
479
480 /*
481 * Construct the path. Start with the base path from the root
482 * node, then append the accumulated components in reverse order.
483 */
484 if (strcmp(root->hp_basepath, "/") != 0) {
485 (void) strlcat(path, root->hp_basepath, MAXPATHLEN);
486 if ((root->hp_type == HP_NODE_DEVICE) &&
487 ((s = strrchr(path, '/')) != NULL))
488 *s = '\0';
489 }
490 for (i = strlen(components) - 1; i >= 0; i--) {
491 if (components[i] == '/') {
|