home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1035 / wn.man < prev   
Text File  |  1990-12-28  |  2KB  |  93 lines

  1. wn(7) ioctls
  2.  
  3.  
  4. EXAMPLE
  5. main()
  6. {
  7.     int fd;
  8.     char dummyblock[512], mbb[512];
  9.  
  10.     if ((fd = open("/dev/dsk/0s0", O_RDWR)) == -1) {
  11.         fprintf(stderr, "Can't open drive, errno=%d\n", errno);
  12.         exit(errno);
  13.     }
  14.  
  15.     /*
  16.     **    WHY is this needed???
  17.     */
  18.  
  19.     read(fd,dummyblock,512);    /* dummy read to force wnsweep */
  20.  
  21.     read_sector( fd, mbb, 0, 0, 1 );    /* read Master Boot Block */
  22.  
  23.     /* user code to modify it ... */
  24.  
  25.     write_sector( fd, mbb, 0, 0, 1 );    /* and write it back */
  26.  
  27.     close( fd );
  28. }
  29.  
  30.  
  31. read_sector(fd, buf, cyl, head, sector)
  32. dev_t fd;
  33. byte *buf,head,sector;
  34. int cyl;
  35. {
  36.     int i;
  37.     struct i1010iopb *io, iopb;
  38.  
  39.     io = &iopb;
  40.     io->i_addr = (long) buf;
  41.     io->i_actcylinder = cyl;
  42.     io->i_acthead = head;
  43.     io->i_sector = sector;
  44.     io->i_funct = WD_READ_OP;
  45.     i = ioctl(fd,I1010_RAWIO,io);
  46.     if (i)
  47.         fprintf(stderr, "\nread_sector(C=%d, H=%d, S=%d) errno= %d\n",
  48.                     cyl, head, sector, i);
  49.     return(i);
  50. }
  51.  
  52. write_sector(fd,buf,cyl,head,sector)
  53. dev_t fd;
  54. byte *buf,head,sector;
  55. int cyl;
  56. {
  57.     int i;
  58.     struct i1010iopb *io, iopb;
  59.  
  60.     io = &iopb;
  61.     io->i_addr = (long) buf;
  62.     io->i_actcylinder = cyl;
  63.     io->i_acthead = head;
  64.     io->i_sector = sector;
  65.     io->i_funct = WD_WRITE_OP;
  66.     i = ioctl(fd, I1010_RAWIO, io);
  67.     if (i)
  68.         fprintf(stderr, "\nwrite_sector(C=%d, H=%d, S=%d) errno= %d\n",
  69.                     cyl, head, sector, i);
  70.     return(i);
  71. }
  72.  
  73. raw_io(fd,buf,cyl,head,sector,op)
  74. dev_t fd;
  75. byte *buf,head,sector;
  76. int cyl,op;
  77. {
  78.     int i;
  79.     struct i1010iopb *io, iopb;
  80.  
  81.     io = &iopb;
  82.     io->i_addr = (long) buf;
  83.     io->i_actcylinder = cyl;
  84.     io->i_acthead = head;
  85.     io->i_sector = sector;
  86.     io->i_funct = op;
  87.     i = ioctl(fd, I1010_RAWIO, io);
  88.     if (i) printf("\nRaw I/O(C=%d H=%d S=%d op=%d) errno= %d\n",
  89.                   cyl, head, sector, op, i);
  90.     return(i);
  91. }
  92.  
  93.