Fix minor bogons in isdisk() and chrtoblk().

This commit is contained in:
mycroft 1994-06-14 19:47:51 +00:00
parent 470742fbc0
commit e38ec56cb5

View File

@ -1 +1,566 @@
revision 1.44 intentionally removed
/*
* Copyright (c) 1994 Charles Hannum. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Charles Hannum.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: conf.c,v 1.45 1994/06/14 19:47:51 mycroft Exp $
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/conf.h>
#include <sys/vnode.h>
int rawread __P((dev_t, struct uio *, int));
int rawwrite __P((dev_t, struct uio *, int));
void swstrategy __P((struct buf *));
int ttselect __P((dev_t, int, struct proc *));
#ifndef LKM
#define lkmenodev enodev
#else
int lkmenodev();
#endif
#define dev_type_open(n) int n __P((dev_t, int, int, struct proc *))
#define dev_type_close(n) int n __P((dev_t, int, int, struct proc *))
#define dev_type_strategy(n) void n __P((struct buf *))
#define dev_type_ioctl(n) \
int n __P((dev_t, int, caddr_t, int, struct proc *))
/* bdevsw-specific types */
#define dev_type_dump(n) int n()
#define dev_type_size(n) int n __P((dev_t))
#define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t))
#define dev_init(c,n,t) \
((c) > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
/* bdevsw-specific initializations */
#define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0)
#define bdev_decl(n) \
dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
#define bdev_disk_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), \
dev_init(c,n,strategy), dev_init(c,n,ioctl), \
dev_init(c,n,dump), dev_size_init(c,n), 0 }
#define bdev_tape_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), \
dev_init(c,n,strategy), dev_init(c,n,ioctl), \
dev_init(c,n,dump), 0, B_TAPE }
#define bdev_swap_init() { \
(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
swstrategy, (dev_type_ioctl((*))) enodev, \
(dev_type_dump((*))) enodev, 0, 0 }
#define bdev_lkm_dummy() { \
(dev_type_open((*))) lkmenodev, (dev_type_close((*))) enodev, \
(dev_type_strategy((*))) enodev, (dev_type_ioctl((*))) enodev, \
(dev_type_dump((*))) enodev, 0, 0 }
#define bdev_notdef() { \
(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
(dev_type_strategy((*))) enodev, (dev_type_ioctl((*))) enodev, \
(dev_type_dump((*))) enodev, 0, 0 }
#include "wd.h"
#include "fd.h"
#include "wt.h"
#include "sd.h"
#include "st.h"
#include "cd.h"
#include "mcd.h"
#include "vn.h"
bdev_decl(wd);
#define fdopen Fdopen /* conflicts with fdopen() in kern_descrip.c */
bdev_decl(fd);
#undef fdopen
bdev_decl(wt);
bdev_decl(sd);
bdev_decl(st);
bdev_decl(cd);
bdev_decl(mcd);
bdev_decl(vn);
struct bdevsw bdevsw[] =
{
bdev_disk_init(NWD,wd), /* 0: ST506/ESDI/IDE disk */
bdev_swap_init(), /* 1: swap pseudo-device */
#define fdopen Fdopen
bdev_disk_init(NFD,fd), /* 2: floppy diskette */
#undef fdopen
bdev_tape_init(NWT,wt), /* 3: QIC-02/QIC-36 tape */
bdev_disk_init(NSD,sd), /* 4: SCSI disk */
bdev_tape_init(NST,st), /* 5: SCSI tape */
bdev_disk_init(NCD,cd), /* 6: SCSI CD-ROM */
bdev_disk_init(NMCD,mcd), /* 7: Mitsumi CD-ROM */
bdev_lkm_dummy(), /* 8 */
bdev_lkm_dummy(), /* 9 */
bdev_lkm_dummy(), /* 10 */
bdev_lkm_dummy(), /* 11 */
bdev_lkm_dummy(), /* 12 */
bdev_lkm_dummy(), /* 13 */
bdev_disk_init(NVN,vn), /* 14: vnode disk driver */
};
int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
/* cdevsw-specific types */
#define dev_type_read(n) int n __P((dev_t, struct uio *, int))
#define dev_type_write(n) int n __P((dev_t, struct uio *, int))
#define dev_type_stop(n) int n __P((struct tty *, int))
#define dev_type_reset(n) int n __P((int))
#define dev_type_select(n) int n __P((dev_t, int, struct proc *))
#define dev_type_mmap(n) int n __P(())
#define cdev_decl(n) \
dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \
dev_decl(n,reset); dev_decl(n,select); dev_decl(n,mmap); \
dev_decl(n,strategy); extern struct tty *__CONCAT(n,_tty)[]
#define dev_tty_init(c,n) (c > 0 ? __CONCAT(n,_tty) : 0)
/* open, close, read, write, ioctl, strategy */
#define cdev_disk_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), rawread, rawwrite, \
dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_mmap((*))) enodev, \
dev_init(c,n,strategy) }
/* open, close, read, write, ioctl, strategy */
#define cdev_tape_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), rawread, rawwrite, \
dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, (dev_type_mmap((*))) enodev, \
dev_init(c,n,strategy) }
/* open, close, read, write, ioctl, stop, tty */
#define cdev_tty_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
(dev_type_reset((*))) nullop, dev_tty_init(c,n), ttselect, \
(dev_type_mmap((*))) enodev, 0 }
/* open, close, read, ioctl, select */
#define cdev_mouse_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
dev_init(c,n,select), (dev_type_mmap((*))) enodev, 0 }
#define cdev_lkm_dummy() { \
(dev_type_open((*))) lkmenodev, (dev_type_close((*))) enodev, \
(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, \
(dev_type_mmap((*))) enodev, 0 }
#define cdev_notdef() { \
(dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, \
(dev_type_mmap((*))) enodev, 0 }
cdev_decl(cn);
/* open, close, read, write, ioctl, select -- XXX should be a tty */
#define cdev_cn_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
(dev_type_mmap((*))) enodev, 0 }
cdev_decl(ctty);
/* open, read, write, ioctl, select -- XXX should be a tty */
#define cdev_ctty_init(c,n) { \
dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
(dev_type_mmap((*))) enodev, 0 }
#define mmread mmrw
#define mmwrite mmrw
cdev_decl(mm);
/* open, close, read, write, mmap */
#define cdev_mm_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
seltrue, dev_init(c,n,mmap), 0 }
/* read, write, strategy */
#define cdev_swap_init(c,n) { \
(dev_type_open((*))) nullop, (dev_type_close((*))) nullop, rawread, \
rawwrite, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, (dev_type_select((*))) enodev, \
(dev_type_mmap((*))) enodev, dev_init(c,n,strategy) }
#include "pty.h"
#define pts_tty pt_tty
#define ptsioctl ptyioctl
cdev_decl(pts);
#define ptc_tty pt_tty
#define ptcioctl ptyioctl
cdev_decl(ptc);
/* open, close, read, write, ioctl, tty, select */
#define cdev_ptc_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
(dev_type_reset((*))) nullop, dev_tty_init(c,n), dev_init(c,n,select), \
(dev_type_mmap((*))) enodev, 0 }
cdev_decl(log);
/* open, close, read, ioctl, select -- XXX should be a generic device */
#define cdev_log_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
dev_init(c,n,select), (dev_type_mmap((*))) enodev, 0 }
cdev_decl(fd);
/* open */
#define cdev_fd_init(c,n) { \
dev_init(c,n,open), (dev_type_close((*))) enodev, \
(dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
(dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, (dev_type_select((*))) enodev, \
(dev_type_mmap((*))) enodev, 0 }
#include "bpfilter.h"
cdev_decl(bpf);
/* open, close, read, write, ioctl, select -- XXX should be generic device */
#define cdev_bpf_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
(dev_type_mmap((*))) enodev, 0 }
#include "tun.h"
cdev_decl(tun);
/* open, close, read, write, ioctl, select -- XXX should be generic device */
#define cdev_tun_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \
(dev_type_mmap((*))) enodev, 0 }
#ifdef LKM
#define NLKM 1
#else
#define NLKM 0
#endif
cdev_decl(lkm);
/* open, close, ioctl */
#define cdev_lkm_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
(dev_type_select((*))) enodev, (dev_type_mmap((*))) enodev, 0 }
#include "ch.h"
cdev_decl(ch);
/* open, close, ioctl */
#define cdev_ch_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
(dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \
(dev_type_select((*))) enodev, (dev_type_mmap((*))) enodev, 0 }
cdev_decl(wd);
cdev_decl(fd);
cdev_decl(wt);
cdev_decl(sd);
cdev_decl(st);
cdev_decl(cd);
cdev_decl(mcd);
cdev_decl(vn);
#include "pc.h"
#include "vt.h"
cdev_decl(pc);
/* open, close, read, write, ioctl, tty, mmap */
#define cdev_pc_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
(dev_type_reset((*))) nullop, dev_tty_init(c,n), ttselect, \
dev_init(c,n,mmap), 0 }
#include "lpt.h"
cdev_decl(lpt);
/* open, close, write, ioctl */
#define cdev_lpt_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, \
(dev_type_mmap((*))) enodev, 0 }
#include "speaker.h"
cdev_decl(spkr);
/* open, close, write, ioctl */
#define cdev_spkr_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, \
(dev_type_mmap((*))) enodev, 0 }
#include "sb.h"
cdev_decl(audio);
/* open, close, read, write, ioctl */
#define cdev_audio_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
(dev_type_reset((*))) nullop, 0, seltrue, \
(dev_type_mmap((*))) enodev, 0 }
#include "com.h"
#include "cy.h"
#include "mms.h"
#include "lms.h"
#include "pms.h"
cdev_decl(com);
cdev_decl(cy);
cdev_decl(mms);
cdev_decl(lms);
cdev_decl(pms);
struct cdevsw cdevsw[] =
{
cdev_cn_init(1,cn), /* 0: virtual console */
cdev_ctty_init(1,ctty), /* 1: controlling terminal */
cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */
cdev_disk_init(NWD,wd), /* 3: ST506/ESDI/IDE disk */
cdev_swap_init(1,sw), /* 4: /dev/drum (swap pseudo-device) */
cdev_tty_init(NPTY,pts), /* 5: pseudo-tty slave */
cdev_ptc_init(NPTY,ptc), /* 6: pseudo-tty master */
cdev_log_init(1,log), /* 7: /dev/klog */
cdev_tty_init(NCOM,com), /* 8: serial port */
#define fdopen Fdopen
cdev_disk_init(NFD,fd), /* 9: floppy diskette */
#undef fdopen
cdev_tape_init(NWT,wt), /* 10: QIC-02/QIC-36 tape */
cdev_notdef(), /* 11: unused */
cdev_pc_init(NPC + NVT,pc), /* 12: PC console */
cdev_disk_init(NSD,sd), /* 13: SCSI disk */
cdev_tape_init(NST,st), /* 14: SCSI tape */
cdev_disk_init(NCD,cd), /* 15: SCSI CD-ROM */
cdev_lpt_init(NLPT,lpt), /* 16: parallel printer */
cdev_ch_init(NCH,ch), /* 17: SCSI autochanger */
cdev_notdef(), /* 18: unused */
cdev_notdef(), /* 19: unused */
cdev_notdef(), /* 20: unused */
cdev_notdef(), /* 21: unused */
cdev_fd_init(1,fd), /* 22: file descriptor pseudo-device */
cdev_bpf_init(NBPFILTER,bpf), /* 23: Berkeley packet filter */
cdev_notdef(), /* 24: unused */
cdev_notdef(), /* 25: unused */
cdev_notdef(), /* 26: unused */
cdev_spkr_init(NSPEAKER,spkr), /* 27: PC speaker */
cdev_lkm_init(NLKM,lkm), /* 28: loadable module driver */
cdev_lkm_dummy(), /* 29 */
cdev_lkm_dummy(), /* 30 */
cdev_lkm_dummy(), /* 31 */
cdev_lkm_dummy(), /* 32 */
cdev_lkm_dummy(), /* 33 */
cdev_lkm_dummy(), /* 34 */
cdev_mouse_init(NMMS,mms), /* 35: Microsoft mouse */
cdev_mouse_init(NLMS,lms), /* 36: Logitech mouse */
cdev_mouse_init(NPMS,pms), /* 37: PS/2 mouse */
cdev_tty_init(NCY,cy), /* 38: Cyclom serial port */
cdev_disk_init(NMCD,mcd), /* 39: Mitsumi CD-ROM */
cdev_tun_init(NTUN,tun), /* 40: network tunnel */
cdev_disk_init(NVN,vn), /* 41: vnode disk driver */
cdev_audio_init(NSB,audio), /* 42: generic audio I/O */
};
int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
int mem_no = 2; /* major device number of memory special file */
/*
* Swapdev is a fake device implemented
* in sw.c used only internally to get to swstrategy.
* It cannot be provided to the users, because the
* swstrategy routine munches the b_dev and b_blkno entries
* before calling the appropriate driver. This would horribly
* confuse, e.g. the hashing routines. Instead, /dev/drum is
* provided as a character (raw) device.
*/
dev_t swapdev = makedev(1, 0);
/*
* Returns true if dev is /dev/mem or /dev/kmem.
*/
iskmemdev(dev)
dev_t dev;
{
return (major(dev) == mem_no && minor(dev) < 2);
}
/*
* Returns true if dev is /dev/zero.
*/
iszerodev(dev)
dev_t dev;
{
return (major(dev) == mem_no && minor(dev) == 12);
}
/*
* Returns true if dev is a disk device.
*/
isdisk(dev, type)
dev_t dev;
int type;
{
/* XXXX This needs to be dynamic for LKMs. */
switch (major(dev)) {
case 0:
case 2:
case 4:
case 6:
case 7:
case 14:
return (type == VBLK);
case 3:
case 9:
case 13:
case 15:
case 39:
case 41:
return (type == VCHR);
default:
return (0);
}
/* NOTREACHED */
}
static int chrtoblktbl[] = {
/* XXXX This needs to be dynamic for LKMs. */
/*VCHR*/ /*VBLK*/
/* 0 */ NODEV,
/* 1 */ NODEV,
/* 2 */ NODEV,
/* 3 */ 0,
/* 4 */ NODEV,
/* 5 */ NODEV,
/* 6 */ NODEV,
/* 7 */ NODEV,
/* 8 */ NODEV,
/* 9 */ 2,
/* 10 */ 3,
/* 11 */ NODEV,
/* 12 */ NODEV,
/* 13 */ 4,
/* 14 */ 5,
/* 15 */ 6,
/* 16 */ NODEV,
/* 17 */ NODEV,
/* 18 */ NODEV,
/* 19 */ NODEV,
/* 20 */ NODEV,
/* 21 */ NODEV,
/* 22 */ NODEV,
/* 23 */ NODEV,
/* 24 */ NODEV,
/* 25 */ NODEV,
/* 26 */ NODEV,
/* 27 */ NODEV,
/* 28 */ NODEV,
/* 29 */ NODEV,
/* 30 */ NODEV,
/* 31 */ NODEV,
/* 32 */ NODEV,
/* 33 */ NODEV,
/* 34 */ NODEV,
/* 35 */ NODEV,
/* 36 */ NODEV,
/* 37 */ NODEV,
/* 38 */ NODEV,
/* 39 */ 7,
/* 40 */ NODEV,
/* 41 */ 14,
/* 42 */ NODEV,
/* 43 */ NODEV,
/* 44 */ NODEV,
/* 45 */ NODEV,
/* 46 */ NODEV,
/* 47 */ NODEV,
/* 48 */ NODEV,
/* 49 */ NODEV,
};
/*
* Convert a character device number to a block device number.
*/
chrtoblk(dev)
dev_t dev;
{
int blkmaj;
if (major(dev) >= nchrdev)
return (NODEV);
blkmaj = chrtoblktbl[major(dev)];
if (blkmaj == NODEV)
return (NODEV);
return (makedev(blkmaj, minor(dev)));
}
/*
* constab is the console configuration for this type of machine.
* XXX - it should probably all be configured automatically.
*/
#include <dev/cons.h>
/* XXX - all this could be autoconfig()ed */
#if NPC > 0 || NVT > 0
int pccnprobe(), pccninit(), pccngetc(), pccnputc();
#endif
#if NCOM > 0
int comcnprobe(), comcninit(), comcngetc(), comcnputc();
#endif
struct consdev constab[] = {
#if NPC > 0 || NVT > 0
{ pccnprobe, pccninit, pccngetc, pccnputc },
#endif
#if NCOM > 0
{ comcnprobe, comcninit, comcngetc, comcnputc },
#endif
{ 0 },
};