home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / mtools_3.6.src.lzh / MTOOLS_3.6 / devices.c < prev    next >
Text File  |  1997-11-12  |  21KB  |  912 lines

  1. /*
  2.  * This file is modified to perform on the UXP/DS operating system 
  3.  * by FUJITSU Limited on 1996.6.4
  4.  */
  5.  
  6. /*
  7.  * Device tables.  See the Configure file for a complete description.
  8.  */
  9.  
  10. #define NO_TERMIO
  11. #include "sysincludes.h"
  12. #include "msdos.h"
  13. #include "mtools.h"
  14. #include "devices.h"
  15.  
  16. #define DEF_ARG1 0, 0x2,0,0, 0, 0, 0
  17. #define DEF_ARG0 0,0,0,DEF_ARG1
  18. #define DEF_ARG 0L,DEF_ARG0
  19.  
  20. #define ED312    12,0,80,2,36,DEF_ARG /* 3 1/2 extra density */
  21. #define HD312    12,0,80,2,18,DEF_ARG /* 3 1/2 high density */
  22. #define DD312    12,0,80,2, 9,DEF_ARG /* 3 1/2 double density */
  23. #define HD514    12,0,80,2,15,DEF_ARG /* 5 1/4 high density */
  24. #define DD514    12,0,40,2, 9,DEF_ARG /* 5 1/4 double density (360k) */
  25. #define DDsmall    12,0,40,2, 8,DEF_ARG /* 5 1/4 double density (320k) */
  26. #define SS514    12,0,40,1, 9,DEF_ARG /* 5 1/4 single sided DD, (180k) */
  27. #define SSsmall    12,0,40,1, 8,DEF_ARG /* 5 1/4 single sided DD, (160k) */
  28. #define GENHD    16,0, 0,0, 0,DEF_ARG /* Generic 16 bit FAT fs */
  29. #define GENFD    12,0, 0,0, 0,DEF_ARG /* Generic 12 bit FAT fs */
  30. #define GEN         0,0, 0,0, 0,DEF_ARG /* Generic fs of any FAT bits */
  31. #define ZIPJAZ(x)     0,x, 0,0, 0,0L,4,0,0,DEF_ARG1 /* Zip or Jaz disks */
  32. #define RZIPJAZ(x)     0,x, 0,0, 0,0L,4,1,1,DEF_ARG1 /* Zip or Jaz disks */
  33.  
  34. static int compare_geom(struct device *dev, struct device *orig_dev)
  35. {
  36.     if(!orig_dev || !orig_dev->tracks || !dev || !dev->tracks)
  37.         return 0; /* no original device. This is ok */
  38.     return(orig_dev->tracks != dev->tracks ||
  39.            orig_dev->heads != dev->heads ||
  40.            orig_dev->sectors  != dev->sectors);
  41. }
  42.  
  43. #define devices const_devices
  44.  
  45.  
  46. #ifdef aux
  47. #define predefined_devices
  48. struct device devices[] = {
  49.    {"/dev/floppy0", 'A', GENFD },
  50.    {"/dev/rdsk/c104d0s31", 'J', ZIPJAZ(O_EXCL) },
  51.    {"/dev/rdsk/c105d0s31", 'Z', ZIPJAZ(O_EXCL) }
  52. };
  53. #define INIT_NOOP
  54. #endif /* aux */
  55.  
  56.  
  57. #ifdef lynxos
  58. #define predefined_devices
  59. struct device devices[] = {
  60.     {"/dev/fd1440.0",     'A', HD312 },
  61. };
  62. #define INIT_NOOP
  63. #endif
  64.  
  65.  
  66. #ifdef __BEOS__
  67. #define predefined_devices
  68. struct device devices[] = {
  69.     {"/dev/floppy_disk",     'A', HD312 },
  70. };
  71. #define INIT_NOOP
  72. #endif /* BEBOX */
  73.  
  74.  
  75. #ifdef hpux
  76. #include <sys/floppy.h>
  77. #undef SSIZE
  78.  
  79. #define predefined_devices
  80. struct device devices[] = {
  81. #ifdef hpux10
  82. /* hpux10 uses different device names according to Frank Maritato
  83.  * <frank@math.hmc.edu> */
  84.     {"/dev/floppy/c0t0d0",        'A', HD312 },
  85.     {"/dev/floppy/c0t0d1",        'B', HD312 }, /* guessed by me */
  86.      {"/dev/rscsi",            'C', GENHD }, /* guessed by me */
  87. #else
  88. /* Use rfloppy, according to Simao Campos <simao@iris.ctd.comsat.com> */
  89.     {"/dev/rfloppy/c201d0s0",    'A', HD312 },
  90.     {"/dev/rfloppy/c20Ad0s0",     'A', HD312 },
  91.      {"/dev/rfloppy/c201d1s0",    'B', HD312 },
  92.      {"/dev/rfloppy/c20Ad1s0",    'B', HD312 },
  93.      {"/dev/rscsi",            'C', GENHD },
  94. #endif
  95.     {"/dev/rdsk/c201d4",        'J', ZIPJAZ(O_EXCL) },
  96.     {"/dev/rdsk/c201d4s0",        'J', ZIPJAZ(O_EXCL) },
  97.     {"/dev/rdsk/c201d5",        'Z', ZIPJAZ(O_EXCL) },
  98.     {"/dev/rdsk/c201d5s0",        'Z', ZIPJAZ(O_EXCL) },
  99. };
  100. #ifdef hpux9
  101. /* geometry setting ioctl's contributed by Paolo Zeppegno
  102.  * <paolo@to.sem.it>, may cause "Not a typewriter" messages on other
  103.  * versions according to support@vital.com */
  104.  
  105. struct generic_floppy_struct
  106. {
  107.   struct floppy_geometry fg;
  108. };
  109.  
  110. #define BLOCK_MAJOR 24
  111. #define CHAR_MAJOR 112
  112.  
  113. static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
  114. {
  115.     if (ioctl(fd, FLOPPY_GET_GEOMETRY, &(floppy->fg)) != 0) {
  116.         perror("FLOPPY_GET_GEOMETRY");
  117.         return(1);
  118.     }
  119.     
  120.     return 0;
  121. }
  122.  
  123. #define TRACKS(floppy) floppy.fg.tracks
  124. #define HEADS(floppy) floppy.fg.heads
  125. #define SECTORS(floppy) floppy.fg.sectors
  126. #define FD_SECTSIZE(floppy) floppy.fg.sector_size
  127. #define FD_SET_SECTSIZE(floppy,v) { floppy.fg.sector_size = v; }
  128.  
  129. static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, 
  130.                  struct stat *buf)
  131. {
  132.     if (ioctl(fd, FLOPPY_SET_GEOMETRY, &(floppy->fg)) != 0) {
  133.         perror("");
  134.         return(1);
  135.     }
  136.     
  137.     return 0;
  138. }
  139. #define INIT_GENERIC
  140. #else
  141. #define INIT_NOOP
  142. #endif
  143.  
  144. #endif /* hpux */
  145.  
  146.  
  147. #if (defined(sinix) || defined(sni) || defined(SNI))
  148. #define predefined_devices
  149. struct device devices[] = {
  150. #ifdef mips     /* for Siemens Nixdorf's  SINIX-N/O (mips) 5.4x SVR4 */
  151.     { "/dev/at/flp/f0t",    'A', HD312},
  152.     { "/dev/fd0",           'A', GENFD},
  153. #else
  154. #ifdef i386     /* for Siemens Nixdorf's  SINIX-D/L (intel) 5.4x SVR4 */
  155.     { "/dev/fd0135ds18",    'A', HD312},
  156.     { "/dev/fd0135ds9",    'A', DD312},
  157.     { "/dev/fd0",        'A', GENFD},
  158.     { "/dev/fd1135ds15",    'B', HD514},
  159.     { "/dev/fd1135ds9",    'B', DD514},
  160.     { "/dev/fd1",        'B', GENFD},
  161. #endif /*i386*/
  162. #endif /*mips*/
  163. };
  164. #define INIT_NOOP
  165. #endif
  166.  
  167. #ifdef ultrix
  168. #define predefined_devices
  169. struct device devices[] = {
  170.     {"/dev/rfd0a",        'A', GENFD}, /* guessed */
  171.     {"/dev/rfd0c",        'A', GENFD}, /* guessed */
  172. };
  173.  
  174. #define INIT_NOOP
  175. #endif
  176.  
  177.  
  178. #ifdef isc
  179. #define predefined_devices
  180. #if (defined(isc2) && defined(OLDSTUFF))
  181. struct device devices[] = {
  182.     {"/dev/rdsk/f0d9dt",       'A', DD514},
  183.     {"/dev/rdsk/f0q15dt",    'A', HD514},
  184.     {"/dev/rdsk/f0d8dt",    'A', DDsmall},
  185.     {"/dev/rdsk/f13ht",    'B', HD312},
  186.     {"/dev/rdsk/f13dt",    'B', DD312},
  187.     {"/dev/rdsk/0p1",    'C', GENHD},
  188.     {"/usr/vpix/defaults/C:",'D',12, 0, 0, 0, 0,8704L,DEF_ARG0},
  189.     {"$HOME/vpix/C:",     'E', 12, 0, 0, 0, 0,8704L,DEF_ARG},
  190. };
  191. #define INIT_NOOP
  192. #else
  193. /* contributed by larry.jones@sdrc.com (Larry Jones) */
  194. struct device devices[] = {
  195.     {"/dev/rfd0",        'A', GEN},
  196.     {"/dev/rfd1",        'B', GEN},
  197.     {"/dev/rdsk/0p1",    'C', GEN},
  198.     {"/usr/vpix/defaults/C:",'D', GEN, 1},
  199.     {"$HOME/vpix/C:",     'E', GEN, 1}
  200. };
  201.  
  202. #include <sys/vtoc.h>
  203. #include <sys/sysmacros.h>
  204. #undef SSIZE
  205. #define BLOCK_MAJOR 1
  206. #define CHAR_MAJOR  1
  207. #define generic_floppy_struct disk_parms
  208. int ioctl(int, int, void *);
  209.  
  210. static int get_parameters(int fd, struct generic_floppy_struct *floppy)
  211. {
  212.     off_t off;
  213.     char buf[512];
  214.  
  215.     off = lseek(fd, 0, SEEK_CUR);
  216.     if (off == 0) {
  217.         /* need to read at least 1 sector to get correct info */
  218.         read(fd, buf, sizeof buf);
  219.         lseek(fd, 0, SEEK_SET);
  220.     }
  221.     return ioctl(fd, V_GETPARMS, floppy);
  222. }
  223.  
  224. #define TRACKS(floppy)  (floppy).dp_cyls
  225. #define HEADS(floppy)   (floppy).dp_heads
  226. #define SECTORS(floppy) (floppy).dp_sectors
  227. #define FD_SECTSIZE(floppy) (floppy).dp_secsiz
  228. #define FD_SET_SECTSIZE(floppy,v) { (floppy).dp_secsiz = (v); }
  229.  
  230. static int set_parameters(int fd, struct generic_floppy_struct *floppy,
  231.     struct stat *buf)
  232. {
  233.     return 1;
  234. }
  235.  
  236. #define INIT_GENERIC
  237. #endif
  238. #endif /* isc */
  239.  
  240. #ifdef i370
  241. #define predefined_devices
  242. struct device devices[] = {
  243.     {"/dev/rfd0", 'A', GENFD},
  244. };
  245. #define INIT_NOOP
  246. #endif /* i370 */
  247.  
  248. #ifdef aix
  249. /* modified by Federico Bianchi */
  250. #define predefined_devices
  251. struct device devices[] = {
  252.   {"/dev/fd0",'A',GENFD},
  253. };
  254. #define INIT_NOOP
  255. #endif /* aix */
  256.  
  257.   
  258. #ifdef osf4
  259. /* modified by Chris Samuel <chris@rivers.dra.hmg.gb> */
  260. #define predefined_devices
  261. struct device devices[] = {
  262.   {"/dev/fd0c",'A',GENFD},
  263. };
  264. #define INIT_NOOP
  265. #endif /* osf4 */
  266.  
  267. #ifdef solaris
  268. #define predefined_devices
  269. struct device devices[] = {
  270. #ifdef    USING_VOLD
  271.     {"/vol/dev/aliases/floppy0", 'A', GENFD},
  272.     {"/dev/rdiskette", 'B', GENFD},
  273. #else    /* ! USING_VOLD */
  274.     {"/dev/rdiskette", 'A', GENFD},
  275.     {"/vol/dev/aliases/floppy0", 'B', GENFD},
  276.  
  277. #endif    /* USING_VOLD */
  278.     {"/dev/rdsk/c0t4d0s2", 'J', RZIPJAZ(O_NDELAY)},
  279.     {"/dev/rdsk/c0t5d0s2", 'Z', RZIPJAZ(O_NDELAY)},
  280. };
  281. #define INIT_NOOP
  282. #endif /* solaris */
  283.  
  284. #ifdef sunos3
  285. #define predefined_devices
  286. struct device devices[] = {
  287.     {"/dev/rfdl0c",    'A', DD312},
  288.     {"/dev/rfd0c",    'A', HD312},
  289. };
  290. #define INIT_NOOP
  291. #endif /* sunos3 */
  292.  
  293. #ifdef xenix
  294. #define predefined_devices
  295. struct device devices[] = {
  296.     {"/dev/fd096ds15",    'A', HD514},
  297.     {"/dev/fd048ds9",    'A', DD514},
  298.     {"/dev/fd1135ds18",    'B', HD312},
  299.     {"/dev/fd1135ds9",    'B', DD312},
  300.     {"/dev/hd0d",        'C', GENHD},
  301. };
  302. #define INIT_NOOP
  303. #endif /* xenix */
  304.  
  305. #ifdef sco
  306. #define predefined_devices
  307. struct device devices[] = {
  308.     { "/dev/fd0135ds18",    'A', HD312},
  309.     { "/dev/fd0135ds9",    'A', DD312},
  310.     { "/dev/fd0",        'A', GENFD},
  311.     { "/dev/fd1135ds15",    'B', HD514},
  312.     { "/dev/fd1135ds9",    'B', DD514},
  313.     { "/dev/fd1",        'B', GENFD},
  314.     { "/dev/hd0d",        'C', GENHD},
  315. };
  316. #define INIT_NOOP
  317. #endif /* sco */
  318.  
  319.  
  320. #ifdef irix
  321. #define predefined_devices
  322. struct device devices[] = {
  323.   { "/dev/rdsk/fds0d2.3.5hi",    'A', HD312},
  324.   { "/dev/rdsk/fds0d2.3.5",    'A', DD312},
  325.   { "/dev/rdsk/fds0d2.96",    'A', HD514},
  326.   {"/dev/rdsk/fds0d2.48",    'A', DD514},
  327. };
  328. #define INIT_NOOP
  329. #endif /* irix */
  330.  
  331.  
  332. #ifdef sunos4
  333. #include <sys/ioctl.h>
  334. #include <sun/dkio.h>
  335.  
  336. #define predefined_devices
  337. struct device devices[] = {
  338.     {"/dev/rfd0c",    'A', GENFD},
  339.     {"/dev/rsd4c",    'J', RZIPJAZ(O_NDELAY)},
  340.     {"/dev/rsd5c",    'Z', RZIPJAZ(O_NDELAY)},
  341. };
  342.  
  343. /*
  344.  * Stuffing back the floppy parameters into the driver allows for gems
  345.  * like 10 sector or single sided floppies from Atari ST systems.
  346.  * 
  347.  * Martin Schulz, Universite de Moncton, N.B., Canada, March 11, 1991.
  348.  */
  349.  
  350. #define INIT_GENERIC
  351.  
  352. struct generic_floppy_struct
  353. {
  354.   struct fdk_char dkbuf;
  355.   struct dk_map dkmap;
  356. };
  357.  
  358. #define BLOCK_MAJOR 16
  359. #define CHAR_MAJOR 54
  360.  
  361. static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
  362. {
  363.     if (ioctl(fd, DKIOCGPART, &(floppy->dkmap)) != 0) {
  364.         perror("DKIOCGPART");
  365.         ioctl(fd, FDKEJECT, NULL);
  366.         return(1);
  367.     }
  368.     
  369.     if (ioctl(fd, FDKIOGCHAR, &( floppy->dkbuf)) != 0) {
  370.         perror("");
  371.         ioctl(fd, FDKEJECT, NULL);
  372.         return(1);
  373.     }
  374.     return 0;
  375. }
  376.  
  377. #define TRACKS(floppy) floppy.dkbuf.ncyl
  378. #define HEADS(floppy) floppy.dkbuf.nhead
  379. #define SECTORS(floppy) floppy.dkbuf.secptrack
  380. #define SECTORS_PER_DISK(floppy) floppy.dkmap.dkl_nblk
  381. #define FD_SECTSIZE(floppy) floppy.dkbuf.sec_size
  382. #define FD_SET_SECTSIZE(floppy,v) { floppy.dkbuf.sec_size = v; }
  383.  
  384. static inline int set_parameters(int fd, struct generic_floppy_struct *floppy, 
  385.                  struct stat *buf)
  386. {
  387.     if (ioctl(fd, FDKIOSCHAR, &(floppy->dkbuf)) != 0) {
  388.         ioctl(fd, FDKEJECT, NULL);
  389.         perror("");
  390.         return(1);
  391.     }
  392.     
  393.     if (ioctl(fd, ( unsigned int) DKIOCSPART, &(floppy->dkmap)) != 0) {
  394.         ioctl(fd, FDKEJECT, NULL);
  395.         perror("");
  396.         return(1);
  397.     }
  398.     return 0;
  399. }
  400. #define INIT_GENERIC
  401. #endif /* sparc && sunos */
  402.  
  403.  
  404. #ifdef DPX1000
  405. #define predefined_devices
  406. struct device devices[] = {
  407.     /* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
  408.     {"/dev/flbm60", 'A', HD514};
  409.     {"/dev/flbm60", 'B', DD514},
  410.     {"/dev/flbm60", 'C', DDsmall},
  411.     {"/dev/flbm60", 'D', SS},
  412.     {"/dev/flbm60", 'E', SSsmall},
  413. };
  414. #define INIT_NOOP
  415. #endif /* DPX1000 */
  416.  
  417. #ifdef bosx
  418. #define predefined_devices
  419. struct device devices[] = {
  420.     /* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
  421.     {"/dev/easyfb", 'A', HD514},
  422.     {"/dev/easyfb", 'B', DD514},
  423.     {"/dev/easyfb", 'C', DDsmall},
  424.     {"/dev/easyfb", 'D', SS},
  425.     {"/dev/easyfb", 'E', SSsmall},
  426. };
  427. #define INIT_NOOP
  428. #endif /* bosx */
  429.  
  430. #ifdef linux
  431.  
  432. #include <linux/fdreg.h>
  433. #include <linux/major.h>
  434. #include <linux/fs.h>
  435.  
  436. #ifndef major
  437. #define major(x) MAJOR(x)
  438. #endif
  439.  
  440. const char *error_msg[22]={
  441. "Missing Data Address Mark",
  442. "Bad cylinder",
  443. "Scan not satisfied",
  444. "Scan equal hit",
  445. "Wrong cylinder",
  446. "CRC error in data field",
  447. "Control Mark = deleted",
  448. 0,
  449.  
  450. "Missing Address Mark",
  451. "Write Protect",
  452. "No Data - unreadable",
  453. 0,
  454. "OverRun",
  455. "CRC error in data or address",
  456. 0,
  457. "End Of Cylinder",
  458.  
  459. 0,
  460. 0,
  461. 0,
  462. "Not ready",
  463. "Equipment check error",
  464. "Seek end" };
  465.  
  466.  
  467. static inline void print_message(RawRequest_t *raw_cmd,const char *message)
  468. {
  469.     int i, code;
  470.     if(!message)
  471.         return;
  472.  
  473.     fprintf(stderr,"   ");
  474.     for (i=0; i< raw_cmd->cmd_count; i++)
  475.         fprintf(stderr,"%2.2x ", 
  476.             (int)raw_cmd->cmd[i] );
  477.     fprintf(stderr,"\n");
  478.     for (i=0; i< raw_cmd->reply_count; i++)
  479.         fprintf(stderr,"%2.2x ",
  480.             (int)raw_cmd->reply[i] );
  481.     fprintf(stderr,"\n");
  482.     code = (raw_cmd->reply[0] <<16) + 
  483.         (raw_cmd->reply[1] << 8) + 
  484.         raw_cmd->reply[2];
  485.     for(i=0; i<22; i++){
  486.         if ((code & (1 << i)) && error_msg[i])
  487.             fprintf(stderr,"%s\n",
  488.                 error_msg[i]);
  489.     }
  490. }
  491.  
  492.  
  493. /* return values:
  494.  *  -1: Fatal error, don't bother retrying.
  495.  *   0: OK
  496.  *   1: minor error, retry
  497.  */
  498.  
  499. int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message)
  500. {
  501.     if (ioctl( fd, FDRAWCMD, raw_cmd) >= 0) {
  502.         if (raw_cmd->reply_count < 7) {
  503.             fprintf(stderr,"Short reply from FDC\n");
  504.             return -1;
  505.         }        
  506.         return 0;
  507.     }
  508.  
  509.     switch(errno) {
  510.         case EBUSY:
  511.             fprintf(stderr, "FDC busy, sleeping for a second\n");
  512.             sleep(1);
  513.             return 1;
  514.         case EIO:
  515.             fprintf(stderr,"resetting controller\n");
  516.             if(ioctl(fd, FDRESET, 2)  < 0){
  517.                 perror("reset");
  518.                 return -1;
  519.             }
  520.             return 1;
  521.         default:
  522.             perror(message);
  523.             return -1;
  524.     }
  525. }
  526.  
  527.  
  528. /*
  529.  * return values
  530.  *  -1: error
  531.  *   0: OK, last sector
  532.  *   1: more raw commands follow
  533.  */
  534.  
  535. int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print)
  536. {
  537.     
  538.     if(raw_cmd->reply_count == 7) {
  539.         *bytes = (raw_cmd->reply[5] - raw_cmd->cmd[4]);
  540.         /* FIXME: over/under run */
  541.         *bytes = *bytes << (7 + raw_cmd->cmd[6]);
  542.     } else
  543.         *bytes = 0;       
  544.  
  545.     switch(raw_cmd->reply[0] & 0xc0){
  546.         case 0x40:
  547.             if ( raw_cmd->reply[1] & ST1_WP ){
  548.                 *bytes = 0;
  549.                 fprintf(stderr,
  550.                     "This disk is write protected\n");
  551.                 return -1;
  552.             }
  553.             if(!*bytes && do_print)
  554.                 print_message(raw_cmd, "");
  555.             return -1;
  556.         case 0x80:
  557.             *bytes = 0;
  558.             fprintf(stderr,
  559.                 "invalid command given\n");
  560.             return -1;
  561.         case 0xc0:
  562.             *bytes = 0;
  563.             fprintf(stderr,
  564.                 "abnormal termination caused by polling\n");
  565.             return -1;
  566.         default:
  567. #ifdef FD_RAW_MORE
  568.             if(raw_cmd->flags & FD_RAW_MORE)
  569.                 return 1;
  570. #endif
  571.             return 0;
  572.     }    
  573. }
  574.  
  575. #define predefined_devices
  576. struct device devices[] = {
  577.     {"/dev/fd0", 'A', 0, O_EXCL, 0,0, 0,DEF_ARG},
  578.     {"/dev/fd1", 'B', 0, O_EXCL, 0,0, 0,DEF_ARG},
  579.     /* we assume that the Zip or Jaz drive is the second on the SCSI bus */
  580.     {"/dev/sdb4",'J', GENHD },
  581.     {"/dev/sdb4",'Z', GENHD },
  582.     /*    {"/dev/sda4",'D', GENHD },*/
  583. };
  584.  
  585. /*
  586.  * Stuffing back the floppy parameters into the driver allows for gems
  587.  * like 21 sector or single sided floppies from Atari ST systems.
  588.  * 
  589.  * Alain Knaff, UniversitΘ Joseph Fourier, France, November 12, 1993.
  590.  */
  591.  
  592.  
  593. #define INIT_GENERIC
  594. #define generic_floppy_struct floppy_struct
  595. #define BLOCK_MAJOR 2
  596. #define SECTORS(floppy) floppy.sect
  597. #define TRACKS(floppy) floppy.track
  598. #define HEADS(floppy) floppy.head
  599. #define SECTORS_PER_DISK(floppy) floppy.size
  600. #define STRETCH(floppy) floppy.stretch
  601. #define USE_2M(floppy) ((floppy.rate & FD_2M) ? 0xff : 0x80 )
  602. #define SSIZE(floppy) ((((floppy.rate & 0x38) >> 3 ) + 2) % 8)
  603.  
  604. static inline void set_2m(struct floppy_struct *floppy, int value)
  605. {
  606.     if (value & 0x7f)
  607.         value = FD_2M;
  608.     else
  609.         value = 0;
  610.     floppy->rate = (floppy->rate & ~FD_2M) | value;       
  611. }
  612. #define SET_2M set_2m
  613.  
  614. static inline void set_ssize(struct floppy_struct *floppy, int value)
  615. {
  616.     value = (( (value & 7) + 6 ) % 8) << 3;
  617.  
  618.     floppy->rate = (floppy->rate & ~0x38) | value;    
  619. }
  620.  
  621. #define SET_SSIZE set_ssize
  622.  
  623. static inline int set_parameters(int fd, struct floppy_struct *floppy, 
  624.                  struct stat *buf)
  625. {
  626.     if ( ( MINOR(buf->st_rdev ) & 0x7f ) > 3 )
  627.         return 1;
  628.     
  629.     return ioctl(fd, FDSETPRM, floppy);
  630. }
  631.  
  632. static inline int get_parameters(int fd, struct floppy_struct *floppy)
  633. {
  634.     return ioctl(fd, FDGETPRM, floppy);
  635. }
  636.  
  637. #endif /* linux */
  638.  
  639.  
  640. /*** /jes -- for D.O.S. 486 BL DX2/80 ***/
  641. #ifdef freebsd
  642. #define predefined_devices
  643. struct device devices[] = {
  644.     {"/dev/rfd0.1440", 'A', HD312},
  645.     {"/dev/rfd0.720",  'A', DD312},
  646.     {"/dev/rfd1.1200", 'B', HD514},
  647.     {"/dev/sd0s1",     'C', GENHD},
  648. };
  649. #define INIT_NOOP
  650. #endif /* __FreeBSD__ */
  651.  
  652. /*** /jes -- for ALR 486 DX4/100 ***/
  653. #ifdef netbsd
  654. #define predefined_devices
  655. struct device devices[] = {
  656.     {"/dev/rfd0a", 'A', HD312},
  657.     {"/dev/rfd0f", 'A', DD312},
  658.     {"/dev/rfd0f", 'S', DD312},
  659.     {"/dev/rfd1a", 'B', HD514},
  660.     {"/dev/rfd1d", 'B', DD514},
  661.     {"/dev/rfd1d", 'T', DD514},
  662.     {"/dev/rwd0d", 'C', 16, 0, 0, 0, 0, 63L*512L, DEF_ARG0},
  663. };
  664. #define INIT_NOOP
  665. #endif /* NetBSD */
  666.  
  667.  
  668. #if (!defined(predefined_devices) && defined (m68000) && defined (sysv))
  669. #include <sys/gdioctl.h>
  670.  
  671. #define predefined_devices
  672. struct device devices[] = {
  673.     {"/dev/rfp020",        'A', 12,O_NDELAY,40,2, 9,DEF_ARG},
  674.     {"/usr/bin/DOS/dvd000", 'C', GENFD},
  675. };
  676.  
  677. int init_geom(int fd, struct device *dev, struct device *orig_dev,
  678.           struct stat *stat)
  679. {
  680.     struct gdctl gdbuf;
  681.  
  682.     if (ioctl(fd, GDGETA, &gdbuf) == -1) {
  683.         ioctl(fd, GDDISMNT, &gdbuf);
  684.         return 1;
  685.     }
  686.     if((dev->use_2m & 0x7f) || (dev->ssize & 0x7f))
  687.         return 1;
  688.     
  689.     SET_INT(gdbuf.params.cyls,dev->ntracks);
  690.     SET_INT(gdbuf.params.heads,dev->nheads);
  691.     SET_INT(gdbuf.params.psectrk,dev->nsect);
  692.     dev->ntracks = gdbuf.params.cyls;
  693.     dev->nheads = gdbuf.params.heads;
  694.     dev->nsect = gdbuf.params.psectrk;
  695.     dev->use_2m = 0x80;
  696.     dev->ssize = 0x82;
  697.  
  698.     gdbuf.params.pseccyl = gdbuf.params.psectrk * gdbuf.params.heads;
  699.     gdbuf.params.flags = 1;        /* disk type flag */
  700.     gdbuf.params.step = 0;        /* step rate for controller */
  701.     gdbuf.params.sectorsz = 512;    /* sector size */
  702.  
  703.     if (ioctl(fd, GDSETA, &gdbuf) < 0) {
  704.         ioctl(fd, GDDISMNT, &gdbuf);
  705.         return(1);
  706.     }
  707.     return(0);
  708. }
  709. #endif /* (defined (m68000) && defined (sysv))*/
  710.  
  711. #ifdef __alpha
  712. #ifndef osf4
  713. #ifdef __osf__
  714. #include <sys/fcntl.h>
  715. #define predefined_devices
  716. struct device devices[] = {
  717.     {"/dev/rfd0c",        'A', GENFD},
  718. };
  719. #define INIT_NOOP
  720. #endif
  721. #endif
  722. #endif
  723.  
  724. #ifdef osf
  725. #ifndef predefined_devices
  726. #define predefined_devices
  727. struct device devices[] = {
  728.   {"/dev/fd0a", 'A',  HD312 } };
  729. #define INIT_NOOP
  730. #endif
  731. #endif
  732.  
  733.  
  734. #if (!defined(predefined_devices) && defined(sysv4))
  735. #ifdef __uxp__
  736. #define predefined_devices
  737. struct device devices[] = {
  738.       {"/dev/fpd0",   'A', HD312},
  739.       {"/dev/fpd0",   'A', DD312},
  740. };
  741. #else
  742. #define predefined_devices
  743. struct device devices[] = {
  744.     {"/dev/rdsk/f1q15dt",    'B', HD514},
  745.     {"/dev/rdsk/f1d9dt",    'B', DD514},
  746.     {"/dev/rdsk/f1d8dt",    'B', DDsmall},
  747.     {"/dev/rdsk/f03ht",    'A', HD312},
  748.     {"/dev/rdsk/f03dt",    'A', DD312},
  749.     {"/dev/rdsk/dos",    'C', GENHD},
  750. };
  751. #endif
  752. #define INIT_NOOP
  753. #endif /* sysv4 */
  754.  
  755. #ifdef INIT_GENERIC
  756.  
  757. #ifndef USE_2M
  758. #define USE_2M(x) 0x80
  759. #endif
  760.  
  761. #ifndef SSIZE
  762. #define SSIZE(x) 0x82
  763. #endif
  764.  
  765. #ifndef SET_2M
  766. #define SET_2M(x,y) return -1
  767. #endif
  768.  
  769. #ifndef SET_SSIZE
  770. #define SET_SSIZE(x,y) return -1
  771. #endif
  772.  
  773. int init_geom(int fd, struct device *dev, struct device *orig_dev,
  774.           struct stat *stat)
  775. {
  776.     struct generic_floppy_struct floppy;
  777.     int change;
  778.     
  779.     /* 
  780.      * succeed if we don't have a floppy
  781.      * this is the case for dosemu floppy image files for instance
  782.      */
  783.     if (!((S_ISBLK(stat->st_mode) && major(stat->st_rdev) == BLOCK_MAJOR)
  784. #ifdef CHAR_MAJOR
  785.           || (S_ISCHR(stat->st_mode) && major(stat->st_rdev) == CHAR_MAJOR) 
  786. #endif
  787.         ))
  788.         return compare_geom(dev, orig_dev);
  789.     
  790.     /*
  791.      * We first try to get the current floppy parameters from the kernel.
  792.      * This allows us to
  793.      * 1. get the rate
  794.      * 2. skip the parameter setting if the parameters are already o.k.
  795.      */
  796.     
  797.     if (get_parameters( fd, & floppy ) )
  798.         /* 
  799.          * autodetection failure.
  800.          * This mostly occurs because of an absent or unformatted disks.
  801.          *
  802.          * It might also occur because of bizarre formats (for example 
  803.          * rate 1 on a 3 1/2 disk).
  804.  
  805.          * If this is the case, the user should do an explicit 
  806.          * setfdprm before calling mtools
  807.          *
  808.          * Another cause might be pre-existing wrong parameters. The 
  809.          * user should do an setfdprm -c to repair this situation.
  810.          *
  811.          * ...fail immediately... ( Theoretically, we could try to save
  812.          * the situation by trying out all rates, but it would be slow 
  813.          * and awkward)
  814.          */
  815.         return 1;
  816.  
  817.  
  818.     /* 
  819.      * if we have already have the correct parameters, keep them.
  820.      * the number of tracks doesn't need to match exactly, it may be bigger.
  821.      * the number of heads and sectors must match exactly, to avoid 
  822.      * miscalculation of the location of a block on the disk
  823.      */
  824.     change = 0;
  825.     if(compare(dev->sectors, SECTORS(floppy))){
  826.         SECTORS(floppy) = dev->sectors;
  827.         change = 1;
  828.     } else
  829.         dev->sectors = SECTORS(floppy);
  830.  
  831.     if(compare(dev->heads, HEADS(floppy))){
  832.         HEADS(floppy) = dev->heads;
  833.         change = 1;
  834.     } else
  835.         dev->heads = HEADS(floppy);
  836.      
  837.     if(compare(dev->tracks, TRACKS(floppy))){
  838.         TRACKS(floppy) = dev->tracks;
  839.         change = 1;
  840.     } else
  841.         dev->tracks = TRACKS(floppy);
  842.  
  843.  
  844.     if(compare(dev->use_2m, USE_2M(floppy))){
  845.         SET_2M(&floppy, dev->use_2m);
  846.         change = 1;
  847.     } else
  848.         dev->use_2m = USE_2M(floppy);
  849.     
  850.     if( ! (dev->ssize & 0x80) )
  851.         dev->ssize = 0;
  852.     if(compare(dev->ssize, SSIZE(floppy) + 128)){
  853.         SET_SSIZE(&floppy, dev->ssize);
  854.         change = 1;
  855.     } else
  856.         dev->ssize = SSIZE(floppy);
  857.  
  858.     if(!change)
  859.         /* no change, succeed */
  860.         return 0;
  861.  
  862. #ifdef SECTORS_PER_TRACK
  863.     SECTORS_PER_TRACK(floppy) = dev->sectors * dev->heads;
  864. #endif
  865.  
  866. #ifdef SECTORS_PER_DISK
  867.     SECTORS_PER_DISK(floppy) = dev->sectors * dev->heads * dev->tracks;
  868. #endif
  869.     
  870. #ifdef STRETCH
  871.     /* ... and the stretch */
  872.     if ( dev->tracks > 41 ) 
  873.         STRETCH(floppy) = 0;
  874.     else
  875.         STRETCH(floppy) = 1;
  876. #endif
  877.     
  878.     return set_parameters( fd, &floppy, stat) ;
  879. }
  880. #endif /* INIT_GENERIC */  
  881.  
  882. #ifdef INIT_NOOP
  883. int init_geom(int fd, struct device *dev, struct device *orig_dev,
  884.           struct stat *stat)
  885. {
  886.     return compare_geom(dev, orig_dev);
  887. }
  888. #endif
  889.  
  890. #ifdef predefined_devices
  891. const int nr_const_devices = sizeof(const_devices) / sizeof(*const_devices);
  892. #else
  893. int init_geom(int fd, struct device *dev, struct device *orig_dev,
  894.           struct stat *stat)
  895. {
  896.   return 0;
  897. }
  898. #ifndef _OSK
  899. struct device devices[]={
  900.     {"/dev/fd0", 'A', 0, O_EXCL, 0,0, 0,DEF_ARG},
  901.     /* to shut up Ultrix's native compiler, we can't make this empty :( */
  902. };
  903. const nr_const_devices = 0;
  904. #else
  905. struct device devices[]={
  906.     {"/pc1@", 'A', HD514},
  907.     {"/pc0@", 'B', HD312},
  908. };
  909. const nr_const_devices = 2;
  910. #endif
  911. #endif
  912.