source: trunk/minix/commands/i386/mtools-3.9.7/devices.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 25.6 KB
Line 
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 INIT_NOOP
17
18#define DEF_ARG1(x) (x), 0x2,0,(char *)0, 0, 0
19#define DEF_ARG0(x) 0,DEF_ARG1(x)
20
21#define MDEF_ARG 0L,DEF_ARG0(MFORMAT_ONLY_FLAG)
22#define FDEF_ARG 0L,DEF_ARG0(0)
23#define VOLD_DEF_ARG 0L,DEF_ARG0(VOLD_FLAG|MFORMAT_ONLY_FLAG)
24
25#define MED312 12,0,80,2,36,0,MDEF_ARG /* 3 1/2 extra density */
26#define MHD312 12,0,80,2,18,0,MDEF_ARG /* 3 1/2 high density */
27#define MDD312 12,0,80,2, 9,0,MDEF_ARG /* 3 1/2 double density */
28#define MHD514 12,0,80,2,15,0,MDEF_ARG /* 5 1/4 high density */
29#define MDD514 12,0,40,2, 9,0,MDEF_ARG /* 5 1/4 double density (360k) */
30#define MSS514 12,0,40,1, 9,0,MDEF_ARG /* 5 1/4 single sided DD, (180k) */
31#define MDDsmall 12,0,40,2, 8,0,MDEF_ARG /* 5 1/4 double density (320k) */
32#define MSSsmall 12,0,40,1, 8,0,MDEF_ARG /* 5 1/4 single sided DD, (160k) */
33
34#define FED312 12,0,80,2,36,0,FDEF_ARG /* 3 1/2 extra density */
35#define FHD312 12,0,80,2,18,0,FDEF_ARG /* 3 1/2 high density */
36#define FDD312 12,0,80,2, 9,0,FDEF_ARG /* 3 1/2 double density */
37#define FHD514 12,0,80,2,15,0,FDEF_ARG /* 5 1/4 high density */
38#define FDD514 12,0,40,2, 9,0,FDEF_ARG /* 5 1/4 double density (360k) */
39#define FSS514 12,0,40,1, 9,0,FDEF_ARG /* 5 1/4 single sided DD, (180k) */
40#define FDDsmall 12,0,40,2, 8,0,FDEF_ARG /* 5 1/4 double density (320k) */
41#define FSSsmall 12,0,40,1, 8,0,FDEF_ARG /* 5 1/4 single sided DD, (160k) */
42
43#define GENHD 16,0, 0,0, 0,0,MDEF_ARG /* Generic 16 bit FAT fs */
44#define GENFD 12,0,80,2,18,0,MDEF_ARG /* Generic 12 bit FAT fs */
45#define VOLDFD 12,0,80,2,18,0,VOLD_DEF_ARG /* Generic 12 bit FAT fs with vold */
46#define GEN 0,0, 0,0, 0,0,MDEF_ARG /* Generic fs of any FAT bits */
47
48#define ZIPJAZ(x,c,h,s,y) 16,(x),(c),(h),(s),(s),0L, 4, \
49 DEF_ARG1((y)|MFORMAT_ONLY_FLAG) /* Jaz disks */
50
51#define JAZ(x) ZIPJAZ(x,1021, 64, 32, 0)
52#define RJAZ(x) ZIPJAZ(x,1021, 64, 32, SCSI_FLAG|PRIV_FLAG)
53#define ZIP(x) ZIPJAZ(x,96, 64, 32, 0)
54#define RZIP(x) ZIPJAZ(x,96, 64, 32, SCSI_FLAG|PRIV_FLAG)
55
56#define REMOTE {"$DISPLAY", 'X', 0,0, 0,0, 0,0,0L, DEF_ARG0(FLOPPYD_FLAG)}
57
58
59
60#if defined(INIT_GENERIC) || defined(INIT_NOOP)
61static int compare_geom(struct device *dev, struct device *orig_dev)
62{
63 if(IS_MFORMAT_ONLY(orig_dev))
64 return 0; /* geometry only for mformatting ==> ok */
65 if(!orig_dev || !orig_dev->tracks || !dev || !dev->tracks)
66 return 0; /* no original device. This is ok */
67 return(orig_dev->tracks != dev->tracks ||
68 orig_dev->heads != dev->heads ||
69 orig_dev->sectors != dev->sectors);
70}
71#endif
72
73#define devices const_devices
74
75
76#ifdef OS_aux
77#define predefined_devices
78struct device devices[] = {
79 {"/dev/floppy0", "A", GENFD },
80 {"/dev/rdsk/c104d0s31", "J", JAZ(O_EXCL) },
81 {"/dev/rdsk/c105d0s31", "Z", ZIP(O_EXCL) },
82 REMOTE
83};
84#endif /* aux */
85
86
87#ifdef OS_lynxos
88#define predefined_devices
89struct device devices[] = {
90 {"/dev/fd1440.0", "A", MHD312 },
91 REMOTE
92};
93#endif
94
95
96#ifdef __BEOS__
97#define predefined_devices
98struct device devices[] = {
99 {"/dev/disk/floppy/raw", "A", MHD312 },
100 REMOTE
101};
102#endif /* BEBOX */
103
104
105#ifdef OS_hpux
106
107#define predefined_devices
108struct device devices[] = {
109#ifdef OS_hpux10
110/* hpux10 uses different device names according to Frank Maritato
111 * <frank@math.hmc.edu> */
112 {"/dev/floppy/c0t0d0", "A", MHD312 },
113 {"/dev/floppy/c0t0d1", "B", MHD312 }, /* guessed by me */
114 {"/dev/rscsi", "C", GENHD }, /* guessed by me */
115#else
116/* Use rfloppy, according to Simao Campos <simao@iris.ctd.comsat.com> */
117 {"/dev/rfloppy/c201d0s0", "A", FHD312 },
118 {"/dev/rfloppy/c20Ad0s0", "A", FHD312 },
119 {"/dev/rfloppy/c201d1s0", "B", FHD312 },
120 {"/dev/rfloppy/c20Ad1s0", "B", FHD312 },
121 {"/dev/rscsi", "C", GENHD },
122#endif
123 {"/dev/rdsk/c201d4", "J", RJAZ(O_EXCL) },
124 {"/dev/rdsk/c201d4s0", "J", RJAZ(O_EXCL) },
125 {"/dev/rdsk/c201d5", "Z", RZIP(O_EXCL) },
126 {"/dev/rdsk/c201d5s0", "Z", RZIP(O_EXCL) },
127 REMOTE
128};
129
130#ifdef HAVE_SYS_FLOPPY
131/* geometry setting ioctl's contributed by Paolo Zeppegno
132 * <paolo@to.sem.it>, may cause "Not a typewriter" messages on other
133 * versions according to support@vital.com */
134
135#include <sys/floppy.h>
136#undef SSIZE
137
138struct generic_floppy_struct
139{
140 struct floppy_geometry fg;
141};
142
143#define BLOCK_MAJOR 24
144#define CHAR_MAJOR 112
145
146static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
147{
148 if (ioctl(fd, FLOPPY_GET_GEOMETRY, &(floppy->fg)) != 0) {
149 perror("FLOPPY_GET_GEOMETRY");
150 return(1);
151 }
152
153 return 0;
154}
155
156#define TRACKS(floppy) floppy.fg.tracks
157#define HEADS(floppy) floppy.fg.heads
158#define SECTORS(floppy) floppy.fg.sectors
159#define FD_SECTSIZE(floppy) floppy.fg.sector_size
160#define FD_SET_SECTSIZE(floppy,v) { floppy.fg.sector_size = v; }
161
162static inline int set_parameters(int fd, struct generic_floppy_struct *floppy,
163 struct stat *buf)
164{
165 if (ioctl(fd, FLOPPY_SET_GEOMETRY, &(floppy->fg)) != 0) {
166 perror("");
167 return(1);
168 }
169
170 return 0;
171}
172#define INIT_GENERIC
173#endif
174
175#endif /* hpux */
176
177
178#if (defined(OS_sinix) || defined(VENDOR_sni) || defined(SNI))
179#define predefined_devices
180struct device devices[] = {
181#ifdef CPU_mips /* for Siemens Nixdorf's SINIX-N/O (mips) 5.4x SVR4 */
182 { "/dev/at/flp/f0t", "A", FHD312},
183 { "/dev/fd0", "A", GENFD},
184#else
185#ifdef CPU_i386 /* for Siemens Nixdorf's SINIX-D/L (intel) 5.4x SVR4 */
186 { "/dev/fd0135ds18", "A", FHD312},
187 { "/dev/fd0135ds9", "A", FDD312},
188 { "/dev/fd0", "A", GENFD},
189 { "/dev/fd1135ds15", "B", FHD514},
190 { "/dev/fd1135ds9", "B", FDD514},
191 { "/dev/fd1", "B", GENFD},
192#endif /* CPU_i386 */
193#endif /*mips*/
194 REMOTE
195};
196#endif
197
198#ifdef OS_ultrix
199#define predefined_devices
200struct device devices[] = {
201 {"/dev/rfd0a", "A", GENFD}, /* guessed */
202 {"/dev/rfd0c", "A", GENFD}, /* guessed */
203 REMOTE
204};
205
206#endif
207
208
209#ifdef OS_isc
210#define predefined_devices
211#if (defined(OS_isc2) && defined(OLDSTUFF))
212struct device devices[] = {
213 {"/dev/rdsk/f0d9dt", "A", FDD514},
214 {"/dev/rdsk/f0q15dt", "A", FHD514},
215 {"/dev/rdsk/f0d8dt", "A", FDDsmall},
216 {"/dev/rdsk/f13ht", "B", FHD312},
217 {"/dev/rdsk/f13dt", "B", FDD312},
218 {"/dev/rdsk/0p1", "C", GENHD},
219 {"/usr/vpix/defaults/C:","D",12, 0, 0, 0, 0,8704L,DEF_ARG0},
220 {"$HOME/vpix/C:", "E", 12, 0, 0, 0, 0,8704L,MDEF_ARG},
221 REMOTE
222};
223#else
224/* contributed by larry.jones@sdrc.com (Larry Jones) */
225struct device devices[] = {
226 {"/dev/rfd0", "A", GEN},
227 {"/dev/rfd1", "B", GEN},
228 {"/dev/rdsk/0p1", "C", GEN},
229 {"/usr/vpix/defaults/C:","D", GEN, 1},
230 {"$HOME/vpix/C:", "E", GEN, 1},
231 REMOTE
232};
233
234#include <sys/vtoc.h>
235#include <sys/sysmacros.h>
236#undef SSIZE
237#define BLOCK_MAJOR 1
238#define CHAR_MAJOR 1
239#define generic_floppy_struct disk_parms
240int ioctl(int, int, void *);
241
242static int get_parameters(int fd, struct generic_floppy_struct *floppy)
243{
244 mt_off_t off;
245 char buf[512];
246
247 off = lseek(fd, 0, SEEK_CUR);
248 if(off < 0) {
249 perror("device seek 1");
250 exit(1);
251 }
252 if (off == 0) {
253 /* need to read at least 1 sector to get correct info */
254 read(fd, buf, sizeof buf);
255 if(lseek(fd, 0, SEEK_SET) < 0) {
256 perror("device seek 2");
257 exit(1);
258 }
259 }
260 return ioctl(fd, V_GETPARMS, floppy);
261}
262
263#define TRACKS(floppy) (floppy).dp_cyls
264#define HEADS(floppy) (floppy).dp_heads
265#define SECTORS(floppy) (floppy).dp_sectors
266#define FD_SECTSIZE(floppy) (floppy).dp_secsiz
267#define FD_SET_SECTSIZE(floppy,v) { (floppy).dp_secsiz = (v); }
268
269static int set_parameters(int fd, struct generic_floppy_struct *floppy,
270 struct stat *buf)
271{
272 return 1;
273}
274
275#define INIT_GENERIC
276#endif
277#endif /* isc */
278
279#ifdef CPU_i370
280#define predefined_devices
281struct device devices[] = {
282 {"/dev/rfd0", "A", GENFD},
283 REMOTE
284};
285#endif /* CPU_i370 */
286
287#ifdef OS_aix
288/* modified by Federico Bianchi */
289#define predefined_devices
290struct device devices[] = {
291 {"/dev/fd0","A",GENFD},
292 REMOTE
293};
294#endif /* aix */
295
296
297#ifdef OS_osf4
298/* modified by Chris Samuel <chris@rivers.dra.hmg.gb> */
299#define predefined_devices
300struct device devices[] = {
301 {"/dev/fd0c","A",GENFD},
302 REMOTE
303};
304#endif /* OS_osf4 */
305
306
307#ifdef OS_solaris
308
309#ifdef USING_NEW_VOLD
310
311char *alias_name = NULL;
312
313extern char *media_oldaliases(char *);
314extern char *media_findname(char *);
315
316char *getVoldName(struct device *dev, char *name)
317{
318 char *rname;
319
320 if(!SHOULD_USE_VOLD(dev))
321 return name;
322
323 /***
324 * Solaris specific routines to use the volume management
325 * daemon and libraries to get the correct device name...
326 ***/
327 rname = media_findname(name);
328#ifdef HAVE_MEDIA_OLDALIASES
329 if (rname == NULL) {
330 if ((alias_name = media_oldaliases(name)) != NULL)
331 rname = media_findname(alias_name);
332 }
333#endif
334 if (rname == NULL) {
335 fprintf(stderr,
336 "No such volume or no media in device: %s.\n",
337 name);
338 exit(1);
339 }
340 return rname;
341}
342#endif /* USING_NEW_VOLD */
343
344#define predefined_devices
345struct device devices[] = {
346#ifdef USING_NEW_VOLD
347 {"floppy", "A", VOLDFD },
348#elif USING_VOLD
349 {"/vol/dev/aliases/floppy0", "A", GENFD},
350 {"/dev/rdiskette", "B", GENFD},
351#else /* ! USING_VOLD */
352 {"/dev/rdiskette", "A", GENFD},
353 {"/vol/dev/aliases/floppy0", "B", GENFD},
354#endif /* USING_VOLD */
355 {"/dev/rdsk/c0t4d0s2", "J", RJAZ(O_NDELAY)},
356 {"/dev/rdsk/c0t5d0s2", "Z", RZIP(O_NDELAY)},
357 REMOTE
358};
359
360
361
362/*
363 * Ofer Licht <ofer@stat.Berkeley.EDU>, May 14, 1997.
364 */
365
366#define INIT_GENERIC
367
368#include <sys/fdio.h>
369#include <sys/mkdev.h> /* for major() */
370
371struct generic_floppy_struct
372{
373 struct fd_char fdchar;
374};
375
376#define BLOCK_MAJOR 36
377#define CHAR_MAJOR 36
378
379static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
380{
381 if (ioctl(fd, FDIOGCHAR, &(floppy->fdchar)) != 0) {
382 perror("");
383 ioctl(fd, FDEJECT, NULL);
384 return(1);
385 }
386 return 0;
387}
388
389#define TRACKS(floppy) floppy.fdchar.fdc_ncyl
390#define HEADS(floppy) floppy.fdchar.fdc_nhead
391#define SECTORS(floppy) floppy.fdchar.fdc_secptrack
392/* SECTORS_PER_DISK(floppy) not used */
393#define FD_SECTSIZE(floppy) floppy.fdchar.fdc_sec_size
394#define FD_SET_SECTSIZE(floppy,v) { floppy.fdchar.fdc_sec_size = v; }
395
396static inline int set_parameters(int fd, struct generic_floppy_struct *floppy,
397 struct stat *buf)
398{
399 if (ioctl(fd, FDIOSCHAR, &(floppy->fdchar)) != 0) {
400 ioctl(fd, FDEJECT, NULL);
401 perror("");
402 return(1);
403 }
404 return 0;
405}
406#define INIT_GENERIC
407#endif /* solaris */
408
409#ifdef OS_sunos3
410#define predefined_devices
411struct device devices[] = {
412 {"/dev/rfdl0c", "A", FDD312},
413 {"/dev/rfd0c", "A", FHD312},
414 REMOTE
415};
416#endif /* OS_sunos3 */
417
418#ifdef OS_xenix
419#define predefined_devices
420struct device devices[] = {
421 {"/dev/fd096ds15", "A", FHD514},
422 {"/dev/fd048ds9", "A", FDD514},
423 {"/dev/fd1135ds18", "B", FHD312},
424 {"/dev/fd1135ds9", "B", FDD312},
425 {"/dev/hd0d", "C", GENHD},
426 REMOTE
427};
428#endif /* OS_xenix */
429
430#ifdef OS_sco
431#define predefined_devices
432struct device devices[] = {
433 { "/dev/fd0135ds18", "A", FHD312},
434 { "/dev/fd0135ds9", "A", FDD312},
435 { "/dev/fd0", "A", GENFD},
436 { "/dev/fd1135ds15", "B", FHD514},
437 { "/dev/fd1135ds9", "B", FDD514},
438 { "/dev/fd1", "B", GENFD},
439 { "/dev/hd0d", "C", GENHD},
440 REMOTE
441};
442#endif /* OS_sco */
443
444
445#ifdef OS_irix
446#define predefined_devices
447struct device devices[] = {
448 { "/dev/rdsk/fds0d2.3.5hi", "A", FHD312},
449 { "/dev/rdsk/fds0d2.3.5", "A", FDD312},
450 { "/dev/rdsk/fds0d2.96", "A", FHD514},
451 {"/dev/rdsk/fds0d2.48", "A", FDD514},
452 REMOTE
453};
454#endif /* OS_irix */
455
456
457#ifdef OS_sunos4
458#include <sys/ioctl.h>
459#include <sun/dkio.h>
460
461#define predefined_devices
462struct device devices[] = {
463 {"/dev/rfd0c", "A", GENFD},
464 {"/dev/rsd4c", "J", RJAZ(O_NDELAY)},
465 {"/dev/rsd5c", "Z", RZIP(O_NDELAY)},
466 REMOTE
467};
468
469/*
470 * Stuffing back the floppy parameters into the driver allows for gems
471 * like 10 sector or single sided floppies from Atari ST systems.
472 *
473 * Martin Schulz, Universite de Moncton, N.B., Canada, March 11, 1991.
474 */
475
476#define INIT_GENERIC
477
478struct generic_floppy_struct
479{
480 struct fdk_char dkbuf;
481 struct dk_map dkmap;
482};
483
484#define BLOCK_MAJOR 16
485#define CHAR_MAJOR 54
486
487static inline int get_parameters(int fd, struct generic_floppy_struct *floppy)
488{
489 if (ioctl(fd, DKIOCGPART, &(floppy->dkmap)) != 0) {
490 perror("DKIOCGPART");
491 ioctl(fd, FDKEJECT, NULL);
492 return(1);
493 }
494
495 if (ioctl(fd, FDKIOGCHAR, &( floppy->dkbuf)) != 0) {
496 perror("");
497 ioctl(fd, FDKEJECT, NULL);
498 return(1);
499 }
500 return 0;
501}
502
503#define TRACKS(floppy) floppy.dkbuf.ncyl
504#define HEADS(floppy) floppy.dkbuf.nhead
505#define SECTORS(floppy) floppy.dkbuf.secptrack
506#define SECTORS_PER_DISK(floppy) floppy.dkmap.dkl_nblk
507#define FD_SECTSIZE(floppy) floppy.dkbuf.sec_size
508#define FD_SET_SECTSIZE(floppy,v) { floppy.dkbuf.sec_size = v; }
509
510static inline int set_parameters(int fd, struct generic_floppy_struct *floppy,
511 struct stat *buf)
512{
513 if (ioctl(fd, FDKIOSCHAR, &(floppy->dkbuf)) != 0) {
514 ioctl(fd, FDKEJECT, NULL);
515 perror("");
516 return(1);
517 }
518
519 if (ioctl(fd, ( unsigned int) DKIOCSPART, &(floppy->dkmap)) != 0) {
520 ioctl(fd, FDKEJECT, NULL);
521 perror("");
522 return(1);
523 }
524 return 0;
525}
526#define INIT_GENERIC
527#endif /* sparc && sunos */
528
529
530#ifdef DPX1000
531#define predefined_devices
532struct device devices[] = {
533 /* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
534 {"/dev/flbm60", "A", MHD514};
535 {"/dev/flbm60", "B", MDD514},
536 {"/dev/flbm60", "C", MDDsmall},
537 {"/dev/flbm60", "D", MSS},
538 {"/dev/flbm60", "E", MSSsmall},
539 REMOTE
540};
541#endif /* DPX1000 */
542
543#ifdef OS_bosx
544#define predefined_devices
545struct device devices[] = {
546 /* [block device]: DPX1000 has /dev/flbm60, DPX2 has /dev/easyfb */
547 {"/dev/easyfb", "A", MHD514},
548 {"/dev/easyfb", "B", MDD514},
549 {"/dev/easyfb", "C", MDDsmall},
550 {"/dev/easyfb", "D", MSS},
551 {"/dev/easyfb", "E", MSSsmall},
552 REMOTE
553};
554#endif /* OS_bosx */
555
556#ifdef OS_linux
557
558const char *error_msg[22]={
559"Missing Data Address Mark",
560"Bad cylinder",
561"Scan not satisfied",
562"Scan equal hit",
563"Wrong cylinder",
564"CRC error in data field",
565"Control Mark = deleted",
5660,
567
568"Missing Address Mark",
569"Write Protect",
570"No Data - unreadable",
5710,
572"OverRun",
573"CRC error in data or address",
5740,
575"End Of Cylinder",
576
5770,
5780,
5790,
580"Not ready",
581"Equipment check error",
582"Seek end" };
583
584
585static inline void print_message(RawRequest_t *raw_cmd,const char *message)
586{
587 int i, code;
588 if(!message)
589 return;
590
591 fprintf(stderr," ");
592 for (i=0; i< raw_cmd->cmd_count; i++)
593 fprintf(stderr,"%2.2x ",
594 (int)raw_cmd->cmd[i] );
595 fprintf(stderr,"\n");
596 for (i=0; i< raw_cmd->reply_count; i++)
597 fprintf(stderr,"%2.2x ",
598 (int)raw_cmd->reply[i] );
599 fprintf(stderr,"\n");
600 code = (raw_cmd->reply[0] <<16) +
601 (raw_cmd->reply[1] << 8) +
602 raw_cmd->reply[2];
603 for(i=0; i<22; i++){
604 if ((code & (1 << i)) && error_msg[i])
605 fprintf(stderr,"%s\n",
606 error_msg[i]);
607 }
608}
609
610
611/* return values:
612 * -1: Fatal error, don't bother retrying.
613 * 0: OK
614 * 1: minor error, retry
615 */
616
617int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message)
618{
619 if (ioctl( fd, FDRAWCMD, raw_cmd) >= 0) {
620 if (raw_cmd->reply_count < 7) {
621 fprintf(stderr,"Short reply from FDC\n");
622 return -1;
623 }
624 return 0;
625 }
626
627 switch(errno) {
628 case EBUSY:
629 fprintf(stderr, "FDC busy, sleeping for a second\n");
630 sleep(1);
631 return 1;
632 case EIO:
633 fprintf(stderr,"resetting controller\n");
634 if(ioctl(fd, FDRESET, 2) < 0){
635 perror("reset");
636 return -1;
637 }
638 return 1;
639 default:
640 perror(message);
641 return -1;
642 }
643}
644
645
646/*
647 * return values
648 * -1: error
649 * 0: OK, last sector
650 * 1: more raw commands follow
651 */
652
653int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print)
654{
655
656 if(raw_cmd->reply_count == 7) {
657 int end;
658
659 if (raw_cmd->reply[3] != raw_cmd->cmd[2]) {
660 /* end of cylinder */
661 end = raw_cmd->cmd[6] + 1;
662 } else {
663 end = raw_cmd->reply[5];
664 }
665
666 *bytes = end - raw_cmd->cmd[4];
667 /* FIXME: over/under run */
668 *bytes = *bytes << (7 + raw_cmd->cmd[5]);
669 } else
670 *bytes = 0;
671
672 switch(raw_cmd->reply[0] & 0xc0){
673 case 0x40:
674 if ((raw_cmd->reply[0] & 0x38) == 0 &&
675 (raw_cmd->reply[1]) == 0x80 &&
676 (raw_cmd->reply[2]) == 0) {
677 *bytes += 1 << (7 + raw_cmd->cmd[5]);
678 break;
679 }
680
681 if ( raw_cmd->reply[1] & ST1_WP ){
682 *bytes = 0;
683 fprintf(stderr,
684 "This disk is write protected\n");
685 return -1;
686 }
687 if(!*bytes && do_print)
688 print_message(raw_cmd, "");
689 return -1;
690 case 0x80:
691 *bytes = 0;
692 fprintf(stderr,
693 "invalid command given\n");
694 return -1;
695 case 0xc0:
696 *bytes = 0;
697 fprintf(stderr,
698 "abnormal termination caused by polling\n");
699 return -1;
700 default:
701 break;
702 }
703#ifdef FD_RAW_MORE
704 if(raw_cmd->flags & FD_RAW_MORE)
705 return 1;
706#endif
707 return 0;
708}
709
710#define predefined_devices
711struct device devices[] = {
712 {"/dev/fd0", "A", 0, O_EXCL, 80,2, 18,0, MDEF_ARG},
713 {"/dev/fd1", "B", 0, O_EXCL, 0,0, 0,0, FDEF_ARG},
714 /* we assume that the Zip or Jaz drive is the second on the SCSI bus */
715 {"/dev/sdb4","J", GENHD },
716 {"/dev/sdb4","Z", GENHD },
717 /* {"/dev/sda4","D", GENHD },*/
718 REMOTE
719};
720
721/*
722 * Stuffing back the floppy parameters into the driver allows for gems
723 * like 21 sector or single sided floppies from Atari ST systems.
724 *
725 * Alain Knaff, Université Joseph Fourier, France, November 12, 1993.
726 */
727
728
729#define INIT_GENERIC
730#define generic_floppy_struct floppy_struct
731#define BLOCK_MAJOR 2
732#define SECTORS(floppy) floppy.sect
733#define TRACKS(floppy) floppy.track
734#define HEADS(floppy) floppy.head
735#define SECTORS_PER_DISK(floppy) floppy.size
736#define STRETCH(floppy) floppy.stretch
737#define USE_2M(floppy) ((floppy.rate & FD_2M) ? 0xff : 0x80 )
738#define SSIZE(floppy) ((((floppy.rate & 0x38) >> 3 ) + 2) % 8)
739
740static inline void set_2m(struct floppy_struct *floppy, int value)
741{
742 if (value & 0x7f)
743 value = FD_2M;
744 else
745 value = 0;
746 floppy->rate = (floppy->rate & ~FD_2M) | value;
747}
748#define SET_2M set_2m
749
750static inline void set_ssize(struct floppy_struct *floppy, int value)
751{
752 value = (( (value & 7) + 6 ) % 8) << 3;
753
754 floppy->rate = (floppy->rate & ~0x38) | value;
755}
756
757#define SET_SSIZE set_ssize
758
759static inline int set_parameters(int fd, struct floppy_struct *floppy,
760 struct stat *buf)
761{
762 if ( ( MINOR(buf->st_rdev ) & 0x7f ) > 3 )
763 return 1;
764
765 return ioctl(fd, FDSETPRM, floppy);
766}
767
768static inline int get_parameters(int fd, struct floppy_struct *floppy)
769{
770 return ioctl(fd, FDGETPRM, floppy);
771}
772
773#endif /* linux */
774
775
776/* OS/2, gcc+emx */
777#ifdef __EMX__
778#define predefined_devices
779struct device devices[] = {
780 {"A:", "A", GENFD},
781 {"B:", "B", GENFD},
782};
783#define INIT_NOOP
784#endif
785
786
787
788/*** /jes -- for D.O.S. 486 BL DX2/80 ***/
789#ifdef OS_freebsd
790#define predefined_devices
791struct device devices[] = {
792 {"/dev/rfd0.1440", "A", FHD312},
793 {"/dev/rfd0.720", "A", FDD312},
794 {"/dev/rfd1.1200", "B", MHD514},
795 {"/dev/sd0s1", "C", GENHD},
796 REMOTE
797};
798#endif /* __FreeBSD__ */
799
800/*** /jes -- for ALR 486 DX4/100 ***/
801#if defined(OS_netbsd)
802#define predefined_devices
803struct device devices[] = {
804 {"/dev/rfd0a", "A", FHD312},
805 {"/dev/rfd0f", "A", FDD312},
806 {"/dev/rfd0f", "S", MDD312},
807 {"/dev/rfd1a", "B", FHD514},
808 {"/dev/rfd1d", "B", FDD514},
809 {"/dev/rfd1d", "T", MDD514},
810 {"/dev/rwd0d", "C", 16, 0, 0, 0, 0, 0, 63L*512L, DEF_ARG0(0)},
811 REMOTE
812};
813#endif /* OS_NetBSD */
814
815/* fgsch@openbsd.org 2000/05/19 */
816#if defined(OS_openbsd)
817#define predefined_devices
818struct device devices[] = {
819 {"/dev/rfd0Bc", "A", FHD312},
820 {"/dev/rfd0Fc", "A", FDD312},
821 {"/dev/rfd1Cc", "B", FHD514},
822 {"/dev/rfd1Dc", "B", FDD514},
823 {"/dev/rwd0c", "C", 16, 0, 0, 0, 0, 0, 63L*512L, DEF_ARG0(0)},
824 REMOTE
825};
826#endif /* OS_openbsd */
827
828
829
830#if (!defined(predefined_devices) && defined (CPU_m68000) && defined (OS_sysv))
831#include <sys/gdioctl.h>
832
833#define predefined_devices
834struct device devices[] = {
835 {"/dev/rfp020", "A", 12,O_NDELAY,40,2, 9, 0, MDEF_ARG},
836 {"/usr/bin/DOS/dvd000", "C", GENFD},
837 REMOTE
838};
839
840#undef INIT_NOOP
841int init_geom(int fd, struct device *dev, struct device *orig_dev,
842 struct stat *stat)
843{
844 struct gdctl gdbuf;
845
846 if (ioctl(fd, GDGETA, &gdbuf) == -1) {
847 ioctl(fd, GDDISMNT, &gdbuf);
848 return 1;
849 }
850 if((dev->use_2m & 0x7f) || (dev->ssize & 0x7f))
851 return 1;
852
853 SET_INT(gdbuf.params.cyls,dev->ntracks);
854 SET_INT(gdbuf.params.heads,dev->nheads);
855 SET_INT(gdbuf.params.psectrk,dev->nsect);
856 dev->ntracks = gdbuf.params.cyls;
857 dev->nheads = gdbuf.params.heads;
858 dev->nsect = gdbuf.params.psectrk;
859 dev->use_2m = 0x80;
860 dev->ssize = 0x82;
861
862 gdbuf.params.pseccyl = gdbuf.params.psectrk * gdbuf.params.heads;
863 gdbuf.params.flags = 1; /* disk type flag */
864 gdbuf.params.step = 0; /* step rate for controller */
865 gdbuf.params.sectorsz = 512; /* sector size */
866
867 if (ioctl(fd, GDSETA, &gdbuf) < 0) {
868 ioctl(fd, GDDISMNT, &gdbuf);
869 return(1);
870 }
871 return(0);
872}
873#endif /* (defined (m68000) && defined (sysv))*/
874
875#ifdef CPU_alpha
876#ifndef OS_osf4
877#ifdef __osf__
878#include <sys/fcntl.h>
879#define predefined_devices
880struct device devices[] = {
881 {"/dev/rfd0c", "A", GENFD},
882 REMOTE
883};
884#endif
885#endif
886#endif
887
888#ifdef OS_osf
889#ifndef predefined_devices
890#define predefined_devices
891struct device devices[] = {
892 {"/dev/fd0a", "A", MHD312 } };
893 REMOTE
894#endif
895#endif
896
897
898#ifdef OS_nextstep
899#define predefined_devices
900struct device devices[] = {
901#ifdef CPU_m68k
902 {"/dev/rfd0b", "A", MED312 },
903 REMOTE
904#else
905 {"/dev/rfd0b", "A", MHD312 },
906 REMOTE
907#endif
908};
909#endif
910
911
912#if (!defined(predefined_devices) && defined(OS_sysv4))
913#ifdef __uxp__
914#define predefined_devices
915struct device devices[] = {
916 {"/dev/fpd0", "A", FHD312},
917 {"/dev/fpd0", "A", FDD312},
918 REMOTE
919};
920#else
921#define predefined_devices
922struct device devices[] = {
923 {"/dev/rdsk/f1q15dt", "B", FHD514},
924 {"/dev/rdsk/f1d9dt", "B", FDD514},
925 {"/dev/rdsk/f1d8dt", "B", FDDsmall},
926 {"/dev/rdsk/f03ht", "A", FHD312},
927 {"/dev/rdsk/f03dt", "A", FDD312},
928 {"/dev/rdsk/dos", "C", GENHD},
929 REMOTE
930};
931#endif
932#endif /* sysv4 */
933
934#ifdef OS_Minix
935/* Minix and Minix-vmd device list. Only present to attach the A: and B:
936 * drive letters to the floppies by default. Other devices can be given
937 * a drive letter by linking the device file to /dev/dosX, where X is a
938 * drive letter. Or one can use something like 'fd0:' for a drive name.
939 * Kees J. Bot <kjb@cs.vu.nl>
940 */
941#include <minix/partition.h>
942#include <minix/u64.h>
943
944#define predefined_devices
945struct device devices[] = {
946 {"/dev/fd0", "A", GEN},
947 {"/dev/fd1", "B", GEN},
948};
949
950#undef INIT_NOOP
951int init_geom(int fd, struct device *dev, struct device *orig_dev,
952 struct stat *stat)
953{
954 /* Try to obtain the device parameters from the device driver.
955 * Don't fret if you can't, mtools will use the DOS boot block.
956 */
957 struct partition geom;
958 unsigned long tot_sectors;
959
960 if (ioctl(fd, DIOCGETP, &geom) == 0) {
961 dev->hidden = div64u(geom.base, 512);
962 tot_sectors = div64u(geom.size, 512);
963 dev->tracks = tot_sectors / (geom.heads * geom.sectors);
964 dev->heads = geom.heads;
965 dev->sectors = geom.sectors;
966 }
967 return(0);
968}
969#endif /* OS_Minix */
970
971#ifdef INIT_GENERIC
972
973#ifndef USE_2M
974#define USE_2M(x) 0x80
975#endif
976
977#ifndef SSIZE
978#define SSIZE(x) 0x82
979#endif
980
981#ifndef SET_2M
982#define SET_2M(x,y) return -1
983#endif
984
985#ifndef SET_SSIZE
986#define SET_SSIZE(x,y) return -1
987#endif
988
989#undef INIT_NOOP
990int init_geom(int fd, struct device *dev, struct device *orig_dev,
991 struct stat *stat)
992{
993 struct generic_floppy_struct floppy;
994 int change;
995
996 /*
997 * succeed if we don't have a floppy
998 * this is the case for dosemu floppy image files for instance
999 */
1000 if (!((S_ISBLK(stat->st_mode) && major(stat->st_rdev) == BLOCK_MAJOR)
1001#ifdef CHAR_MAJOR
1002 || (S_ISCHR(stat->st_mode) && major(stat->st_rdev) == CHAR_MAJOR)
1003#endif
1004 ))
1005 return compare_geom(dev, orig_dev);
1006
1007 /*
1008 * We first try to get the current floppy parameters from the kernel.
1009 * This allows us to
1010 * 1. get the rate
1011 * 2. skip the parameter setting if the parameters are already o.k.
1012 */
1013
1014 if (get_parameters( fd, & floppy ) )
1015 /*
1016 * autodetection failure.
1017 * This mostly occurs because of an absent or unformatted disks.
1018 *
1019 * It might also occur because of bizarre formats (for example
1020 * rate 1 on a 3 1/2 disk).
1021
1022 * If this is the case, the user should do an explicit
1023 * setfdprm before calling mtools
1024 *
1025 * Another cause might be pre-existing wrong parameters. The
1026 * user should do an setfdprm -c to repair this situation.
1027 *
1028 * ...fail immediately... ( Theoretically, we could try to save
1029 * the situation by trying out all rates, but it would be slow
1030 * and awkward)
1031 */
1032 return 1;
1033
1034
1035 /*
1036 * if we have already have the correct parameters, keep them.
1037 * the number of tracks doesn't need to match exactly, it may be bigger.
1038 * the number of heads and sectors must match exactly, to avoid
1039 * miscalculation of the location of a block on the disk
1040 */
1041 change = 0;
1042 if(compare(dev->sectors, SECTORS(floppy))){
1043 SECTORS(floppy) = dev->sectors;
1044 change = 1;
1045 } else
1046 dev->sectors = SECTORS(floppy);
1047
1048 if(compare(dev->heads, HEADS(floppy))){
1049 HEADS(floppy) = dev->heads;
1050 change = 1;
1051 } else
1052 dev->heads = HEADS(floppy);
1053
1054 if(compare(dev->tracks, TRACKS(floppy))){
1055 TRACKS(floppy) = dev->tracks;
1056 change = 1;
1057 } else
1058 dev->tracks = TRACKS(floppy);
1059
1060
1061 if(compare(dev->use_2m, USE_2M(floppy))){
1062 SET_2M(&floppy, dev->use_2m);
1063 change = 1;
1064 } else
1065 dev->use_2m = USE_2M(floppy);
1066
1067 if( ! (dev->ssize & 0x80) )
1068 dev->ssize = 0;
1069 if(compare(dev->ssize, SSIZE(floppy) + 128)){
1070 SET_SSIZE(&floppy, dev->ssize);
1071 change = 1;
1072 } else
1073 dev->ssize = SSIZE(floppy);
1074
1075 if(!change)
1076 /* no change, succeed */
1077 return 0;
1078
1079#ifdef SECTORS_PER_TRACK
1080 SECTORS_PER_TRACK(floppy) = dev->sectors * dev->heads;
1081#endif
1082
1083#ifdef SECTORS_PER_DISK
1084 SECTORS_PER_DISK(floppy) = dev->sectors * dev->heads * dev->tracks;
1085#endif
1086
1087#ifdef STRETCH
1088 /* ... and the stretch */
1089 if ( dev->tracks > 41 )
1090 STRETCH(floppy) = 0;
1091 else
1092 STRETCH(floppy) = 1;
1093#endif
1094
1095 return set_parameters( fd, &floppy, stat) ;
1096}
1097#endif /* INIT_GENERIC */
1098
1099#ifdef INIT_NOOP
1100int init_geom(int fd, struct device *dev, struct device *orig_dev,
1101 struct stat *stat)
1102{
1103 return compare_geom(dev, orig_dev);
1104}
1105#endif
1106
1107#ifdef predefined_devices
1108const int nr_const_devices = sizeof(const_devices) / sizeof(*const_devices);
1109#else
1110struct device devices[]={
1111 {"/dev/fd0", "A", 0, O_EXCL, 0,0, 0,0, MDEF_ARG},
1112 /* to shut up Ultrix's native compiler, we can't make this empty :( */
1113};
1114const nr_const_devices = 0;
1115#endif
Note: See TracBrowser for help on using the repository browser.