home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum16.lzh
/
SOFTWARE
/
C
/
DEVPRC
/
devprc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-06
|
6KB
|
225 lines
/*
* This software is copyrighted (c)1990 by Hellmuth Michaelis
*
* Permission is granted to reproduce and distribute
* this package by any means as long as no fee is charged
* and as long as this notice is always included in the copies.
* Commerical use or incorporation into commercial software
* is prohibited without the written permission of the author.
*
* Other rights are reserved except as explicitly granted
* by written permission of the author.
*
* Hellmuth Michaelis
* Eggerstedtstr.28
* 2000 Hamburg 50
* Tel: +49 40 384298
* uucp(subnet): helle@ktshh
*
* I would like to thank Martin Gasthuber (martin@odinhh) and
* Heino Peters (heino@hphal) for their suggestions and helpful
* support ! (and also Reimer Mellin for his Copyright text ...)
*/
#include <stdio.h>
#include <module.h>
#include <procid.h>
#include <sgstat.h>
#include <sg_codes.h>
#include <strings.h>
#define MAXPRC 63 /* max no of pid's (better get it from init ?)*/
#define MAXDNL 32 /* device name length */
#define MAXPATH 32 /* no of paths per process */
#define VERSION "V.1.01" /* version info */
typedef procid *p_procid; /* ptr to procid structure */
typedef struct /* got back from _get_process_table() */
{
unsigned short maxblock; /* max no of blocks */
unsigned short blocksize; /* size of block */
p_procid ptr_pids[MAXPRC]; /* pointers to process id structs */
}gpt_ret;
main(argc,argv)
int argc;
char *argv[];
{
int c; /* character */
extern char *optarg; /* for getopt() */
int aflag,dflag,hflag; /* option flags */
int errflag; /* error flag */
char *devnam; /* name of device to search for */
errflag = aflag = dflag = hflag = 0;
while((c = getopt(argc,argv,"?ad:h")) != EOF)
{
switch(c)
{
case 'a':
if(dflag || hflag)
errflag++;
else
aflag++;
break;
case 'd':
if(aflag)
errflag++;
else
dflag++;
devnam = optarg;
break;
case 'h':
if(aflag)
errflag++;
else
hflag++;
break;
default:
errflag++;
break;
}
if((errflag) || ((!aflag) && (!dflag)))
usage(argv[0]); /* no return.. */
}
if(dflag)
do_d(devnam,hflag); /* display procs for dev */
else
do_a(); /* display all */
return(0);
}
usage(name)
char *name; /* program name */
{
fprintf(stderr,"%s: display device(s) belonging to process(es), ",name);
fprintf(stderr,VERSION);
fprintf(stderr,"\noptions: -a display all devices belonging to all processes");
fprintf(stderr,"\n -d [dev] display process having device [dev] open");
fprintf(stderr,"\n -h print header (with -d option)\n");
exit(0);
}
error(string)
char *string;
{
perror(string);
exit(101);
}
do_a() /* all option */
{
procid *pp; /* pointer to one process table struct */
mod_exec *pmodul; /* pointer to module */
int i,j; /* counters */
char name[32]; /* device name buffer */
struct sgbuf temp; /* device option section buffer */
unsigned short *ptp; /* path table ptr */
int devid; /* system device path no */
gpt_ret proc_buff; /* actual buffer for _get_process_table() */
if ((_get_process_table( &proc_buff, sizeof(proc_buff))) < 1)
error("can't get process table");
for (i=0;i<MAXPRC;i++) /* every process .. */
{
if(((pp = proc_buff.ptr_pids[i]) !=0) && \
((pmodul = pp->_pmodul) !=0) && \
(pmodul->_mh._msync == MODSYNC)) /* valid descriptor ? */
{
printf("\nPID=%d, NAME=%s",pp->_id,(char *) \
((unsigned int)pmodul->_mh._mname + \
(unsigned int)pmodul)); /* print pid & name */
ptp = pp->_path; /* get ptr to path table */
for(j=0; j < MAXPATH; j++) /* for every possible path */
{
devid = (int)*ptp; /* get system path no */
if(!devid) /* valid ?? */
continue; /* no, continue .. */
printf("\n\tPROCESSPATH=%d, ",j); /* yes */
if((_gs_sdevn(devid,name)) == -1)
error("cannot get device name");
printf("SYSPATH=%d, DEVICE=/%s",devid,name);
if((_gs_sopt(devid,&temp)) == -1)
error("cannot get system path options");
if(temp.sg_class == DT_RBF)
printf(", FILENAME=%s",temp.sg_fname);
ptp++; /* next path no */
}
}
}
printf("\n");
}
do_d(name,hflag)
char *name; /* ptr to devicename-string */
int hflag; /* print headerline flag */
{
procid *pp; /* pointer to one process table struct */
mod_exec *pmodul; /* pointer to module */
int i,j; /* counters */
unsigned short *ptp; /* path table ptr */
char srcdev[MAXDNL]; /* devicename to search for */
char tstdev[MAXDNL]; /* devicename to test */
char gsdev[MAXDNL]; /* buffer for _gs_sdevn */
char *sptr,*dptr; /* character pointers */
gpt_ret proc_buff; /* actual buffer for _get_process_table() */
int devid; /* system path no */
if(strlen(name) > MAXDNL) /* supplied devname too long */
error("device name too long");
dptr = srcdev;
if(*name == '/') /* allow "/dev" as well as "dev" */
name++;
while(*name) /* uppercase devicename */
*dptr++ = toupper(*name++);
*dptr = '\0'; /* terminate .. */
if ((_get_process_table( &proc_buff, sizeof(proc_buff))) < 1)
error("can't get process table");
if(hflag) /* header printing requested ? */
printf("PID\tNAME\n---\t----------------------------\n");
for (i=0;i<MAXPRC;i++)
{
if(((pp = proc_buff.ptr_pids[i]) !=0) && \
((pmodul = pp->_pmodul) !=0) && \
(pmodul->_mh._msync == MODSYNC))
{
ptp = pp->_path;
for(j=0; j < MAXPATH; j++)
{
devid = (int)*ptp;
if(!devid)
continue;
if((_gs_sdevn(devid,gsdev)) == -1)
error("cannot get device name");
dptr = tstdev;
sptr = gsdev; /* uppercase devicename */
while(*sptr)
*dptr++ = toupper(*sptr++);
*dptr = '\0';
if(!strcmp(srcdev,tstdev)) /* searched for ?? */
{
printf("%d\t%s\n",pp->_id,(char *) \
((unsigned int)pmodul->_mh._mname + \
(unsigned int)pmodul));
break; /* next process */
}
ptp++;
}
}
}
}