home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
CMDS
/
dmode.lzh
/
dmode.c
next >
Wrap
C/C++ Source or Header
|
2005-10-13
|
12KB
|
552 lines
/* DMODE.C - Change RBF descriptor values.
Version history:
1.0 Initial Release Jun 1988
Ron D Voights
2024 Baldwin Court
Glendale Heights
IL 60139
USA
1.1 Added help display Aug 1988
RDV
2.0 Converted to OS9/68K Feb 1991
Martin Gregorie
10 Sadlers Mead
Harlow, Essex
UK.
2.1 Copyright notice added Aug 1992
2.2 Upgraded for OSK 2.4 Nov 1994
2.3 hex can be $ff or 0xff Oct 1995
2.4 added detach/attach Oct 1995
the deiniz;dmode;iniz
seq. is not needed
2.5 Removed dependency on Oct 2005
environment library.
*/
#define VERSION "2.5"
#define COPYRIGHT "(c) Ron D.Voights, M.C.Gregorie, 2005"
#include <modes.h>
#include <stdio.h>
#include <strings.h>
#include "rbfparams.h"
extern int errno;
#define CMNDCNT 21
#define TRUE 1
#define FALSE 0
static char *p[] =
{
"drv", "stp", "typ",
"dns", "cyl", "sid",
"vfy", "sct", "tos",
"sas", "ilv", "tof",
"sof", "siz", "ctl",
"try", "prk", "lsn",
"tot", "rts", "xfr"
};
static char *desc[] =
{
"Drive number", "Step rate", "Device type",
"Media density", "Number of cylinders", "Number of sides",
"Verify disk writes", "Sectors per track", "Sectors on track 0",
"Segment allocation", "Interleave factor", "Track base offset",
"Sector base offset", "Sector size (bytes)", "Control word",
"Retry count", "Hard disk park cyl", "Logical sector offset",
"Total cylinders", "Rpm, xfr rate", "Maximum transfer"
};
static int hex[] =
{
FALSE, FALSE, TRUE,
TRUE, FALSE, FALSE,
TRUE , FALSE, FALSE,
FALSE, FALSE, FALSE,
FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE
};
rbf_dev *modlink();
rbf_dev *munlink();
void help();
void display_descriptor();
void update_descriptor();
void error();
main(argc,argv)
int argc;
char **argv;
{
int i;
/*
Start by checking for help requests
*/
if (argc < 2)
help();
for (i = 1; i < argc; i++)
if (strcmp(argv[i],"-?") == 0)
help();
/*
If just the device descriptor name is given,
show current device parameters and exit.
If more parameters are given attempt to modify the
descriptor.
*/
if (argc == 2)
display_descriptor(argv[0],argv[1]);
else
update_descriptor(argc,argv);
return(0);
}
/*
Display explanation of program usage
*/
void help()
{
int i;
int nlr;
char hexreqd[6];
printf("\ndmode v%s %s\n\n",VERSION,COPYRIGHT);
printf("Syntax : dmode <RBF descriptor> [<RBF parameter list>]\n");
printf("Function : Change RBF device parameters in a descriptor\n");
printf(" The device is detached, changed, and re-attached\n");
printf(" If it isn't in use this should re-initialise it.\n");
printf("Parameters:\n");
for(i = 0; i < CMNDCNT; i++)
{
if (hex[i])
strcpy(hexreqd,"(hex)");
else
strcpy(hexreqd,"");
printf(" %-3s%-5s = %-22s",p[i],hexreqd,desc[i]);
if (i%2 == 0)
nlr = TRUE;
else
{
printf("\n");
nlr = FALSE;
}
}
if (nlr)
printf("\n");
exit(0);
}
/*
Show the current state of an RBF descriptor
*/
void display_descriptor(pn,dev)
char *pn;
char *dev;
{
mod_dev *mod;
struct modhcom *hddr;
rbf_dev *it;
char *devname;
int i;
int x;
int floppy_disk;
if (dev[0] != '/')
error(pn,dev,"is not a valid device name");
mod = (mod_dev*)modlink(dev+1,mktypelang(15,0));
if (mod == (mod_dev*)-1)
exit(errno);
if ((int)mod->_mdtype != 1)
error(pn,dev,"is not an RBF device");
hddr = (struct modhcom*)mod;
devname = (char*) hddr + hddr->_mname;
it = (rbf_dev*) ( (char*)mod + sizeof(mod_dev) -2 );
printf("Parameters for /%s\n",devname);
for (i = 0; i < CMNDCNT; i++)
{
printf("%-22s (%s) =",desc[i],p[i]);
switch (i)
{
case 0: printf(" %4d \n",(int)(it->pd_drv)); break;
case 1: printf(" %4d \n",(int)(it->pd_stp)); break;
case 2: printf(" 0x%02x ",(int)(it->pd_typ));
floppy_disk = FALSE;
if (it->pd_typ == 0 && it->pd_dns == 0)
{
printf("\n");
break;
}
if (it->pd_typ & TYP_HARD)
{
printf("Hard disk\n");
break;
}
if (it->pd_typ & TYP_HREMOV)
{
printf("Removable hard disk\n");
break;
}
floppy_disk = TRUE;
x = (it->pd_typ >> 1) & 0xf;
if (x == SIZE_OLD)
{
if (it->pd_typ & TYP_EIGHT)
printf("8\" ");
else
printf("5 1/4\" ");
}
else
{
if (x == TYP_SIZE8)
printf("8\" ");
if (x == TYP_SIZE5)
printf("5 1/4\" ");
if (x == TYP_SIZE3)
printf("3 1/2\" ");
}
printf("floppy ");
if (it->pd_typ & TYP_DDTRK0)
printf("DD ");
else
printf("SD ");
printf("track 0");
printf("\n");
break;
case 3: printf(" 0x%02x ",(int)(it->pd_dns));
if (!floppy_disk)
{
printf("\n");
break;
}
if (it->pd_dns & DNS_DD)
printf("DD ");
else
printf("SD ");
if (it->pd_dns & DNS_DT)
{
x = (it->pd_typ >> 1) & 0xf;
if (x == TYP_SIZE3)
printf("135tpi ");
else
printf("96tpi ");
}
else
if (it->pd_dns & DNS_QUAD)
printf("192tpi ");
else
if (it->pd_dns & DNS_OCTAL)
printf("384tpi ");
else
printf("48tpi ");
printf("\n");
break;
case 4: printf(" %4d \n",(int)(it->pd_cyl)); break;
case 5: printf(" %4d \n",(int)(it->pd_sid)); break;
case 6: printf(" 0x%02x Verify ",(int)(it->pd_vfy));
if (it->pd_vfy)
printf("off");
else
printf("on");
printf("\n");
break;
case 7: printf(" %4d \n",(int)(it->pd_sct)); break;
case 8: printf(" %4d \n",(int)(it->pd_t0s)); break;
case 9: printf(" %4d \n",(int)(it->pd_sas)); break;
case 10: printf(" %4d \n",(int)(it->pd_ilv)); break;
case 11: printf(" %4d \n",(int)(it->pd_toffs)); break;
case 12: printf(" %4d \n",(int)(it->pd_soffs)); break;
case 13: printf(" %4d \n",(int)(it->pd_ssize)); break;
case 14: printf(" 0x%04x ",(int)(it->pd_cntl));
if (it->pd_cntl & CNTL_NOFMT)
printf ("Nofmt ");
if (it->pd_cntl & CNTL_MULTSECT)
printf ("M/secI/O ");
if (it->pd_cntl & CNTL_STABID)
printf ("Stabid ");
if (it->pd_cntl & CNTL_AUTOSIZE)
printf ("Autosize ");
if (it->pd_cntl & CNTL_FMTTRK)
printf ("Trkfmt ");
printf("\n");
break;
case 15: printf(" %4d ",(int)(it->pd_trys));
if (it->pd_trys == 0)
printf("(driver default)");
printf("\n");
break;
case 16: printf(" %4d \n",(int)(it->pd_park)); break;
case 17: printf(" %4d \n",(int)(it->pd_lsnoffs)); break;
case 18: printf(" %5d \n",(int)(it->pd_totcyls)); break;
case 19: printf(" 0x%02x ",(int)(it->pd_rate));
if (!floppy_disk)
{
printf("\n");
break;
}
x = it->pd_rate & 0x7;
if (x == RPM_300)
printf("300");
if (x == RPM_360)
printf("360");
if (x == RPM_600)
printf("600");
printf(" rpm, ");
x = (it->pd_rate >> 4) & 0xf;
if (x == XFR_125K)
printf("125 k/bytes sec.");
if (x == XFR_250K)
printf("250 k/bytes sec.");
if (x == XFR_300K)
printf("300 k/bytes sec.");
if (x == XFR_500K)
printf("500 k/bytes sec.");
if (x == XFR_1M)
printf("1 m/bytes sec.");
if (x == XFR_2M)
printf("2 m/bytes sec.");
if (x == XFR_5M)
printf("5 m/bytes sec.");
printf("\n");
break;
case 20: printf(" %5d ",(int)(it->pd_maxcnt));
if ((it->pd_maxcnt) == 0xffffffff)
printf("(unlimited)\n");
else
printf("bytes\n");
break;
default: printf("**** Unknown data subscript\n");
}
}
munlink((mod_exec*)mod);
}
/*
Change parameter values in an RBF descriptor
*/
void update_descriptor(n,args)
int n;
char **args;
{
mod_dev *mod;
rbf_dev *it;
char *devptr;
int i,
cmndref,
newval;
char* attach();
if (args[1][0] != '/')
error(args[0],args[1],"is not a valid device name");
/*
Get the device table pointer and detach the device
*/
devptr = attach(args[1]+1,0);
if (devptr == (char*)-1)
error(args[0],"Can't find",args[1]);
/*
Cancel the attachment
*/
i = detach(devptr);
/*
Detach the device before modifying it
*/
if (!errno)
i = detach(devptr);
if (errno)
error(args[0],"Detach error while detaching %s\n", args[1]);
mod = (mod_dev*)modlink(args[1]+1,mktypelang(MT_DEVDESC,ML_ANY));
if (mod == (mod_dev*)-1)
exit(errno);
if ((int)mod->_mdtype != 1)
error(args[0],args[1],"is not an RBF device");
it = (rbf_dev*) ( (char*)mod + sizeof(mod_dev) -2 );
for (i = 2; i < n; i++)
{
cmndref = isin(args[i]);
if (cmndref == -1)
error(args[0],"invalid keyword:",args[i]);
newval = value(args[i],hex[cmndref],args[0]);
switch (cmndref)
{
case 0: it->pd_drv = (u_char)newval; break;
case 1: it->pd_stp = (u_char)newval; break;
case 2: it->pd_typ = (u_char)newval; break;
case 3: it->pd_dns = (u_char)newval; break;
case 4: it->pd_cyl = (u_short)newval; break;
case 5: it->pd_sid = (u_char)newval; break;
case 6: it->pd_vfy = (u_char)newval; break;
case 7: it->pd_sct = (u_short)newval; break;
case 8: it->pd_t0s = (u_short)newval; break;
case 9: it->pd_sas = (u_short)newval; break;
case 10: it->pd_ilv = (u_char)newval; break;
case 11: it->pd_toffs = (u_char)newval; break;
case 12: it->pd_soffs = (u_char)newval; break;
case 13: it->pd_ssize = (u_short)newval; break;
case 14: it->pd_cntl = (u_short)newval; break;
case 15: it->pd_trys = (u_char)newval; break;
case 16: it->pd_park = (u_short)newval; break;
case 17: it->pd_lsnoffs = (u_int)newval; break;
case 18: it->pd_totcyls = (u_short)newval; break;
case 19: it->pd_rate = (u_short)newval; break;
case 20: it->pd_maxcnt = (int)newval; break;
default: printf("**** Unknown data subscript\n");
}
}
if (_setcrc((mod_exec*)mod) == -1)
exit(errno);
munlink((mod_exec*)mod);
/*
Re-attach the device now its modified
*/
devptr = attach(args[1]+1,0);
if (devptr == (char*)-1)
error(args[0],"Can't re-attach",args[1]);
}
/*
Utility functions follow
*/
/*
isin returns the table location of the argument
*/
int isin(s)
char *s;
{
int i;
lowercase(s);
for ( i = 0 ; i < CMNDCNT ; i++ )
if (findstr(1,s,p[i]))
return(i);
return(-1);
}
/*
Returns value integer from argument
*/
int value(s,hex,prog)
char *s;
int hex;
char *prog;
{
char *param;
int foundhex;
param = s;
while (*s != '=')
{
if (*s == NULL)
error(prog,param,"must have value ( xxx=value )");
s++;
}
s++;
if (strncmp(s,"$",1) == 0)
{
s++;
foundhex = TRUE;
}
else
if (strncmp(s,"0x",2) == 0 || strncmp(s,"0X",2) == 0)
{
s = s+2;
foundhex = TRUE;
}
else
foundhex = FALSE;
if (hex && !foundhex)
error(prog,
param,
"must have a hex value ( xxx=0xff or xxx=$ff )");
if (!hex && foundhex)
error(prog,param,"must have a decimal value ( xxx=val )");
if (hex)
return(atohex(s));
else
return(atoi(s));
}
/*
Converts a hex string to binary
*/
int atohex(s)
char *s;
{
int hex,i;
static char hc[] = "0123456789abcdef";
hex = 0;
while (*s)
{
i = 0;
while (hc[i] && *s != hc[i])
i++;
if (i > 15)
break; /* non-hex found */
hex = hex * 16 + i;
s++;
}
return(hex);
}
/*
Convert string to lower case
*/
lowercase(s)
char *s;
{
while(*s)
{
*s = tolower(*s);
s++;
}
}
/*
Output an error message and quit
*/
void error(progname,s1,s2)
char *progname;
char *s1;
char *s2;
{
fprintf(stderr, "%s: %s %s\n", progname, s1, s2);
exit(1);
}