1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include <config.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <linux/fd.h>
#include <sys/ioctl.h>
#include <linux/major.h>
#include "parse.h"
#include "driveprm.h"
#include "driveprmP.h"
typedef drive_field_t field_t;
static int TPI, RPM, DEVIATION, FF, DENSITY, CMOS;
#define F_CMOS FE__CMOS,&CMOS
#define F_TPI FE__TPI,&TPI
#define F_FF FE__FF,&FF
#define F_RPM FE__RPM,&RPM
#define F_DEVIATION FE__DEVIATION,&DEVIATION
#define F_DENSITY FE__DENSITY,&DENSITY
drivetypedesc_t cmos_types[]= {
{ 0, FF_UNKNOWN, DENS_UNKNOWN, 0, 0 },
{ 1, FF_525, DENS_DD, 48, 300, 0 },
{ 2, FF_525, DENS_HD, 96, 360, 0 },
{ 3, FF_35, DENS_DD, 0, 300, 0 },
{ 4, FF_35, DENS_HD, 0, 300, 0 },
{ 5, FF_35, DENS_ED, 0, 300, 0 },
{ 6, FF_35, DENS_ED, 0, 300, 0 }
};
static keyword_t ids[]= {
{ "cmos", F_CMOS, 0},
{ "tpi", F_TPI, 0 },
{ "rpm", F_RPM, 0},
{ "deviation", F_DEVIATION, 0},
{ "sd", F_DENSITY, DENS_SD },
{ "dd", F_DENSITY, DENS_DD },
{ "qd", F_DENSITY, DENS_QD },
{ "hd", F_DENSITY, DENS_HD },
{ "ed", F_DENSITY, DENS_ED },
{ "5.25", F_FF, FF_525 },
{ "3.5", F_FF, FF_35 },
{ "8", F_FF, FF_8 }
};
static int mask;
#define ISSET(x) ((mask) & ( 1 << FE__##x))
static void compute_params(drivedesc_t *drive)
{
/* initialize out array */
drive->type.cmos = 0;
drive->type.ff = FF_UNKNOWN;
drive->type.max_density = DENS_UNKNOWN;
drive->type.tpi = 0;
drive->type.rpm = 0;
drive->type.deviation = 0;
if(!ISSET(CMOS)) {
if(ISSET(FF) && ISSET(DENSITY)) {
switch(DENSITY) {
case DENS_DD:
if(FF == FF_525)
CMOS = 1;
else
CMOS = 3;
break;
case DENS_HD:
switch(FF) {
case FF_525:
CMOS = 2;
break;
case FF_35:
CMOS = 4;
break;
}
break;
case DENS_ED:
switch(FF) {
case FF_35:
CMOS = 6;
break;
}
break;
}
} else {
CMOS = drive->drvprm.cmos;
if (CMOS < 1 || CMOS > 6)
CMOS = 4;
}
}
if(CMOS) {
if(CMOS > 6 || CMOS < 1) {
fprintf(stderr, "Bad cmos code %d\n", CMOS);
exit(1);
}
drive->type = cmos_types[CMOS];
}
if(ISSET(RPM))
drive->type.rpm = RPM;
if(ISSET(TPI))
drive->type.tpi = TPI;
if(ISSET(FF))
drive->type.ff = FF;
if(ISSET(DENSITY))
drive->type.max_density = DENSITY;
if(ISSET(RPM))
drive->type.rpm = RPM;
if(ISSET(DEVIATION))
drive->type.deviation = DEVIATION;
drive->mask = mask;
}
static int getdrivenum(int fd, struct stat *buf)
{
int num;
if (fstat (fd, buf) < 0) {
perror("Can't fstat drive");
exit(1);
}
if (!S_ISBLK(buf->st_mode) ||
major(buf->st_rdev) != FLOPPY_MAJOR) {
fprintf(stderr,"Not a floppy drive\n");
exit(1);
}
num = minor( buf->st_rdev );
return (num & 3) + ((num & 0x80) >> 5);
}
/* ========================================= *
* Routines called by other parts of fdutils *
* ========================================= */
int parse_driveprm(int fd, drivedesc_t *drive)
{
int found;
drive->drivenum = getdrivenum(fd, &drive->buf);
if(drive->drivenum < 0)
return -1;
ioctl(fd, FDRESET, FD_RESET_IF_RAWCMD);
if (ioctl(fd, FDGETDRVPRM, & drive->drvprm ) < 0 ){
perror("get drive characteristics");
exit(1);
}
zero_all(ids, &mask);
driveprmin = fopen(DRIVEPRMFILE, "r");
if(driveprmin) {
/* if the file doesn't exist, infer all info from the cmos type
* stored in the floppy driver */
found = 0;
driveprmlex(drive->drivenum, ids, sizeof(ids)/sizeof(ids[0]),
&mask, &found);
if(!found)
zero_all(ids, &mask);
fclose(driveprmin);
}
compute_params(drive);
return 0;
}
|