SCSI Pass-Through Programmer's Guide
/* that path. */
(void) io_str_to_hw_path (path_ptr, device_ptr);
if (io_errno != 0)
{
printf ("io_query - token: %x io_error: %x \n",
token,
io_errno );
exit(5);
}
/* if we're here we must have a valid device path syntax */
/* therefore io_query and io_search should work w/o major error */
/* search the tree for a node with the same path as input */
token = 0; /* start at "root" of io tree */
token = io_search ( token, S_IOTREE, 0, "hw_path", device_ptr);
/* if token is null then exit the program */
if (token == NULL)
{ printf (" io_search didn't find path matching: %s \n", path_name);
exit (6);
}
else /* get the minor number to use with mknod */
(void) io_query (token, S_IOTREE, "minor_num", &query_minor_num);
/* convert device path into a string good for a file name we can use */
/* 10/4/4.12.0 ===> 10_4_4.12.0 */
while ( *path_ptr)
{
*path_ptr = (*path_ptr == '/') ? '_' : *path_ptr ;
path_ptr++;
}
strcpy (file_name, "/dev/tm_diag_");
strcat (file_name, path_name);
printf ("%s \n", file_name);
/* start by unlink (delete/purge) any old file with same name */
/* don't care too much about results. . . */
r = unlink (file_name);
/* for tm_diag type file */
/* mknod "character special" with dev_t using lower 24 bits of port with */
/* zeroed upper byte ('major'), makedev is macro from sys/sysmacros.h */
r = mknod (file_name, S_IFCHR, makedev (0, query_minor_num));
if (r != 0)
{
printf ("mknod: Error number: %d \n", errno);
exit (7);
}
/* (else) no mknod problem */
fd = open(file_name,O_RDWR);
if (fd < 0) {
perror("open");
fprintf(stderr, "Can't open device file %s\n", file_name);
exit(3);
}
/* do an inquiry */
memset(command, 0, sizeof(struct sctl_io));
- 20 -