home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sun / hardware / 3455 < prev    next >
Encoding:
Text File  |  1992-07-21  |  2.2 KB  |  71 lines

  1. Xref: sparky comp.sys.sun.hardware:3455 comp.sys.sun.misc:3264
  2. Newsgroups: comp.sys.sun.hardware,comp.sys.sun.misc
  3. Path: sparky!uunet!island!coney!hue
  4. From: hue@island.COM (Pond Scum)
  5. Subject: Re: Better format program
  6. Message-ID: <hue.711742829@coney>
  7. Sender: usenet@island.COM (The Usenet mail target)
  8. Organization: Island Graphics Corp.
  9. References: <1992Jul20.083045.8775@newsroom.bsc.no>
  10. Date: Tue, 21 Jul 1992 18:20:29 GMT
  11. Lines: 58
  12.  
  13. md@bsc.no (Mark Dapoz) writes:
  14. >Does anyone know if there's available somewhere a format program for SCSI
  15. >disks which is a little more flexible than the one provided by SunOS?  I
  16. >have a rather peculiar SCSI drive that needs to have some unique pages
  17. >set up via the Mode Select command before doing the format.  The SunOS
  18.  
  19. There is a company that sells a formatting program, but I don't know if it
  20. would allow you to do what you need to do.  They have ads in the Sun rags.
  21.  
  22. >for such a program would be appreciated.  Alternative if someone could
  23. >provide enough detail on how to talk directly to the scsi device driver
  24.  
  25. This code uses an ioctl to read block 0 off of a SCSI disk.  You should be
  26. able to use the same ioctl to do the mode selects (I think).  I once read
  27. that the sd driver supports the uscsi.h ioctls, but I've never tried it so
  28. I can't say whether or not it works.  If it does, it would probably be a
  29. better way to go.  Remember, if you are opening an unlabeled or unformatted
  30. device, or in the O_NDELAY flag into the open(), otherwise the open will
  31. fail.
  32.  
  33. -Jonathan        hue@island.COM
  34.  
  35. ------------------------------------------------------------------------------
  36.  
  37. #include <fcntl.h>
  38. #include <sun/dkio.h>
  39. #include <scsi/generic/commands.h>
  40. #include <errno.h>
  41. #include <stdio.h>
  42.  
  43. char buf[512];
  44.  
  45. main()
  46. {
  47.     int fd;
  48.     static struct dk_cmd rcmd =
  49.     {
  50.         SCMD_READ, DK_DIAGNOSE, 0, 0, 0, 0
  51.     };
  52.  
  53.  
  54.     if ((fd = open("/dev/rsd3c", O_NDELAY)) < 0)
  55.     {
  56.     perror("open");
  57.     exit(1);
  58.     }
  59.     rcmd.dkc_blkno = 0;
  60.     rcmd.dkc_secnt = 1;
  61.     rcmd.dkc_bufaddr = buf;
  62.     rcmd.dkc_buflen = sizeof(buf);
  63.     if (ioctl(fd, DKIOCSCMD, &rcmd) < 0)
  64.     {
  65.     perror("ioctl");
  66.     exit(2);
  67.     }
  68.     write(fileno(stdout), buf, sizeof(buf));
  69.     exit(0);
  70. }
  71.