From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,ac224eeceac97358 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-06-29 13:58:35 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!news.cpqcorp.net!not-for-mail Message-ID: <3B3CEBFA.62619DE6@zk3.dec.com> From: Sean Davidson X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.tru64 Subject: Re: Load loadable kernel driver References: <2f6bec0a.0106280036.16304a21@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 29 Jun 2001 16:58:34 -0400 NNTP-Posting-Host: 16.140.96.143 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 993848315 16.140.96.143 (Fri, 29 Jun 2001 13:58:35 PDT) NNTP-Posting-Date: Fri, 29 Jun 2001 13:58:35 PDT Organization: Compaq Computer Corporation Xref: archiver1.google.com comp.unix.tru64:2845 Here is an example of a most simple loadable module. This example has the different includes needed to compile V4 and V5 modules. Missing the *_attributes structure or the *_configure routine will cause missing symbols. Also not include all the correct header files will also cause missing symbols. You should really only copy the loadable module into the /subsys or /var/subsys directories. Sean Davidson Compaq Tru64 UNIX Release Engineering = = = = = = = = /etc/sysconfigtab entries = = = = = nhdzz: Debug = 1 = = = = = = = = == = = = = = = = /* * * Dummy nhd disk driver * */ #include #include #include #include #include #include #include #include #if defined(OSVERS_V4) || defined(OSVERS_V5) #include #include #if defined(OSVERS_V5) #include #endif #endif #include #include #define NHD_NODEV (-1) #define NHD_INSTANCE (1) #define NHD_UNITMAX 255 #define NHD_DEV_NULL (0) #define nhdzz_unit(x) ((minor(x) >> 3) & 0x7) struct nhdzz_devs { int d_flags; /* flags */ size_t d_size; /* size of device */ unsigned char * d_buf; /* controll xfer buffer */ }; /* * forward declarations */ int nodev(), nulldev(); int nhdzz_open(), nhdzz_close(), nhdzz_read(), nhdzz_write(), nhdzz_ioctl(); int nhdzz_dump(), nhdzz_size(); void nhdzz_strategy(); /* * softc structure */ struct nhdzz_softc { int nhdzz_openflag; /* Open flag */ int nhdzz_count; /* Count chars out to device */ int nhdzz_state; /* Device state */ } nhdzz_softc[1]; /* * other data */ int nhdzz_config = FALSE; /* configured status */ int nhdzz_unit_count; /* current number of units */ struct nhdzz_devs *nhdzz_devs[NHD_UNITMAX]; /* disk device structures */ static unsigned char nhdzz_data_buffer[65536]; /* disk data buffer */ #define NHDZZ_DEVS_NULL ((struct nhdzz_devs *) NULL) /* * system configuration data */ static int nhdzz_units = 2; static int nhdzz_majnum = NHD_NODEV; #define nhdzz_bmajnum nhdzz_majnum #define nhdzz_cmajnum nhdzz_majnum static int nhdzz_version = 1; static int nhdzz_debug = 0; static unsigned char nhdzz_cfgname[CFG_ATTR_NAME_SZ] = "NHDa Device"; static unsigned char nhdzz_modtype[CFG_ATTR_NAME_SZ] = "Dynamic"; /* * device switch table */ struct dsent nhdzz_devsw_entry = { nhdzz_open, /* d_open */ nhdzz_close, /* d_close */ (int(*)(struct buf *))nhdzz_strategy, /* d_strategy */ nhdzz_read, /* d_read */ nhdzz_write, /* d_write */ nhdzz_ioctl, /* d_ioctl */ nhdzz_dump, /* d_dump */ nhdzz_size, /* d_psize */ nodev, /* d_stop */ nodev, /* d_reset */ nodev, /* d_select */ 0, /* d_mmap */ 0, /* d_segmap */ NULL, /* d_ttys */ DEV_FUNNEL_NULL, /* d_funnell */ 0, /* d_bflags */ 0 /* d_cflags */ }; /* * configuration attributes */ cfg_subsys_attr_t nhdzz_attributes[] = { {"Module_Config_Name", CFG_ATTR_STRTYPE, CFG_OP_QUERY, (caddr_t)nhdzz_cfgname, 2, CFG_ATTR_NAME_SZ, 0}, {"Module_Type", CFG_ATTR_STRTYPE, CFG_OP_QUERY, (caddr_t)nhdzz_modtype, 2, CFG_ATTR_NAME_SZ, 0}, {"Number_of_units", CFG_ATTR_INTTYPE, CFG_OP_QUERY | CFG_OP_RECONFIGURE | CFG_OP_CONFIGURE, (caddr_t)&nhdzz_units, 1, NHD_UNITMAX, 0}, {"Major_device_number", CFG_ATTR_INTTYPE, CFG_OP_QUERY | CFG_OP_RECONFIGURE | CFG_OP_CONFIGURE, (caddr_t)&nhdzz_majnum, 0, 512, 0}, {"Version", CFG_ATTR_INTTYPE, CFG_OP_QUERY, (caddr_t)&nhdzz_version, 0, 9999999, 0}, {"Debug", CFG_ATTR_INTTYPE, CFG_OP_QUERY | CFG_OP_RECONFIGURE | CFG_OP_CONFIGURE, (caddr_t)&nhdzz_debug, 0, 255, 0}, {"", 0, 0, 0, 0, 0, 0} }; /* * configure */ int nhdzz_configure(optype, indata, indatalen, outdata, outdatalen) cfg_op_t optype; cfg_attr_t *indata; size_t indatalen; cfg_attr_t *outdata; size_t outdatalen; { int i, error = ESUCCESS; unsigned char *buf; struct nhdzz_devs *vdisk; switch (optype) { case CFG_OP_CONFIGURE: /* * check for device already configured */ if (nhdzz_config == TRUE) { error = EBUSY; break; } /* * set device configured */ nhdzz_config = TRUE; printf("nhdzz: configured\n"); printf("nhdzz: debug = %d\n", nhdzz_debug); break; case CFG_OP_UNCONFIGURE: /* * make sure configuration was successfull */ if (nhdzz_config != TRUE) { error = ENXIO; break; } /* * set device unconfigured */ nhdzz_config = FALSE; printf("nhdzz: unconfigured\n"); break; case CFG_OP_QUERY: break; case CFG_OP_RECONFIGURE: /* * don't allow the number of units to get smaller */ if (nhdzz_units < nhdzz_unit_count) { error = EINVAL; } break; default: error = EINVAL; break; } return(error); } /* * open */ int nhdzz_open(dev, flags, mode) dev_t dev; int flags; int mode; { int unit; /* * make sure unit is in range */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(ENXIO); return(0); } /* * close */ int nhdzz_close(dev, flags, mode) dev_t dev; int flags; int mode; { int unit; /* * verify unit and device structure */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(ENXIO); return(0); } /* * block read/write */ void nhdzz_strategy(bp) struct buf *bp; { struct partition *pp; int bn, sz; int unit; /* * check for good unit and being online */ unit = nhdzz_unit(bp->b_dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) { bp->b_error = ENXIO; bp->b_flags |= B_ERROR; biodone(bp); return; } bp->b_resid = 0; biodone(bp); return; } /* * raw read */ int nhdzz_read(dev, uio) dev_t dev; struct uio *uio; { int unit, error; struct buf *bp; /* * verify unit and device structure */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(ENXIO); /* * get a buffer for i/o and just do a physical i/o read */ MALLOC(bp, struct buf *, sizeof(struct buf), M_DEVBUF, M_WAITOK); bzero(bp, sizeof(struct buf)); error = physio(nhdzz_strategy, bp, dev, B_READ, minphys, uio); FREE(bp, M_DEVBUF); return(error); } /* * raw write */ int nhdzz_write(dev, uio) dev_t dev; struct uio *uio; { int unit, error; struct buf *bp; /* * verify unit and device structure */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(ENXIO); /* * get a buffer for i/o and just do a physical i/o write */ MALLOC(bp, struct buf *, sizeof(struct buf), M_DEVBUF, M_WAITOK); bzero(bp, sizeof(struct buf)); error = physio(nhdzz_strategy, bp, dev, B_WRITE, minphys, uio); FREE(bp, M_DEVBUF); return(error); } /* * size */ int nhdzz_size(dev) dev_t dev; { int unit; /* * verify unit and device structure */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(-1); /* * return size of virtual disk */ return(2097152); } /* * dump */ int nhdzz_dump(dev) dev_t dev; { return(ENXIO); } /* * ioctl */ nhdzz_ioctl(dev, cmd, data, flag) dev_t dev; u_long cmd; caddr_t data; int flag; { int unit, flags, size, i, junk, error = 0; unsigned long addr; struct nhdzz_devs *vdisk; struct nhdzz_ioctl *ioctl_data = (struct nhdzz_ioctl *) data; DEVGEOMST *devgeom; v1_device_info_t *devi_p; v1_disk_dev_info_t *diskp; struct devget *devget; struct disklabel *lp; struct partition *pp; struct pt_tbl *pt; struct buf *bp; /* * trim the ioctl command and verify user is super user */ cmd = (cmd & 0xffffffff); if (error = suser(u.u_cred, &u.u_acflag)) return(error); /* * verify that unit is valid */ unit = nhdzz_unit(dev); if (unit < 0 || unit >= nhdzz_units || nhdzz_devs[unit] == NHDZZ_DEVS_NULL) return(ENXIO); /* * process ioctl command */ switch (cmd) { case DIOCGDINFO: break; case DIOCGPART: break; case DIOCSDINFO: break; case DIOCWLABEL: break; case DIOCWDINFO: break; case DIOCGDEFPT: break; case DIOCGCURPT: break; case DEVIOCGET: break; case DEVGETINFO: break; case DEVGETGEOM: break; default: error = ENXIO; } return(error); }