disk.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #pragma src "/sys/src/libdisk"
  10. #pragma lib "libdisk.a"
  11. /* SCSI interface */
  12. typedef struct Scsi Scsi;
  13. struct Scsi {
  14. QLock QLock;
  15. char* inquire;
  16. int rawfd;
  17. int nchange;
  18. unsigned long changetime;
  19. };
  20. enum {
  21. Sread = 0,
  22. Swrite,
  23. Snone,
  24. };
  25. char* scsierror(int, int);
  26. int scsicmd(Scsi*, uint8_t*, int, void*, int, int);
  27. int scsi(Scsi*, uint8_t*, int, void*, int, int);
  28. Scsi* openscsi(char*);
  29. void closescsi(Scsi*);
  30. int scsiready(Scsi*);
  31. extern int scsiverbose;
  32. /* disk partition interface */
  33. typedef struct Disk Disk;
  34. struct Disk {
  35. char *prefix;
  36. char *part;
  37. int fd;
  38. int wfd;
  39. int ctlfd;
  40. int rdonly;
  41. int type;
  42. int64_t secs;
  43. int64_t secsize;
  44. int64_t size;
  45. int64_t offset; /* within larger disk, perhaps */
  46. int width; /* of disk size in bytes as decimal string */
  47. int c;
  48. int h;
  49. int s;
  50. int chssrc;
  51. };
  52. Disk* opendisk(char*, int, int);
  53. enum {
  54. Tfile = 0,
  55. Tsd,
  56. Tfloppy,
  57. Gpart = 0, /* partition info source */
  58. Gdisk,
  59. Gguess,
  60. };
  61. enum { /* SCSI command codes */
  62. ScmdTur = 0x00, /* test unit ready */
  63. ScmdRewind = 0x01, /* rezero/rewind */
  64. ScmdRsense = 0x03, /* request sense */
  65. ScmdFormat = 0x04, /* format unit */
  66. ScmdRblimits = 0x05, /* read block limits */
  67. ScmdRead = 0x08, /* read */
  68. ScmdWrite = 0x0A, /* write */
  69. ScmdSeek = 0x0B, /* seek */
  70. ScmdFmark = 0x10, /* write filemarks */
  71. ScmdSpace = 0x11, /* space forward/backward */
  72. ScmdInq = 0x12, /* inquiry */
  73. ScmdMselect6 = 0x15, /* mode select */
  74. ScmdMselect10 = 0x55, /* mode select */
  75. ScmdMsense6 = 0x1A, /* mode sense */
  76. ScmdMsense10 = 0x5A, /* mode sense */
  77. ScmdStart = 0x1B, /* start/stop unit */
  78. ScmdRcapacity = 0x25, /* read capacity */
  79. ScmdRcapacity16 = 0x9e, /* long read capacity */
  80. ScmdRformatcap = 0x23, /* read format capacity */
  81. ScmdExtread = 0x28, /* extended read (10 bytes) */
  82. ScmdRead16 = 0x88, /* long read (16 bytes) */
  83. ScmdExtwrite = 0x2A, /* extended write (10 bytes) */
  84. ScmdExtwritever = 0x2E, /* extended write and verify (10) */
  85. ScmdWrite16 = 0x8A, /* long write (16 bytes) */
  86. ScmdExtseek = 0x2B, /* extended seek */
  87. ScmdSynccache = 0x35, /* flush cache */
  88. ScmdRTOC = 0x43, /* read TOC data */
  89. ScmdRdiscinfo = 0x51, /* read disc information */
  90. ScmdRtrackinfo = 0x52, /* read track information */
  91. ScmdReserve = 0x53, /* reserve track */
  92. ScmdBlank = 0xA1, /* blank *-RW media */
  93. ScmdCDpause = 0x4B, /* pause/resume */
  94. ScmdCDstop = 0x4E, /* stop play/scan */
  95. ScmdCDplay = 0xA5, /* play audio */
  96. ScmdCDload = 0xA6, /* load/unload */
  97. ScmdCDscan = 0xBA, /* fast forward/reverse */
  98. ScmdCDstatus = 0xBD, /* mechanism status */
  99. Scmdgetconf = 0x46, /* get configuration */
  100. ScmdEInitialise = 0x07, /* initialise element status */
  101. ScmdMMove = 0xA5, /* move medium */
  102. ScmdEStatus = 0xB8, /* read element status */
  103. ScmdMExchange = 0xA6, /* exchange medium */
  104. ScmdEposition = 0x2B, /* position to element */
  105. ScmdReadDVD = 0xAD, /* read dvd structure */
  106. ScmdReportKey = 0xA4, /* read dvd key */
  107. ScmdSendKey = 0xA3, /* write dvd key */
  108. ScmdClosetracksess= 0x5B,
  109. ScmdRead12 = 0xA8,
  110. ScmdSetcdspeed = 0xBB,
  111. ScmdReadcd = 0xBE,
  112. /* vendor-specific */
  113. ScmdFwaddr = 0xE2, /* first writeable address */
  114. ScmdTreserve = 0xE4, /* reserve track */
  115. ScmdTinfo = 0xE5, /* read track info */
  116. ScmdTwrite = 0xE6, /* write track */
  117. ScmdMload = 0xE7, /* medium load/unload */
  118. ScmdFixation = 0xE9, /* fixation */
  119. };
  120. /* proto file parsing */
  121. typedef void Protoenum(char *new, char *old, Dir *d, void *a);
  122. typedef void Protowarn(char *msg, void *a);
  123. int rdproto(char*, char*, Protoenum*, Protowarn*, void*);