From e4c9c0c82658e0eca11c3e516c41021ba48b0093 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 19 May 2004 22:53:06 +0000 Subject: [PATCH] Device layer rollup commit. * cdevsw_add() is now required. cdevsw_add() and cdevsw_remove() may specify a mask/match indicating the range of supported minor numbers. Multiple cdevsw_add()'s using the same major number, but distinctly different ranges, may be issued. All devices that failed to call cdevsw_add() before now do. * cdevsw_remove() now automatically marks all devices within its supported range as being destroyed. * vnode->v_rdev is no longer resolved when the vnode is created. Instead, only v_udev (a newly added field) is resolved. v_rdev is resolved when the vnode is opened and cleared on the last close. * A great deal of code was making rather dubious assumptions with regards to the validity of devices associated with vnodes, primarily due to the persistence of a device structure due to being indexed by (major, minor) instead of by (cdevsw, major, minor). In particular, if you run a program which connects to a USB device and then you pull the USB device and plug it back in, the vnode subsystem will continue to believe that the device is open when, in fact, it isn't (because it was destroyed and recreated). In particular, note that all the VFS mount procedures now check devices via v_udev instead of v_rdev prior to calling VOP_OPEN(), since v_rdev is NULL prior to the first open. * The disk layer's device interaction has been rewritten. The disk layer (i.e. the slice and disklabel management layer) no longer overloads its data onto the device structure representing the underlying physical disk. Instead, the disk layer uses the new cdevsw_add() functionality to register its own cdevsw using the underlying device's major number, and simply does NOT register the underlying device's cdevsw. No confusion is created because the device hash is now based on (cdevsw,major,minor) rather then (major,minor). NOTE: This also means that underlying raw disk devices may use the entire device minor number instead of having to reserve the bits used by the disk layer, and also means that can we (theoretically) stack a fully disklabel-supported 'disk' on top of any block device. * The new reference counting scheme prevents this by associating a device with a cdevsw and disconnecting the device from its cdevsw when the cdevsw is removed. Additionally, all udev2dev() lookups run through the cdevsw mask/match and only successfully find devices still associated with an active cdevsw. * Major work on MFS: MFS no longer shortcuts vnode and device creation. It now creates a real vnode and a real device and implements real open and close VOPs. Additionally, due to the disk layer changes, MFS is no longer limited to 255 mounts. The new limit is 16 million. Since MFS creates a real device node, mount_mfs will now create a real /dev/mfs device that can be read from userland (e.g. so you can dump an MFS filesystem). * BUF AND DEVICE STRATEGY changes. The struct buf contains a b_dev field. In order to properly handle stacked devices we now require that the b_dev field be initialized before the device strategy routine is called. This required some additional work in various VFS implementations. To enforce this requirement, biodone() now sets b_dev to NODEV. The new disk layer will adjust b_dev before forwarding a request to the actual physical device. * A bug in the ISO CD boot sequence which resulted in a panic has been fixed. Testing by: lots of people, but David Rhodus found the most aggregious bugs. --- sbin/newfs/newfs.8 | 9 +- sbin/newfs/newfs.c | 33 +- sys/bus/cam/cam_xpt.c | 3 +- sys/bus/cam/scsi/scsi_cd.c | 8 +- sys/bus/cam/scsi/scsi_ch.c | 12 +- sys/bus/cam/scsi/scsi_da.c | 16 +- sys/bus/cam/scsi/scsi_pass.c | 13 +- sys/bus/cam/scsi/scsi_pt.c | 12 +- sys/bus/cam/scsi/scsi_sa.c | 45 +-- sys/bus/cam/scsi/scsi_ses.c | 13 +- sys/bus/cam/scsi/scsi_target.c | 9 +- sys/bus/firewire/firewire.h | 5 +- sys/bus/firewire/fwdev.c | 34 +- sys/bus/iicbus/iic.c | 3 +- sys/bus/isa/vga_isa.c | 4 +- sys/bus/pci/pci.c | 12 +- sys/bus/smbus/smb.c | 3 +- sys/bus/usb/usb.c | 8 +- sys/contrib/ipfilter/netinet/mlfk_ipl.c | 22 +- sys/dev/acpica/Osd/OsdSynch.c | 4 +- sys/dev/acpica/acpi.c | 3 +- sys/dev/acpica5/acpi.c | 3 +- sys/dev/agp/agp.c | 13 +- sys/dev/agp/agppriv.h | 3 +- sys/dev/disk/ata/ata-all.c | 3 +- sys/dev/disk/ata/ata-disk.c | 13 +- sys/dev/disk/ata/ata-raid.h | 4 +- sys/dev/disk/ata/atapi-cd.c | 14 +- sys/dev/disk/ata/atapi-tape.c | 8 +- sys/dev/disk/ata/atapi-tape.h | 3 +- sys/dev/disk/ccd/ccd.c | 21 +- sys/dev/disk/fd/fd.c | 18 +- sys/dev/disk/isp/isp_freebsd.c | 5 +- sys/dev/disk/mcd/mcd.c | 7 +- sys/dev/disk/scd/scd.c | 7 +- sys/dev/disk/vn/vn.c | 44 +-- sys/dev/disk/wt/wt.c | 7 +- sys/dev/drm/drm_drv.h | 5 +- sys/dev/misc/gpib/gpib.c | 9 +- sys/dev/misc/joy/joy.c | 5 +- sys/dev/misc/kbd/kbd.c | 18 +- sys/dev/misc/labpc/labpc.c | 7 +- sys/dev/misc/lpt/lpt.c | 4 +- sys/dev/misc/mse/mse.c | 15 +- sys/dev/misc/nmdm/nmdm.c | 27 +- sys/dev/misc/pcfclock/pcfclock.c | 3 +- sys/dev/misc/ppi/ppi.c | 3 +- sys/dev/misc/pps/pps.c | 12 +- sys/dev/misc/psm/psm.c | 20 +- sys/dev/misc/snp/snp.c | 9 +- sys/dev/misc/spic/spic.c | 5 +- sys/dev/misc/spigot/spigot.c | 12 +- sys/dev/misc/streams/streams.c | 54 +-- sys/dev/misc/syscons/syscons.c | 23 +- sys/dev/misc/syscons/syscons.h | 4 +- sys/dev/misc/syscons/sysmouse.c | 3 +- sys/dev/misc/tw/tw.c | 6 +- sys/dev/misc/xrpu/xrpu.c | 5 +- sys/dev/netif/cx/cx.c | 10 +- sys/dev/netif/cx/if_cx.c | 3 +- sys/dev/raid/aac/aac.c | 8 +- sys/dev/raid/aac/aac_disk.c | 8 +- sys/dev/raid/amr/amr.c | 10 +- sys/dev/raid/amr/amr_disk.c | 8 +- sys/dev/raid/asr/asr.c | 37 +- sys/dev/raid/ciss/ciss.c | 3 +- sys/dev/raid/dpt/dpt_control.c | 5 +- sys/dev/raid/ida/ida_disk.c | 8 +- sys/dev/raid/iir/iir_ctrl.c | 5 +- sys/dev/raid/ips/ips.c | 11 +- sys/dev/raid/ips/ips.h | 3 +- sys/dev/raid/mlx/mlx.c | 12 +- sys/dev/raid/mlx/mlxvar.h | 3 +- sys/dev/raid/mly/mly.c | 8 +- sys/dev/raid/twa/twa.h | 3 +- sys/dev/raid/twa/twa_freebsd.c | 16 +- sys/dev/raid/twe/twe_compat.h | 3 +- sys/dev/raid/twe/twe_freebsd.c | 22 +- sys/dev/raid/vinum/vinum.c | 16 +- sys/dev/raid/vinum/vinumext.h | 5 +- sys/dev/raid/vinum/vinumio.c | 17 +- sys/dev/raid/vinum/vinumvar.h | 49 ++- sys/dev/serial/cy/cy.c | 4 +- sys/dev/serial/dgb/dgm.c | 31 +- sys/dev/serial/rc/rc.c | 4 +- sys/dev/serial/rp/rp.c | 54 ++- sys/dev/serial/rp/rpreg.h | 5 +- sys/dev/serial/rp2/rp.c | 6 +- sys/dev/serial/si/si.c | 3 +- sys/dev/serial/sio/sio.c | 18 +- sys/dev/serial/stl/stallion.c | 5 +- sys/dev/serial/stli/istallion.c | 7 +- sys/dev/sound/isa/i386/pca/pcaudio.c | 3 +- sys/dev/sound/isa/i386/soundcard.c | 4 +- sys/dev/sound/isa/i386/spkr/spkr.c | 3 +- sys/dev/sound/pcm/dsp.c | 28 +- sys/dev/sound/pcm/mixer.c | 17 +- sys/dev/sound/pcm/sndstat.c | 18 +- sys/dev/usbmisc/ucom/ucom.c | 19 +- sys/dev/usbmisc/ufm/ufm.c | 5 +- sys/dev/usbmisc/ugen/ugen.c | 53 ++- sys/dev/usbmisc/uhid/uhid.c | 15 +- sys/dev/usbmisc/ulpt/ulpt.c | 15 +- sys/dev/usbmisc/ums/ums.c | 15 +- sys/dev/usbmisc/urio/urio.c | 13 +- sys/dev/usbmisc/uscanner/uscanner.c | 10 +- sys/dev/video/bktr/bktr_os.c | 19 +- sys/dev/video/bktr/bktr_reg.h | 8 +- sys/dev/video/ctx/ctx.c | 14 +- sys/dev/video/fb/fb.c | 60 ++-- sys/dev/video/fb/vgareg.h | 4 +- sys/dev/video/gfb/gfb_pci.c | 4 +- sys/dev/video/gsc/gsc.c | 7 +- sys/dev/video/meteor/meteor.c | 8 +- sys/dev/video/pcvt/i386/pcvt_drv.c | 7 +- sys/dev/video/pcvt/i386/pcvt_hdr.h | 3 +- sys/dev/video/pcvt/i386/pcvt_kbd.c | 10 +- sys/dev/video/tga/tga_pci.c | 4 +- sys/emulation/linux/linux_stats.c | 16 +- sys/emulation/svr4/svr4_types.h | 6 +- sys/i386/acpica/acpi_machdep.c | 4 +- sys/i386/acpica5/acpi_machdep.c | 3 +- sys/i386/apm/apm.c | 3 +- sys/i386/gnu/isa/dgb.c | 18 +- sys/i386/i386/autoconf.c | 9 +- sys/i386/i386/elan-mmcr.c | 3 +- sys/i386/i386/mem.c | 3 +- sys/i386/i386/perfmon.c | 5 +- sys/i386/isa/asc.c | 7 +- sys/kern/kern_conf.c | 332 ++++++++++++++--- sys/kern/kern_descrip.c | 6 +- sys/kern/kern_device.c | 437 +++++++++-------------- sys/kern/kern_memio.c | 3 +- sys/kern/subr_disk.c | 245 ++++++++----- sys/kern/subr_log.c | 4 +- sys/kern/subr_xxx.c | 99 +++-- sys/kern/tty_cons.c | 283 +++++++++------ sys/kern/tty_pty.c | 21 +- sys/kern/tty_tty.c | 47 +-- sys/kern/vfs_bio.c | 7 +- sys/kern/vfs_conf.c | 25 +- sys/kern/vfs_default.c | 6 +- sys/kern/vfs_subr.c | 186 ++++++---- sys/kern/vfs_syscalls.c | 4 +- sys/kern/vfs_vnops.c | 17 +- sys/net/bpf.c | 8 +- sys/net/i4b/driver/i4b_ctl.c | 6 +- sys/net/i4b/driver/i4b_rbch.c | 4 +- sys/net/i4b/driver/i4b_tel.c | 4 +- sys/net/i4b/driver/i4b_trace.c | 4 +- sys/net/i4b/layer4/i4b_i4bdrv.c | 4 +- sys/net/tap/if_tap.c | 7 +- sys/net/tun/if_tun.c | 8 +- sys/netgraph/ng_device.c | 6 +- sys/netproto/smb/smb_dev.c | 18 +- sys/opencrypto/cryptodev.c | 11 +- sys/platform/pc32/acpica/acpi_machdep.c | 4 +- sys/platform/pc32/acpica5/acpi_machdep.c | 3 +- sys/platform/pc32/apm/apm.c | 3 +- sys/platform/pc32/gnu/isa/dgb.c | 18 +- sys/platform/pc32/i386/autoconf.c | 9 +- sys/platform/pc32/i386/elan-mmcr.c | 3 +- sys/platform/pc32/i386/mem.c | 3 +- sys/platform/pc32/i386/perfmon.c | 5 +- sys/platform/pc32/isa/asc.c | 7 +- sys/sys/conf.h | 61 ++-- sys/sys/device.h | 18 +- sys/sys/disk.h | 35 +- sys/sys/disklabel.h | 20 +- sys/sys/disklabel32.h | 20 +- sys/sys/odisklabel.h | 20 +- sys/sys/systm.h | 3 +- sys/sys/vnode.h | 13 +- sys/vfs/coda/coda_fbsd.c | 6 +- sys/vfs/coda/coda_vfsops.c | 10 +- sys/vfs/gnu/ext2fs/ext2_vfsops.c | 15 +- sys/vfs/hpfs/hpfs_vfsops.c | 19 +- sys/vfs/isofs/cd9660/cd9660_vfsops.c | 17 +- sys/vfs/mfs/mfs_vfsops.c | 81 ++++- sys/vfs/mfs/mfs_vnops.c | 41 ++- sys/vfs/mfs/mfsnode.h | 3 +- sys/vfs/msdosfs/msdosfs_vfsops.c | 12 +- sys/vfs/nfs/nfs_subs.c | 7 +- sys/vfs/nfs/nfs_vfsops.c | 4 +- sys/vfs/ntfs/ntfs_vfsops.c | 15 +- sys/vfs/nullfs/null_subr.c | 4 +- sys/vfs/specfs/spec_vnops.c | 136 +++++-- sys/vfs/udf/udf_vfsops.c | 15 +- sys/vfs/ufs/ffs_softdep.c | 11 +- sys/vfs/ufs/ffs_vfsops.c | 34 +- sys/vfs/ufs/ffs_vnops.c | 6 +- sys/vm/vm_extern.h | 4 +- sys/vm/vm_swap.c | 26 +- 193 files changed, 2294 insertions(+), 1765 deletions(-) diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8 index 118d4ce806..517f13cd8d 100644 --- a/sbin/newfs/newfs.8 +++ b/sbin/newfs/newfs.8 @@ -31,7 +31,7 @@ .\" .\" @(#)newfs.8 8.6 (Berkeley) 5/3/95 .\" $FreeBSD: src/sbin/newfs/newfs.8,v 1.26.2.15 2003/05/13 12:16:08 joerg Exp $ -.\" $DragonFly: src/sbin/newfs/newfs.8,v 1.3 2003/12/01 04:36:57 dillon Exp $ +.\" $DragonFly: src/sbin/newfs/newfs.8,v 1.4 2004/05/19 22:52:34 dillon Exp $ .\" .Dd May 13, 2003 .Dt NEWFS 8 @@ -131,6 +131,13 @@ since that is where the file system will be backed up when free memory gets low and the memory supporting the file system has to be paged. .Pp +.Nm mount_mfs +creates the raw character device +.Pa /dev/mfs +to represent the backing store while the mount is active. This device may +be read but not written and allows swap-based MFS filesystems to be dumped +if desired. +.Pp The following options define the general layout policies: .Bl -tag -width indent .It Fl T Ar disktype diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 69e8a7f396..42090c3ead 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1983, 1989, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)newfs.c 8.13 (Berkeley) 5/1/95 * $FreeBSD: src/sbin/newfs/newfs.c,v 1.30.2.9 2003/05/13 12:03:55 joerg Exp $ - * $DragonFly: src/sbin/newfs/newfs.c,v 1.8 2004/03/04 00:03:23 dillon Exp $ + * $DragonFly: src/sbin/newfs/newfs.c,v 1.9 2004/05/19 22:52:34 dillon Exp $ */ /* @@ -200,11 +200,13 @@ int unlabeled; #endif char device[MAXPATHLEN]; +char mfsdevname[256]; char *progname; struct disklabel *getdisklabel(char *, int); static void rewritelabel(char *, int, struct disklabel *); static void usage(void); +static void mfsintr(int signo); int main(int argc, char **argv) @@ -222,7 +224,6 @@ main(int argc, char **argv) #ifdef MFS struct vfsconf vfc; int error; - char buf[BUFSIZ]; #endif vflag = 0; @@ -622,9 +623,11 @@ havelabel: #ifdef MFS if (mfs) { struct mfs_args args; + int udev; - snprintf(buf, sizeof(buf), "mfs:%d", getpid()); - args.fspec = buf; + snprintf(mfsdevname, sizeof(mfsdevname), "/dev/mfs%d", + getpid()); + args.fspec = mfsdevname; args.export.ex_root = -2; if (mntflags & MNT_RDONLY) args.export.ex_flags = MNT_EXRDONLY; @@ -643,16 +646,32 @@ havelabel: if (error) fatal("mfs filesystem not available"); + udev = (253 << 8) | (getpid() & 255) | + ((getpid() & ~0xFF) << 8); + if (mknod(mfsdevname, S_IFCHR | 0700, udev) < 0) + printf("Warning: unable to create %s\n", mfsdevname); + signal(SIGINT, mfsintr); if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0) fatal("%s: %s", argv[1], strerror(errno)); - if (filename) { - munmap(membase,fssize * sectorsize); - } + signal(SIGINT, SIG_DFL); + mfsintr(SIGINT); } #endif exit(0); } +#ifdef MFS + +static void +mfsintr(int signo) +{ + if (filename) + munmap(membase, fssize * sectorsize); + remove(mfsdevname); +} + +#endif + #ifdef COMPAT char lmsg[] = "%s: can't read disk label; disk type must be specified"; #else diff --git a/sys/bus/cam/cam_xpt.c b/sys/bus/cam/cam_xpt.c index 0f8027afa2..295a04e6fd 100644 --- a/sys/bus/cam/cam_xpt.c +++ b/sys/bus/cam/cam_xpt.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/cam_xpt.c,v 1.80.2.18 2002/12/09 17:31:55 gibbs Exp $ - * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.14 2004/05/13 23:49:09 dillon Exp $ + * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.15 2004/05/19 22:52:37 dillon Exp $ */ #include #include @@ -882,6 +882,7 @@ dev_allocq_is_runnable(struct cam_devq *devq) static void xpt_periph_init() { + cdevsw_add(&xpt_cdevsw, 0, 0); make_dev(&xpt_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "xpt0"); } diff --git a/sys/bus/cam/scsi/scsi_cd.c b/sys/bus/cam/scsi/scsi_cd.c index a117cf929e..1a073df5dd 100644 --- a/sys/bus/cam/scsi/scsi_cd.c +++ b/sys/bus/cam/scsi/scsi_cd.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_cd.c,v 1.31.2.16 2003/10/21 22:26:11 thomas Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.14 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.15 2004/05/19 22:52:38 dillon Exp $ */ /* * Portions of this driver taken from the original FreeBSD cd driver. @@ -545,7 +545,7 @@ cdcleanup(struct cam_periph *periph) } devstat_remove_entry(&softc->device_stats); cam_extend_release(cdperiphs, periph->unit_number); - if (softc->disk.d_dev) { + if (softc->disk.d_rawdev) { disk_destroy(&softc->disk); } free(softc, M_DEVBUF); @@ -2856,7 +2856,7 @@ cdcheckmedia(struct cam_periph *periph) * We don't bother checking the return value here, * since we already have an error... */ - dsioctl(softc->disk.d_dev, DIOCSYNCSLICEINFO, + dsioctl(softc->disk.d_cdev, DIOCSYNCSLICEINFO, /*data*/(caddr_t)&force, /*flags*/ 0, &softc->disk.d_slice); } @@ -2887,7 +2887,7 @@ cdcheckmedia(struct cam_periph *periph) force = 1; - error = dsioctl(softc->disk.d_dev, DIOCSYNCSLICEINFO, + error = dsioctl(softc->disk.d_cdev, DIOCSYNCSLICEINFO, /*data*/(caddr_t)&force, /*flags*/ 0, &softc->disk.d_slice); if (error != 0) { diff --git a/sys/bus/cam/scsi/scsi_ch.c b/sys/bus/cam/scsi/scsi_ch.c index 8e550d7530..f29d608330 100644 --- a/sys/bus/cam/scsi/scsi_ch.c +++ b/sys/bus/cam/scsi/scsi_ch.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_ch.c,v 1.20.2.2 2000/10/31 08:09:49 dwmalone Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.9 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.10 2004/05/19 22:52:38 dillon Exp $ */ /* * Derived from the NetBSD SCSI changer driver. @@ -148,7 +148,6 @@ struct ch_softc { ch_quirks quirks; union ccb saved_ccb; struct devstat device_stats; - dev_t dev; int sc_picker; /* current picker */ @@ -311,10 +310,10 @@ chcleanup(struct cam_periph *periph) softc = (struct ch_softc *)periph->softc; devstat_remove_entry(&softc->device_stats); - destroy_dev(softc->dev); cam_extend_release(chperiphs, periph->unit_number); xpt_print_path(periph->path); printf("removing device entry\n"); + cdevsw_remove(&ch_cdevsw, -1, periph->unit_number); free(softc, M_DEVBUF); } @@ -395,9 +394,10 @@ chregister(struct cam_periph *periph, void *arg) DEVSTAT_PRIORITY_OTHER); /* Register the device */ - softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT, - GID_OPERATOR, 0600, "%s%d", periph->periph_name, - periph->unit_number); + cdevsw_add(&ch_cdevsw, -1, periph->unit_number); + make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT, + GID_OPERATOR, 0600, "%s%d", periph->periph_name, + periph->unit_number); /* * Add an async callback so that we get diff --git a/sys/bus/cam/scsi/scsi_da.c b/sys/bus/cam/scsi/scsi_da.c index 5795b9ad94..bad41f4617 100644 --- a/sys/bus/cam/scsi/scsi_da.c +++ b/sys/bus/cam/scsi/scsi_da.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_da.c,v 1.42.2.46 2003/10/21 22:18:19 thomas Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.16 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.17 2004/05/19 22:52:38 dillon Exp $ */ #ifdef _KERNEL @@ -807,20 +807,15 @@ daioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) } static int -dadump(dev_t dev) +dadump(dev_t dev, u_int num, u_int blknum, u_int secsize) { struct cam_periph *periph; struct da_softc *softc; u_int unit; - u_int part; - u_int secsize; - u_int num; /* number of sectors to write */ - u_int blknum; long blkcnt; vm_paddr_t addr; struct ccb_scsiio csio; int dumppages = MAXDUMPPGS; - int error; int i; /* toss any characters present prior to dump */ @@ -828,7 +823,6 @@ dadump(dev_t dev) ; unit = dkunit(dev); - part = dkpart(dev); periph = cam_extend_get(daperiphs, unit); if (periph == NULL) { return (ENXIO); @@ -838,10 +832,6 @@ dadump(dev_t dev) if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) return (ENXIO); - error = disk_dumpcheck(dev, &num, &blknum, &secsize); - if (error) - return (error); - addr = 0; /* starting address */ blkcnt = howmany(PAGE_SIZE, secsize); @@ -1060,7 +1050,7 @@ dacleanup(struct cam_periph *periph) xpt_print_path(periph->path); printf("can't remove sysctl context\n"); } - if (softc->disk.d_dev) { + if (softc->disk.d_rawdev) { disk_destroy(&softc->disk); } free(softc, M_DEVBUF); diff --git a/sys/bus/cam/scsi/scsi_pass.c b/sys/bus/cam/scsi/scsi_pass.c index 15f7bb77ae..b268aac3f2 100644 --- a/sys/bus/cam/scsi/scsi_pass.c +++ b/sys/bus/cam/scsi/scsi_pass.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_pass.c,v 1.19 2000/01/17 06:27:37 mjacob Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.11 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.12 2004/05/19 22:52:38 dillon Exp $ */ #include @@ -81,7 +81,6 @@ struct pass_softc { struct buf_queue_head buf_queue; union ccb saved_ccb; struct devstat device_stats; - dev_t dev; }; #define PASS_CDEV_MAJOR 31 @@ -236,14 +235,13 @@ passcleanup(struct cam_periph *periph) devstat_remove_entry(&softc->device_stats); - destroy_dev(softc->dev); - cam_extend_release(passperiphs, periph->unit_number); if (bootverbose) { xpt_print_path(periph->path); printf("removing device entry\n"); } + cdevsw_remove(&pass_cdevsw, -1, periph->unit_number); free(softc, M_DEVBUF); } @@ -325,9 +323,10 @@ passregister(struct cam_periph *periph, void *arg) DEVSTAT_PRIORITY_PASS); /* Register the device */ - softc->dev = make_dev(&pass_cdevsw, periph->unit_number, UID_ROOT, - GID_OPERATOR, 0600, "%s%d", periph->periph_name, - periph->unit_number); + cdevsw_add(&pass_cdevsw, -1, periph->unit_number); + make_dev(&pass_cdevsw, periph->unit_number, UID_ROOT, + GID_OPERATOR, 0600, "%s%d", periph->periph_name, + periph->unit_number); /* * Add an async callback so that we get diff --git a/sys/bus/cam/scsi/scsi_pt.c b/sys/bus/cam/scsi/scsi_pt.c index c8cda6c8f5..1caa81b61b 100644 --- a/sys/bus/cam/scsi/scsi_pt.c +++ b/sys/bus/cam/scsi/scsi_pt.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_pt.c,v 1.17 2000/01/17 06:27:37 mjacob Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.10 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.11 2004/05/19 22:52:38 dillon Exp $ */ #include @@ -349,9 +349,10 @@ ptctor(struct cam_periph *periph, void *arg) SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_OTHER); - softc->dev = make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, - GID_OPERATOR, 0600, "%s%d", periph->periph_name, - periph->unit_number); + cdevsw_add(&pt_cdevsw, -1, periph->unit_number); + make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, + GID_OPERATOR, 0600, "%s%d", periph->periph_name, + periph->unit_number); /* * Add async callbacks for bus reset and * bus device reset calls. I don't bother @@ -431,11 +432,10 @@ ptdtor(struct cam_periph *periph) devstat_remove_entry(&softc->device_stats); - destroy_dev(softc->dev); - cam_extend_release(ptperiphs, periph->unit_number); xpt_print_path(periph->path); printf("removing device entry\n"); + cdevsw_remove(&pt_cdevsw, -1, periph->unit_number); free(softc, M_DEVBUF); } diff --git a/sys/bus/cam/scsi/scsi_sa.c b/sys/bus/cam/scsi/scsi_sa.c index 5e84cc7953..a4e1ce042e 100644 --- a/sys/bus/cam/scsi/scsi_sa.c +++ b/sys/bus/cam/scsi/scsi_sa.c @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/cam/scsi/scsi_sa.c,v 1.45.2.13 2002/12/17 17:08:50 trhodes Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.11 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.12 2004/05/19 22:52:38 dillon Exp $ * * Implementation of SCSI Sequential Access Peripheral driver for CAM. * @@ -195,18 +195,10 @@ typedef enum { ((ctl << 29) | ((unit & 0x3f0) << 16) | ((unit & 0xf) << 4) | \ (mode << 0x2) | (access & 0x3)) +#define SA_UNITMASK SAMINOR(0, -1, 0, 0) +#define SA_UNIT(unit) SAMINOR(0, unit, 0, 0) + #define SA_NUM_MODES 4 -struct sa_devs { - dev_t ctl_dev; - struct sa_mode_devs { - dev_t r_dev; - dev_t nr_dev; - dev_t er_dev; - } mode_devs[SA_NUM_MODES]; - dev_t r_dev; - dev_t nr_dev; - dev_t er_dev; -}; struct sa_softc { sa_state state; @@ -215,7 +207,6 @@ struct sa_softc { struct buf_queue_head buf_queue; int queue_count; struct devstat device_stats; - struct sa_devs devs; int blk_gran; int blk_mask; int blk_shift; @@ -1365,26 +1356,15 @@ static void sacleanup(struct cam_periph *periph) { struct sa_softc *softc; - int i; softc = (struct sa_softc *)periph->softc; devstat_remove_entry(&softc->device_stats); - destroy_dev(softc->devs.ctl_dev); - destroy_dev(softc->devs.r_dev); - destroy_dev(softc->devs.nr_dev); - destroy_dev(softc->devs.er_dev); - - for (i = 0; i < SA_NUM_MODES; i++) { - destroy_dev(softc->devs.mode_devs[i].r_dev); - destroy_dev(softc->devs.mode_devs[i].nr_dev); - destroy_dev(softc->devs.mode_devs[i].er_dev); - } - cam_extend_release(saperiphs, periph->unit_number); xpt_print_path(periph->path); printf("removing device entry\n"); + cdevsw_remove(&sa_cdevsw, SA_UNITMASK, SA_UNIT(periph->unit_number)); free(softc, M_DEVBUF); } @@ -1489,36 +1469,37 @@ saregister(struct cam_periph *periph, void *arg) DEVSTAT_BS_UNAVAILABLE, SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_TAPE); - softc->devs.ctl_dev = make_dev(&sa_cdevsw, SAMINOR(SA_CTLDEV, + cdevsw_add(&sa_cdevsw, SA_UNITMASK, SA_UNIT(periph->unit_number)); + make_dev(&sa_cdevsw, SAMINOR(SA_CTLDEV, periph->unit_number, 0, SA_ATYPE_R), UID_ROOT, GID_OPERATOR, 0660, "r%s%d.ctl", periph->periph_name, periph->unit_number); - softc->devs.r_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, 0, SA_ATYPE_R), UID_ROOT, GID_OPERATOR, 0660, "r%s%d", periph->periph_name, periph->unit_number); - softc->devs.nr_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, 0, SA_ATYPE_NR), UID_ROOT, GID_OPERATOR, 0660, "nr%s%d", periph->periph_name, periph->unit_number); - softc->devs.er_dev = make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, 0, SA_ATYPE_ER), UID_ROOT, GID_OPERATOR, 0660, "er%s%d", periph->periph_name, periph->unit_number); for (i = 0; i < SA_NUM_MODES; i++) { - softc->devs.mode_devs[i].r_dev = make_dev(&sa_cdevsw, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, i, SA_ATYPE_R), UID_ROOT, GID_OPERATOR, 0660, "r%s%d.%d", periph->periph_name, periph->unit_number, i); - softc->devs.mode_devs[i].nr_dev = make_dev(&sa_cdevsw, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, i, SA_ATYPE_NR), UID_ROOT, GID_OPERATOR, 0660, "nr%s%d.%d", periph->periph_name, periph->unit_number, i); - softc->devs.mode_devs[i].er_dev = make_dev(&sa_cdevsw, + make_dev(&sa_cdevsw, SAMINOR(SA_NOT_CTLDEV, periph->unit_number, i, SA_ATYPE_ER), UID_ROOT, GID_OPERATOR, 0660, "er%s%d.%d", periph->periph_name, periph->unit_number, i); diff --git a/sys/bus/cam/scsi/scsi_ses.c b/sys/bus/cam/scsi/scsi_ses.c index 6ec1e46390..6f9224f424 100644 --- a/sys/bus/cam/scsi/scsi_ses.c +++ b/sys/bus/cam/scsi/scsi_ses.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */ -/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.10 2004/05/13 23:49:11 dillon Exp $ */ +/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.11 2004/05/19 22:52:38 dillon Exp $ */ /* * Copyright (c) 2000 Matthew Jacob * All rights reserved. @@ -149,7 +149,6 @@ struct ses_softc { ses_encstat ses_encstat; /* overall status */ u_int8_t ses_flags; union ccb ses_saved_ccb; - dev_t ses_dev; struct cam_periph *periph; }; #define SES_FLAG_INVALID 0x01 @@ -271,11 +270,10 @@ sescleanup(struct cam_periph *periph) softc = (struct ses_softc *)periph->softc; - destroy_dev(softc->ses_dev); - cam_extend_release(sesperiphs, periph->unit_number); xpt_print_path(periph->path); printf("removing device entry\n"); + cdevsw_remove(&ses_cdevsw, -1, periph->unit_number); free(softc, M_DEVBUF); } @@ -379,9 +377,10 @@ sesregister(struct cam_periph *periph, void *arg) cam_extend_set(sesperiphs, periph->unit_number, periph); - softc->ses_dev = make_dev(&ses_cdevsw, periph->unit_number, - UID_ROOT, GID_OPERATOR, 0600, "%s%d", - periph->periph_name, periph->unit_number); + cdevsw_add(&ses_cdevsw, -1, periph->unit_number); + make_dev(&ses_cdevsw, periph->unit_number, + UID_ROOT, GID_OPERATOR, 0600, "%s%d", + periph->periph_name, periph->unit_number); /* * Add an async callback so that we get diff --git a/sys/bus/cam/scsi/scsi_target.c b/sys/bus/cam/scsi/scsi_target.c index 9ca7ace9f9..5401383586 100644 --- a/sys/bus/cam/scsi/scsi_target.c +++ b/sys/bus/cam/scsi/scsi_target.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_target.c,v 1.22.2.7 2003/02/18 22:07:10 njl Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.8 2004/05/13 23:49:11 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.9 2004/05/19 22:52:38 dillon Exp $ */ #include @@ -174,6 +174,7 @@ targopen(dev_t dev, int flags, int fmt, struct proc *p) /* Mark device busy before any potentially blocking operations */ dev->si_drv1 = (void *)~0; + reference_dev(dev); /* save ref for later destroy_dev() */ /* Create the targ device, allocate its softc, initialize it */ make_dev(&targ_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, @@ -208,8 +209,10 @@ targclose(dev_t dev, int flag, int fmt, struct proc *p) cam_periph_invalidate(softc->periph); softc->periph = NULL; } - destroy_dev(dev); + destroy_dev(dev); /* eats the open ref */ FREE(softc, M_TARG); + } else { + release_dev(dev); } return (error); } @@ -1006,7 +1009,7 @@ targgetdescr(struct targ_softc *softc) static void targinit(void) { - cdevsw_add(&targ_cdevsw); + cdevsw_add(&targ_cdevsw, 0, 0); } static void diff --git a/sys/bus/firewire/firewire.h b/sys/bus/firewire/firewire.h index 36f6552dbc..bb459849d7 100644 --- a/sys/bus/firewire/firewire.h +++ b/sys/bus/firewire/firewire.h @@ -32,7 +32,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/firewire/firewire.h,v 1.17 2003/11/07 09:01:41 simokawa Exp $ - * $DragonFly: src/sys/bus/firewire/firewire.h,v 1.4 2004/02/05 17:51:43 joerg Exp $ + * $DragonFly: src/sys/bus/firewire/firewire.h,v 1.5 2004/05/19 22:52:38 dillon Exp $ * */ @@ -422,6 +422,9 @@ struct fw_crom_buf { #define DEV2UNIT(x) ((dev2unit(x) & 0xff00) >> 8) #define DEV2SUB(x) (dev2unit(x) & 0xff) +#define FW_UNITMASK MAKEMINOR(0, -1, 0) +#define FW_UNIT(unit) MAKEMINOR(0, unit, 0) + #define FWMEM_FLAG 0x10000 #define DEV_FWMEM(x) (dev2unit(x) & FWMEM_FLAG) #endif diff --git a/sys/bus/firewire/fwdev.c b/sys/bus/firewire/fwdev.c index c2beebd68c..e8d09f3e25 100644 --- a/sys/bus/firewire/fwdev.c +++ b/sys/bus/firewire/fwdev.c @@ -32,7 +32,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/firewire/fwdev.c,v 1.36 2004/01/22 14:41:17 simokawa Exp $ - * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.8 2004/04/07 05:54:27 dillon Exp $ + * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.9 2004/05/19 22:52:38 dillon Exp $ * */ @@ -789,41 +789,21 @@ fw_strategy(struct bio *bp) int fwdev_makedev(struct firewire_softc *sc) { - int err = 0; - -#if defined(__DragonFly__) || __FreeBSD_version < 500000 - cdevsw_add(&firewire_cdevsw); -#else - dev_t d; int unit; unit = device_get_unit(sc->fc->bdev); - sc->dev = make_dev(&firewire_cdevsw, MAKEMINOR(0, unit, 0), - UID_ROOT, GID_OPERATOR, 0660, - "fw%d.%d", unit, 0); - d = make_dev(&firewire_cdevsw, - MAKEMINOR(FWMEM_FLAG, unit, 0), - UID_ROOT, GID_OPERATOR, 0660, - "fwmem%d.%d", unit, 0); - dev_depends(sc->dev, d); - make_dev_alias(sc->dev, "fw%d", unit); - make_dev_alias(d, "fwmem%d", unit); -#endif - - return (err); + cdevsw_add(&firewire_cdevsw, FW_UNITMASK, FW_UNIT(unit)); + return(0); } int fwdev_destroydev(struct firewire_softc *sc) { - int err = 0; + int unit; -#if defined(__DragonFly__) || __FreeBSD_version < 500000 - cdevsw_remove(&firewire_cdevsw); -#else - destroy_dev(sc->dev); -#endif - return (err); + unit = device_get_unit(sc->fc->bdev); + cdevsw_remove(&firewire_cdevsw, FW_UNITMASK, FW_UNIT(unit)); + return(0); } #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 diff --git a/sys/bus/iicbus/iic.c b/sys/bus/iicbus/iic.c index 8825f1b286..b0333ca560 100644 --- a/sys/bus/iicbus/iic.c +++ b/sys/bus/iicbus/iic.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/iicbus/iic.c,v 1.18 1999/11/18 05:43:32 peter Exp $ - * $DragonFly: src/sys/bus/iicbus/iic.c,v 1.6 2004/05/13 23:49:13 dillon Exp $ + * $DragonFly: src/sys/bus/iicbus/iic.c,v 1.7 2004/05/19 22:52:38 dillon Exp $ * */ #include @@ -133,6 +133,7 @@ iic_probe(device_t dev) static int iic_attach(device_t dev) { + cdevsw_add(&iic_cdevsw, -1, device_get_unit(dev)); make_dev(&iic_cdevsw, device_get_unit(dev), /* XXX cleanup */ UID_ROOT, GID_WHEEL, 0600, "iic%d", device_get_unit(dev)); diff --git a/sys/bus/isa/vga_isa.c b/sys/bus/isa/vga_isa.c index 1a5877f0f5..92171d787c 100644 --- a/sys/bus/isa/vga_isa.c +++ b/sys/bus/isa/vga_isa.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/isa/vga_isa.c,v 1.17 2000/01/29 15:08:56 peter Exp $ - * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.7 2004/05/13 23:49:13 dillon Exp $ + * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.8 2004/05/19 22:52:38 dillon Exp $ */ #include "opt_vga.h" @@ -164,7 +164,9 @@ isavga_attach(device_t dev) #ifdef FB_INSTALL_CDEV /* attach a virtual frame buffer device */ + cdevsw_add(&isavga_cdevsw, VGA_MKMINOR(-1), VGA_MKMINOR(unit)); sc->devt = make_dev(&isavga_cdevsw, VGA_MKMINOR(unit), 0, 0, 02660, "vga%x", VGA_MKMINOR(unit)); + reference_dev(sc->devt); error = fb_attach(sc->devt, sc->adp); if (error) return error; diff --git a/sys/bus/pci/pci.c b/sys/bus/pci/pci.c index a8023f4826..e16b1130ee 100644 --- a/sys/bus/pci/pci.c +++ b/sys/bus/pci/pci.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/pci.c,v 1.141.2.15 2002/04/30 17:48:18 tmm Exp $ - * $DragonFly: src/sys/bus/pci/pci.c,v 1.20 2004/05/13 23:49:13 dillon Exp $ + * $DragonFly: src/sys/bus/pci/pci.c,v 1.21 2004/05/19 22:52:39 dillon Exp $ * */ @@ -1373,6 +1373,10 @@ static int pci_attach(device_t dev) { int busno; + int lunit = device_get_unit(dev); + + cdevsw_add(&pcicdev, -1, lunit); + make_dev(&pcicdev, lunit, UID_ROOT, GID_WHEEL, 0644, "pci%d", lunit); /* * Since there can be multiple independantly numbered PCI @@ -1752,17 +1756,11 @@ pci_assign_interrupt_method(device_t dev, device_t child) static int pci_modevent(module_t mod, int what, void *arg) { - static dev_t pci_cdev; - switch (what) { case MOD_LOAD: STAILQ_INIT(&pci_devq); - pci_cdev = make_dev(&pcicdev, 0, UID_ROOT, GID_WHEEL, 0644, - "pci"); break; - case MOD_UNLOAD: - destroy_dev(pci_cdev); break; } diff --git a/sys/bus/smbus/smb.c b/sys/bus/smbus/smb.c index 60616ded09..7308f4b014 100644 --- a/sys/bus/smbus/smb.c +++ b/sys/bus/smbus/smb.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/smbus/smb.c,v 1.20 1999/11/18 05:44:56 peter Exp $ - * $DragonFly: src/sys/bus/smbus/smb.c,v 1.6 2004/05/13 23:49:13 dillon Exp $ + * $DragonFly: src/sys/bus/smbus/smb.c,v 1.7 2004/05/19 22:52:39 dillon Exp $ * */ #include @@ -134,6 +134,7 @@ smb_probe(device_t dev) static int smb_attach(device_t dev) { + cdevsw_add(&smb_cdevsw, -1, device_get_unit(dev)); make_dev(&smb_cdevsw, device_get_unit(dev), /* XXX cleanup */ UID_ROOT, GID_WHEEL, 0600, "smb%d", device_get_unit(dev)); diff --git a/sys/bus/usb/usb.c b/sys/bus/usb/usb.c index c582366b83..bf914c9a10 100644 --- a/sys/bus/usb/usb.c +++ b/sys/bus/usb/usb.c @@ -1,7 +1,7 @@ /* * $NetBSD: usb.c,v 1.68 2002/02/20 20:30:12 christos Exp $ * $FreeBSD: src/sys/dev/usb/usb.c,v 1.95 2003/11/09 23:54:21 joe Exp $ - * $DragonFly: src/sys/bus/usb/usb.c,v 1.13 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/bus/usb/usb.c,v 1.14 2004/05/19 22:52:39 dillon Exp $ */ /* Also already merged from NetBSD: @@ -317,14 +317,16 @@ USB_ATTACH(usb) usb_create_event_thread(sc); /* The per controller devices (used for usb_discover) */ /* XXX This is redundant now, but old usbd's will want it */ - make_dev(&usb_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, - 0660, "usb%d", device_get_unit(self)); if (!global_init_done) { /* The device spitting out events */ + cdevsw_add(&usb_cdevsw, -1, USB_DEV_MINOR); make_dev(&usb_cdevsw, USB_DEV_MINOR, UID_ROOT, GID_OPERATOR, 0660, "usb"); global_init_done = 1; } + cdevsw_add(&usb_cdevsw, -1, device_get_unit(self)); + make_dev(&usb_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, + 0660, "usb%d", device_get_unit(self)); #endif USB_ATTACH_SUCCESS_RETURN; diff --git a/sys/contrib/ipfilter/netinet/mlfk_ipl.c b/sys/contrib/ipfilter/netinet/mlfk_ipl.c index 1f99a7346d..fdcb7321f1 100644 --- a/sys/contrib/ipfilter/netinet/mlfk_ipl.c +++ b/sys/contrib/ipfilter/netinet/mlfk_ipl.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/contrib/ipfilter/netinet/mlfk_ipl.c,v 1.9.2.2 2002/04/27 17:37:12 darrenr Exp $ - * $DragonFly: src/sys/contrib/ipfilter/netinet/mlfk_ipl.c,v 1.6 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/contrib/ipfilter/netinet/mlfk_ipl.c,v 1.7 2004/05/19 22:52:39 dillon Exp $ */ @@ -56,8 +56,6 @@ #include "ip_frag.h" #include "ip_proxy.h" -static dev_t ipf_devs[IPL_LOGMAX + 1]; - SYSCTL_DECL(_net_inet); SYSCTL_NODE(_net_inet, OID_AUTO, ipf, CTLFLAG_RW, 0, "IPF"); SYSCTL_INT(_net_inet_ipf, OID_AUTO, fr_flags, CTLFLAG_RW, &fr_flags, 0, ""); @@ -136,6 +134,7 @@ ipfilter_modevent(module_t mod, int type, void *unused) error = iplattach(); if (error) break; + cdevsw_add(&ipl_cdevsw, 0, 0); c = NULL; for(i=strlen(IPL_NAME); i>0; i--) @@ -145,8 +144,7 @@ ipfilter_modevent(module_t mod, int type, void *unused) } if (!c) c = IPL_NAME; - ipf_devs[IPL_LOGIPF] = - make_dev(&ipl_cdevsw, IPL_LOGIPF, 0, 0, 0600, c); + make_dev(&ipl_cdevsw, IPL_LOGIPF, 0, 0, 0600, c); c = NULL; for(i=strlen(IPL_NAT); i>0; i--) @@ -156,8 +154,7 @@ ipfilter_modevent(module_t mod, int type, void *unused) } if (!c) c = IPL_NAT; - ipf_devs[IPL_LOGNAT] = - make_dev(&ipl_cdevsw, IPL_LOGNAT, 0, 0, 0600, c); + make_dev(&ipl_cdevsw, IPL_LOGNAT, 0, 0, 0600, c); c = NULL; for(i=strlen(IPL_STATE); i>0; i--) @@ -167,8 +164,7 @@ ipfilter_modevent(module_t mod, int type, void *unused) } if (!c) c = IPL_STATE; - ipf_devs[IPL_LOGSTATE] = - make_dev(&ipl_cdevsw, IPL_LOGSTATE, 0, 0, 0600, c); + make_dev(&ipl_cdevsw, IPL_LOGSTATE, 0, 0, 0600, c); c = NULL; for(i=strlen(IPL_AUTH); i>0; i--) @@ -178,15 +174,11 @@ ipfilter_modevent(module_t mod, int type, void *unused) } if (!c) c = IPL_AUTH; - ipf_devs[IPL_LOGAUTH] = - make_dev(&ipl_cdevsw, IPL_LOGAUTH, 0, 0, 0600, c); + make_dev(&ipl_cdevsw, IPL_LOGAUTH, 0, 0, 0600, c); break; case MOD_UNLOAD : - destroy_dev(ipf_devs[IPL_LOGIPF]); - destroy_dev(ipf_devs[IPL_LOGNAT]); - destroy_dev(ipf_devs[IPL_LOGSTATE]); - destroy_dev(ipf_devs[IPL_LOGAUTH]); + cdevsw_remove(&ipl_cdevsw, 0, 0); error = ipldetach(); break; default: diff --git a/sys/dev/acpica/Osd/OsdSynch.c b/sys/dev/acpica/Osd/OsdSynch.c index 19e0f700ed..e57db4de6a 100644 --- a/sys/dev/acpica/Osd/OsdSynch.c +++ b/sys/dev/acpica/Osd/OsdSynch.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/Osd/OsdSynch.c,v 1.17.2.1 2003/08/22 20:49:21 jhb Exp $ - * $DragonFly: src/sys/dev/acpica/Osd/Attic/OsdSynch.c,v 1.3 2004/05/05 22:18:09 dillon Exp $ + * $DragonFly: src/sys/dev/acpica/Osd/Attic/OsdSynch.c,v 1.4 2004/05/19 22:52:40 dillon Exp $ */ /* @@ -121,7 +121,9 @@ ACPI_STATUS AcpiOsDeleteSemaphore (ACPI_HANDLE Handle) { #ifndef ACPI_NO_SEMAPHORES +#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 struct acpi_semaphore *as = (struct acpi_semaphore *)Handle; +#endif ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index b7875f4316..6010a71d25 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpi.c,v 1.95.2.1 2003/08/22 20:49:20 jhb Exp $ - * $DragonFly: src/sys/dev/acpica/Attic/acpi.c,v 1.5 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/acpica/Attic/acpi.c,v 1.6 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_acpi.h" @@ -497,6 +497,7 @@ acpi_attach(device_t dev) /* * Create the control device */ + cdevsw_add(&acpi_cdevsw, 0, 0); sc->acpi_dev_t = make_dev(&acpi_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644, "acpi"); sc->acpi_dev_t->si_drv1 = sc; diff --git a/sys/dev/acpica5/acpi.c b/sys/dev/acpica5/acpi.c index 1b305231cc..597df64436 100644 --- a/sys/dev/acpica5/acpi.c +++ b/sys/dev/acpica5/acpi.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpi.c,v 1.118 2004/02/19 18:20:03 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi.c,v 1.3 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi.c,v 1.4 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_acpi.h" @@ -523,6 +523,7 @@ acpi_attach(device_t dev) sc->acpi_sleep_disabled = 0; /* Create the control device */ + cdevsw_add(&acpi_cdevsw, 0, 0); sc->acpi_dev_t = make_dev(&acpi_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644, "acpi"); sc->acpi_dev_t->si_drv1 = sc; diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c index 51748a6138..46d69bbad5 100644 --- a/sys/dev/agp/agp.c +++ b/sys/dev/agp/agp.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/pci/agp.c,v 1.3.2.4 2002/08/11 19:58:12 alc Exp $ - * $DragonFly: src/sys/dev/agp/agp.c,v 1.12 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/agp/agp.c,v 1.13 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_bus.h" @@ -260,12 +260,9 @@ agp_generic_attach(device_t dev) TAILQ_INIT(&sc->as_memory); sc->as_nextid = 1; - sc->as_devnode = make_dev(&agp_cdevsw, - device_get_unit(dev), - UID_ROOT, - GID_WHEEL, - 0600, - "agpgart"); + cdevsw_add(&agp_cdevsw, -1, device_get_unit(dev)); + make_dev(&agp_cdevsw, device_get_unit(dev), UID_ROOT, GID_WHEEL, + 0600, "agpgart"); return 0; } @@ -276,8 +273,8 @@ agp_generic_detach(device_t dev) struct agp_softc *sc = device_get_softc(dev); bus_release_resource(dev, SYS_RES_MEMORY, AGP_APBASE, sc->as_aperture); lockmgr(&sc->as_lock, LK_DRAIN, NULL, curthread); /* XXX */ - destroy_dev(sc->as_devnode); agp_flush_cache(); + cdevsw_remove(&agp_cdevsw, -1, device_get_unit(dev)); return 0; } diff --git a/sys/dev/agp/agppriv.h b/sys/dev/agp/agppriv.h index 7c40133b00..dc9d2a23a6 100644 --- a/sys/dev/agp/agppriv.h +++ b/sys/dev/agp/agppriv.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/pci/agppriv.h,v 1.3.2.1 2000/07/19 09:48:04 ru Exp $ - * $DragonFly: src/sys/dev/agp/agppriv.h,v 1.3 2003/08/07 21:16:48 dillon Exp $ + * $DragonFly: src/sys/dev/agp/agppriv.h,v 1.4 2004/05/19 22:52:40 dillon Exp $ */ #ifndef _PCI_AGPPRIV_H_ @@ -76,7 +76,6 @@ struct agp_softc { struct agp_memory_list as_memory; /* list of allocated memory */ int as_nextid; /* next memory block id */ int as_isopen; /* user device is open */ - dev_t as_devnode; /* from make_dev */ struct lock as_lock; /* lock for access to GATT */ }; diff --git a/sys/dev/disk/ata/ata-all.c b/sys/dev/disk/ata/ata-all.c index cd6e4e33a6..5b6d670ee6 100644 --- a/sys/dev/disk/ata/ata-all.c +++ b/sys/dev/disk/ata/ata-all.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-all.c,v 1.50.2.45 2003/03/12 14:47:12 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-all.c,v 1.17 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-all.c,v 1.18 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_ata.h" @@ -1582,6 +1582,7 @@ static void ata_init(void) { /* register controlling device */ + cdevsw_add(&ata_cdevsw, 0, 0); make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata"); /* register boot attach to be run when interrupts are enabled */ diff --git a/sys/dev/disk/ata/ata-disk.c b/sys/dev/disk/ata/ata-disk.c index 616e1a2e90..da6e5153a5 100644 --- a/sys/dev/disk/ata/ata-disk.c +++ b/sys/dev/disk/ata/ata-disk.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-disk.c,v 1.60.2.24 2003/01/30 07:19:59 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.17 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.18 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_ata.h" @@ -297,6 +297,10 @@ adclose(dev_t dev, int flags, int fmt, struct thread *td) return 0; } +/* + * note: always use the passed device rather then bp->b_dev, as the bp + * may have been translated through several layers. + */ static void adstrategy(struct buf *bp) { @@ -316,20 +320,15 @@ adstrategy(struct buf *bp) } int -addump(dev_t dev) +addump(dev_t dev, u_int count, u_int blkno, u_int secsize) { struct ad_softc *adp = dev->si_drv1; struct ad_request request; - u_int count, blkno, secsize; vm_paddr_t addr = 0; long blkcnt; int dumppages = MAXDUMPPGS; - int error; int i; - if ((error = disk_dumpcheck(dev, &count, &blkno, &secsize))) - return error; - if (!adp) return ENXIO; diff --git a/sys/dev/disk/ata/ata-raid.h b/sys/dev/disk/ata/ata-raid.h index 820fb1de87..cea51e5dba 100644 --- a/sys/dev/disk/ata/ata-raid.h +++ b/sys/dev/disk/ata/ata-raid.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-raid.h,v 1.2.2.8 2002/04/11 09:31:57 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.3 2003/07/22 17:03:27 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.4 2004/05/19 22:52:40 dillon Exp $ */ /* misc defines */ @@ -36,7 +36,7 @@ #define AR_READ 0x01 #define AR_WRITE 0x02 #define AR_WAIT 0x04 -#define AR_STRATEGY(x) dev_port_dstrategy((x)->b_dev->si_disk->d_fwdport, (x)->b_dev->si_disk->d_dev, x) +#define AR_STRATEGY(x) dev_dstrategy((x)->b_dev, x) #define AD_SOFTC(x) ((struct ad_softc *)(x.device->driver)) #define ATA_MAGIC "FreeBSD ATA driver RAID " diff --git a/sys/dev/disk/ata/atapi-cd.c b/sys/dev/disk/ata/atapi-cd.c index 973263f08f..b767a0ac58 100644 --- a/sys/dev/disk/ata/atapi-cd.c +++ b/sys/dev/disk/ata/atapi-cd.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/atapi-cd.c,v 1.48.2.20 2002/11/25 05:30:31 njl Exp $ - * $DragonFly: src/sys/dev/disk/ata/atapi-cd.c,v 1.16 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/atapi-cd.c,v 1.17 2004/05/19 22:52:40 dillon Exp $ */ #include "opt_ata.h" @@ -201,9 +201,9 @@ acddetach(struct ata_device *atadev) bp->b_error = ENXIO; biodone(bp); } - destroy_dev(cdp->driver[subdev]->dev); + release_dev(cdp->driver[subdev]->dev); while ((entry = TAILQ_FIRST(&cdp->driver[subdev]->dev_list))) { - destroy_dev(entry->dev); + release_dev(entry->dev); TAILQ_REMOVE(&cdp->driver[subdev]->dev_list, entry, chain); free(entry, M_ACD); } @@ -221,12 +221,13 @@ acddetach(struct ata_device *atadev) biodone(bp); } while ((entry = TAILQ_FIRST(&cdp->dev_list))) { - destroy_dev(entry->dev); + release_dev(entry->dev); TAILQ_REMOVE(&cdp->dev_list, entry, chain); free(entry, M_ACD); } - destroy_dev(cdp->dev); + release_dev(cdp->dev); devstat_remove_entry(cdp->stats); + cdevsw_remove(&acd_cdevsw, dkunitmask(), dkmakeunit(cdp->lun)); free(cdp->stats, M_ACD); ata_free_name(atadev); ata_free_lun(&acd_lun_map, cdp->lun); @@ -256,8 +257,10 @@ acd_make_dev(struct acd_softc *cdp) { dev_t dev; + cdevsw_add(&acd_cdevsw, dkunitmask(), dkmakeunit(cdp->lun)); dev = make_dev(&acd_cdevsw, dkmakeminor(cdp->lun, 0, 0), UID_ROOT, GID_OPERATOR, 0644, "acd%d", cdp->lun); + reference_dev(dev); dev->si_drv1 = cdp; cdp->dev = dev; cdp->device->flags |= ATA_D_MEDIA_CHANGED; @@ -1330,6 +1333,7 @@ acd_read_toc(struct acd_softc *cdp) entry->dev = make_dev(&acd_cdevsw, (cdp->lun << 3) | (track << 16), 0, 0, 0644, name, NULL); entry->dev->si_drv1 = cdp->dev->si_drv1; + reference_dev(entry->dev); TAILQ_INSERT_TAIL(&cdp->dev_list, entry, chain); } diff --git a/sys/dev/disk/ata/atapi-tape.c b/sys/dev/disk/ata/atapi-tape.c index 3a52fbbd9f..28431a64de 100644 --- a/sys/dev/disk/ata/atapi-tape.c +++ b/sys/dev/disk/ata/atapi-tape.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/atapi-tape.c,v 1.36.2.12 2002/07/31 11:19:26 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/atapi-tape.c,v 1.10 2004/05/13 23:49:14 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/atapi-tape.c,v 1.11 2004/05/19 22:52:41 dillon Exp $ */ #include "opt_ata.h" @@ -136,16 +136,15 @@ astattach(struct ata_device *atadev) DEVSTAT_NO_ORDERED_TAGS, DEVSTAT_TYPE_SEQUENTIAL | DEVSTAT_TYPE_IF_IDE, DEVSTAT_PRIORITY_TAPE); + cdevsw_add(&ast_cdevsw, dkunitmask(), dkmakeunit(stp->lun)); dev = make_dev(&ast_cdevsw, dkmakeminor(stp->lun, 0, 0), UID_ROOT, GID_OPERATOR, 0640, "ast%d", stp->lun); dev->si_drv1 = stp; dev->si_iosize_max = 256 * DEV_BSIZE; - stp->dev1 = dev; dev = make_dev(&ast_cdevsw, dkmakeminor(stp->lun, 0, 1), UID_ROOT, GID_OPERATOR, 0640, "nast%d", stp->lun); dev->si_drv1 = stp; dev->si_iosize_max = 256 * DEV_BSIZE; - stp->dev2 = dev; stp->device->flags |= ATA_D_MEDIA_CHANGED; ast_describe(stp); atadev->driver = stp; @@ -164,9 +163,8 @@ astdetach(struct ata_device *atadev) bp->b_error = ENXIO; biodone(bp); } - destroy_dev(stp->dev1); - destroy_dev(stp->dev2); devstat_remove_entry(&stp->stats); + cdevsw_remove(&ast_cdevsw, dkunitmask(), dkmakeunit(stp->lun)); ata_free_name(atadev); ata_free_lun(&ast_lun_map, stp->lun); free(stp, M_AST); diff --git a/sys/dev/disk/ata/atapi-tape.h b/sys/dev/disk/ata/atapi-tape.h index 187499495d..c81ec63841 100644 --- a/sys/dev/disk/ata/atapi-tape.h +++ b/sys/dev/disk/ata/atapi-tape.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/atapi-tape.h,v 1.11.2.5 2002/03/18 08:37:34 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/atapi-tape.h,v 1.2 2003/06/17 04:28:22 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/atapi-tape.h,v 1.3 2004/05/19 22:52:41 dillon Exp $ */ /* ATAPI tape drive Capabilities and Mechanical Status Page */ @@ -159,5 +159,4 @@ struct ast_softc { struct atapi_params *param; /* drive parameters table */ struct ast_cappage cap; /* capabilities page info */ struct devstat stats; /* devstat entry */ - dev_t dev1, dev2; /* device place holders */ }; diff --git a/sys/dev/disk/ccd/ccd.c b/sys/dev/disk/ccd/ccd.c index 8269ab2aca..2fe21024a3 100644 --- a/sys/dev/disk/ccd/ccd.c +++ b/sys/dev/disk/ccd/ccd.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/dev/ccd/ccd.c,v 1.73.2.1 2001/09/11 09:49:52 kris Exp $ */ -/* $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.15 2004/05/13 23:49:15 dillon Exp $ */ +/* $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.16 2004/05/19 22:52:41 dillon Exp $ */ /* $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ */ @@ -159,7 +159,7 @@ struct ccdbuf { #define CCDPF_MIRROR_DONE 1 /* if set, mirror counterpart is done */ #define CCDLABELDEV(dev) \ - (makedev(major((dev)), dkmakeminor(ccdunit((dev)), 0, RAW_PART))) + (make_sub_dev(dev, dkmakeminor(ccdunit((dev)), 0, RAW_PART))) static d_open_t ccdopen; static d_close_t ccdclose; @@ -316,7 +316,7 @@ ccdattach() M_WAITOK | M_ZERO); numccd = num; - cdevsw_add(&ccd_cdevsw); + cdevsw_add(&ccd_cdevsw, 0, 0); /* XXX: is this necessary? */ for (i = 0; i < numccd; ++i) ccddevs[i].ccd_dk = -1; @@ -1462,9 +1462,10 @@ ccdioctl(dev_t dev, u_long cmd, caddr_t data, int flag, d_thread_t *td) error = setdisklabel(&cs->sc_label, (struct disklabel *)data, 0); if (error == 0) { - if (cmd == DIOCWDINFO) - error = writedisklabel(CCDLABELDEV(dev), - &cs->sc_label); + if (cmd == DIOCWDINFO) { + dev_t cdev = CCDLABELDEV(dev); + error = writedisklabel(cdev, &cs->sc_label); + } } cs->sc_flags &= ~CCDF_LABELLING; @@ -1521,10 +1522,8 @@ ccdsize(dev_t dev) } static int -ccddump(dev) - dev_t dev; +ccddump(dev_t dev, u_int count, u_int blkno, u_int secsize) { - /* Not implemented. */ return ENXIO; } @@ -1593,6 +1592,7 @@ ccdgetdisklabel(dev) char *errstring; struct disklabel *lp = &cs->sc_label; struct ccdgeom *ccg = &cs->sc_geom; + dev_t cdev; bzero(lp, sizeof(*lp)); @@ -1625,7 +1625,8 @@ ccdgetdisklabel(dev) /* * Call the generic disklabel extraction routine. */ - errstring = readdisklabel(CCDLABELDEV(dev), &cs->sc_label); + cdev = CCDLABELDEV(dev); + errstring = readdisklabel(cdev, &cs->sc_label); if (errstring != NULL) ccdmakedisklabel(cs); diff --git a/sys/dev/disk/fd/fd.c b/sys/dev/disk/fd/fd.c index 7c9967abaf..89b265bfd0 100644 --- a/sys/dev/disk/fd/fd.c +++ b/sys/dev/disk/fd/fd.c @@ -51,7 +51,7 @@ * * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 * $FreeBSD: src/sys/isa/fd.c,v 1.176.2.8 2002/05/15 21:56:14 joerg Exp $ - * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.15 2004/05/13 23:49:15 dillon Exp $ + * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.16 2004/05/19 22:52:41 dillon Exp $ * */ @@ -1019,14 +1019,10 @@ fd_attach(device_t dev) int typemynor; int typesize; #endif - static int cdevsw_add_done = 0; fd = device_get_softc(dev); - if (!cdevsw_add_done) { - cdevsw_add(&fd_cdevsw); /* XXX */ - cdevsw_add_done++; - } + cdevsw_add(&fd_cdevsw, -1 << 6, fd->fdu << 6); make_dev(&fd_cdevsw, (fd->fdu << 6), UID_ROOT, GID_OPERATOR, 0640, "rfd%d", fd->fdu); @@ -2102,16 +2098,18 @@ retrier(struct fdc_data *fdc) fail: { int printerror = (fd->options & FDOPT_NOERRLOG) == 0; - dev_t sav_b_dev = bp->b_dev; + dev_t sav_b_dev; /* Trick diskerr */ - bp->b_dev = makedev(major(bp->b_dev), + if (printerror) { + sav_b_dev = bp->b_dev; + bp->b_dev = make_sub_dev(bp->b_dev, (FDUNIT(minor(bp->b_dev))<<3)|RAW_PART); - if (printerror) diskerr(bp, "hard error", LOG_PRINTF, fdc->fd->skip / DEV_BSIZE, (struct disklabel *)NULL); - bp->b_dev = sav_b_dev; + bp->b_dev = sav_b_dev; + } if (printerror) { if (fdc->flags & FDC_STAT_VALID) printf( diff --git a/sys/dev/disk/isp/isp_freebsd.c b/sys/dev/disk/isp/isp_freebsd.c index 1ea6f15f78..dc2e4ac691 100644 --- a/sys/dev/disk/isp/isp_freebsd.c +++ b/sys/dev/disk/isp/isp_freebsd.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/dev/isp/isp_freebsd.c,v 1.32.2.20 2002/10/11 18:49:25 mjacob Exp $ */ -/* $DragonFly: src/sys/dev/disk/isp/isp_freebsd.c,v 1.9 2004/05/13 23:49:15 dillon Exp $ */ +/* $DragonFly: src/sys/dev/disk/isp/isp_freebsd.c,v 1.10 2004/05/19 22:52:41 dillon Exp $ */ /* * Platform (FreeBSD) dependent common attachment code for Qlogic adapters. * @@ -203,7 +203,8 @@ isp_attach(struct ispsoftc *isp) /* * Create device nodes */ - (void) make_dev(&isp_cdevsw, device_get_unit(isp->isp_dev), UID_ROOT, + cdevsw_add(&isp_cdevsw, -1, device_get_unit(isp->isp_dev)); + make_dev(&isp_cdevsw, device_get_unit(isp->isp_dev), UID_ROOT, GID_OPERATOR, 0600, "%s", device_get_nameunit(isp->isp_dev)); if (isp->isp_role != ISP_ROLE_NONE) { diff --git a/sys/dev/disk/mcd/mcd.c b/sys/dev/disk/mcd/mcd.c index c921ab159b..9be7afb4a8 100644 --- a/sys/dev/disk/mcd/mcd.c +++ b/sys/dev/disk/mcd/mcd.c @@ -41,7 +41,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/mcd.c,v 1.115 2000/01/29 16:17:34 peter Exp $ - * $DragonFly: src/sys/dev/disk/mcd/Attic/mcd.c,v 1.8 2004/05/13 23:49:15 dillon Exp $ + * $DragonFly: src/sys/dev/disk/mcd/Attic/mcd.c,v 1.9 2004/05/19 22:52:41 dillon Exp $ */ static const char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; @@ -257,6 +257,7 @@ int mcd_attach(struct isa_device *dev) mcd_configure(cd); #endif /* name filled in probe */ + cdevsw_add(&mcd_cdevsw, dkunitmask(), dkmakeunit(unit)); make_dev(&mcd_cdevsw, dkmakeminor(unit, 0, 0), UID_ROOT, GID_OPERATOR, 0640, "rmcd%da", unit); make_dev(&mcd_cdevsw, dkmakeminor(unit, 0, RAW_PART), @@ -728,10 +729,6 @@ mcd_probe(struct isa_device *dev) int unit = dev->id_unit; int i, j; unsigned char stbytes[3]; - static int once; - - if (!once++) - cdevsw_add(&mcd_cdevsw); mcd_data[unit].flags = MCDPROBING; diff --git a/sys/dev/disk/scd/scd.c b/sys/dev/disk/scd/scd.c index b1e220226c..48a7b00fc1 100644 --- a/sys/dev/disk/scd/scd.c +++ b/sys/dev/disk/scd/scd.c @@ -42,7 +42,7 @@ /* $FreeBSD: src/sys/i386/isa/scd.c,v 1.54 2000/01/29 16:00:30 peter Exp $ */ -/* $DragonFly: src/sys/dev/disk/scd/Attic/scd.c,v 1.9 2004/05/13 23:49:15 dillon Exp $ */ +/* $DragonFly: src/sys/dev/disk/scd/Attic/scd.c,v 1.10 2004/05/19 22:52:41 dillon Exp $ */ /* Please send any comments to micke@dynas.se */ @@ -218,6 +218,7 @@ scd_attach(struct isa_device *dev) cd->audio_status = CD_AS_AUDIO_INVALID; bufq_init(&cd->head); + cdevsw_add(&scd_cdevsw, dkunitmask(), dkmakeunit(unit)); make_dev(&scd_cdevsw, dkmakeminor(unit, 0, 0), UID_ROOT, GID_OPERATOR, 0640, "rscd%da", unit); make_dev(&scd_cdevsw, dkmakeminor(unit, 0, RAW_PART), @@ -694,10 +695,6 @@ scd_probe(struct isa_device *dev) static char namebuf[8+16+8+3]; char *s = namebuf; int loop_count = 0; - static int once; - - if (!once++) - cdevsw_add(&scd_cdevsw); scd_data[unit].flags = SCDPROBING; scd_data[unit].iobase = dev->id_iobase; diff --git a/sys/dev/disk/vn/vn.c b/sys/dev/disk/vn/vn.c index 013889af71..dd3cd5995b 100644 --- a/sys/dev/disk/vn/vn.c +++ b/sys/dev/disk/vn/vn.c @@ -39,7 +39,7 @@ * * from: @(#)vn.c 8.6 (Berkeley) 4/1/94 * $FreeBSD: src/sys/dev/vn/vn.c,v 1.105.2.4 2001/11/18 07:11:00 dillon Exp $ - * $DragonFly: src/sys/dev/disk/vn/vn.c,v 1.9 2004/05/13 23:49:15 dillon Exp $ + * $DragonFly: src/sys/dev/disk/vn/vn.c,v 1.10 2004/05/19 22:52:42 dillon Exp $ */ /* @@ -180,31 +180,29 @@ vnfindvn(dev_t dev) struct vn_softc *vn; unit = dkunit(dev); - vn = dev->si_drv1; - if (!vn) { - SLIST_FOREACH(vn, &vn_list, sc_list) { - if (vn->sc_unit == unit) { - dev->si_drv2 = vn->sc_devlist; - vn->sc_devlist = dev; - dev->si_drv1 = vn; - break; - } + SLIST_FOREACH(vn, &vn_list, sc_list) { + if (vn->sc_unit == unit) { + dev->si_drv2 = vn->sc_devlist; + vn->sc_devlist = dev; + reference_dev(dev); + dev->si_drv1 = vn; + break; } } - if (!vn) { - vn = malloc(sizeof *vn, M_DEVBUF, M_WAITOK); - if (!vn) - return (NULL); - bzero(vn, sizeof *vn); + if (vn == NULL) { + vn = malloc(sizeof *vn, M_DEVBUF, M_WAITOK | M_ZERO); vn->sc_unit = unit; dev->si_drv1 = vn; - vn->sc_devlist = make_dev(&vn_cdevsw, 0, - UID_ROOT, GID_OPERATOR, 0640, "vn%d", unit); + vn->sc_devlist = make_dev(&vn_cdevsw, 0, UID_ROOT, + GID_OPERATOR, 0640, "vn%d", unit); + reference_dev(vn->sc_devlist); vn->sc_devlist->si_drv1 = vn; vn->sc_devlist->si_drv2 = NULL; if (vn->sc_devlist != dev) { + dev->si_drv1 = vn; dev->si_drv2 = vn->sc_devlist; vn->sc_devlist = dev; + reference_dev(dev); } SLIST_INSERT_HEAD(&vn_list, vn, sc_list); } @@ -293,8 +291,7 @@ vnstrategy(struct buf *bp) int error; unit = dkunit(bp->b_dev); - vn = bp->b_dev->si_drv1; - if (!vn) + if ((vn = bp->b_dev->si_drv1) == NULL) vn = vnfindvn(bp->b_dev); IFOPT(vn, VN_DEBUG) @@ -772,9 +769,8 @@ vn_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: - cdevsw_add(&vn_cdevsw); + cdevsw_add(&vn_cdevsw, 0, 0); break; - case MOD_UNLOAD: /* fall through */ case MOD_SHUTDOWN: @@ -789,13 +785,11 @@ vn_modevent(module_t mod, int type, void *data) while ((dev = vn->sc_devlist) != NULL) { vn->sc_devlist = dev->si_drv2; dev->si_drv1 = dev->si_drv2 = NULL; - /* If the last one, destroy it. */ - if (vn->sc_devlist == NULL) - destroy_dev(dev); + destroy_dev(dev); } free(vn, M_DEVBUF); } - cdevsw_remove(&vn_cdevsw); + cdevsw_remove(&vn_cdevsw, -1, 0); break; default: break; diff --git a/sys/dev/disk/wt/wt.c b/sys/dev/disk/wt/wt.c index da43c33201..f0885c88a5 100644 --- a/sys/dev/disk/wt/wt.c +++ b/sys/dev/disk/wt/wt.c @@ -21,7 +21,7 @@ * * Version 1.3, Thu Nov 11 12:09:13 MSK 1993 * $FreeBSD: src/sys/i386/isa/wt.c,v 1.57.2.1 2000/08/08 19:49:53 peter Exp $ - * $DragonFly: src/sys/dev/disk/wt/wt.c,v 1.7 2004/05/13 23:49:15 dillon Exp $ + * $DragonFly: src/sys/dev/disk/wt/wt.c,v 1.8 2004/05/19 22:52:42 dillon Exp $ * */ @@ -208,10 +208,6 @@ static int wtprobe (struct isa_device *id) { wtinfo_t *t = wttab + id->id_unit; - static int once; - - if (!once++) - cdevsw_add(&wt_cdevsw); t->unit = id->id_unit; t->chan = id->id_drq; @@ -268,6 +264,7 @@ wtattach (struct isa_device *id) t->dens = -1; /* unknown density */ isa_dmainit(t->chan, 1024); + cdevsw_add(&wt_cdevsw, -1, id->id_unit); make_dev(&wt_cdevsw, id->id_unit, 0, 0, 0600, "rwt%d", id->id_unit); return (1); } diff --git a/sys/dev/drm/drm_drv.h b/sys/dev/drm/drm_drv.h index c76d72a310..428afc8ecb 100644 --- a/sys/dev/drm/drm_drv.h +++ b/sys/dev/drm/drm_drv.h @@ -29,7 +29,7 @@ * Gareth Hughes * * $FreeBSD: src/sys/dev/drm/drm_drv.h,v 1.13.2.1 2003/04/26 07:05:28 anholt Exp $ - * $DragonFly: src/sys/dev/drm/Attic/drm_drv.h,v 1.7 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/drm/Attic/drm_drv.h,v 1.8 2004/05/19 22:52:42 dillon Exp $ */ /* @@ -654,12 +654,14 @@ static int DRM(init)( device_t nbdev ) dev = device_get_softc(nbdev); memset( (void *)dev, 0, sizeof(*dev) ); dev->device = nbdev; + cdevsw_add(&DRM(cdevsw), -1, unit); dev->devnode = make_dev( &DRM(cdevsw), unit, DRM_DEV_UID, DRM_DEV_GID, DRM_DEV_MODE, "dri/card%d", unit ); + reference_dev(dev->devnode); #elif defined(__NetBSD__) unit = minor(dev->device.dv_unit); #endif @@ -772,6 +774,7 @@ static void DRM(cleanup)(device_t nbdev) #endif } #endif + cdevsw_remove(&DRM(cdevsw), -1, device_get_unit(nbdev)); DRM(takedown)( dev ); diff --git a/sys/dev/misc/gpib/gpib.c b/sys/dev/misc/gpib/gpib.c index 17cd638912..a5e1e61a69 100644 --- a/sys/dev/misc/gpib/gpib.c +++ b/sys/dev/misc/gpib/gpib.c @@ -17,7 +17,7 @@ * all derivative works or modified versions. * * $FreeBSD: src/sys/i386/isa/gpib.c,v 1.29 2000/01/29 16:17:32 peter Exp $ - * $DragonFly: src/sys/dev/misc/gpib/gpib.c,v 1.8 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/gpib/gpib.c,v 1.9 2004/05/19 22:52:42 dillon Exp $ * */ /*Please read the README file for usage information*/ @@ -106,10 +106,6 @@ gpprobe(struct isa_device *dvp) { int status; struct gpib_softc *sc = &gpib_sc; - static int once; - - if (!once++) - cdevsw_add(&gp_cdevsw); gpib_port = dvp->id_iobase; status=1; @@ -141,7 +137,8 @@ gpattach(isdp) printf ("gp%d: type AT-GPIB chip NAT4882A\n",sc->sc_unit); sc->sc_flags |=ATTACHED; - make_dev(&gp_cdevsw, 0, 0, 0, 0600, "gp"); + cdevsw_add(&gp_cdevsw, -1, sc->sc_unit); + make_dev(&gp_cdevsw, sc->sc_unit, 0, 0, 0600, "gp"); return (1); } diff --git a/sys/dev/misc/joy/joy.c b/sys/dev/misc/joy/joy.c index 69012afe49..515776504a 100644 --- a/sys/dev/misc/joy/joy.c +++ b/sys/dev/misc/joy/joy.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/isa/joy.c,v 1.38.2.1 2001/09/01 05:55:31 murray Exp $ - * $DragonFly: src/sys/dev/misc/joy/joy.c,v 1.6 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/joy/joy.c,v 1.7 2004/05/19 22:52:42 dillon Exp $ */ #include @@ -143,7 +143,8 @@ joy_attach (device_t dev) joy->bt = rman_get_bustag(res); joy->port = rman_get_bushandle(res); joy->timeout[0] = joy->timeout[1] = 0; - make_dev(&joy_cdevsw, 0, 0, 0, 0600, "joy%d", unit); + cdevsw_add(&joy_cdevsw, -1, unit); + make_dev(&joy_cdevsw, unit, 0, 0, 0600, "joy%d", unit); return 0; } diff --git a/sys/dev/misc/kbd/kbd.c b/sys/dev/misc/kbd/kbd.c index 6645cf5e7d..2d97477e68 100644 --- a/sys/dev/misc/kbd/kbd.c +++ b/sys/dev/misc/kbd/kbd.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/kbd/kbd.c,v 1.17.2.2 2001/07/30 16:46:43 yokota Exp $ - * $DragonFly: src/sys/dev/misc/kbd/kbd.c,v 1.9 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/kbd/kbd.c,v 1.10 2004/05/19 22:52:42 dillon Exp $ */ #include "opt_kbd.h" @@ -447,6 +447,7 @@ kbd_attach(keyboard_t *kbd) if (keyboard[kbd->kb_index] != kbd) return EINVAL; + cdevsw_add(&kbd_cdevsw, -1, kbd->kb_index); dev = make_dev(&kbd_cdevsw, kbd->kb_index, UID_ROOT, GID_WHEEL, 0600, "kbd%r", kbd->kb_index); if (dev->si_drv1 == NULL) @@ -468,10 +469,17 @@ kbd_detach(keyboard_t *kbd) if (keyboard[kbd->kb_index] != kbd) return EINVAL; - dev = makedev(kbd_cdevsw.d_maj, kbd->kb_index); - if (dev->si_drv1) - free(dev->si_drv1, M_DEVBUF); - destroy_dev(dev); + /* + * Deal with refs properly. The KBD driver really ought to have + * recorded the dev_t separately. + */ + if ((dev = make_adhoc_dev(&kbd_cdevsw, kbd->kb_index)) != NODEV) { + if (dev->si_drv1) { + free(dev->si_drv1, M_DEVBUF); + dev->si_drv1 = NULL; + } + } + cdevsw_remove(&kbd_cdevsw, -1, kbd->kb_index); return 0; } diff --git a/sys/dev/misc/labpc/labpc.c b/sys/dev/misc/labpc/labpc.c index 36eb744223..367b80ccd5 100644 --- a/sys/dev/misc/labpc/labpc.c +++ b/sys/dev/misc/labpc/labpc.c @@ -39,7 +39,7 @@ * dufault@hda.com * * $FreeBSD: src/sys/i386/isa/labpc.c,v 1.35 1999/09/25 18:24:08 phk Exp $ - * $DragonFly: src/sys/dev/misc/labpc/labpc.c,v 1.7 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/labpc/labpc.c,v 1.8 2004/05/19 22:52:43 dillon Exp $ * */ @@ -413,7 +413,6 @@ labpcinit(void) if (labpcs) { return 1; } - cdevsw_add(&labpc_cdevsw); return 0; } @@ -491,7 +490,9 @@ labpcattach(struct isa_device *dev) ctlr->dcr_is = 0x80; loutb(DCR(ctlr), ctlr->dcr_val); - make_dev(&labpc_cdevsw, 0, 0, 0, 0600, "labpc%d", dev->id_unit); + cdevsw_add(&labpc_cdevsw, -1, dev->id_unit); + make_dev(&labpc_cdevsw, dev->id_unit, 0, 0, 0600, + "labpc%d", dev->id_unit); return 1; } diff --git a/sys/dev/misc/lpt/lpt.c b/sys/dev/misc/lpt/lpt.c index d907d14a94..addee22908 100644 --- a/sys/dev/misc/lpt/lpt.c +++ b/sys/dev/misc/lpt/lpt.c @@ -49,7 +49,7 @@ * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp * From Id: nlpt.c,v 1.14 1999/02/08 13:55:43 des Exp * $FreeBSD: src/sys/dev/ppbus/lpt.c,v 1.15.2.3 2000/07/07 00:30:40 obrien Exp $ - * $DragonFly: src/sys/dev/misc/lpt/lpt.c,v 1.8 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/lpt/lpt.c,v 1.9 2004/05/19 22:52:43 dillon Exp $ */ /* @@ -115,6 +115,7 @@ struct lpt_data { prime once */ u_char sc_control; char sc_flags; +#define LP_UNITMASK 0x03 /* up to 4 units */ #define LP_POS_INIT 0x04 /* if we are a postive init signal */ #define LP_POS_ACK 0x08 /* if we are a positive going ack */ #define LP_NO_PRIME 0x10 /* don't prime the printer at all */ @@ -415,6 +416,7 @@ lpt_attach(device_t dev) lpt_release_ppbus(dev); + cdevsw_add(&lpt_cdevsw, LP_UNITMASK, unit); make_dev(&lpt_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d", unit); make_dev(&lpt_cdevsw, unit | LP_BYPASS, diff --git a/sys/dev/misc/mse/mse.c b/sys/dev/misc/mse/mse.c index a66fc14323..9cdd9f70ae 100644 --- a/sys/dev/misc/mse/mse.c +++ b/sys/dev/misc/mse/mse.c @@ -12,7 +12,7 @@ * without express or implied warranty. * * $FreeBSD: src/sys/i386/isa/mse.c,v 1.49.2.1 2000/03/20 13:58:47 yokota Exp $ - * $DragonFly: src/sys/dev/misc/mse/mse.c,v 1.8 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/mse/mse.c,v 1.9 2004/05/19 22:52:43 dillon Exp $ */ /* * Driver for the Logitech and ATI Inport Bus mice for use with 386bsd and @@ -95,8 +95,6 @@ typedef struct mse_softc { u_char sc_bytes[MOUSE_SYS_PACKETSIZE]; struct callout_handle sc_callout; int sc_watchdog; - dev_t sc_dev; - dev_t sc_ndev; mousehw_t hw; mousemode_t mode; mousestatus_t status; @@ -362,10 +360,9 @@ mse_attach(dev) sc->mode.accelfactor = (flags & MSE_CONFIG_ACCEL) >> 4; callout_handle_init(&sc->sc_callout); - sc->sc_dev = make_dev(&mse_cdevsw, unit << 1, 0, 0, 0600, - "mse%d", unit); - sc->sc_ndev = make_dev(&mse_cdevsw, (unit<<1)+1, 0, 0, 0600, - "nmse%d", unit); + cdevsw_add(&mse_cdevsw, ~1, unit << 1); + make_dev(&mse_cdevsw, unit << 1, 0, 0, 0600, "mse%d", unit); + make_dev(&mse_cdevsw, (unit<<1)+1, 0, 0, 0600, "nmse%d", unit); return 0; } @@ -385,9 +382,7 @@ mse_detach(dev) BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->sc_intr, sc->sc_ih); bus_release_resource(dev, SYS_RES_IRQ, rid, sc->sc_intr); bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port); - - destroy_dev(sc->sc_dev); - destroy_dev(sc->sc_ndev); + cdevsw_remove(&mse_cdevsw, ~1, device_get_unit(dev) << 1); return 0; } diff --git a/sys/dev/misc/nmdm/nmdm.c b/sys/dev/misc/nmdm/nmdm.c index 4b8f142f29..7ddf20a36f 100644 --- a/sys/dev/misc/nmdm/nmdm.c +++ b/sys/dev/misc/nmdm/nmdm.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/nmdm/nmdm.c,v 1.5.2.1 2001/08/11 00:54:14 mp Exp $ - * $DragonFly: src/sys/dev/misc/nmdm/nmdm.c,v 1.9 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/nmdm/nmdm.c,v 1.10 2004/05/19 22:52:43 dillon Exp $ */ /* @@ -130,15 +130,19 @@ nmdminit(n) dev_t dev1, dev2; struct nm_softc *pt; - /* For now we only map the lower 8 bits of the minor */ - if (n & ~0xff) + /* + * Simplified unit number, use low 8 bits of minor number + * (remember, the minor number mask is 0xffff00ff). + */ + if (n & ~0x7f) return; pt = malloc(sizeof(*pt), M_NLMDM, M_WAITOK); bzero(pt, sizeof(*pt)); - pt->part1.dev = dev1 = make_dev(&nmdm_cdevsw, n+n, + cdevsw_add(&nmdm_cdevsw, ~1, n << 1); + pt->part1.dev = dev1 = make_dev(&nmdm_cdevsw, n << 1, 0, 0, 0666, "nmdm%dA", n); - pt->part2.dev = dev2 = make_dev(&nmdm_cdevsw, n+n+1, + pt->part2.dev = dev2 = make_dev(&nmdm_cdevsw, (n << 1) + 1, 0, 0, 0666, "nmdm%dB", n); dev1->si_drv1 = dev2->si_drv1 = pt; @@ -162,7 +166,9 @@ nmdmopen(dev_t dev, int flag, int devtype, struct thread *td) struct tty *tp, *tp2; int error; int minr; +#if 0 dev_t nextdev; +#endif struct nm_softc *pti; int is_b; int pair; @@ -170,21 +176,23 @@ nmdmopen(dev_t dev, int flag, int devtype, struct thread *td) KKASSERT(p != NULL); + minr = lminor(dev); + pair = minr >> 1; + is_b = minr & 1; + +#if 0 /* * XXX: Gross hack for DEVFS: * If we openned this device, ensure we have the * next one too, so people can open it. */ - minr = lminor(dev); - pair = minr >> 1; - is_b = minr & 1; - if (pair < 127) { nextdev = makedev(major(dev), (pair+pair) + 1); if (!nextdev->si_drv1) { nmdminit(pair + 1); } } +#endif if (!dev->si_drv1) nmdminit(pair); @@ -565,7 +573,6 @@ static void nmdm_drvinit(unused) void *unused; { - cdevsw_add(&nmdm_cdevsw); /* XXX: Gross hack for DEVFS */ nmdminit(0); } diff --git a/sys/dev/misc/pcfclock/pcfclock.c b/sys/dev/misc/pcfclock/pcfclock.c index 7704d7f389..9093df2acf 100644 --- a/sys/dev/misc/pcfclock/pcfclock.c +++ b/sys/dev/misc/pcfclock/pcfclock.c @@ -22,7 +22,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ppbus/pcfclock.c,v 1.3.2.1 2000/05/24 00:20:57 n_hibma Exp $ - * $DragonFly: src/sys/dev/misc/pcfclock/pcfclock.c,v 1.6 2004/05/13 23:49:16 dillon Exp $ + * $DragonFly: src/sys/dev/misc/pcfclock/pcfclock.c,v 1.7 2004/05/19 22:52:43 dillon Exp $ * */ @@ -152,6 +152,7 @@ pcfclock_attach(device_t dev) unit = device_get_unit(dev); + cdevsw_add(&pcfclock_cdevsw, -1, unit); make_dev(&pcfclock_cdevsw, unit, UID_ROOT, GID_WHEEL, 0444, PCFCLOCK_NAME "%d", unit); diff --git a/sys/dev/misc/ppi/ppi.c b/sys/dev/misc/ppi/ppi.c index 7b57899820..418e59efd9 100644 --- a/sys/dev/misc/ppi/ppi.c +++ b/sys/dev/misc/ppi/ppi.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ppbus/ppi.c,v 1.21.2.3 2000/08/07 18:24:43 peter Exp $ - * $DragonFly: src/sys/dev/misc/ppi/ppi.c,v 1.7 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/ppi/ppi.c,v 1.8 2004/05/19 22:52:43 dillon Exp $ * */ #include "opt_ppb_1284.h" @@ -181,6 +181,7 @@ ppi_attach(device_t dev) &zero, irq, irq, 1, RF_ACTIVE); #endif /* PERIPH_1284 */ + cdevsw_add(&ppi_cdevsw, -1, device_get_unit(dev)); make_dev(&ppi_cdevsw, device_get_unit(dev), /* XXX cleanup */ UID_ROOT, GID_WHEEL, 0600, "ppi%d", device_get_unit(dev)); diff --git a/sys/dev/misc/pps/pps.c b/sys/dev/misc/pps/pps.c index d8131dfef7..11047747d5 100644 --- a/sys/dev/misc/pps/pps.c +++ b/sys/dev/misc/pps/pps.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/dev/ppbus/pps.c,v 1.24.2.1 2000/05/24 00:20:57 n_hibma Exp $ - * $DragonFly: src/sys/dev/misc/pps/pps.c,v 1.8 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/pps/pps.c,v 1.9 2004/05/19 22:52:43 dillon Exp $ * * This driver implements a draft-mogul-pps-api-02.txt PPS source. * @@ -91,15 +91,10 @@ ppsprobe(device_t ppsdev) { struct pps_data *sc; dev_t dev; - int unit; sc = DEVTOSOFTC(ppsdev); bzero(sc, sizeof(struct pps_data)); - unit = device_get_unit(ppsdev); - dev = make_dev(&pps_cdevsw, unit, - UID_ROOT, GID_WHEEL, 0644, PPS_NAME "%d", unit); - device_set_desc(ppsdev, "Pulse per second Timing Interface"); sc->pps.ppscap = PPS_CAPTUREASSERT | PPS_ECHOASSERT; @@ -113,6 +108,7 @@ ppsattach(device_t dev) struct pps_data *sc = DEVTOSOFTC(dev); device_t ppbus = device_get_parent(dev); int irq, zero = 0; + int unit; /* retrieve the ppbus irq */ BUS_READ_IVAR(ppbus, dev, PPBUS_IVAR_IRQ, &irq); @@ -126,6 +122,10 @@ ppsattach(device_t dev) if (sc->intr_resource == 0) return (ENXIO); + unit = device_get_unit(ppsdev); + cdevsw_add(&pps_cdevsw, -1, unit); + dev = make_dev(&pps_cdevsw, unit, UID_ROOT, GID_WHEEL, 0644, + PPS_NAME "%d", unit); return (0); } diff --git a/sys/dev/misc/psm/psm.c b/sys/dev/misc/psm/psm.c index b9dd0bb8ea..c4cbbcc0a8 100644 --- a/sys/dev/misc/psm/psm.c +++ b/sys/dev/misc/psm/psm.c @@ -21,7 +21,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/isa/psm.c,v 1.23.2.7 2003/11/12 04:26:26 mikeh Exp $ - * $DragonFly: src/sys/dev/misc/psm/psm.c,v 1.10 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/psm/psm.c,v 1.11 2004/05/19 22:52:44 dillon Exp $ */ /* @@ -130,7 +130,7 @@ /* some macros */ #define PSM_UNIT(dev) (minor(dev) >> 1) #define PSM_NBLOCKIO(dev) (minor(dev) & 1) -#define PSM_MKMINOR(unit,block) (((unit) << 1) | ((block) ? 0:1)) +#define PSM_MKMINOR(unit,block) ((((unit) & 0xff) << 1) | ((block) ? 0:1)) #ifndef max #define max(x,y) ((x) > (y) ? (x) : (y)) @@ -173,8 +173,6 @@ struct psm_softc { /* Driver status information */ struct timeval inputtimeout; int watchdog; /* watchdog timer flag */ struct callout_handle callout; /* watchdog timer call out */ - dev_t dev; - dev_t bdev; }; devclass_t psm_devclass; #define PSM_SOFTC(unit) ((struct psm_softc*)devclass_get_softc(psm_devclass, unit)) @@ -1250,10 +1248,9 @@ psmattach(device_t dev) } /* Done */ - sc->dev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, FALSE), 0, 0, 0666, - "psm%d", unit); - sc->bdev = make_dev(&psm_cdevsw, PSM_MKMINOR(unit, TRUE), 0, 0, 0666, - "bpsm%d", unit); + cdevsw_add(&psm_cdevsw, PSM_MKMINOR(-1, 0), PSM_MKMINOR(unit, 0)); + make_dev(&psm_cdevsw, PSM_MKMINOR(unit, FALSE), 0, 0, 0666, "psm%d", unit); + make_dev(&psm_cdevsw, PSM_MKMINOR(unit, TRUE), 0, 0, 0666, "bpsm%d", unit); if (!verbose) { printf("psm%d: model %s, device ID %d\n", @@ -1279,17 +1276,18 @@ psmdetach(device_t dev) { struct psm_softc *sc; int rid; + int unit; sc = device_get_softc(dev); if (sc->state & PSM_OPEN) return EBUSY; + unit = device_get_unit(dev); + rid = 0; BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->intr, sc->ih); bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); - - destroy_dev(sc->dev); - destroy_dev(sc->bdev); + cdevsw_remove(&psm_cdevsw, PSM_MKMINOR(-1, 0), PSM_MKMINOR(unit, 0)); return 0; } diff --git a/sys/dev/misc/snp/snp.c b/sys/dev/misc/snp/snp.c index f6392ad594..bd6b21c859 100644 --- a/sys/dev/misc/snp/snp.c +++ b/sys/dev/misc/snp/snp.c @@ -13,7 +13,7 @@ * Snoop stuff. * * $FreeBSD: src/sys/dev/snp/snp.c,v 1.69.2.2 2002/05/06 07:30:02 dd Exp $ - * $DragonFly: src/sys/dev/misc/snp/snp.c,v 1.9 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/snp/snp.c,v 1.10 2004/05/19 22:52:44 dillon Exp $ */ #include @@ -386,8 +386,9 @@ snpopen(dev_t dev, int flag, int mode, d_thread_t *td) 0600, "snp%d", minor(dev)); dev->si_drv1 = snp = malloc(sizeof(*snp), M_SNP, M_WAITOK | M_ZERO); - } else + } else { return (EBUSY); + } /* * We intentionally do not OR flags with SNOOP_OPEN, but set them so @@ -596,13 +597,13 @@ snp_modevent(mod, type, data) switch (type) { case MOD_LOAD: snooplinedisc = ldisc_register(LDISC_LOAD, &snpdisc); - cdevsw_add(&snp_cdevsw); + cdevsw_add(&snp_cdevsw, 0, 0); break; case MOD_UNLOAD: if (!LIST_EMPTY(&snp_sclist)) return (EBUSY); ldisc_deregister(snooplinedisc); - cdevsw_remove(&snp_cdevsw); + cdevsw_remove(&snp_cdevsw, 0, 0); break; default: break; diff --git a/sys/dev/misc/spic/spic.c b/sys/dev/misc/spic/spic.c index 4bbcf843b4..01492f80d9 100644 --- a/sys/dev/misc/spic/spic.c +++ b/sys/dev/misc/spic/spic.c @@ -48,7 +48,7 @@ * also provided sample code upon which this driver was based. * * $FreeBSD: src/sys/i386/isa/spic.c,v 1.4.2.1 2002/04/15 00:52:12 will Exp $ - * $DragonFly: src/sys/dev/misc/spic/spic.c,v 1.7 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/spic/spic.c,v 1.8 2004/05/19 22:52:44 dillon Exp $ */ #include @@ -355,7 +355,8 @@ spic_attach(device_t dev) spic_call1(sc, 0x92); /* There can be only one */ - make_dev(&spic_cdevsw, 0, 0, 0, 0600, "jogdial"); + cdevsw_add(&spic_cdevsw, -1, device_get_unit(dev)); + make_dev(&spic_cdevsw, device_get_unit(deV), 0, 0, 0600, "jogdial"); return 0; } diff --git a/sys/dev/misc/spigot/spigot.c b/sys/dev/misc/spigot/spigot.c index 4e2be6c29c..5bdfa88140 100644 --- a/sys/dev/misc/spigot/spigot.c +++ b/sys/dev/misc/spigot/spigot.c @@ -43,7 +43,7 @@ * Version 1.7, December 1995. * * $FreeBSD: src/sys/i386/isa/spigot.c,v 1.44 2000/01/29 16:17:36 peter Exp $ - * $DragonFly: src/sys/dev/misc/spigot/spigot.c,v 1.8 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/spigot/spigot.c,v 1.9 2004/05/19 22:52:44 dillon Exp $ * */ @@ -120,13 +120,10 @@ static ointhand2_t spigintr; static int spigot_probe(struct isa_device *devp) { -int status; -struct spigot_softc *ss=(struct spigot_softc *)&spigot_softc[devp->id_unit]; -static int once; - - if (!once++) - cdevsw_add(&spigot_cdevsw); + struct spigot_softc *ss; + int status; + ss = (struct spigot_softc *)&spigot_softc[devp->id_unit]; ss->flags = 0; ss->maddr = 0; ss->irq = 0; @@ -150,6 +147,7 @@ spigot_attach(struct isa_device *devp) devp->id_ointr = spigintr; ss->maddr = kvtop(devp->id_maddr); ss->irq = devp->id_irq; + cdevsw_add(&spigot_cdevsw, -1, unit); make_dev(&spigot_cdevsw, unit, 0, 0, 0644, "spigot%d", unit); return 1; } diff --git a/sys/dev/misc/streams/streams.c b/sys/dev/misc/streams/streams.c index f58076de72..84e5e920d2 100644 --- a/sys/dev/misc/streams/streams.c +++ b/sys/dev/misc/streams/streams.c @@ -31,7 +31,7 @@ * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-). * * $FreeBSD: src/sys/dev/streams/streams.c,v 1.16.2.1 2001/02/26 04:23:07 jlemon Exp $ - * $DragonFly: src/sys/dev/misc/streams/Attic/streams.c,v 1.11 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/streams/Attic/streams.c,v 1.12 2004/05/19 22:52:44 dillon Exp $ */ #include @@ -96,9 +96,6 @@ enum { dev_unix_ord_stream = 40 }; -dev_t dt_ptm, dt_arp, dt_icmp, dt_ip, dt_tcp, dt_udp, dt_rawip, - dt_unix_dgram, dt_unix_stream, dt_unix_ord_stream; - static struct fileops svr4_netops = { NULL, /* port */ NULL, /* clone */ @@ -140,46 +137,23 @@ streams_modevent(module_t mod, int type, void *unused) switch (type) { case MOD_LOAD: /* XXX should make sure it isn't already loaded first */ - dt_ptm = make_dev(&streams_cdevsw, dev_ptm, 0, 0, 0666, - "ptm"); - dt_arp = make_dev(&streams_cdevsw, dev_arp, 0, 0, 0666, - "arp"); - dt_icmp = make_dev(&streams_cdevsw, dev_icmp, 0, 0, 0666, - "icmp"); - dt_ip = make_dev(&streams_cdevsw, dev_ip, 0, 0, 0666, - "ip"); - dt_tcp = make_dev(&streams_cdevsw, dev_tcp, 0, 0, 0666, - "tcp"); - dt_udp = make_dev(&streams_cdevsw, dev_udp, 0, 0, 0666, - "udp"); - dt_rawip = make_dev(&streams_cdevsw, dev_rawip, 0, 0, 0666, - "rawip"); - dt_unix_dgram = make_dev(&streams_cdevsw, dev_unix_dgram, - 0, 0, 0666, "ticlts"); - dt_unix_stream = make_dev(&streams_cdevsw, dev_unix_stream, + cdevsw_add(&streams_cdevsw, 0, 0); + make_dev(&streams_cdevsw, dev_ptm, 0, 0, 0666, "ptm"); + make_dev(&streams_cdevsw, dev_arp, 0, 0, 0666, "arp"); + make_dev(&streams_cdevsw, dev_icmp, 0, 0, 0666, "icmp"); + make_dev(&streams_cdevsw, dev_ip, 0, 0, 0666, "ip"); + make_dev(&streams_cdevsw, dev_tcp, 0, 0, 0666, "tcp"); + make_dev(&streams_cdevsw, dev_udp, 0, 0, 0666, "udp"); + make_dev(&streams_cdevsw, dev_rawip, 0, 0, 0666, "rawip"); + make_dev(&streams_cdevsw, dev_unix_dgram, 0, 0, 0666, "ticlts"); + make_dev(&streams_cdevsw, dev_unix_stream, 0, 0, 0666, "ticots"); - dt_unix_ord_stream = make_dev(&streams_cdevsw, - dev_unix_ord_stream, 0, 0, 0666, "ticotsord"); - - if (! (dt_ptm && dt_arp && dt_icmp && dt_ip && dt_tcp && - dt_udp && dt_rawip && dt_unix_dgram && - dt_unix_stream && dt_unix_ord_stream)) { - printf("WARNING: device config for STREAMS failed\n"); - printf("Suggest unloading streams KLD\n"); - } + make_dev(&streams_cdevsw, dev_unix_ord_stream, + 0, 0, 0666, "ticotsord"); return 0; case MOD_UNLOAD: /* XXX should check to see if it's busy first */ - destroy_dev(dt_ptm); - destroy_dev(dt_arp); - destroy_dev(dt_icmp); - destroy_dev(dt_ip); - destroy_dev(dt_tcp); - destroy_dev(dt_udp); - destroy_dev(dt_rawip); - destroy_dev(dt_unix_dgram); - destroy_dev(dt_unix_stream); - destroy_dev(dt_unix_ord_stream); + cdevsw_remove(&streams_cdevsw, 0, 0); return 0; default: diff --git a/sys/dev/misc/syscons/syscons.c b/sys/dev/misc/syscons/syscons.c index 381bdb1602..ae2e48cf4f 100644 --- a/sys/dev/misc/syscons/syscons.c +++ b/sys/dev/misc/syscons/syscons.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $ - * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.10 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.11 2004/05/19 22:52:44 dillon Exp $ */ #include "use_splash.h" @@ -216,8 +216,8 @@ static struct cdevsw sc_cdevsw = { /* poll */ ttypoll, /* mmap */ scmmap, /* strategy */ nostrategy, - /* psize */ nopsize, /* dump */ nodump, + /* psize */ nopsize, /* kqfilter */ ttykqfilter }; @@ -378,6 +378,12 @@ sc_attach_unit(int unit, int flags) EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT); + /* + * create devices. cdevsw_add() must be called to make devices under + * this major number available to userland. + */ + cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS); + for (vc = 0; vc < sc->vtys; vc++) { dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS, UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS); @@ -389,6 +395,7 @@ sc_attach_unit(int unit, int flags) */ } + cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */ dev = make_dev(&sc_cdevsw, SC_CONSOLECTL, UID_ROOT, GID_WHEEL, 0600, "consolectl"); dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty); @@ -1328,7 +1335,8 @@ sccnprobe(struct consdev *cp) return; /* initialize required fields */ - cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL); + cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL, + UID_ROOT, GID_WHEEL, 0600, "consolectl"); #endif /* __i386__ */ #if __alpha__ @@ -1408,7 +1416,8 @@ sccnattach(void) scinit(unit, flags | SC_KERNEL_CONSOLE); sc_console_unit = unit; sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); - consdev.cn_dev = makedev(CDEV_MAJOR, 0); + consdev.cn_dev = make_dev(&sc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, + "ttyv%r", 0); cn_tab = &consdev; } @@ -2559,7 +2568,8 @@ scinit(int unit, int flags) sc->vtys = MAXCONS; /* XXX: should be configurable */ if (flags & SC_KERNEL_CONSOLE) { sc->dev = main_devs; - sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS); + sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT, + GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS); sc->dev[0]->si_tty = &main_tty; ttyregister(&main_tty); scp = &main_console; @@ -2575,7 +2585,8 @@ scinit(int unit, int flags) /* assert(sc_malloc) */ sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK); bzero(sc->dev, sizeof(dev_t)*sc->vtys); - sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS); + sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT, + GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS); sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty); scp = alloc_scp(sc, sc->first_vty); } diff --git a/sys/dev/misc/syscons/syscons.h b/sys/dev/misc/syscons/syscons.h index 3cb235a2af..ae6a346178 100644 --- a/sys/dev/misc/syscons/syscons.h +++ b/sys/dev/misc/syscons/syscons.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/syscons/syscons.h,v 1.60.2.6 2002/09/15 22:30:45 dd Exp $ - * $DragonFly: src/sys/dev/misc/syscons/syscons.h,v 1.5 2003/11/12 22:08:04 dillon Exp $ + * $DragonFly: src/sys/dev/misc/syscons/syscons.h,v 1.6 2004/05/19 22:52:44 dillon Exp $ */ #ifndef _DEV_SYSCONS_SYSCONS_H_ @@ -45,7 +45,7 @@ /* default values for configuration options */ #ifndef MAXCONS -#define MAXCONS 16 +#define MAXCONS 16 /* power of 2 */ #endif #ifdef SC_NO_SYSMOUSE diff --git a/sys/dev/misc/syscons/sysmouse.c b/sys/dev/misc/syscons/sysmouse.c index a335fb9841..dbc085934e 100644 --- a/sys/dev/misc/syscons/sysmouse.c +++ b/sys/dev/misc/syscons/sysmouse.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/syscons/sysmouse.c,v 1.2.2.2 2001/07/16 05:21:24 yokota Exp $ - * $DragonFly: src/sys/dev/misc/syscons/sysmouse.c,v 1.7 2004/05/13 23:49:17 dillon Exp $ + * $DragonFly: src/sys/dev/misc/syscons/sysmouse.c,v 1.8 2004/05/19 22:52:44 dillon Exp $ */ #include "opt_syscons.h" @@ -259,6 +259,7 @@ sm_attach_mouse(void *unused) { dev_t dev; + cdevsw_add(&sm_cdevsw, -1, SC_MOUSE); dev = make_dev(&sm_cdevsw, SC_MOUSE, UID_ROOT, GID_WHEEL, 0600, "sysmouse"); /* sysmouse doesn't have scr_stat */ diff --git a/sys/dev/misc/tw/tw.c b/sys/dev/misc/tw/tw.c index d85a4b9c53..bfbd57106d 100644 --- a/sys/dev/misc/tw/tw.c +++ b/sys/dev/misc/tw/tw.c @@ -29,7 +29,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/tw.c,v 1.38 2000/01/29 16:00:32 peter Exp $ - * $DragonFly: src/sys/dev/misc/tw/tw.c,v 1.9 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/misc/tw/tw.c,v 1.10 2004/05/19 22:52:45 dillon Exp $ * */ @@ -347,10 +347,7 @@ static int twprobe(idp) struct tw_sc sc; int d; int tries; - static int once; - if (!once++) - cdevsw_add(&tw_cdevsw); sc.sc_port = idp->id_iobase; /* Search for the zero crossing signal at ports, bit combinations. */ tw_zcport = tw_control; @@ -406,6 +403,7 @@ static int twattach(idp) sc->sc_state = 0; sc->sc_rcount = 0; callout_handle_init(&sc->abortrcv_ch); + cdevsw_add(&tw_cdevsw, -1, unit); make_dev(&tw_cdevsw, unit, 0, 0, 0600, "tw%d", unit); return (1); } diff --git a/sys/dev/misc/xrpu/xrpu.c b/sys/dev/misc/xrpu/xrpu.c index 956f05d613..2ca96f2a75 100644 --- a/sys/dev/misc/xrpu/xrpu.c +++ b/sys/dev/misc/xrpu/xrpu.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/pci/xrpu.c,v 1.19.2.1 2000/08/02 22:19:57 peter Exp $ - * $DragonFly: src/sys/dev/misc/xrpu/Attic/xrpu.c,v 1.7 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/misc/xrpu/Attic/xrpu.c,v 1.8 2004/05/19 22:52:45 dillon Exp $ * * A very simple device driver for PCI cards based on Xilinx 6200 series * FPGA/RPU devices. Current Functionality is to allow you to open and @@ -253,7 +253,8 @@ xrpu_attach(device_t self) printf("Mapped physbase %#lx to virbase %#lx\n", (u_long)sc->physbase, (u_long)sc->virbase); - make_dev(&xrpu_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "xrpu%d", unit); + cdevsw_add(&xrpu_cdevsw, -1, unit); + make_dev(&xrpu_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, "xrpu%d", unit); return 0; } diff --git a/sys/dev/netif/cx/cx.c b/sys/dev/netif/cx/cx.c index 0a80ef90e3..0674d1004e 100644 --- a/sys/dev/netif/cx/cx.c +++ b/sys/dev/netif/cx/cx.c @@ -16,7 +16,7 @@ * Version 1.9, Wed Oct 4 18:58:15 MSK 1995 * * $FreeBSD: src/sys/i386/isa/cx.c,v 1.45.2.1 2001/02/26 04:23:09 jlemon Exp $ - * $DragonFly: src/sys/dev/netif/cx/cx.c,v 1.11 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/netif/cx/cx.c,v 1.12 2004/05/19 22:52:45 dillon Exp $ * */ #undef DEBUG @@ -945,13 +945,13 @@ void cxtimeout (void *a) #if defined(__DragonFly__) || (defined(__FreeBSD__) && (__FreeBSD__ > 1 )) -static void cx_drvinit(void *unused) -{ - cdevsw_add(&cx_cdevsw); +static +void +cx_drvinit(void *unused) +{ } SYSINIT(cxdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cx_drvinit,NULL) - #endif diff --git a/sys/dev/netif/cx/if_cx.c b/sys/dev/netif/cx/if_cx.c index bb21905a23..897f6e7b29 100644 --- a/sys/dev/netif/cx/if_cx.c +++ b/sys/dev/netif/cx/if_cx.c @@ -17,7 +17,7 @@ * Version 1.9, Wed Oct 4 18:58:15 MSK 1995 * * $FreeBSD: src/sys/i386/isa/if_cx.c,v 1.32 1999/11/18 08:36:42 peter Exp $ - * $DragonFly: src/sys/dev/netif/cx/if_cx.c,v 1.11 2004/05/04 12:12:13 hmp Exp $ + * $DragonFly: src/sys/dev/netif/cx/if_cx.c,v 1.12 2004/05/19 22:52:45 dillon Exp $ * */ #undef DEBUG @@ -294,6 +294,7 @@ cxattach (struct isa_device *id) timeout (cxtimeout, 0, hz*5); printf ("cx%d: \n", unit, b->name); + cdevsw_add(&cx_cdevsw, -1, unit); make_dev(&cx_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, "cx%d", unit); return (1); } diff --git a/sys/dev/raid/aac/aac.c b/sys/dev/raid/aac/aac.c index 98d144c67b..8cd0cd41ae 100644 --- a/sys/dev/raid/aac/aac.c +++ b/sys/dev/raid/aac/aac.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aac.c,v 1.9.2.14 2003/04/08 13:22:08 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aac.c,v 1.11 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aac.c,v 1.12 2004/05/19 22:52:46 dillon Exp $ */ /* @@ -296,6 +296,7 @@ aac_attach(struct aac_softc *sc) * Make the control device. */ unit = device_get_unit(sc->aac_dev); + cdevsw_add(&aac_cdevsw, -1, unit); sc->aac_dev_t = make_dev(&aac_cdevsw, unit, UID_ROOT, GID_WHEEL, 0644, "aac%d", unit); #if defined(__FreeBSD__) && __FreeBSD_version > 500005 @@ -303,6 +304,7 @@ aac_attach(struct aac_softc *sc) (void)make_dev_alias(sc->aac_dev_t, "hpn%d", unit); #endif sc->aac_dev_t->si_drv1 = sc; + reference_dev(sc->aac_dev_t); /* Create the AIF thread */ #if defined(__FreeBSD__) && __FreeBSD_version > 500005 @@ -466,9 +468,11 @@ aac_free(struct aac_softc *sc) bus_dma_tag_destroy(sc->aac_parent_dmat); /* release the register window mapping */ - if (sc->aac_regs_resource != NULL) + if (sc->aac_regs_resource != NULL) { bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, sc->aac_regs_rid, sc->aac_regs_resource); + } + cdevsw_remove(&aac_cdevsw, -1, device_get_unit(sc->aac_dev)); } /* diff --git a/sys/dev/raid/aac/aac_disk.c b/sys/dev/raid/aac/aac_disk.c index c40c032c0d..5ec4c972d7 100644 --- a/sys/dev/raid/aac/aac_disk.c +++ b/sys/dev/raid/aac/aac_disk.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.3.2.8 2003/01/11 18:39:39 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.7 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.8 2004/05/19 22:52:46 dillon Exp $ */ #include "opt_aac.h" @@ -221,13 +221,12 @@ aac_disk_strategy(struct bio *bp) * for the controller to complete the requests. */ static int -aac_disk_dump(dev_t dev) +aac_disk_dump(dev_t dev, u_int count, u_int blkno, u_int secsize) { struct aac_disk *ad; struct aac_softc *sc; vm_offset_t addr; long blkcnt; - unsigned int count, blkno, secsize; int dumppages; int i, error; @@ -235,9 +234,6 @@ aac_disk_dump(dev_t dev) addr = 0; dumppages = AAC_MAXIO / PAGE_SIZE; - if ((error = disk_dumpcheck(dev, &count, &blkno, &secsize))) - return (error); - if (ad == NULL) return (ENXIO); diff --git a/sys/dev/raid/amr/amr.c b/sys/dev/raid/amr/amr.c index f7d171fb36..5dcfb6b5d3 100644 --- a/sys/dev/raid/amr/amr.c +++ b/sys/dev/raid/amr/amr.c @@ -53,7 +53,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/amr/amr.c,v 1.7.2.13 2003/01/15 13:41:18 emoore Exp $ - * $DragonFly: src/sys/dev/raid/amr/amr.c,v 1.9 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/amr/amr.c,v 1.10 2004/05/19 22:52:46 dillon Exp $ */ /* @@ -253,9 +253,12 @@ amr_attach(struct amr_softc *sc) /* * Create the control device. */ - sc->amr_dev_t = make_dev(&amr_cdevsw, device_get_unit(sc->amr_dev), UID_ROOT, GID_OPERATOR, - S_IRUSR | S_IWUSR, "amr%d", device_get_unit(sc->amr_dev)); + cdevsw_add(&amr_cdevsw, -1, device_get_unit(sc->amr_dev)); + sc->amr_dev_t = make_dev(&amr_cdevsw, device_get_unit(sc->amr_dev), + UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, + "amr%d", device_get_unit(sc->amr_dev)); sc->amr_dev_t->si_drv1 = sc; + reference_dev(sc->amr_dev_t); /* * Schedule ourselves to bring the controller up once interrupts are @@ -360,6 +363,7 @@ amr_free(struct amr_softc *sc) /* destroy control device */ if( sc->amr_dev_t != (dev_t)NULL) destroy_dev(sc->amr_dev_t); + cdevsw_remove(&amr_cdevsw, -1, device_get_unit(sc->amr_dev)); } /******************************************************************************* diff --git a/sys/dev/raid/amr/amr_disk.c b/sys/dev/raid/amr/amr_disk.c index 7a0df682e8..d494656ab3 100644 --- a/sys/dev/raid/amr/amr_disk.c +++ b/sys/dev/raid/amr/amr_disk.c @@ -54,7 +54,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/amr/amr_disk.c,v 1.5.2.5 2002/12/20 15:12:04 emoore Exp $ - * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.8 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.9 2004/05/19 22:52:46 dillon Exp $ */ /* @@ -195,12 +195,11 @@ amrd_ioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, d_thread_t *td) * System crashdump support */ int -amrd_dump(dev_t dev) +amrd_dump(dev_t dev, u_int count, u_int blkno, u_int secsize) { struct amrd_softc *amrd_sc = (struct amrd_softc *)dev->si_drv1; struct amr_softc *amr_sc; - u_int count, blkno, secsize; vm_paddr_t addr = 0; long blkcnt; int dumppages = MAXDUMPPGS; @@ -210,9 +209,6 @@ amrd_dump(dev_t dev) debug_called(1); - if ((error = disk_dumpcheck(dev, &count, &blkno, &secsize))) - return(error); - amr_sc = (struct amr_softc *)amrd_sc->amrd_controller; if (!amrd_sc || !amr_sc) diff --git a/sys/dev/raid/asr/asr.c b/sys/dev/raid/asr/asr.c index 811bb30e76..a7d880ec64 100644 --- a/sys/dev/raid/asr/asr.c +++ b/sys/dev/raid/asr/asr.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/dev/asr/asr.c,v 1.3.2.2 2001/08/23 05:21:29 scottl Exp $ */ -/* $DragonFly: src/sys/dev/raid/asr/asr.c,v 1.13 2004/03/15 03:05:08 dillon Exp $ */ +/* $DragonFly: src/sys/dev/raid/asr/asr.c,v 1.14 2004/05/19 22:52:46 dillon Exp $ */ /* * Copyright (c) 1996-2000 Distributed Processing Technology Corporation * Copyright (c) 2000-2001 Adaptec Corporation @@ -602,8 +602,7 @@ STATIC u_int32_t asr_time_delta (IN struct timeval start, * Initialize the dynamic cdevsw hooks. */ STATIC void -asr_drvinit ( - void * unused) +asr_drvinit (void * unused) { static int asr_devsw_installed = 0; @@ -614,25 +613,28 @@ asr_drvinit ( /* * Find a free spot (the report during driver load used by * osd layer in engine to generate the controlling nodes). + * + * XXX this is garbage code, store a unit number in asr_cdevsw + * and iterate through that instead? */ - while ((asr_cdevsw.d_maj < NUMCDEVSW) - && (dev_dport(makedev(asr_cdevsw.d_maj,0)) != NULL)) { + while (asr_cdevsw.d_maj < NUMCDEVSW && + cdevsw_get(asr_cdevsw.d_maj, -1) != NULL + ) { ++asr_cdevsw.d_maj; } - if (asr_cdevsw.d_maj >= NUMCDEVSW) for ( - asr_cdevsw.d_maj = 0; - (asr_cdevsw.d_maj < CDEV_MAJOR) - && (dev_dport(makedev(asr_cdevsw.d_maj,0)) != NULL); - ++asr_cdevsw.d_maj); + if (asr_cdevsw.d_maj >= NUMCDEVSW) { + asr_cdevsw.d_maj = 0; + while (asr_cdevsw.d_maj < CDEV_MAJOR && + cdevsw_get(asr_cdevsw.d_maj, -1) != NULL + ) { + ++asr_cdevsw.d_maj; + } + } + /* * Come to papa */ - cdevsw_add(&asr_cdevsw); - /* - * delete any nodes that would attach to the primary adapter, - * let the adapter scans add them. - */ - destroy_dev(makedev(asr_cdevsw.d_maj,0)); + cdevsw_add(&asr_cdevsw, 0, 0); } /* asr_drvinit */ /* Must initialize before CAM layer picks up our HBA driver */ @@ -3176,8 +3178,7 @@ asr_attach (ATTACH_ARGS) /* * Generate the device node information */ - (void)make_dev(&asr_cdevsw, unit, 0, 0, S_IRWXU, "rasr%d", unit); - destroy_dev(makedev(asr_cdevsw.d_maj,unit+1)); + make_dev(&asr_cdevsw, unit, 0, 0, S_IRWXU, "rasr%d", unit); ATTACH_RETURN(0); } /* asr_attach */ diff --git a/sys/dev/raid/ciss/ciss.c b/sys/dev/raid/ciss/ciss.c index 0920524a0e..cd541a9408 100644 --- a/sys/dev/raid/ciss/ciss.c +++ b/sys/dev/raid/ciss/ciss.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ciss/ciss.c,v 1.2.2.6 2003/02/18 22:27:41 ps Exp $ - * $DragonFly: src/sys/dev/raid/ciss/ciss.c,v 1.7 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ciss/ciss.c,v 1.8 2004/05/19 22:52:46 dillon Exp $ */ /* @@ -407,6 +407,7 @@ ciss_attach(device_t dev) /* * Create the control device. */ + cdevsw_add(&ciss_cdevsw, -1, device_get_unit(sc->ciss_dev)); sc->ciss_dev_t = make_dev(&ciss_cdevsw, device_get_unit(sc->ciss_dev), UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, "ciss%d", device_get_unit(sc->ciss_dev)); diff --git a/sys/dev/raid/dpt/dpt_control.c b/sys/dev/raid/dpt/dpt_control.c index 7ef887716a..00c77cd05d 100644 --- a/sys/dev/raid/dpt/dpt_control.c +++ b/sys/dev/raid/dpt/dpt_control.c @@ -37,7 +37,7 @@ */ #ident "$FreeBSD: src/sys/dev/dpt/dpt_control.c,v 1.16 1999/09/25 18:23:48 phk Exp $" -#ident "$DragonFly: src/sys/dev/raid/dpt/dpt_control.c,v 1.6 2004/05/13 23:49:18 dillon Exp $" +#ident "$DragonFly: src/sys/dev/raid/dpt/dpt_control.c,v 1.7 2004/05/19 22:52:47 dillon Exp $" #include "opt_dpt.h" @@ -849,14 +849,13 @@ static dpt_devsw_installed = 0; static void dpt_drvinit(void *unused) { - if (!dpt_devsw_installed) { if (bootverbose) printf("DPT: RAID Manager driver, Version %d.%d.%d\n", DPT_CTL_RELEASE, DPT_CTL_VERSION, DPT_CTL_PATCH); /* Add the I/O (data) channel */ - cdevsw_add(&dpt_cdevsw); + cdevsw_add(&dpt_cdevsw, 0, 0); dpt_devsw_installed = 1; } diff --git a/sys/dev/raid/ida/ida_disk.c b/sys/dev/raid/ida/ida_disk.c index 138d8f6905..e2c686940d 100644 --- a/sys/dev/raid/ida/ida_disk.c +++ b/sys/dev/raid/ida/ida_disk.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ida/ida_disk.c,v 1.12.2.6 2001/11/27 20:21:02 ps Exp $ - * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.7 2004/05/13 23:49:18 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.8 2004/05/19 22:52:47 dillon Exp $ */ /* @@ -200,18 +200,14 @@ done: } static int -idad_dump(dev_t dev) +idad_dump(dev_t dev, u_int count, u_int blkno, u_int secsize) { struct idad_softc *drv; - u_int count, blkno, secsize; long blkcnt; int i, error, dumppages; caddr_t va; vm_offset_t addr, a; - if ((error = disk_dumpcheck(dev, &count, &blkno, &secsize))) - return (error); - drv = idad_getsoftc(dev); if (drv == NULL) return (ENXIO); diff --git a/sys/dev/raid/iir/iir_ctrl.c b/sys/dev/raid/iir/iir_ctrl.c index 233581bf6b..20e794ef6d 100644 --- a/sys/dev/raid/iir/iir_ctrl.c +++ b/sys/dev/raid/iir/iir_ctrl.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/dev/iir/iir_ctrl.c,v 1.2.2.4 2002/05/05 08:18:12 asmodai Exp $ */ -/* $DragonFly: src/sys/dev/raid/iir/iir_ctrl.c,v 1.6 2004/05/13 23:49:19 dillon Exp $ */ +/* $DragonFly: src/sys/dev/raid/iir/iir_ctrl.c,v 1.7 2004/05/19 22:52:47 dillon Exp $ */ /* * Copyright (c) 2000-01 Intel Corporation * All Rights Reserved @@ -115,6 +115,7 @@ gdt_make_dev(int unit) S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir"); sdev_made = 1; #endif + reference_dev(dev); return (dev); } @@ -366,7 +367,7 @@ iir_drvinit(void *unused) if (!iir_devsw_installed) { /* Add the I/O (data) channel */ - cdevsw_add(&iir_cdevsw); + cdevsw_add(&iir_cdevsw, 0, 0); iir_devsw_installed = 1; } } diff --git a/sys/dev/raid/ips/ips.c b/sys/dev/raid/ips/ips.c index 8ede49135a..90c9bdc798 100644 --- a/sys/dev/raid/ips/ips.c +++ b/sys/dev/raid/ips/ips.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips.c,v 1.6 2003/11/27 08:37:36 mbr - * $DragonFly: src/sys/dev/raid/ips/ips.c,v 1.3 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips.c,v 1.4 2004/05/19 22:52:47 dillon Exp $ */ #include @@ -416,6 +416,7 @@ int ips_adapter_init(ips_softc_t *sc) { int i; + dev_t dev; DEVICE_PRINTF(1, sc->dev, "initializing\n"); if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, @@ -494,10 +495,11 @@ ips_adapter_init(ips_softc_t *sc) "failed to initialize command buffers\n"); goto error; } - sc->device_file = make_dev(&ips_cdevsw, device_get_unit(sc->dev), + cdevsw_add(&ips_cdevsw, -1, device_get_unit(sc->dev)); + dev = make_dev(&ips_cdevsw, device_get_unit(sc->dev), UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, "ips%d", device_get_unit(sc->dev)); - sc->device_file->si_drv1 = sc; + dev->si_drv1 = sc; ips_diskdev_init(sc); sc->timer = timeout(ips_timeout, sc, 10*hz); return 0; @@ -587,8 +589,7 @@ ips_adapter_free(ips_softc_t *sc) bus_dma_tag_destroy(sc->sg_dmatag); if (sc->command_dmatag) bus_dma_tag_destroy(sc->command_dmatag); - if (sc->device_file) - destroy_dev(sc->device_file); + cdevsw_remove(&ips_cdevsw, -1, device_get_unit(sc->dev)); return 0; } diff --git a/sys/dev/raid/ips/ips.h b/sys/dev/raid/ips/ips.h index f730251866..5baa9a0e65 100644 --- a/sys/dev/raid/ips/ips.h +++ b/sys/dev/raid/ips/ips.h @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ips/ips.h,v 1.5 2003/11/27 08:37:36 mbr Exp $ - * $DragonFly: src/sys/dev/raid/ips/ips.h,v 1.1 2004/01/15 15:41:23 drhodus Exp $ + * $DragonFly: src/sys/dev/raid/ips/ips.h,v 1.2 2004/05/19 22:52:47 dillon Exp $ */ @@ -460,7 +460,6 @@ typedef struct ips_softc { bus_dma_tag_t command_dmatag; bus_dma_tag_t sg_dmatag; device_t dev; - dev_t device_file; struct callout_handle timer; u_int16_t adapter_type; ips_adapter_info_t adapter_info; diff --git a/sys/dev/raid/mlx/mlx.c b/sys/dev/raid/mlx/mlx.c index cdb87e66af..47022e6be1 100644 --- a/sys/dev/raid/mlx/mlx.c +++ b/sys/dev/raid/mlx/mlx.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/mlx/mlx.c,v 1.14.2.5 2001/09/11 09:49:53 kris Exp $ - * $DragonFly: src/sys/dev/raid/mlx/mlx.c,v 1.7 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/raid/mlx/mlx.c,v 1.8 2004/05/19 22:52:47 dillon Exp $ */ /* @@ -208,9 +208,7 @@ mlx_free(struct mlx_softc *sc) if (sc->mlx_enq2 != NULL) free(sc->mlx_enq2, M_DEVBUF); - /* destroy control device */ - if (sc->mlx_dev_t != (dev_t)NULL) - destroy_dev(sc->mlx_dev_t); + cdevsw_remove(&mlx_cdevsw, -1, device_get_unit(sc->mlx_dev)); } /******************************************************************************** @@ -483,8 +481,10 @@ mlx_attach(struct mlx_softc *sc) /* * Create the control device. */ - sc->mlx_dev_t = make_dev(&mlx_cdevsw, device_get_unit(sc->mlx_dev), UID_ROOT, GID_OPERATOR, - S_IRUSR | S_IWUSR, "mlx%d", device_get_unit(sc->mlx_dev)); + cdevsw_add(&mlx_cdevsw, -1, device_get_unit(sc->mlx_dev)); + make_dev(&mlx_cdevsw, device_get_unit(sc->mlx_dev), + UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, + "mlx%d", device_get_unit(sc->mlx_dev)); /* * Start the timeout routine. diff --git a/sys/dev/raid/mlx/mlxvar.h b/sys/dev/raid/mlx/mlxvar.h index 256967844e..468334df25 100644 --- a/sys/dev/raid/mlx/mlxvar.h +++ b/sys/dev/raid/mlx/mlxvar.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/mlx/mlxvar.h,v 1.5.2.3 2001/06/25 04:37:51 msmith Exp $ - * $DragonFly: src/sys/dev/raid/mlx/mlxvar.h,v 1.3 2003/06/23 17:55:32 dillon Exp $ + * $DragonFly: src/sys/dev/raid/mlx/mlxvar.h,v 1.4 2004/05/19 22:52:47 dillon Exp $ */ /* @@ -108,7 +108,6 @@ struct mlx_softc { /* bus connections */ device_t mlx_dev; - dev_t mlx_dev_t; struct resource *mlx_mem; /* mailbox interface window */ int mlx_mem_rid; int mlx_mem_type; diff --git a/sys/dev/raid/mly/mly.c b/sys/dev/raid/mly/mly.c index adb2e04ffd..f72cc8cbb6 100644 --- a/sys/dev/raid/mly/mly.c +++ b/sys/dev/raid/mly/mly.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/mly/mly.c,v 1.3.2.3 2001/03/05 20:17:24 msmith Exp $ - * $DragonFly: src/sys/dev/raid/mly/mly.c,v 1.8 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/raid/mly/mly.c,v 1.9 2004/05/19 22:52:48 dillon Exp $ */ #include @@ -206,8 +206,10 @@ mly_attach(struct mly_softc *sc) /* * Create the control device. */ - sc->mly_dev_t = make_dev(&mly_cdevsw, device_get_unit(sc->mly_dev), UID_ROOT, GID_OPERATOR, - S_IRUSR | S_IWUSR, "mly%d", device_get_unit(sc->mly_dev)); + cdevsw_add(&mly_cdevsw, -1, device_get_unit(sc->mly_dev)); + sc->mly_dev_t = make_dev(&mly_cdevsw, device_get_unit(sc->mly_dev), + UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, + "mly%d", device_get_unit(sc->mly_dev)); sc->mly_dev_t->si_drv1 = sc; /* enable interrupts now */ diff --git a/sys/dev/raid/twa/twa.h b/sys/dev/raid/twa/twa.h index e6e3c51e0e..37f972d6da 100644 --- a/sys/dev/raid/twa/twa.h +++ b/sys/dev/raid/twa/twa.h @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD$ - * $DragonFly: src/sys/dev/raid/twa/twa.h,v 1.1 2004/04/16 20:13:16 drhodus Exp $ + * $DragonFly: src/sys/dev/raid/twa/twa.h,v 1.2 2004/05/19 22:52:48 dillon Exp $ */ /* @@ -175,7 +175,6 @@ struct twa_softc { between ioctl calls */ device_t twa_bus_dev; /* bus device */ - dev_t twa_ctrl_dev; /* control device */ struct resource *twa_io_res; /* register interface window */ bus_space_handle_t twa_bus_handle; /* bus space handle */ bus_space_tag_t twa_bus_tag; /* bus space tag */ diff --git a/sys/dev/raid/twa/twa_freebsd.c b/sys/dev/raid/twa/twa_freebsd.c index 25dba4f4db..b7b7a0c2f6 100644 --- a/sys/dev/raid/twa/twa_freebsd.c +++ b/sys/dev/raid/twa/twa_freebsd.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD$ - * $DragonFly: src/sys/dev/raid/twa/twa_freebsd.c,v 1.1 2004/04/16 20:13:16 drhodus Exp $ + * $DragonFly: src/sys/dev/raid/twa/twa_freebsd.c,v 1.2 2004/05/19 22:52:48 dillon Exp $ */ /* @@ -232,6 +232,7 @@ twa_attach(device_t dev) u_int32_t command; int res_id; int error; + dev_t xdev; twa_dbg_dprint_enter(3, sc); @@ -298,10 +299,11 @@ twa_attach(device_t dev) twa_describe_controller(sc); /* Create the control device. */ - sc->twa_ctrl_dev = make_dev(&twa_cdevsw, device_get_unit(sc->twa_bus_dev), - UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, - "twa%d", device_get_unit(sc->twa_bus_dev)); - sc->twa_ctrl_dev->si_drv1 = sc; + cdevsw_add(&twa_cdevsw, -1, device_get_unit(sc->twa_bus_dev)); + xdev = make_dev(&twa_cdevsw, device_get_unit(sc->twa_bus_dev), + UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, + "twa%d", device_get_unit(sc->twa_bus_dev)); + xdev->si_drv1 = sc; /* * Schedule ourselves to bring the controller up once interrupts are @@ -376,9 +378,7 @@ twa_free(struct twa_softc *sc) bus_release_resource(sc->twa_bus_dev, SYS_RES_IOPORT, TWA_IO_CONFIG_REG, sc->twa_io_res); - /* Destroy the control device. */ - if (sc->twa_ctrl_dev != (dev_t)NULL) - destroy_dev(sc->twa_ctrl_dev); + cdevsw_remove(&twa_cdevsw, -1, device_get_unit(sc->twa_bus_dev)); sysctl_ctx_free(&sc->twa_sysctl_ctx); } diff --git a/sys/dev/raid/twe/twe_compat.h b/sys/dev/raid/twe/twe_compat.h index ba6b5bdb26..4b01ce7790 100644 --- a/sys/dev/raid/twe/twe_compat.h +++ b/sys/dev/raid/twe/twe_compat.h @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/twe/twe_compat.h,v 1.1.2.3 2002/03/07 09:57:02 msmith Exp $ - * $DragonFly: src/sys/dev/raid/twe/twe_compat.h,v 1.8 2004/02/21 06:37:06 dillon Exp $ + * $DragonFly: src/sys/dev/raid/twe/twe_compat.h,v 1.9 2004/05/19 22:52:48 dillon Exp $ */ /* * Portability and compatibility interfaces. @@ -107,7 +107,6 @@ */ #define TWE_PLATFORM_SOFTC \ device_t twe_dev; /* bus device */ \ - dev_t twe_dev_t; /* control device */ \ struct resource *twe_io; /* register interface window */ \ bus_space_handle_t twe_bhandle; /* bus space handle */ \ bus_space_tag_t twe_btag; /* bus space tag */ \ diff --git a/sys/dev/raid/twe/twe_freebsd.c b/sys/dev/raid/twe/twe_freebsd.c index 750542fc9f..c7c999c56d 100644 --- a/sys/dev/raid/twe/twe_freebsd.c +++ b/sys/dev/raid/twe/twe_freebsd.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/twe/twe_freebsd.c,v 1.2.2.5 2002/03/07 09:57:02 msmith Exp $ - * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.9 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.10 2004/05/19 22:52:48 dillon Exp $ */ /* @@ -200,6 +200,7 @@ twe_attach(device_t dev) struct twe_softc *sc; int rid, error; u_int32_t command; + dev_t xdev; debug_called(4); @@ -310,9 +311,12 @@ twe_attach(device_t dev) /* * Create the control device. */ - sc->twe_dev_t = make_dev(&twe_cdevsw, device_get_unit(sc->twe_dev), UID_ROOT, GID_OPERATOR, - S_IRUSR | S_IWUSR, "twe%d", device_get_unit(sc->twe_dev)); - sc->twe_dev_t->si_drv1 = sc; + cdevsw_add(&twe_cdevsw, -1, device_get_unit(sc->twe_dev)); + xdev = make_dev(&twe_cdevsw, device_get_unit(sc->twe_dev), + UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, + "twe%d", device_get_unit(sc->twe_dev)); + xdev->si_drv1 = sc; + /* * Schedule ourselves to bring the controller up once interrupts are available. * This isn't strictly necessary, since we disable interrupts while probing the @@ -364,9 +368,7 @@ twe_free(struct twe_softc *sc) if (sc->twe_io != NULL) bus_release_resource(sc->twe_dev, SYS_RES_IOPORT, TWE_IO_CONFIG_REG, sc->twe_io); - /* destroy control device */ - if (sc->twe_dev_t != (dev_t)NULL) - destroy_dev(sc->twe_dev_t); + cdevsw_remove(&twe_cdevsw, -1, device_get_unit(sc->twe_dev)); sysctl_ctx_free(&sc->sysctl_ctx); } @@ -727,20 +729,16 @@ twed_strategy(twe_bio *bp) * System crashdump support */ int -twed_dump(dev_t dev) +twed_dump(dev_t dev, u_int count, u_int blkno, u_int secsize) { struct twed_softc *twed_sc = (struct twed_softc *)dev->si_drv1; struct twe_softc *twe_sc = (struct twe_softc *)twed_sc->twed_controller; - u_int count, blkno, secsize; vm_paddr_t addr = 0; long blkcnt; int dumppages = MAXDUMPPGS; int error; int i; - if ((error = disk_dumpcheck(dev, &count, &blkno, &secsize))) - return(error); - if (!twed_sc || !twe_sc) return(ENXIO); diff --git a/sys/dev/raid/vinum/vinum.c b/sys/dev/raid/vinum/vinum.c index 4595faf18d..37c97bf055 100644 --- a/sys/dev/raid/vinum/vinum.c +++ b/sys/dev/raid/vinum/vinum.c @@ -37,7 +37,7 @@ * * $Id: vinum.c,v 1.33 2001/01/09 06:19:15 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinum.c,v 1.38.2.3 2003/01/07 12:14:16 joerg Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinum.c,v 1.10 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinum.c,v 1.11 2004/05/19 22:52:48 dillon Exp $ */ #define STATIC static /* nothing while we're testing XXX */ @@ -54,7 +54,7 @@ extern struct mc malloced[]; #endif #include "request.h" -STATIC struct cdevsw vinum_cdevsw = +struct cdevsw vinum_cdevsw = { /* name */ "vinum", /* cmaj */ VINUM_CDEV_MAJOR, @@ -96,7 +96,7 @@ vinumattach(void *dummy) daemonq = NULL; /* initialize daemon's work queue */ dqend = NULL; - cdevsw_add(&vinum_cdevsw); /* add the cdevsw entry */ + cdevsw_add(&vinum_cdevsw, 0, 0); /* add the cdevsw entry */ /* allocate space: drives... */ DRIVE = (struct drive *) Malloc(sizeof(struct drive) * INITIAL_DRIVES); @@ -153,8 +153,10 @@ vinumattach(void *dummy) for (i = 0; i < vinum_conf.volumes_used; i++) { vol = &vinum_conf.volume[i]; if ((vol->state == volume_up) - && (strcmp (vol->name, cp) == 0) ) { - rootdev = makedev(VINUM_CDEV_MAJOR, i); + && (strcmp (vol->name, cp) == 0) + ) { + rootdev = make_dev(&vinum_cdevsw, i, UID_ROOT, GID_OPERATOR, + 0640, "vinum"); log(LOG_INFO, "vinum: using volume %s for root device\n", cp); break; } @@ -276,7 +278,7 @@ vinum_modevent(module_t mod, modeventtype_t type, void *unused) } } #endif - cdevsw_remove(&vinum_cdevsw); + cdevsw_remove(&vinum_cdevsw, 0, 0); log(LOG_INFO, "vinum: unloaded\n"); /* tell the world */ return 0; default: @@ -496,7 +498,7 @@ vinumsize(dev_t dev) } int -vinumdump(dev_t dev) +vinumdump(dev_t dev, u_int count, u_int blkno, u_int secsize) { /* Not implemented. */ return ENXIO; diff --git a/sys/dev/raid/vinum/vinumext.h b/sys/dev/raid/vinum/vinumext.h index 91ab0e08c9..b3d20d7ba4 100644 --- a/sys/dev/raid/vinum/vinumext.h +++ b/sys/dev/raid/vinum/vinumext.h @@ -35,7 +35,7 @@ * * $Id: vinumext.h,v 1.26 2000/05/16 07:38:08 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumext.h,v 1.25.2.3 2001/05/11 02:11:06 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumext.h,v 1.3 2003/06/29 03:28:42 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumext.h,v 1.4 2004/05/19 22:52:48 dillon Exp $ */ /* vinumext.h: external definitions */ @@ -147,6 +147,7 @@ void sdio(struct buf *bp); int vinumpart(dev_t); extern jmp_buf command_fail; /* return here if config fails */ +extern struct cdevsw vinum_cdevsw; #ifdef VINUMDEBUG /* Memory allocation and request tracing */ @@ -154,12 +155,12 @@ void vinum_meminfo(caddr_t data); int vinum_mallocinfo(caddr_t data); int vinum_rqinfo(caddr_t data); void LongJmp(jmp_buf, int); -char *basename(char *); #else void longjmp(jmp_buf, int); /* the kernel doesn't define this */ #endif int setjmp(jmp_buf); +char *basename(char *); void expand_table(void **, int, int); struct request; diff --git a/sys/dev/raid/vinum/vinumio.c b/sys/dev/raid/vinum/vinumio.c index d676e07897..b36888a12f 100644 --- a/sys/dev/raid/vinum/vinumio.c +++ b/sys/dev/raid/vinum/vinumio.c @@ -35,7 +35,7 @@ * * $Id: vinumio.c,v 1.30 2000/05/10 23:23:30 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumio.c,v 1.52.2.6 2002/05/02 08:43:44 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.5 2003/08/07 21:17:09 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.6 2004/05/19 22:52:48 dillon Exp $ */ #include "vinumhdr.h" @@ -134,15 +134,13 @@ open_drive(struct drive *drive, struct proc *p, int verbose) if ((devminor & 7) == 2) /* partition c */ return ENOTTY; /* not buying that */ - drive->dev = makedev(devmajor, devminor); /* find the device */ - if (drive->dev == NULL) /* didn't find anything */ - return ENODEV; + drive->dev = udev2dev(makeudev(devmajor, devminor), 0); drive->dev->si_iosize_max = DFLTPHYS; - if (dev_dport(drive->dev) == NULL) - drive->lasterror = ENOENT; - else + if (dev_is_good(drive->dev)) drive->lasterror = dev_dopen(drive->dev, FWRITE, 0, NULL); + else + drive->lasterror = ENOENT; if (drive->lasterror != 0) { /* failed */ drive->state = drive_down; /* just force it down */ @@ -771,6 +769,7 @@ write_volume_label(int volno) struct disklabel *dlp; struct volume *vol; int error; + dev_t dev; lp = (struct disklabel *) Malloc((sizeof(struct disklabel) + (DEV_BSIZE - 1)) & (DEV_BSIZE - 1)); if (lp == 0) @@ -794,7 +793,8 @@ write_volume_label(int volno) * unless it's already there. */ bp = geteblk((int) lp->d_secsize); /* get a buffer */ - bp->b_dev = makedev(VINUM_CDEV_MAJOR, vol->volno); /* our own raw volume */ + dev = make_adhoc_dev(&vinum_cdevsw, vol->volno); + bp->b_dev = dev; bp->b_blkno = LABELSECTOR * ((int) lp->d_secsize / DEV_BSIZE); bp->b_bcount = lp->d_secsize; bzero(bp->b_data, lp->d_secsize); @@ -814,7 +814,6 @@ write_volume_label(int volno) error = biowait(bp); bp->b_flags |= B_INVAL | B_AGE; bp->b_flags &= ~B_ERROR; - brelse(bp); return error; } diff --git a/sys/dev/raid/vinum/vinumvar.h b/sys/dev/raid/vinum/vinumvar.h index e7c542d4f5..4d7af32167 100644 --- a/sys/dev/raid/vinum/vinumvar.h +++ b/sys/dev/raid/vinum/vinumvar.h @@ -39,7 +39,7 @@ * * $Id: vinumvar.h,v 1.24 2000/03/01 02:34:57 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumvar.h,v 1.32.2.4 2001/05/28 05:56:27 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumvar.h,v 1.4 2003/08/07 21:17:10 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumvar.h,v 1.5 2004/05/19 22:52:48 dillon Exp $ */ #include @@ -108,18 +108,43 @@ enum constants { | (s << VINUM_SD_SHIFT) \ | (t << VINUM_TYPE_SHIFT) ) - /* Create device minor numbers */ -#define VINUMDEV(v,p,s,t) makedev (VINUM_CDEV_MAJOR, VINUMMINOR (v, p, s, t)) +/* Create device minor numbers */ -#define VINUM_PLEX(p) makedev (VINUM_CDEV_MAJOR, \ - (VINUM_RAWPLEX_TYPE << VINUM_TYPE_SHIFT) \ - | (p & 0xff) \ - | ((p & ~0xff) << 8) ) +#ifdef _KERNEL + +#define VINUMDEV(v,p,s,t) \ + make_adhoc_dev (&vinum_cdevsw, VINUMMINOR (v, p, s, t)) + +#define VINUM_PLEX(p) \ + make_adhoc_dev (&vinum_cdevsw, \ + (VINUM_RAWPLEX_TYPE << VINUM_TYPE_SHIFT) \ + | (p & 0xff) \ + | ((p & ~0xff) << 8) ) + +#define VINUM_SD(s) \ + make_adhoc_dev (&vinum_cdevsw, \ + (VINUM_RAWSD_TYPE << VINUM_TYPE_SHIFT) \ + | (s & 0xff) \ + | ((s & ~0xff) << 8) ) + +#else -#define VINUM_SD(s) makedev (VINUM_CDEV_MAJOR, \ - (VINUM_RAWSD_TYPE << VINUM_TYPE_SHIFT) \ - | (s & 0xff) \ - | ((s & ~0xff) << 8) ) +#define VINUMDEV(v,p,s,t) \ + makedev(VINUM_CDEV_MAJOR, VINUMMINOR (v, p, s, t)) + +#define VINUM_PLEX(p) \ + makedev(VINUM_CDEV_MAJOR, \ + (VINUM_RAWPLEX_TYPE << VINUM_TYPE_SHIFT) \ + | (p & 0xff) \ + | ((p & ~0xff) << 8) ) + +#define VINUM_SD(s) \ + makedev(VINUM_CDEV_MAJOR, \ + (VINUM_RAWSD_TYPE << VINUM_TYPE_SHIFT) \ + | (s & 0xff) \ + | ((s & ~0xff) << 8) ) + +#endif /* Create a bit mask for x bits */ #define MASK(x) ((1 << (x)) - 1) @@ -130,8 +155,6 @@ enum constants { << (VINUM_PLEX_SHIFT + VINUM_VOL_WIDTH)) \ | (t << VINUM_TYPE_SHIFT) ) -#define VINUMRBDEV(d,t) makedev (VINUM_BDEV_MAJOR, VINUMRMINOR (d, t)) - /* extract device type */ #define DEVTYPE(x) ((minor (x) >> VINUM_TYPE_SHIFT) & 7) diff --git a/sys/dev/serial/cy/cy.c b/sys/dev/serial/cy/cy.c index 4371b59229..5bbfb0fc27 100644 --- a/sys/dev/serial/cy/cy.c +++ b/sys/dev/serial/cy/cy.c @@ -28,7 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/cy.c,v 1.97.2.2 2001/08/22 13:04:58 bde Exp $ - * $DragonFly: src/sys/dev/serial/cy/cy.c,v 1.10 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/serial/cy/cy.c,v 1.11 2004/05/19 22:52:48 dillon Exp $ */ #include "opt_compat.h" @@ -621,11 +621,11 @@ cyattach_common(cy_iobase, cy_align) splx(s); if (!sio_registered) { - cdevsw_add(&sio_cdevsw); register_swi(SWI_TTY, siopoll, NULL, "cy"); sio_registered = TRUE; } minorbase = UNIT_TO_MINOR(unit); + cdevsw_add(&sio_cdevsw, UNIT_TO_MINOR(-1), minorbase); make_dev(&sio_cdevsw, minorbase, UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter, unit % CY_MAX_PORTS); diff --git a/sys/dev/serial/dgb/dgm.c b/sys/dev/serial/dgb/dgm.c index 0bf065a24d..07e8fe491c 100644 --- a/sys/dev/serial/dgb/dgm.c +++ b/sys/dev/serial/dgb/dgm.c @@ -1,6 +1,6 @@ /*- * $FreeBSD: src/sys/dev/dgb/dgm.c,v 1.31.2.3 2001/10/07 09:02:25 brian Exp $ - * $DragonFly: src/sys/dev/serial/dgb/dgm.c,v 1.8 2004/05/13 23:49:19 dillon Exp $ + * $DragonFly: src/sys/dev/serial/dgb/dgm.c,v 1.9 2004/05/19 22:52:49 dillon Exp $ * * This driver and the associated header files support the ISA PC/Xem * Digiboards. Its evolutionary roots are described below. @@ -112,6 +112,9 @@ #define IO_SIZE 0x04 #define MEM_SIZE 0x8000 +#define DGM_UNITMASK 0x30000 +#define DGM_UNIT(unit) ((unit) << 16) + struct dgm_softc; /* digiboard port structure */ @@ -261,11 +264,8 @@ dgmmodhandler(module_t mod, int event, void *arg) switch (event) { case MOD_LOAD: - cdevsw_add(&dgm_cdevsw); break; - case MOD_UNLOAD: - cdevsw_remove(&dgm_cdevsw); break; } @@ -421,7 +421,15 @@ dgmprobe(device_t dev) struct dgm_softc *sc = device_get_softc(dev); int i, v; + /* + * Assign unit number. Due to bits we use in the minor number for + * the various tty types, only 4 units are supported. + */ sc->unit = device_get_unit(dev); + if (sc->unit > 3) { + device_printf(dev, "Too many units, only 4 supported\n"); + return(ENXIO); + } /* Check that we've got a valid i/o address */ if ((sc->port = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0) @@ -775,6 +783,7 @@ dgmattach(device_t dev) else shrinkmem = 0; + cdevsw_add(&dgm_cdevsw, DGM_UNITMASK, DGM_UNIT(sc->unit)); for (i = 0; i < sc->numports; i++, bc++) { DPRINT3(DB_INFO, "dgm%d: Set up port %d\n", sc->unit, i); port = &sc->ports[i]; @@ -887,14 +896,12 @@ dgmdetach(device_t dev) DPRINT2(DB_INFO, "dgm%d: detach\n", sc->unit); - for (i = 0; i < sc->numports; i++) { - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i)); - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i + 64)); - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i + 128)); - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i + 262144)); - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i + 262208)); - destroy_dev(makedev(CDEV_MAJOR, sc->unit * 65536 + i + 262272)); - } + /* + * The cdevsw_remove() call will destroy all associated devices + * and dereference any ad-hoc-created devices, but does not + * dereference devices created via make_dev(). + */ + cdevsw_remove(&dgm_cdevsw, DGM_UNITMASK, DGM_UNIT(sc->unit)); untimeout(dgmpoll, (void *)(int)sc->unit, sc->toh); callout_handle_init(&sc->toh); diff --git a/sys/dev/serial/rc/rc.c b/sys/dev/serial/rc/rc.c index 5287cd0fb8..30bba37426 100644 --- a/sys/dev/serial/rc/rc.c +++ b/sys/dev/serial/rc/rc.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/rc.c,v 1.53.2.1 2001/02/26 04:23:10 jlemon Exp $ - * $DragonFly: src/sys/dev/serial/rc/rc.c,v 1.10 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/rc/rc.c,v 1.11 2004/05/19 22:52:49 dillon Exp $ * */ @@ -266,7 +266,7 @@ rcattach(dvp) } rcb->rcb_probed = RC_ATTACHED; if (!rc_started) { - cdevsw_add(&rc_cdevsw); + cdevsw_add(&rc_cdevsw, -1, rcb->rcb_unit); register_swi(SWI_TTY, rcpoll, NULL, "rcpoll"); rc_wakeup((void *)NULL); rc_started = 1; diff --git a/sys/dev/serial/rp/rp.c b/sys/dev/serial/rp/rp.c index 95e15d6d63..e6ce7a8b13 100644 --- a/sys/dev/serial/rp/rp.c +++ b/sys/dev/serial/rp/rp.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/rp/rp.c,v 1.45.2.2 2002/11/07 22:26:59 tegge Exp $ - * $DragonFly: src/sys/dev/serial/rp/rp.c,v 1.10 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/rp/rp.c,v 1.11 2004/05/19 22:52:49 dillon Exp $ */ /* @@ -813,7 +813,6 @@ rp_attachcommon(CONTROLLER_T *ctlp, int num_aiops, int num_ports) int retval; struct rp_port *rp; struct tty *tty; - dev_t *dev_nodes; unit = device_get_unit(ctlp->dev); @@ -847,32 +846,26 @@ rp_attachcommon(CONTROLLER_T *ctlp, int num_aiops, int num_ports) rp_addr(unit) = rp; splx(oldspl); - dev_nodes = ctlp->dev_nodes = malloc(sizeof(*(ctlp->dev_nodes)) * rp_num_ports[unit] * 6, M_DEVBUF, M_NOWAIT | M_ZERO); - if(ctlp->dev_nodes == NULL) { - device_printf(ctlp->dev, "rp_attachcommon: Could not malloc device node structures.\n"); - retval = ENOMEM; - goto nogo; - } - + cdevsw_add(&rp_cdevsw, 0xffff0000, (unit + 1) << 16); for (i = 0 ; i < rp_num_ports[unit] ; i++) { - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i, - UID_ROOT, GID_WHEEL, 0666, "ttyR%c", - i <= 9 ? '0' + i : 'a' + i - 10); - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x20, - UID_ROOT, GID_WHEEL, 0666, "ttyiR%c", - i <= 9 ? '0' + i : 'a' + i - 10); - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x40, - UID_ROOT, GID_WHEEL, 0666, "ttylR%c", - i <= 9 ? '0' + i : 'a' + i - 10); - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x80, - UID_ROOT, GID_WHEEL, 0666, "cuaR%c", - i <= 9 ? '0' + i : 'a' + i - 10); - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0xa0, - UID_ROOT, GID_WHEEL, 0666, "cuaiR%c", - i <= 9 ? '0' + i : 'a' + i - 10); - *(dev_nodes++) = make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0xc0, - UID_ROOT, GID_WHEEL, 0666, "cualR%c", - i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i, + UID_ROOT, GID_WHEEL, 0666, "ttyR%c", + i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x20, + UID_ROOT, GID_WHEEL, 0666, "ttyiR%c", + i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x40, + UID_ROOT, GID_WHEEL, 0666, "ttylR%c", + i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0x80, + UID_ROOT, GID_WHEEL, 0666, "cuaR%c", + i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0xa0, + UID_ROOT, GID_WHEEL, 0666, "cuaiR%c", + i <= 9 ? '0' + i : 'a' + i - 10); + make_dev(&rp_cdevsw, ((unit + 1) << 16) | i | 0xc0, + UID_ROOT, GID_WHEEL, 0666, "cualR%c", + i <= 9 ? '0' + i : 'a' + i - 10); } port = 0; @@ -950,12 +943,9 @@ rp_releaseresource(CONTROLLER_t *ctlp) free(ctlp->tty, M_DEVBUF); ctlp->tty = NULL; } - if (ctlp->dev != NULL) { - for (i = 0 ; i < rp_num_ports[unit] * 6 ; i++) - destroy_dev(ctlp->dev_nodes[i]); - free(ctlp->dev_nodes, M_DEVBUF); + if (ctlp->dev != NULL) ctlp->dev = NULL; - } + cdevsw_remove(&rp_cdevsw, 0xffff0000, (unit + 1) << 16); } int diff --git a/sys/dev/serial/rp/rpreg.h b/sys/dev/serial/rp/rpreg.h index 9efcb05d7b..e3673b542a 100644 --- a/sys/dev/serial/rp/rpreg.h +++ b/sys/dev/serial/rp/rpreg.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/rp/rpreg.h,v 1.4.2.1 2002/06/18 03:11:46 obrien Exp $ - * $DragonFly: src/sys/dev/serial/rp/rpreg.h,v 1.2 2003/06/17 04:28:29 dillon Exp $ + * $DragonFly: src/sys/dev/serial/rp/rpreg.h,v 1.3 2004/05/19 22:52:49 dillon Exp $ */ /* @@ -371,9 +371,6 @@ struct CONTROLLER_str struct rp_port *rp; /* port */ struct tty *tty; /* tty */ - /* Device nodes */ - dev_t *dev_nodes; - /* Bus-specific properties */ void *bus_ctlp; diff --git a/sys/dev/serial/rp2/rp.c b/sys/dev/serial/rp2/rp.c index 62e67d57b3..2b2d0c97db 100644 --- a/sys/dev/serial/rp2/rp.c +++ b/sys/dev/serial/rp2/rp.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/rp.c,v 1.33.2.2 2001/02/26 04:23:10 jlemon Exp $ - * $DragonFly: src/sys/dev/serial/rp2/Attic/rp.c,v 1.11 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/rp2/Attic/rp.c,v 1.12 2004/05/19 22:52:49 dillon Exp $ */ /* @@ -1131,7 +1131,7 @@ rp_pciattach(pcici_t tag, int unit) rp_addr(unit) = rp; splx(oldspl); - cdevsw_add(&rp_cdevsw); + cdevsw_add(&rp_cdevsw, 0, 0); port = 0; for(aiop=0; aiop < num_aiops; aiop++) { @@ -1234,7 +1234,7 @@ struct isa_device *dev; rp_addr(unit) = rp; splx(oldspl); - cdevsw_add(&rp_cdevsw); + cdevsw_add(&rp_cdevsw, 0, 0); port = 0; for(aiop=0; aiop < num_aiops; aiop++) { diff --git a/sys/dev/serial/si/si.c b/sys/dev/serial/si/si.c index 50715b87ed..02d83ad3c1 100644 --- a/sys/dev/serial/si/si.c +++ b/sys/dev/serial/si/si.c @@ -31,7 +31,7 @@ * NO EVENT SHALL THE AUTHORS BE LIABLE. * * $FreeBSD: src/sys/dev/si/si.c,v 1.101.2.1 2001/02/26 04:23:06 jlemon Exp $ - * $DragonFly: src/sys/dev/serial/si/si.c,v 1.9 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/si/si.c,v 1.10 2004/05/19 22:52:49 dillon Exp $ */ #ifndef lint @@ -599,6 +599,7 @@ try_next2: done_chartimes = 1; } + cdevsw_add(&si_cdevsw, 0x7f, unit); /* path name devsw minor type uid gid perm*/ for (x = 0; x < sc->sc_nport; x++) { /* sync with the manuals that start at 1 */ diff --git a/sys/dev/serial/sio/sio.c b/sys/dev/serial/sio/sio.c index 4990c5378f..e69e6e30b4 100644 --- a/sys/dev/serial/sio/sio.c +++ b/sys/dev/serial/sio/sio.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/isa/sio.c,v 1.291.2.35 2003/05/18 08:51:15 murray Exp $ - * $DragonFly: src/sys/dev/serial/sio/sio.c,v 1.15 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/sio/sio.c,v 1.16 2004/05/19 22:52:49 dillon Exp $ * from: @(#)com.c 7.5 (Berkeley) 5/16/91 * from: i386/isa sio.c,v 1.234 */ @@ -1182,6 +1182,7 @@ determined_type: ; sio_registered = TRUE; } minorbase = UNIT_TO_MINOR(unit); + cdevsw_add(&sio_cdevsw, UNIT_TO_MINOR(-1), minorbase); make_dev(&sio_cdevsw, minorbase, UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit); make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE, @@ -2963,7 +2964,9 @@ siocnprobe(cp) splx(s); if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) { - cp->cn_dev = makedev(CDEV_MAJOR, unit); + cp->cn_dev = make_dev(&sio_cdevsw, unit, + UID_ROOT, GID_WHEEL, 0600, + "ttyd%r", unit); cp->cn_pri = COM_FORCECONSOLE(flags) || boothowto & RB_SERIAL ? CN_REMOTE : CN_NORMAL; @@ -2975,7 +2978,9 @@ siocnprobe(cp) siogdbiobase = iobase; siogdbunit = unit; #if DDB > 0 - gdbdev = makedev(CDEV_MAJOR, unit); + gdbdev = make_dev(&sio_cdevsw, unit, + UID_ROOT, GID_WHEEL, 0600, + "ttyd%r", unit); gdb_getc = siocngetc; gdb_putc = siocnputc; #endif @@ -2996,7 +3001,9 @@ siocnprobe(cp) printf("configuration file (currently sio only).\n"); siogdbiobase = siocniobase; siogdbunit = siocnunit; - gdbdev = makedev(CDEV_MAJOR, siocnunit); + gdbdev = make_dev(&sio_cdevsw, siocnunit, + UID_ROOT, GID_WHEEL, 0600, + "ttyd%r", siocnunit); gdb_getc = siocngetc; gdb_putc = siocnputc; } @@ -3021,7 +3028,8 @@ siocnattach(port, speed) siocniobase = port; comdefaultrate = speed; sio_consdev.cn_pri = CN_NORMAL; - sio_consdev.cn_dev = makedev(CDEV_MAJOR, 0); + sio_consdev.cn_dev = make_dev(&sio_cdevsw, 0, UID_ROOT, GID_WHEEL, + 0600, "ttyd%r", 0); s = spltty(); diff --git a/sys/dev/serial/stl/stallion.c b/sys/dev/serial/stl/stallion.c index e1b5542e12..b28598b178 100644 --- a/sys/dev/serial/stl/stallion.c +++ b/sys/dev/serial/stl/stallion.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/stallion.c,v 1.39.2.2 2001/08/30 12:29:57 murray Exp $ - * $DragonFly: src/sys/dev/serial/stl/stallion.c,v 1.9 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/stl/stallion.c,v 1.10 2004/05/19 22:52:49 dillon Exp $ */ /*****************************************************************************/ @@ -767,8 +767,6 @@ static struct cdevsw stl_cdevsw = { static void stl_drvinit(void *unused) { - - cdevsw_add(&stl_cdevsw); } SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL) @@ -880,6 +878,7 @@ static int stlattach(struct isa_device *idp) /* register devices for DEVFS */ boardnr = brdp->brdnr; + cdevsw_add(&stl_cdevsw, 31, boardnr); make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL, 0600, "staliomem%d", boardnr); diff --git a/sys/dev/serial/stli/istallion.c b/sys/dev/serial/stli/istallion.c index b2000782f1..9051df727f 100644 --- a/sys/dev/serial/stli/istallion.c +++ b/sys/dev/serial/stli/istallion.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/istallion.c,v 1.36.2.2 2001/08/30 12:29:57 murray Exp $ - * $DragonFly: src/sys/dev/serial/stli/istallion.c,v 1.10 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/serial/stli/istallion.c,v 1.11 2004/05/19 22:52:50 dillon Exp $ */ /*****************************************************************************/ @@ -816,10 +816,6 @@ static int stliprobe(struct isa_device *idp) { stlibrd_t *brdp; int btype, bclass; - static int once; - - if (!once++) - cdevsw_add(&stli_cdevsw); #if STLDEBUG printf("stliprobe(idp=%x): unit=%d iobase=%x flags=%x\n", (int) idp, @@ -3543,6 +3539,7 @@ static int stli_brdattach(stlibrd_t *brdp) printf("stli%d: %s (driver version %s), unit=%d nrpanels=%d " "nrports=%d\n", brdp->unitid, stli_brdnames[brdp->brdtype], stli_drvversion, brdp->brdnr, brdp->nrpanels, brdp->nrports); + cdevsw_add(&stli_cdevsw, -1, brdp->unitid); return(0); } diff --git a/sys/dev/sound/isa/i386/pca/pcaudio.c b/sys/dev/sound/isa/i386/pca/pcaudio.c index e258dd95bd..d3274d1f23 100644 --- a/sys/dev/sound/isa/i386/pca/pcaudio.c +++ b/sys/dev/sound/isa/i386/pca/pcaudio.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/pcaudio.c,v 1.58 2000/01/25 21:58:43 dfr Exp $ - * $DragonFly: src/sys/dev/sound/isa/i386/pca/Attic/pcaudio.c,v 1.9 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/sound/isa/i386/pca/Attic/pcaudio.c,v 1.10 2004/05/19 22:52:50 dillon Exp $ */ #include @@ -345,6 +345,7 @@ static int pcaattach(device_t dev) { pca_init(); + cdevsw_add(&pca_cdevsw, 0, 0); make_dev(&pca_cdevsw, 0, 0, 0, 0600, "pcaudio"); make_dev(&pca_cdevsw, 128, 0, 0, 0600, "pcaudioctl"); return 0; diff --git a/sys/dev/sound/isa/i386/soundcard.c b/sys/dev/sound/isa/i386/soundcard.c index 6a9fd801f1..7b12c5c581 100644 --- a/sys/dev/sound/isa/i386/soundcard.c +++ b/sys/dev/sound/isa/i386/soundcard.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/sound/soundcard.c,v 1.87 1999/12/20 18:05:01 eivind Exp $ - * $DragonFly: src/sys/dev/sound/isa/i386/Attic/soundcard.c,v 1.6 2004/05/13 23:49:20 dillon Exp $ + * $DragonFly: src/sys/dev/sound/isa/i386/Attic/soundcard.c,v 1.7 2004/05/19 22:52:50 dillon Exp $ * */ #include "use_snd.h" @@ -501,7 +501,7 @@ sndattach(struct isa_device * dev) sequencer_init(); } - cdevsw_add(&snd_cdevsw); + cdevsw_add(&snd_cdevsw, 0xf0, dev->id_unit << 4); #define GID_SND GID_GAMES #define UID_SND UID_ROOT #define PERM_SND 0660 diff --git a/sys/dev/sound/isa/i386/spkr/spkr.c b/sys/dev/sound/isa/i386/spkr/spkr.c index 4aa9174359..b5c2b84c89 100644 --- a/sys/dev/sound/isa/i386/spkr/spkr.c +++ b/sys/dev/sound/isa/i386/spkr/spkr.c @@ -5,7 +5,7 @@ * modified for FreeBSD by Andrew A. Chernov * * $FreeBSD: src/sys/i386/isa/spkr.c,v 1.45 2000/01/29 16:00:32 peter Exp $ - * $DragonFly: src/sys/dev/sound/isa/i386/spkr/Attic/spkr.c,v 1.10 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/sound/isa/i386/spkr/Attic/spkr.c,v 1.11 2004/05/19 22:52:50 dillon Exp $ */ #include @@ -571,6 +571,7 @@ spkrioctl(dev_t dev, unsigned long cmd, caddr_t cmdarg, int flags, struct thread static void spkr_drvinit(void *unused) { + cdevsw_add(&spkr_cdevsw, 0, 0); make_dev(&spkr_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "speaker"); } diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 863f21c27d..341881fe9a 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/dsp.c,v 1.15.2.13 2002/08/30 13:53:03 orion Exp $ - * $DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.5 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.6 2004/05/19 22:52:50 dillon Exp $ */ #include @@ -32,7 +32,7 @@ #include -SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.5 2004/05/13 23:49:21 dillon Exp $"); +SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.6 2004/05/19 22:52:50 dillon Exp $"); #define OLDPCM_IOCTL @@ -453,7 +453,8 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td) if (IOCGROUP(cmd) == 'M') { dev_t pdev; - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0)); + pdev = make_adhoc_dev(&dsp_cdevsw, + PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0)); return mixer_ioctl(pdev, cmd, arg, mode, td); } @@ -575,7 +576,7 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td) (wrch? chn_getformats(wrch) : 0xffffffff); if (rdch && wrch) p->formats |= (dsp_get_flags(i_dev) & SD_F_SIMPLEX)? 0 : AFMT_FULLDUPLEX; - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0)); + pdev = make_adhoc_dev(&dsp_cdevsw, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0)); p->mixers = 1; /* default: one mixer */ p->inputs = pdev->si_drv1? mix_getdevs(pdev->si_drv1) : 0; p->left = p->right = 100; @@ -1049,6 +1050,7 @@ dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot) int dsp_register(int unit, int channel) { + cdevsw_add(&dsp_cdevsw, PCMMKMINOR(-1, 0, 0), PCMMKMINOR(unit, 0, 0)); make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP, channel), UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d", unit, channel); make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP16, channel), @@ -1071,26 +1073,14 @@ dsp_registerrec(int unit, int channel) int dsp_unregister(int unit, int channel) { - dev_t pdev; - - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP, channel)); - destroy_dev(pdev); - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP16, channel)); - destroy_dev(pdev); - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_AUDIO, channel)); - destroy_dev(pdev); - + cdevsw_remove(&dsp_cdevsw, + PCMMKMINOR(-1, 0, 0), PCMMKMINOR(unit, 0, 0)); return 0; } int dsp_unregisterrec(int unit, int channel) { - dev_t pdev; - - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSPREC, channel)); - destroy_dev(pdev); - return 0; } @@ -1124,7 +1114,7 @@ dsp_clone(void *arg, char *name, int namelen, dev_t *dev) cont = 1; for (i = 0; cont; i++) { - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, devtype, i)); + pdev = make_adhoc_dev(&dsp_cdevsw, PCMMKMINOR(unit, devtype, i)); if (pdev->si_flags & SI_NAMED) { if ((pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) { *dev = pdev; diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c index b11126f424..e819b7e876 100644 --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -24,14 +24,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/mixer.c,v 1.4.2.8 2002/04/22 15:49:36 cg Exp $ - * $DragonFly: src/sys/dev/sound/pcm/mixer.c,v 1.5 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/sound/pcm/mixer.c,v 1.6 2004/05/19 22:52:50 dillon Exp $ */ #include #include "mixer_if.h" -SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/mixer.c,v 1.5 2004/05/13 23:49:21 dillon Exp $"); +SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/mixer.c,v 1.6 2004/05/19 22:52:50 dillon Exp $"); MALLOC_DEFINE(M_MIXER, "mixer", "mixer"); @@ -105,7 +105,7 @@ mixer_get_devt(device_t dev) int unit; unit = device_get_unit(dev); - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_CTL, 0)); + pdev = make_adhoc_dev(&mixer_cdevsw, PCMMKMINOR(unit, SND_DEV_CTL, 0)); return pdev; } @@ -224,6 +224,7 @@ mixer_init(device_t dev, kobj_class_t cls, void *devinfo) mixer_setrecsrc(m, SOUND_MASK_MIC); unit = device_get_unit(dev); + cdevsw_add(&mixer_cdevsw, PCMMKMINOR(-1, 0, 0), PCMMKMINOR(unit, 0, 0)); pdev = make_dev(&mixer_cdevsw, PCMMKMINOR(unit, SND_DEV_CTL, 0), UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit); pdev->si_drv1 = m; @@ -254,6 +255,13 @@ mixer_uninit(device_t dev) } pdev->si_drv1 = NULL; + + /* + * The mixer might be used by several entities, so we do not + * want to remove the cdevsw here. Destroy the device instead. + * destroy_dev() requires a reference count. + */ + reference_dev(pdev); destroy_dev(pdev); for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) @@ -497,7 +505,8 @@ mixer_clone(void *arg, char *name, int namelen, dev_t *dev) if (*dev != NODEV) return; if (strcmp(name, "mixer") == 0) { - pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(snd_unit, SND_DEV_CTL, 0)); + pdev = make_adhoc_dev(&mixer_cdevsw, + PCMMKMINOR(snd_unit, SND_DEV_CTL, 0)); if (pdev->si_flags & SI_NAMED) *dev = pdev; } diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index 7fc7acc437..bc1498b15e 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -24,13 +24,13 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/sndstat.c,v 1.4.2.2 2002/04/22 15:49:36 cg Exp $ - * $DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.5 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.6 2004/05/19 22:52:50 dillon Exp $ */ #include #include -SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.5 2004/05/13 23:49:21 dillon Exp $"); +SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.6 2004/05/19 22:52:50 dillon Exp $"); #define SS_TYPE_MODULE 0 #define SS_TYPE_FIRST 1 @@ -71,7 +71,6 @@ struct sndstat_entry { }; static struct sbuf sndstat_sbuf; -static dev_t sndstat_dev = 0; static int sndstat_isopen = 0; static int sndstat_bufptr; static int sndstat_maxunit = -1; @@ -326,9 +325,10 @@ sndstat_prepare(struct sbuf *s) static int sndstat_init(void) { - sndstat_dev = make_dev(&sndstat_cdevsw, SND_DEV_STATUS, UID_ROOT, GID_WHEEL, 0444, "sndstat"); - - return (sndstat_dev != 0)? 0 : ENXIO; + cdevsw_add(&sndstat_cdevsw, 0, 0); + make_dev(&sndstat_cdevsw, SND_DEV_STATUS, + UID_ROOT, GID_WHEEL, 0444, "sndstat"); + return (0); } static int @@ -341,11 +341,7 @@ sndstat_uninit(void) splx(s); return EBUSY; } - - if (sndstat_dev) - destroy_dev(sndstat_dev); - sndstat_dev = 0; - + cdevsw_remove(&sndstat_cdevsw, 0, 0); splx(s); return 0; } diff --git a/sys/dev/usbmisc/ucom/ucom.c b/sys/dev/usbmisc/ucom/ucom.c index ec6e0f5cca..33445f0afa 100644 --- a/sys/dev/usbmisc/ucom/ucom.c +++ b/sys/dev/usbmisc/ucom/ucom.c @@ -2,7 +2,7 @@ * $NetBSD: ucom.c,v 1.39 2001/08/16 22:31:24 augustss Exp $ * $NetBSD: ucom.c,v 1.40 2001/11/13 06:24:54 lukem Exp $ * $FreeBSD: src/sys/dev/usb/ucom.c,v 1.35 2003/11/16 11:58:21 akiyama Exp $ - * $DragonFly: src/sys/dev/usbmisc/ucom/ucom.c,v 1.14 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/ucom/ucom.c,v 1.15 2004/05/19 22:52:51 dillon Exp $ */ /*- * Copyright (c) 2001-2002, Shunsuke Akiyama . @@ -182,6 +182,7 @@ ucom_attach(struct ucom_softc *sc) { struct tty *tp; int unit; + dev_t dev; unit = device_get_unit(sc->sc_dev); @@ -194,10 +195,11 @@ ucom_attach(struct ucom_softc *sc) DPRINTF(("ucom_attach: make_dev: ucom%d\n", unit)); - sc->dev = make_dev(&ucom_cdevsw, unit | UCOM_CALLOUT_MASK, + cdevsw_add(&ucom_cdevsw, UCOMUNIT_MASK, unit); + dev = make_dev(&ucom_cdevsw, unit | UCOM_CALLOUT_MASK, UID_UUCP, GID_DIALER, 0660, "ucom%d", unit); - sc->dev->si_tty = tp; + dev->si_tty = tp; return (0); } @@ -207,6 +209,7 @@ ucom_detach(struct ucom_softc *sc) { struct tty *tp = sc->sc_tty; int s; + int unit; DPRINTF(("ucom_detach: sc = %p, tp = %p\n", sc, sc->sc_tty)); @@ -239,7 +242,8 @@ ucom_detach(struct ucom_softc *sc) } splx(s); - destroy_dev(sc->dev); + unit = device_get_unit(sc->sc_dev); + cdevsw_remove(&ucom_cdevsw, UCOMUNIT_MASK, unit); return (0); } @@ -302,7 +306,7 @@ ucomopen(dev_t dev, int flag, int mode, usb_proc_ptr td) sc->sc_poll = 0; sc->sc_lsr = sc->sc_msr = sc->sc_mcr = 0; - tp->t_dev = dev; + tp->t_dev = reference_dev(dev); /* * Initialize the termios status to the defaults. Add in the @@ -472,6 +476,11 @@ ucomclose(dev_t dev, int flag, int mode, usb_proc_ptr p) DPRINTF(("%s: ucomclose: unit = %d\n", USBDEVNAME(sc->sc_dev), UCOMUNIT(dev))); + if (tp->t_dev) { + release_dev(tp->t_dev); + tp->t_dev = NULL; + } + if (!ISSET(tp->t_state, TS_ISOPEN)) goto quit; diff --git a/sys/dev/usbmisc/ufm/ufm.c b/sys/dev/usbmisc/ufm/ufm.c index fb59d9a01f..03b00a847d 100644 --- a/sys/dev/usbmisc/ufm/ufm.c +++ b/sys/dev/usbmisc/ufm/ufm.c @@ -30,7 +30,7 @@ /* * $FreeBSD: src/sys/dev/usb/ufm.c,v 1.16 2003/10/04 21:41:01 joe Exp $ - * $DragonFly: src/sys/dev/usbmisc/ufm/ufm.c,v 1.7 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/ufm/ufm.c,v 1.8 2004/05/19 22:52:51 dillon Exp $ */ #include @@ -208,7 +208,8 @@ USB_ATTACH(ufm) #if defined(__FreeBSD__) || defined(__DragonFly__) /* XXX no error trapping, no storing of dev_t */ - (void) make_dev(&ufm_cdevsw, device_get_unit(self), + cdevsw_add(&ufm_cdevsw, -1, device_get_unit(self)); + make_dev(&ufm_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, 0644, "ufm%d", device_get_unit(self)); #elif defined(__NetBSD__) || defined(__OpenBSD__) diff --git a/sys/dev/usbmisc/ugen/ugen.c b/sys/dev/usbmisc/ugen/ugen.c index 1fb1faff8f..c373723bf2 100644 --- a/sys/dev/usbmisc/ugen/ugen.c +++ b/sys/dev/usbmisc/ugen/ugen.c @@ -2,7 +2,7 @@ * $NetBSD: ugen.c,v 1.27 1999/10/28 12:08:38 augustss Exp $ * $NetBSD: ugen.c,v 1.59 2002/07/11 21:14:28 augustss Exp $ * $FreeBSD: src/sys/dev/usb/ugen.c,v 1.81 2003/11/09 09:17:22 tanimura Exp $ - * $DragonFly: src/sys/dev/usbmisc/ugen/ugen.c,v 1.12 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/ugen/ugen.c,v 1.13 2004/05/19 22:52:51 dillon Exp $ */ /* @@ -129,9 +129,6 @@ struct ugen_endpoint { struct ugen_softc { USBBASEDEVICE sc_dev; /* base device */ usbd_device_handle sc_udev; -#if defined(__FreeBSD__) || defined(__DragonFly__) - dev_t dev; -#endif char sc_is_open[USB_MAX_ENDPOINTS]; struct ugen_endpoint sc_endpoints[USB_MAX_ENDPOINTS][2]; @@ -192,9 +189,10 @@ Static usb_config_descriptor_t *ugen_get_cdesc(struct ugen_softc *sc, Static usbd_status ugen_set_interface(struct ugen_softc *, int, int); Static int ugen_get_alt_index(struct ugen_softc *sc, int ifaceidx); -#define UGENUNIT(n) ((minor(n) >> 4) & 0xf) +#define UGENUNIT(n) ((lminor(n) >> 4) & 0xff) #define UGENENDPOINT(n) (minor(n) & 0xf) -#define UGENMINOR(u, e) (((u) << 4) | (e)) +#define UGENMINOR(u, e) (((u & 0xf) << 4) | ((u & 0xf0) << 12) | (e)) +#define UGENUNITMASK 0xffff00f0 USB_DECLARE_DRIVER(ugen); @@ -249,7 +247,9 @@ USB_ATTACH(ugen) #if defined(__FreeBSD__) || defined(__DragonFly__) /* the main device, ctrl endpoint */ - sc->dev = make_dev(&ugen_cdevsw, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0), + cdevsw_add(&ugen_cdevsw, + UGENUNITMASK, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0)); + make_dev(&ugen_cdevsw, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0), UID_ROOT, GID_OPERATOR, 0644, "%s", USBDEVNAME(sc->sc_dev)); #endif @@ -279,10 +279,20 @@ ugen_make_devnodes(struct ugen_softc *sc) UID_ROOT, GID_OPERATOR, 0644, "%s.%d", USBDEVNAME(sc->sc_dev), endptno); - if (sc->sc_endpoints[endptno][IN].sc != NULL) + if (sc->sc_endpoints[endptno][IN].sc != NULL) { + printf("X1"); + reference_dev(dev); + if (sc->sc_endpoints[endptno][IN].dev) + release_dev(sc->sc_endpoints[endptno][IN].dev); sc->sc_endpoints[endptno][IN].dev = dev; - if (sc->sc_endpoints[endptno][OUT].sc != NULL) + } + if (sc->sc_endpoints[endptno][OUT].sc != NULL) { + printf("X2"); + reference_dev(dev); + if (sc->sc_endpoints[endptno][OUT].dev) + release_dev(sc->sc_endpoints[endptno][OUT].dev); sc->sc_endpoints[endptno][OUT].dev = dev; + } } } } @@ -305,11 +315,18 @@ ugen_destroy_devnodes(struct ugen_softc *sc) * In the if clause above we check whether one * of the structs is populated. */ - if (sc->sc_endpoints[endptno][IN].sc != NULL) - dev = sc->sc_endpoints[endptno][IN].dev; - else - dev = sc->sc_endpoints[endptno][OUT].dev; - destroy_dev(dev); + dev = sc->sc_endpoints[endptno][IN].dev; + if (dev != NULL) { + printf("X3"); + destroy_dev(dev); + sc->sc_endpoints[endptno][IN].dev = NULL; + } + dev = sc->sc_endpoints[endptno][OUT].dev; + if (dev != NULL) { + printf("X4"); + destroy_dev(dev); + sc->sc_endpoints[endptno][OUT].dev = NULL; + } } } } @@ -337,13 +354,14 @@ ugen_set_config(struct ugen_softc *sc, int configno) /* We start at 1, not 0, because we don't care whether the * control endpoint is open or not. It is always present. */ - for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) + for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) { if (sc->sc_is_open[endptno]) { DPRINTFN(1, ("ugen_set_config: %s - endpoint %d is open\n", USBDEVNAME(sc->sc_dev), endptno)); return (USBD_IN_USE); } + } /* Avoid setting the current value. */ if (usbd_get_config_descriptor(dev)->bConfigurationValue != configno) { @@ -891,7 +909,6 @@ USB_DETACH(ugen) usbd_abort_pipe(sce->pipeh); } } - s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wake everyone */ @@ -913,10 +930,10 @@ USB_DETACH(ugen) vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR); #elif defined(__FreeBSD__) || defined(__DragonFly__) /* destroy the device for the control endpoint */ - destroy_dev(sc->dev); ugen_destroy_devnodes(sc); + cdevsw_remove(&ugen_cdevsw, + UGENUNITMASK, UGENMINOR(USBDEVUNIT(sc->sc_dev), 0)); #endif - return (0); } diff --git a/sys/dev/usbmisc/uhid/uhid.c b/sys/dev/usbmisc/uhid/uhid.c index 56fb539cb9..b44398d002 100644 --- a/sys/dev/usbmisc/uhid/uhid.c +++ b/sys/dev/usbmisc/uhid/uhid.c @@ -1,7 +1,7 @@ /* * $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ * $FreeBSD: src/sys/dev/usb/uhid.c,v 1.65 2003/11/09 09:17:22 tanimura Exp $ - * $DragonFly: src/sys/dev/usbmisc/uhid/uhid.c,v 1.12 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/uhid/uhid.c,v 1.13 2004/05/19 22:52:51 dillon Exp $ */ /* Also already merged from NetBSD: @@ -135,10 +135,6 @@ struct uhid_softc { int sc_refcnt; u_char sc_dying; - -#if defined(__FreeBSD__) || defined(__DragonFly__) - dev_t dev; -#endif }; #define UHIDUNIT(dev) (minor(dev)) @@ -276,9 +272,10 @@ USB_ATTACH(uhid) sc->sc_repdesc_size = size; #if defined(__FreeBSD__) || defined(__DragonFly__) - sc->dev = make_dev(&uhid_cdevsw, device_get_unit(self), - UID_ROOT, GID_OPERATOR, - 0644, "uhid%d", device_get_unit(self)); + cdevsw_add(&uhid_cdevsw, -1, device_get_unit(self)); + make_dev(&uhid_cdevsw, device_get_unit(self), + UID_ROOT, GID_OPERATOR, + 0644, "uhid%d", device_get_unit(self)); #endif USB_ATTACH_SUCCESS_RETURN; @@ -341,7 +338,7 @@ USB_DETACH(uhid) mn = self->dv_unit; vdevgone(maj, mn, mn, VCHR); #elif defined(__FreeBSD__) || defined(__DragonFly__) - destroy_dev(sc->dev); + cdevsw_remove(&uhid_cdevsw, -1, device_get_unit(self)); #endif if (sc->sc_repdesc) diff --git a/sys/dev/usbmisc/ulpt/ulpt.c b/sys/dev/usbmisc/ulpt/ulpt.c index f60aee7ae9..0ba279b626 100644 --- a/sys/dev/usbmisc/ulpt/ulpt.c +++ b/sys/dev/usbmisc/ulpt/ulpt.c @@ -1,7 +1,7 @@ /* * $NetBSD: ulpt.c,v 1.55 2002/10/23 09:14:01 jdolecek Exp $ * $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.59 2003/09/28 20:48:13 phk Exp $ - * $DragonFly: src/sys/dev/usbmisc/ulpt/ulpt.c,v 1.9 2004/05/13 23:49:21 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/ulpt/ulpt.c,v 1.10 2004/05/19 22:52:51 dillon Exp $ */ /* @@ -120,11 +120,6 @@ struct ulpt_softc { int sc_refcnt; u_char sc_dying; - -#if defined(__FreeBSD__) || defined(__DragonFly__) - dev_t dev; - dev_t dev_noprime; -#endif }; #if defined(__NetBSD__) @@ -345,9 +340,10 @@ USB_ATTACH(ulpt) #endif #if defined(__FreeBSD__) || defined(__DragonFly__) - sc->dev = make_dev(&ulpt_cdevsw, device_get_unit(self), + cdevsw_add(&ulpt_cdevsw, -1, device_get_unit(self)); + make_dev(&ulpt_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, 0644, "ulpt%d", device_get_unit(self)); - sc->dev_noprime = make_dev(&ulpt_cdevsw, + make_dev(&ulpt_cdevsw, device_get_unit(self)|ULPT_NOPRIME, UID_ROOT, GID_OPERATOR, 0644, "unlpt%d", device_get_unit(self)); #endif @@ -418,8 +414,7 @@ USB_DETACH(ulpt) mn = self->dv_unit; vdevgone(maj, mn, mn, VCHR); #elif defined(__FreeBSD__) || defined(__DragonFly__) - destroy_dev(sc->dev); - destroy_dev(sc->dev_noprime); + cdevsw_remove(&ulpt_cdevsw, -1, device_get_unit(self)); #endif usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, diff --git a/sys/dev/usbmisc/ums/ums.c b/sys/dev/usbmisc/ums/ums.c index e7d536c929..dc532aa346 100644 --- a/sys/dev/usbmisc/ums/ums.c +++ b/sys/dev/usbmisc/ums/ums.c @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/dev/usb/ums.c,v 1.64 2003/11/09 09:17:22 tanimura Exp $ - * $DragonFly: src/sys/dev/usbmisc/ums/ums.c,v 1.11 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/ums/ums.c,v 1.12 2004/05/19 22:52:51 dillon Exp $ */ /* @@ -130,8 +130,6 @@ struct ums_softc { # define UMS_ASLEEP 0x01 /* readFromDevice is waiting */ # define UMS_SELECT 0x02 /* select is waiting */ struct selinfo rsel; /* process waiting in select */ - - dev_t dev; /* specfs */ }; #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE) @@ -349,10 +347,10 @@ USB_ATTACH(ums) sc->rsel.si_flags = 0; sc->rsel.si_pid = 0; #endif - - sc->dev = make_dev(&ums_cdevsw, device_get_unit(self), - UID_ROOT, GID_OPERATOR, - 0644, "ums%d", device_get_unit(self)); + cdevsw_add(&ums_cdevsw, -1, device_get_unit(self)); + make_dev(&ums_cdevsw, device_get_unit(self), + UID_ROOT, GID_OPERATOR, + 0644, "ums%d", device_get_unit(self)); if (usbd_get_quirks(uaa->device)->uq_flags & UQ_SPUR_BUT_UP) { DPRINTF(("%s: Spurious button up events\n", @@ -393,8 +391,7 @@ ums_detach(device_t self) sc->state &= ~UMS_SELECT; selwakeuppri(&sc->rsel, 0); } - - destroy_dev(sc->dev); + cdevsw_remove(&ums_cdevsw, -1, device_get_unit(self)); return 0; } diff --git a/sys/dev/usbmisc/urio/urio.c b/sys/dev/usbmisc/urio/urio.c index 57cb0d4f14..4132cb0ba6 100644 --- a/sys/dev/usbmisc/urio/urio.c +++ b/sys/dev/usbmisc/urio/urio.c @@ -30,7 +30,7 @@ /* * $FreeBSD: src/sys/dev/usb/urio.c,v 1.28 2003/08/25 22:01:06 joe Exp $ - * $DragonFly: src/sys/dev/usbmisc/urio/urio.c,v 1.9 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/urio/urio.c,v 1.10 2004/05/19 22:52:52 dillon Exp $ */ /* @@ -147,9 +147,6 @@ struct urio_softc { int sc_epaddr[2]; int sc_refcnt; -#if defined(__FreeBSD__) || defined(__DragonFly__) - dev_t sc_dev_t; -#endif /* defined(__FreeBSD__) */ #if defined(__NetBSD__) || defined(__OpenBSD__) u_char sc_dying; #endif @@ -262,8 +259,8 @@ USB_ATTACH(urio) } #if defined(__FreeBSD__) || defined(__DragonFly__) - /* XXX no error trapping, no storing of dev_t */ - sc->sc_dev_t = make_dev(&urio_cdevsw, device_get_unit(self), + cdevsw_add(&urio_cdevsw, -1, device_get_unit(self)); + make_dev(&urio_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, 0644, "urio%d", device_get_unit(self)); #elif defined(__NetBSD__) || defined(__OpenBSD__) @@ -675,10 +672,8 @@ USB_DETACH(urio) Static int urio_detach(device_t self) { - struct urio_softc *sc = device_get_softc(self); - DPRINTF(("%s: disconnected\n", USBDEVNAME(self))); - destroy_dev(sc->sc_dev_t); + cdevsw_remove(&urio_cdevsw, -1, device_get_unit(self)); /* XXX not implemented yet */ device_set_desc(self, NULL); return 0; diff --git a/sys/dev/usbmisc/uscanner/uscanner.c b/sys/dev/usbmisc/uscanner/uscanner.c index 70e5ac92d2..e4d3224623 100644 --- a/sys/dev/usbmisc/uscanner/uscanner.c +++ b/sys/dev/usbmisc/uscanner/uscanner.c @@ -1,7 +1,7 @@ /* * $NetBSD: uscanner.c,v 1.30 2002/07/11 21:14:36 augustss Exp $ * $FreeBSD: src/sys/dev/usb/uscanner.c,v 1.48 2003/12/22 19:58:27 sanpei Exp $ - * $DragonFly: src/sys/dev/usbmisc/uscanner/uscanner.c,v 1.8 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/usbmisc/uscanner/uscanner.c,v 1.9 2004/05/19 22:52:52 dillon Exp $ */ /* Also already merged from NetBSD: @@ -227,9 +227,6 @@ struct uscanner_softc { USBBASEDEVICE sc_dev; /* base device */ usbd_device_handle sc_udev; usbd_interface_handle sc_iface; -#if defined(__FreeBSD__) || defined(__DragonFly__) - dev_t dev; -#endif u_int sc_dev_flags; @@ -371,7 +368,8 @@ USB_ATTACH(uscanner) #if defined(__FreeBSD__) || defined(__DragonFly__) /* the main device, ctrl endpoint */ - sc->dev = make_dev(&uscanner_cdevsw, USBDEVUNIT(sc->sc_dev), + cdevsw_add(&uscanner_cdevsw, -1, USBDEVUNIT(sc->sc_dev)); + make_dev(&uscanner_cdevsw, USBDEVUNIT(sc->sc_dev), UID_ROOT, GID_OPERATOR, 0644, "%s", USBDEVNAME(sc->sc_dev)); #endif @@ -666,7 +664,7 @@ USB_DETACH(uscanner) vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR); #elif defined(__FreeBSD__) || defined(__DragonFly__) /* destroy the device for the control endpoint */ - destroy_dev(sc->dev); + cdevsw_remove(&uscanner_cdevsw, -1, USBDEVUNIT(sc->sc_dev)); #endif usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, diff --git a/sys/dev/video/bktr/bktr_os.c b/sys/dev/video/bktr/bktr_os.c index 8e9fc1f6b5..445b5ab02f 100644 --- a/sys/dev/video/bktr/bktr_os.c +++ b/sys/dev/video/bktr/bktr_os.c @@ -31,7 +31,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/bktr/bktr_os.c,v 1.45 2004/03/17 17:50:28 njl Exp $ - * $DragonFly: src/sys/dev/video/bktr/bktr_os.c,v 1.9 2004/05/15 17:54:12 joerg Exp $ + * $DragonFly: src/sys/dev/video/bktr/bktr_os.c,v 1.10 2004/05/19 22:52:52 dillon Exp $ */ /* @@ -363,12 +363,10 @@ bktr_attach( device_t dev ) common_bktr_attach( bktr, unit, fun, rev ); /* make the device entries */ - bktr->bktrdev = make_dev(&bktr_cdevsw, unit, - 0, 0, 0444, "bktr%d", unit); - bktr->tunerdev= make_dev(&bktr_cdevsw, unit+16, - 0, 0, 0444, "tuner%d", unit); - bktr->vbidev = make_dev(&bktr_cdevsw, unit+32, - 0, 0, 0444, "vbi%d" , unit); + cdevsw_add(&bktr_cdevsw, 0x0f, unit); + make_dev(&bktr_cdevsw, unit, 0, 0, 0444, "bktr%d", unit); + make_dev(&bktr_cdevsw, unit+16, 0, 0, 0444, "tuner%d", unit); + make_dev(&bktr_cdevsw, unit+32, 0, 0, 0444, "vbi%d" , unit); return 0; @@ -413,11 +411,8 @@ bktr_detach( device_t dev ) /* The memory is retained by the bktr_mem module so we can unload and */ /* then reload the main bktr driver module */ - /* Unregister the /dev/bktrN, tunerN and vbiN devices, - * the aliases for unit 0 are automatically destroyed */ - destroy_dev(bktr->vbidev); - destroy_dev(bktr->tunerdev); - destroy_dev(bktr->bktrdev); + /* removing the cdevsw automatically destroys all related devices */ + cdevsw_remove(&bktr_cdevsw, 0x0f, device_get_unit(dev)); /* * Deallocate resources. diff --git a/sys/dev/video/bktr/bktr_reg.h b/sys/dev/video/bktr/bktr_reg.h index 0cacff81c0..28eeb25ab6 100644 --- a/sys/dev/video/bktr/bktr_reg.h +++ b/sys/dev/video/bktr/bktr_reg.h @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/dev/bktr/bktr_reg.h,v 1.46 2003/12/01 19:03:50 truckman Exp $ - * $DragonFly: src/sys/dev/video/bktr/bktr_reg.h,v 1.5 2004/05/15 17:54:13 joerg Exp $ + * $DragonFly: src/sys/dev/video/bktr/bktr_reg.h,v 1.6 2004/05/19 22:52:52 dillon Exp $ * * Copyright (c) 1999 Roger Hardiman * Copyright (c) 1998 Amancio Hasty @@ -455,12 +455,6 @@ struct bktr_softc { int irq_rid; /* 4.x resource id */ struct resource *res_irq; /* 4.x resource descriptor for interrupt */ void *res_ih; /* 4.x newbus interrupt handler cookie */ - dev_t bktrdev; /* 4.x device entry for /dev/bktrN */ - dev_t tunerdev; /* 4.x device entry for /dev/tunerN */ - dev_t vbidev; /* 4.x device entry for /dev/vbiN */ - dev_t bktrdev_alias; /* alias /dev/bktr to /dev/bktr0 */ - dev_t tunerdev_alias; /* alias /dev/tuner to /dev/tuner0 */ - dev_t vbidev_alias; /* alias /dev/vbi to /dev/vbi0 */ bus_space_tag_t memt; /* Bus space register access functions */ bus_space_handle_t memh; /* Bus space register access functions */ bus_size_t obmemsz;/* Size of card (bytes) */ diff --git a/sys/dev/video/ctx/ctx.c b/sys/dev/video/ctx/ctx.c index 7a2b73a161..2f59116940 100644 --- a/sys/dev/video/ctx/ctx.c +++ b/sys/dev/video/ctx/ctx.c @@ -9,7 +9,7 @@ * for damages incurred with its use. * * $FreeBSD: src/sys/i386/isa/ctx.c,v 1.36 2000/01/29 16:17:31 peter Exp $ - * $DragonFly: src/sys/dev/video/ctx/ctx.c,v 1.7 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/video/ctx/ctx.c,v 1.8 2004/05/19 22:52:53 dillon Exp $ */ /* @@ -182,15 +182,11 @@ static int ctxprobe(struct isa_device * devp) { int status; - static int once; - if (!once++) - cdevsw_add(&ctx_cdevsw); if (inb(devp->id_iobase) == 0xff) /* 0xff only if board absent */ status = 0; - else { - status = 1; /*XXX uses only one port? */ - } + else + status = 1; /*XXX uses only one port? */ return (status); } @@ -206,7 +202,9 @@ ctxattach(struct isa_device * devp) sr->iobase = devp->id_iobase; sr->maddr = devp->id_maddr; sr->msize = devp->id_msize; - make_dev(&ctx_cdevsw, 0, 0, 0, 0600, "ctx%d", devp->id_unit); + cdevsw_add(&ctx_cdevsw, -1, devp->id_unit); + make_dev(&ctx_cdevsw, devp->id_unit, 0, 0, 0600, + "ctx%d", devp->id_unit); return (1); } diff --git a/sys/dev/video/fb/fb.c b/sys/dev/video/fb/fb.c index 1727ca834d..e200b1a1fc 100644 --- a/sys/dev/video/fb/fb.c +++ b/sys/dev/video/fb/fb.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fb/fb.c,v 1.11.2.2 2000/08/02 22:35:22 peter Exp $ - * $DragonFly: src/sys/dev/video/fb/fb.c,v 1.8 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/fb.c,v 1.9 2004/05/19 22:52:54 dillon Exp $ */ #include "opt_fb.h" @@ -65,8 +65,8 @@ static video_switch_t *vidsw_ini; video_switch_t **vidsw = &vidsw_ini; #ifdef FB_INSTALL_CDEV -static struct lwkt_port *vidcdevsw_ini; -static struct lwkt_port **vidcdevsw = &vidcdevsw_ini; +static dev_t vidcdevsw_ini; +static dev_t *vidcdevsw = &vidcdevsw_ini; #endif #define ARRAY_DELTA 4 @@ -77,7 +77,7 @@ vid_realloc_array(void) video_adapter_t **new_adp; video_switch_t **new_vidsw; #ifdef FB_INSTALL_CDEV - struct lwkt_port **new_cdevsw; + dev_t *new_cdevsw; #endif int newsize; int s; @@ -388,7 +388,7 @@ vfbattach(void *arg) static int fb_devsw_installed = FALSE; if (!fb_devsw_installed) { - cdevsw_add(&fb_cdevsw); + cdevsw_add(&fb_cdevsw, 0, 0); fb_devsw_installed = TRUE; } } @@ -409,15 +409,15 @@ fb_attach(dev_t dev, video_adapter_t *adp) return EINVAL; s = spltty(); + reference_dev(dev); adp->va_minor = minor(dev); - vidcdevsw[adp->va_index] = dev_dport(dev); + vidcdevsw[adp->va_index] = dev; splx(s); printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit); return 0; } -#if 0 /* never seems to be called */ /* * Note: dev represents the actual video device, not the frame buffer */ @@ -430,94 +430,88 @@ fb_detach(dev_t dev, video_adapter_t *adp) return EINVAL; if (adapter[adp->va_index] != adp) return EINVAL; - if (vidcdevsw[adp->va_index] != port) + if (vidcdevsw[adp->va_index] != dev) return EINVAL; s = spltty(); vidcdevsw[adp->va_index] = NULL; splx(s); + release_dev(dev); return 0; } -#endif static int fbopen(dev_t dev, int flag, int mode, struct thread *td) { int unit; + dev_t fdev; unit = FB_UNIT(dev); if (unit >= adapters) return ENXIO; - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return dev_port_dopen(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - flag, mode, td); + return dev_dopen(fdev, flag, mode, td); } static int fbclose(dev_t dev, int flag, int mode, struct thread *td) { int unit; + dev_t fdev; unit = FB_UNIT(dev); - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return dev_port_dclose(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - flag, mode, td); + return dev_dclose(fdev, flag, mode, td); } static int fbread(dev_t dev, struct uio *uio, int flag) { int unit; + dev_t fdev; unit = FB_UNIT(dev); - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return dev_port_dread(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - uio, flag); + return dev_dread(fdev, uio, flag); } static int fbwrite(dev_t dev, struct uio *uio, int flag) { int unit; + dev_t fdev; unit = FB_UNIT(dev); - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return dev_port_dwrite(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - uio, flag); + return dev_dwrite(fdev, uio, flag); } static int fbioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) { int unit; + dev_t fdev; unit = FB_UNIT(dev); - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return dev_port_dioctl(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - cmd, arg, flag, td); + return dev_dioctl(fdev, cmd, arg, flag, td); } static int fbmmap(dev_t dev, vm_offset_t offset, int nprot) { int unit; + dev_t fdev; unit = FB_UNIT(dev); - if (vidcdevsw[unit] == NULL) + if ((fdev = vidcdevsw[unit]) == NULL) return ENXIO; - return (dev_port_dmmap(vidcdevsw[unit], - makedev(0, adapter[unit]->va_minor), - offset, nprot)); + return (dev_dmmap(fdev, offset, nprot)); } #if experimental diff --git a/sys/dev/video/fb/vgareg.h b/sys/dev/video/fb/vgareg.h index c102d35a2a..5f6ed5d14d 100644 --- a/sys/dev/video/fb/vgareg.h +++ b/sys/dev/video/fb/vgareg.h @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fb/vgareg.h,v 1.4 1999/12/29 04:35:37 peter Exp $ - * $DragonFly: src/sys/dev/video/fb/vgareg.h,v 1.4 2003/07/22 17:03:28 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/vgareg.h,v 1.5 2004/05/19 22:52:54 dillon Exp $ */ #ifndef _DEV_FB_VGAREG_H_ @@ -63,7 +63,7 @@ #define VGA_DRIVER_NAME "vga" #define VGA_UNIT(dev) minor(dev) -#define VGA_MKMINOR(unit) (unit) +#define VGA_MKMINOR(unit) (unit & 0xff) #ifdef _KERNEL diff --git a/sys/dev/video/gfb/gfb_pci.c b/sys/dev/video/gfb/gfb_pci.c index e13315ae4c..d0c019fcb5 100644 --- a/sys/dev/video/gfb/gfb_pci.c +++ b/sys/dev/video/gfb/gfb_pci.c @@ -27,7 +27,7 @@ * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi * * $FreeBSD: src/sys/dev/gfb/gfb_pci.c,v 1.1.2.1 2001/11/01 08:33:15 obrien Exp $ - * $DragonFly: src/sys/dev/video/gfb/Attic/gfb_pci.c,v 1.4 2003/08/07 21:17:16 dillon Exp $ + * $DragonFly: src/sys/dev/video/gfb/Attic/gfb_pci.c,v 1.5 2004/05/19 22:52:54 dillon Exp $ */ #include @@ -245,7 +245,7 @@ pcigfb_detach(device_t dev) sc = device_get_softc(dev); #ifdef FB_INSTALL_CDEV - destroy_dev(sc->devt); + fb_detach(sc->devt, sc->adp); #endif /*FB_INSTALL_CDEV*/ bus_teardown_intr(dev, sc->irq, sc->intrhand); rid = 0x0; diff --git a/sys/dev/video/gsc/gsc.c b/sys/dev/video/gsc/gsc.c index 59f03a5a41..92fb92e4b1 100644 --- a/sys/dev/video/gsc/gsc.c +++ b/sys/dev/video/gsc/gsc.c @@ -32,7 +32,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/gsc.c,v 1.35.2.1 2000/08/08 19:49:53 peter Exp $ - * $DragonFly: src/sys/dev/video/gsc/gsc.c,v 1.8 2004/05/13 23:49:22 dillon Exp $ + * $DragonFly: src/sys/dev/video/gsc/gsc.c,v 1.9 2004/05/19 22:52:54 dillon Exp $ * */ @@ -387,10 +387,6 @@ gscprobe (struct isa_device *isdp) struct gsc_unit *scu = unittab + unit; int stb; struct gsc_geom geom = NEW_GEOM; - static int once; - - if (!once++) - cdevsw_add(&gsc_cdevsw); scu->flags = FLAG_DEBUG; @@ -533,6 +529,7 @@ gscattach(struct isa_device *isdp) scu->flags &= ~FLAG_DEBUG; #define GSC_UID 0 #define GSC_GID 13 + cdevsw_add(&gsc_cdevsw, 0xc0, unit << 6); make_dev(&gsc_cdevsw, unit<<6, GSC_UID, GSC_GID, 0666, "gsc%d", unit); make_dev(&gsc_cdevsw, ((unit<<6) + FRMT_PBM), GSC_UID, GSC_GID, 0666, "gsc%dp", unit); diff --git a/sys/dev/video/meteor/meteor.c b/sys/dev/video/meteor/meteor.c index 536e67c959..cd8bcd5743 100644 --- a/sys/dev/video/meteor/meteor.c +++ b/sys/dev/video/meteor/meteor.c @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/pci/meteor.c,v 1.49 1999/09/25 18:24:41 phk Exp $ - * $DragonFly: src/sys/dev/video/meteor/meteor.c,v 1.12 2004/05/15 17:54:13 joerg Exp $ + * $DragonFly: src/sys/dev/video/meteor/meteor.c,v 1.13 2004/05/19 22:52:54 dillon Exp $ */ /* Change History: @@ -528,11 +528,6 @@ int err = 0; static const char * met_probe (pcici_t tag, pcidi_t type) { - static int once; - - if (!once++) - cdevsw_add(&meteor_cdevsw); - switch (type) { case SAA7116_PHILIPS_ID: /* meteor */ return("Philips SAA 7116"); @@ -1118,6 +1113,7 @@ met_attach(pcici_t tag, int unit) mtr->flags |= METEOR_INITALIZED | METEOR_AUTOMODE | METEOR_DEV0 | METEOR_RGB16; + cdevsw_add(&meteor_cdevsw, -1, unit); make_dev(&meteor_cdevsw, unit, 0, 0, 0644, "meteor"); } diff --git a/sys/dev/video/pcvt/i386/pcvt_drv.c b/sys/dev/video/pcvt/i386/pcvt_drv.c index 35d23e32c3..5ace9bade4 100644 --- a/sys/dev/video/pcvt/i386/pcvt_drv.c +++ b/sys/dev/video/pcvt/i386/pcvt_drv.c @@ -51,7 +51,7 @@ * Last Edit-Date: [Mon Dec 27 14:03:36 1999] * * $FreeBSD: src/sys/i386/isa/pcvt/pcvt_drv.c,v 1.63.2.1 2001/02/26 04:23:13 jlemon Exp $ - * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_drv.c,v 1.9 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_drv.c,v 1.10 2004/05/19 22:52:54 dillon Exp $ * *---------------------------------------------------------------------------*/ @@ -102,7 +102,7 @@ static d_ioctl_t pcioctl; static d_mmap_t pcmmap; #define CDEV_MAJOR 12 -static struct cdevsw pc_cdevsw = { +struct cdevsw pc_cdevsw = { /* name */ "vt", /* maj */ CDEV_MAJOR, /* flags */ D_TTY | D_KQFILTER, @@ -335,6 +335,7 @@ pcattach(struct isa_device *dev) #endif /* PCVT_NETBSD || PCVT_FREEBSD */ #if !PCVT_NETBSD && !(PCVT_FREEBSD > 110 && PCVT_FREEBSD < 200) + cdevsw_add(&pc_cdevsw, 0, 0); for(i = 0; i < totalscreens; i++) { ttyregister(&pccons[i]); @@ -1127,7 +1128,7 @@ pccnprobe(struct consdev *cp) /* initialize required fields */ - cp->cn_dev = makedev(CDEV_MAJOR, 0); + cp->cn_dev = make_adhoc_dev(&pc_cdevsw, 0); cp->cn_pri = CN_INTERNAL; #if !PCVT_NETBSD diff --git a/sys/dev/video/pcvt/i386/pcvt_hdr.h b/sys/dev/video/pcvt/i386/pcvt_hdr.h index 655689f2ee..17f70f90b1 100644 --- a/sys/dev/video/pcvt/i386/pcvt_hdr.h +++ b/sys/dev/video/pcvt/i386/pcvt_hdr.h @@ -42,7 +42,7 @@ * Last Edit-Date: [Mon Dec 27 14:06:31 1999] * * $FreeBSD: src/sys/i386/isa/pcvt/pcvt_hdr.h,v 1.36.2.3 2001/08/06 15:30:21 joerg Exp $ - * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_hdr.h,v 1.4 2004/02/13 01:45:15 joerg Exp $ + * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_hdr.h,v 1.5 2004/05/19 22:52:54 dillon Exp $ * *---------------------------------------------------------------------------*/ @@ -1121,6 +1121,7 @@ u_char sgr_tab_imono[16] = { extern u_char vga_type; extern struct tty *pcconsp; extern video_state *vsp; +extern struct cdevsw pc_cdevsw; #if PCVT_EMU_MOUSE extern struct mousestat mouse; diff --git a/sys/dev/video/pcvt/i386/pcvt_kbd.c b/sys/dev/video/pcvt/i386/pcvt_kbd.c index 5aa065162f..d2732532a0 100644 --- a/sys/dev/video/pcvt/i386/pcvt_kbd.c +++ b/sys/dev/video/pcvt/i386/pcvt_kbd.c @@ -48,7 +48,7 @@ * Last Edit-Date: [Mon Dec 27 14:01:50 1999] * * $FreeBSD: src/sys/i386/isa/pcvt/pcvt_kbd.c,v 1.32.2.1 2000/10/29 16:59:28 dwmalone Exp $ - * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_kbd.c,v 1.4 2003/08/07 21:17:16 dillon Exp $ + * $DragonFly: src/sys/dev/video/pcvt/i386/Attic/pcvt_kbd.c,v 1.5 2004/05/19 22:52:54 dillon Exp $ * *---------------------------------------------------------------------------*/ @@ -1263,8 +1263,12 @@ loop: } move; struct timeval now; - dev_t dummy = makedev(0, mouse.minor); - struct tty *mousetty = get_pccons(dummy); + dev_t dummy; + struct tty *mousetty; + + dummy = make_adhoc_dev(&pc_cdevsw, mouse.minor); + mousetty = get_pccons(dummy); + /* * strings to send for each mouse event, * indexed by the movement direction and diff --git a/sys/dev/video/tga/tga_pci.c b/sys/dev/video/tga/tga_pci.c index e6a4ab1dce..f825030e6b 100644 --- a/sys/dev/video/tga/tga_pci.c +++ b/sys/dev/video/tga/tga_pci.c @@ -27,7 +27,7 @@ * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi * * $FreeBSD: src/sys/dev/tga/tga_pci.c,v 1.1.2.1 2001/11/01 08:33:15 obrien Exp $ - * $DragonFly: src/sys/dev/video/tga/Attic/tga_pci.c,v 1.6 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/dev/video/tga/Attic/tga_pci.c,v 1.7 2004/05/19 22:52:54 dillon Exp $ */ #include @@ -192,7 +192,9 @@ tga_attach(device_t dev) break; } #ifdef FB_INSTALL_CDEV + cdevsw_add(&tga_cdevsw, -1, unit); sc->devt = make_dev(&tga_cdevsw, unit, 0, 0, 02660, "tga%x", unit); + reference_dev(sc->devt); /* XXX fb_attach done too early in pcigfb_attach? */ #endif /*FB_INSTALL_CDEV*/ goto done; diff --git a/sys/emulation/linux/linux_stats.c b/sys/emulation/linux/linux_stats.c index 633977a538..aa8d1db186 100644 --- a/sys/emulation/linux/linux_stats.c +++ b/sys/emulation/linux/linux_stats.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/compat/linux/linux_stats.c,v 1.22.2.3 2001/11/05 19:08:23 marcel Exp $ - * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.11 2003/11/13 04:04:42 daver Exp $ + * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.12 2004/05/19 22:52:55 dillon Exp $ */ #include @@ -76,7 +76,7 @@ newstat_copyout(struct stat *buf, void *ubuf) */ if (S_ISCHR(tbuf.st_mode) && (dev = udev2dev(buf->st_rdev, 0)) != NODEV) { - if (dev_dport(dev) != NULL && (dev_dflags(dev) & D_DISK)) { + if (dev_is_good(dev) && (dev_dflags(dev) & D_DISK)) { tbuf.st_mode &= ~S_IFMT; tbuf.st_mode |= S_IFBLK; @@ -311,19 +311,19 @@ linux_ustat(struct linux_ustat_args *args) * dev_t returned from previous syscalls. Just return a bzeroed * ustat in that case. */ - dev = makedev(args->dev >> 8, args->dev & 0xFF); - if (vfinddev(dev, VCHR, &vp)) { - if (vp->v_mount == NULL) + dev = udev2dev(makeudev(args->dev >> 8, args->dev & 0xFF), 0); + if (dev != NODEV && vfinddev(dev, VCHR, &vp)) { + if (vp->v_mount == NULL) { return (EINVAL); + } stat = &(vp->v_mount->mnt_stat); error = VFS_STATFS(vp->v_mount, stat, td); - if (error) + if (error) { return (error); - + } lu.f_tfree = stat->f_bfree; lu.f_tinode = stat->f_ffree; } - return (copyout(&lu, args->ubuf, sizeof(lu))); } diff --git a/sys/emulation/svr4/svr4_types.h b/sys/emulation/svr4/svr4_types.h index 4998c5d088..9f878f5e35 100644 --- a/sys/emulation/svr4/svr4_types.h +++ b/sys/emulation/svr4/svr4_types.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/svr4/svr4_types.h,v 1.3 1999/08/28 00:51:27 peter Exp $ - * $DragonFly: src/sys/emulation/svr4/Attic/svr4_types.h,v 1.2 2003/06/17 04:28:58 dillon Exp $ + * $DragonFly: src/sys/emulation/svr4/Attic/svr4_types.h,v 1.3 2004/05/19 22:52:55 dillon Exp $ */ #ifndef _SVR4_TYPES_H_ @@ -69,14 +69,14 @@ typedef struct timespec svr4_timestruc_t; #define svr4_omakedev(x,y) ((svr4_o_dev_t)((((x) << 8) & 0x7f00) | \ (((y) << 0) & 0x00ff))) -#define svr4_to_bsd_odev_t(d) makedev(svr4_omajor(d), svr4_ominor(d)) +#define svr4_to_bsd_odev_t(d) makeudev(svr4_omajor(d), svr4_ominor(d)) #define bsd_to_svr4_odev_t(d) svr4_omakedev(umajor(d), uminor(d)) #define svr4_major(x) ((int32_t)((((x) & 0xfffc0000) >> 18))) #define svr4_minor(x) ((int32_t)((((x) & 0x0003ffff) >> 0))) #define svr4_makedev(x,y) ((svr4_dev_t)((((x) << 18) & 0xfffc0000) | \ (((y) << 0) & 0x0003ffff))) -#define svr4_to_bsd_dev_t(d) makedev(svr4_major(d), svr4_minor(d)) +#define svr4_to_bsd_dev_t(d) makeudev(svr4_major(d), svr4_minor(d)) #define bsd_to_svr4_dev_t(d) svr4_makedev(umajor(d), uminor(d)) #endif /* !_SVR4_TYPES_H_ */ diff --git a/sys/i386/acpica/acpi_machdep.c b/sys/i386/acpica/acpi_machdep.c index 721956b232..51dcab4ecc 100644 --- a/sys/i386/acpica/acpi_machdep.c +++ b/sys/i386/acpica/acpi_machdep.c @@ -22,7 +22,7 @@ * 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. - * $DragonFly: src/sys/i386/acpica/Attic/acpi_machdep.c,v 1.2 2004/02/12 23:33:26 joerg Exp $ + * $DragonFly: src/sys/i386/acpica/Attic/acpi_machdep.c,v 1.3 2004/05/19 22:52:56 dillon Exp $ */ #include @@ -320,7 +320,7 @@ apmpoll(dev_t dev, int events, d_thread_t *td) static void acpi_capm_init(struct acpi_softc *sc) { - + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); } diff --git a/sys/i386/acpica5/acpi_machdep.c b/sys/i386/acpica5/acpi_machdep.c index 91390d194b..6b872f54f8 100644 --- a/sys/i386/acpica5/acpi_machdep.c +++ b/sys/i386/acpica5/acpi_machdep.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/acpica/acpi_machdep.c,v 1.15 2003/11/01 00:18:29 njl Exp $ - * $DragonFly: src/sys/i386/acpica5/Attic/acpi_machdep.c,v 1.2 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/acpica5/Attic/acpi_machdep.c,v 1.3 2004/05/19 22:52:56 dillon Exp $ */ #include @@ -303,6 +303,7 @@ apmpoll(dev_t dev, int events, d_thread_t *td) static void acpi_capm_init(struct acpi_softc *sc) { + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); } diff --git a/sys/i386/apm/apm.c b/sys/i386/apm/apm.c index de555e54c4..44e0203eda 100644 --- a/sys/i386/apm/apm.c +++ b/sys/i386/apm/apm.c @@ -16,7 +16,7 @@ * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * * $FreeBSD: src/sys/i386/apm/apm.c,v 1.114.2.5 2002/11/02 04:41:50 iwasaki Exp $ - * $DragonFly: src/sys/i386/apm/Attic/apm.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/apm/Attic/apm.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include @@ -1118,6 +1118,7 @@ apm_attach(device_t dev) sc->initialized = 1; + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0660, "apm"); make_dev(&apm_cdevsw, 8, 0, 5, 0660, "apmctl"); return 0; diff --git a/sys/i386/gnu/isa/dgb.c b/sys/i386/gnu/isa/dgb.c index e867af5d66..5fb65e19be 100644 --- a/sys/i386/gnu/isa/dgb.c +++ b/sys/i386/gnu/isa/dgb.c @@ -1,6 +1,6 @@ /*- * dgb.c $FreeBSD: src/sys/gnu/i386/isa/dgb.c,v 1.56.2.1 2001/02/26 04:23:09 jlemon Exp $ - * dgb.c $DragonFly: src/sys/i386/gnu/isa/Attic/dgb.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * dgb.c $DragonFly: src/sys/i386/gnu/isa/Attic/dgb.c,v 1.11 2004/05/19 22:52:57 dillon Exp $ * * Digiboard driver. * @@ -405,10 +405,7 @@ dgbprobe(dev) int i, v; u_long win_size; /* size of vizible memory window */ int unit=dev->id_unit; - static int once; - if (!once++) - cdevsw_add(&dgb_cdevsw); sc->unit=dev->id_unit; sc->port=dev->id_iobase; @@ -897,22 +894,23 @@ load_fep: port->it_out = port->it_in; /* MAX_DGB_PORTS is 32 => [0-9a-v] */ suffix = i < 10 ? '0' + i : 'a' + i - 10; - make_dev(&dgb_cdevsw, (unit*32)+i, + cdevsw_add(&dgb_cdevsw, 0xffff0000, unit << 16); + make_dev(&dgb_cdevsw, (unit<<16)+i, UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+32, + make_dev(&dgb_cdevsw, (unit<<16)+i+32, UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+64, + make_dev(&dgb_cdevsw, (unit<<16)+i+64, UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+128, + make_dev(&dgb_cdevsw, (unit<<16)+i+128, UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+160, + make_dev(&dgb_cdevsw, (unit<<16)+i+160, UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+192, + make_dev(&dgb_cdevsw, (unit<<16)+i+192, UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix); } diff --git a/sys/i386/i386/autoconf.c b/sys/i386/i386/autoconf.c index c90f667ddd..6669ad8aba 100644 --- a/sys/i386/i386/autoconf.c +++ b/sys/i386/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/i386/i386/Attic/autoconf.c,v 1.11 2004/01/06 03:17:24 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/autoconf.c,v 1.12 2004/05/19 22:52:57 dillon Exp $ */ /* @@ -306,8 +306,8 @@ setroot() return; } majdev = boot_translate_majdev(B_TYPE(bootdev)); - dev = makedev(majdev, 0); - if (dev_dport(dev) == NULL) + dev = udev2dev(makeudev(majdev, 0), 0); + if (!dev_is_good(dev)) return; unit = B_UNIT(bootdev); slice = B_SLICE(bootdev); @@ -330,8 +330,7 @@ setroot() part = B_PARTITION(bootdev); mindev = dkmakeminor(unit, slice, part); } - - newrootdev = makedev(majdev, mindev); + newrootdev = udev2dev(makeudev(majdev, mindev), 0); sname = dsname(newrootdev, unit, slice, part, partname); rootdevnames[0] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); sprintf(rootdevnames[0], "ufs:%s%s", sname, partname); diff --git a/sys/i386/i386/elan-mmcr.c b/sys/i386/i386/elan-mmcr.c index ec76df5a93..65cc4a1f0c 100644 --- a/sys/i386/i386/elan-mmcr.c +++ b/sys/i386/i386/elan-mmcr.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/i386/i386/elan-mmcr.c,v 1.6.2.1 2002/09/17 22:39:53 sam Exp $ - * $DragonFly: src/sys/i386/i386/Attic/elan-mmcr.c,v 1.6 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/elan-mmcr.c,v 1.7 2004/05/19 22:52:57 dillon Exp $ * The AMD Elan sc520 is a system-on-chip gadget which is used in embedded * kind of things, see www.soekris.com for instance, and it has a few quirks * we need to deal with. @@ -147,6 +147,7 @@ elan_drvinit(void) if (elan_mmcr == NULL) return; printf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr); + cdevsw_add(&elan_cdevsw, 0, 0); make_dev(&elan_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "elan-mmcr"); return; } diff --git a/sys/i386/i386/mem.c b/sys/i386/i386/mem.c index 6d0afb1367..866fd9b2ba 100644 --- a/sys/i386/i386/mem.c +++ b/sys/i386/i386/mem.c @@ -39,7 +39,7 @@ * from: Utah $Hdr: mem.c 1.13 89/10/08$ * from: @(#)mem.c 7.2 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/mem.c,v 1.79.2.9 2003/01/04 22:58:01 njl Exp $ - * $DragonFly: src/sys/i386/i386/Attic/mem.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/mem.c,v 1.11 2004/05/19 22:52:57 dillon Exp $ */ /* @@ -528,6 +528,7 @@ mem_drvinit(void *unused) if (mem_range_softc.mr_op != NULL) mem_range_softc.mr_op->init(&mem_range_softc); + cdevsw_add(&mem_cdevsw, 0xf0, 0); make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM, 0640, "mem"); make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM, 0640, "kmem"); make_dev(&mem_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "null"); diff --git a/sys/i386/i386/perfmon.c b/sys/i386/i386/perfmon.c index 4cc17eac4f..7611c58db9 100644 --- a/sys/i386/i386/perfmon.c +++ b/sys/i386/i386/perfmon.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/perfmon.c,v 1.21 1999/09/25 18:24:04 phk Exp $ - * $DragonFly: src/sys/i386/i386/Attic/perfmon.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/perfmon.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include @@ -110,6 +110,9 @@ perfmon_init(void) break; } #endif /* SMP */ + + /* NOTE: really a minor of mem. perfmon gets 32-47 */ + cdevsw_add(&perfmon_cdevsw, 0xf0, 32); make_dev(&perfmon_cdevsw, 32, UID_ROOT, GID_KMEM, 0640, "perfmon"); } diff --git a/sys/i386/isa/asc.c b/sys/i386/isa/asc.c index b6a0a3dc77..5265f0a315 100644 --- a/sys/i386/isa/asc.c +++ b/sys/i386/isa/asc.c @@ -35,7 +35,7 @@ */ /* * $FreeBSD: src/sys/i386/isa/asc.c,v 1.42.2.2 2001/03/01 03:22:39 jlemon Exp $ - * $DragonFly: src/sys/i386/isa/Attic/asc.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/i386/isa/Attic/asc.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include "use_asc.h" @@ -363,10 +363,6 @@ ascprobe (struct isa_device *isdp) int unit = isdp->id_unit; struct asc_unit *scu = unittab + unit; int stb; - static int once; - - if (!once++) - cdevsw_add(&asc_cdevsw); scu->base = isdp->id_iobase; /*** needed by the following macros ***/ scu->flags = FLAG_DEBUG; @@ -483,6 +479,7 @@ ascattach(struct isa_device *isdp) scu->selp.si_pid=(pid_t)0; #define ASC_UID 0 #define ASC_GID 13 + cdevsw_add(&asc_cdevsw, 0xc0, unit << 6); make_dev(&asc_cdevsw, unit<<6, ASC_UID, ASC_GID, 0666, "asc%d", unit); make_dev(&asc_cdevsw, ((unit<<6) + FRMT_PBM), ASC_UID, ASC_GID, 0666, "asc%dp", unit); diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 9791acc900..853e0c7a3a 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_conf.c,v 1.73.2.3 2003/03/10 02:18:25 imp Exp $ - * $DragonFly: src/sys/kern/kern_conf.c,v 1.7 2004/05/13 00:23:39 dillon Exp $ + * $DragonFly: src/sys/kern/kern_conf.c,v 1.8 2004/05/19 22:52:58 dillon Exp $ */ #include @@ -61,18 +61,19 @@ MALLOC_DEFINE(M_DEVT, "dev_t", "dev_t storage"); #define DEVT_STASH 50 static struct specinfo devt_stash[DEVT_STASH]; - static LIST_HEAD(, specinfo) dev_hash[DEVT_HASH]; - -static LIST_HEAD(, specinfo) dev_free; +static LIST_HEAD(, specinfo) dev_free_list; static int free_devt; SYSCTL_INT(_debug, OID_AUTO, free_devt, CTLFLAG_RW, &free_devt, 0, ""); +int dev_ref_debug = 0; +SYSCTL_INT(_debug, OID_AUTO, dev_refs, CTLFLAG_RW, &dev_ref_debug, 0, ""); /* - * dev_t and u_dev_t primitives + * dev_t and u_dev_t primitives. Note that the major number is always + * extracted from si_udev, not from si_devsw, because si_devsw is replaced + * when a device is destroyed. */ - int major(dev_t x) { @@ -100,59 +101,62 @@ lminor(dev_t x) return ((i & 0xff) | (i >> 8)); } +/* + * This is a bit complex because devices are always created relative to + * a particular cdevsw, including 'hidden' cdevsw's (such as the raw device + * backing a disk subsystem overlay), so we have to compare both the + * devsw and udev fields to locate the correct device. + * + * The device is created if it does not already exist. If SI_ADHOC is not + * set the device will be referenced (once) and SI_ADHOC will be set. + * The caller must explicitly add additional references to the device if + * the caller wishes to track additional references. + */ +static dev_t -makedev(int x, int y) +hashdev(struct cdevsw *devsw, int x, int y) { struct specinfo *si; udev_t udev; int hash; static int stashed; - if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) - Debugger("makedev of NOUDEV"); - udev = (x << 8) | y; + udev = makeudev(x, y); hash = udev % DEVT_HASH; LIST_FOREACH(si, &dev_hash[hash], si_hash) { - if (si->si_udev == udev) + if (si->si_devsw == devsw && si->si_udev == udev) return (si); } if (stashed >= DEVT_STASH) { MALLOC(si, struct specinfo *, sizeof(*si), M_DEVT, - M_WAITOK|M_USE_RESERVE); - bzero(si, sizeof(*si)); - } else if (LIST_FIRST(&dev_free)) { - si = LIST_FIRST(&dev_free); + M_WAITOK|M_USE_RESERVE|M_ZERO); + } else if (LIST_FIRST(&dev_free_list)) { + si = LIST_FIRST(&dev_free_list); LIST_REMOVE(si, si_hash); } else { si = devt_stash + stashed++; si->si_flags |= SI_STASHED; } + si->si_devsw = devsw; + si->si_flags |= SI_HASHED | SI_ADHOC; si->si_udev = udev; + si->si_refs = 1; LIST_INSERT_HEAD(&dev_hash[hash], si, si_hash); - return (si); -} - -void -freedev(dev_t dev) -{ - int hash; - - if (!free_devt) - return; - if (SLIST_FIRST(&dev->si_hlist)) - return; - if (dev->si_devsw || dev->si_drv1 || dev->si_drv2) - return; - hash = dev->si_udev % DEVT_HASH; - LIST_REMOVE(dev, si_hash); - if (dev->si_flags & SI_STASHED) { - bzero(dev, sizeof(*dev)); - LIST_INSERT_HEAD(&dev_free, dev, si_hash); - } else { - FREE(dev, M_DEVT); + si->si_port = devsw->d_port; + devsw->d_clone(si); + if (devsw != &dead_cdevsw) + ++devsw->d_refs; + if (dev_ref_debug) { + printf("create dev %p %s(minor=%08x) refs=%d\n", + si, devtoname(si), uminor(si->si_udev), + si->si_refs); } + return (si); } +/* + * Convert a device pointer to a device number + */ udev_t dev2udev(dev_t x) { @@ -161,24 +165,41 @@ dev2udev(dev_t x) return (x->si_udev); } +/* + * Convert a device number to a device pointer. The device is referenced + * ad-hoc, meaning that the caller should call reference_dev() if it wishes + * to keep ahold of the returned structure long term. + * + * The returned device is associated with the currently installed cdevsw + * for the requested major number. NODEV is returned if the major number + * has not been registered. + */ dev_t udev2dev(udev_t x, int b) { + dev_t dev; + struct cdevsw *devsw; - if (x == NOUDEV) - return (NODEV); - switch (b) { - case 0: - return makedev(umajor(x), uminor(x)); - case 1: - printf("udev2dev: attempt to lookup block dev(%d)", x); - return NODEV; - default: - Debugger("udev2dev(...,X)"); - return NODEV; - } + if (x == NOUDEV || b != 0) + return(NODEV); + devsw = cdevsw_get(umajor(x), uminor(x)); + if (devsw == NULL) + return(NODEV); + dev = hashdev(devsw, umajor(x), uminor(x)); + return(dev); } +int +dev_is_good(dev_t dev) +{ + if (dev != NODEV && dev->si_devsw != &dead_cdevsw) + return(1); + return(0); +} + +/* + * Various user device number extraction and conversion routines + */ int uminor(udev_t dev) { @@ -197,40 +218,236 @@ makeudev(int x, int y) return ((x << 8) | y); } +/* + * Create an internal or external device. + * + * Device majors can be overloaded and used directly by the kernel without + * conflict, but userland will only see the particular device major that + * has been installed with cdevsw_add(). + * + * This routine creates an ad-hoc entry for the device. The caller must + * call reference_dev() to track additional references beyond the ad-hoc + * entry. If an entry already exists, this function will set (or override) + * its cred requirements and name (XXX DEVFS interface). + */ dev_t -make_dev(struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...) +make_dev(struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, + int perms, const char *fmt, ...) { dev_t dev; __va_list ap; int i; + /* + * compile the cdevsw and install the device + */ compile_devsw(devsw); - dev = makedev(devsw->d_maj, minor); + dev = hashdev(devsw, devsw->d_maj, minor); + + /* + * Set additional fields (XXX DEVFS interface goes here) + */ __va_start(ap, fmt); i = kvprintf(fmt, NULL, dev->si_name, 32, ap); dev->si_name[i] = '\0'; __va_end(ap); - dev->si_devsw = devsw; return (dev); } /* - * Because the device might not be immediately removed, destroy_dev - * must clean out any potential module data references and install - * a device switch that returns an error for all future requests. + * This function is similar to make_dev() but no cred information or name + * need be specified. + */ +dev_t +make_adhoc_dev(struct cdevsw *devsw, int minor) +{ + dev_t dev; + + dev = hashdev(devsw, devsw->d_maj, minor); + return(dev); +} + +/* + * This function is similar to make_dev() except the new device is created + * using an old device as a template. + */ +dev_t +make_sub_dev(dev_t odev, int minor) +{ + dev_t dev; + + dev = hashdev(odev->si_devsw, umajor(odev->si_udev), minor); + + /* + * Copy cred requirements and name info XXX DEVFS. + */ + if (dev->si_name[0] == 0 && odev->si_name[0]) + bcopy(odev->si_name, dev->si_name, sizeof(dev->si_name)); + return (dev); +} + +/* + * destroy_dev() removes the adhoc association for a device and revectors + * its devsw to &dead_cdevsw. + * + * This routine releases the reference count associated with the ADHOC + * entry, plus releases the reference count held by the caller. What this + * means is that you should not call destroy_dev(make_dev(...)), because + * make_dev() does not bump the reference count (beyond what it needs to + * create the ad-hoc association). Any procedure that intends to destroy + * a device must have its own reference to it first. */ void destroy_dev(dev_t dev) { - static struct cdevsw dead_cdevsw; + int hash; + if (dev == NODEV) + return; + if ((dev->si_flags & SI_ADHOC) == 0) { + release_dev(dev); + return; + } + if (dev_ref_debug) { + printf("destroy dev %p %s(minor=%08x) refs=%d\n", + dev, devtoname(dev), uminor(dev->si_udev), + dev->si_refs); + } + if (dev->si_refs < 2) { + printf("destroy_dev(): too few references on device! " + "%p %s(minor=%08x) refs=%d\n", + dev, devtoname(dev), uminor(dev->si_udev), + dev->si_refs); + } + dev->si_flags &= ~SI_ADHOC; + if (dev->si_flags & SI_HASHED) { + hash = dev->si_udev % DEVT_HASH; + LIST_REMOVE(dev, si_hash); + dev->si_flags &= ~SI_HASHED; + } if (dead_cdevsw.d_port == NULL) compile_devsw(&dead_cdevsw); + if (dev->si_devsw && dev->si_devsw != &dead_cdevsw) + cdevsw_release(dev->si_devsw); dev->si_drv1 = 0; dev->si_drv2 = 0; dev->si_devsw = &dead_cdevsw; - freedev(dev); + dev->si_port = dev->si_devsw->d_port; + --dev->si_refs; /* release adhoc association reference */ + release_dev(dev); /* release callers reference */ +} + +/* + * Destroy all ad-hoc device associations associated with a domain within a + * device switch. + */ +void +destroy_all_dev(struct cdevsw *devsw, u_int mask, u_int match) +{ + int i; + dev_t dev; + dev_t ndev; + + for (i = 0; i < DEVT_HASH; ++i) { + ndev = LIST_FIRST(&dev_hash[i]); + while ((dev = ndev) != NULL) { + ndev = LIST_NEXT(dev, si_hash); + KKASSERT(dev->si_flags & SI_ADHOC); + if (dev->si_devsw == devsw && + (dev->si_udev & mask) == match + ) { + ++dev->si_refs; + destroy_dev(dev); + } + } + } +} + +/* + * Add a reference to a device. Callers generally add their own references + * when they are going to store a device node in a variable for long periods + * of time, to prevent a disassociation from free()ing the node. + * + * Also note that a caller that intends to call destroy_dev() must first + * obtain a reference on the device. The ad-hoc reference you get with + * make_dev() and friends is NOT sufficient to be able to call destroy_dev(). + */ +dev_t +reference_dev(dev_t dev) +{ + if (dev != NODEV) { + ++dev->si_refs; + if (dev_ref_debug) { + printf("reference dev %p %s(minor=%08x) refs=%d\n", + dev, devtoname(dev), uminor(dev->si_udev), + dev->si_refs); + } + } + return(dev); +} + +/* + * release a reference on a device. The device will be freed when the last + * reference has been released. + * + * NOTE: we must use si_udev to figure out the original (major, minor), + * because si_devsw could already be pointing at dead_cdevsw. + */ +void +release_dev(dev_t dev) +{ + if (dev == NODEV) + return; + if (free_devt) { + KKASSERT(dev->si_refs > 0); + } else { + if (dev->si_refs <= 0) { + printf("Warning: extra release of dev %p(%s)\n", + dev, devtoname(dev)); + free_devt = 0; /* prevent bad things from occuring */ + } + } + --dev->si_refs; + if (dev_ref_debug) { + printf("release dev %p %s(minor=%08x) refs=%d\n", + dev, devtoname(dev), uminor(dev->si_udev), + dev->si_refs); + } + if (dev->si_refs == 0) { + if (dev->si_flags & SI_ADHOC) { + printf("Warning: illegal final release on ADHOC" + " device %p(%s), the device was never" + " destroyed!\n", + dev, devtoname(dev)); + } + if (dev->si_flags & SI_HASHED) { + printf("Warning: last release on device, no call" + " to destroy_dev() was made! dev %p(%s)\n", + dev, devtoname(dev)); + dev->si_refs = 3; + destroy_dev(dev); + dev->si_refs = 0; + } + if (SLIST_FIRST(&dev->si_hlist) != NULL) { + printf("Warning: last release on device, vnode" + " associations still exist! dev %p(%s)\n", + dev, devtoname(dev)); + free_devt = 0; /* prevent bad things from occuring */ + } + if (dev->si_devsw && dev->si_devsw != &dead_cdevsw) { + cdevsw_release(dev->si_devsw); + dev->si_devsw = NULL; + } + if (free_devt) { + if (dev->si_flags & SI_STASHED) { + bzero(dev, sizeof(*dev)); + LIST_INSERT_HEAD(&dev_free_list, dev, si_hash); + } else { + FREE(dev, M_DEVT); + } + } + } } const char * @@ -241,6 +458,8 @@ devtoname(dev_t dev) char *p; const char *dname; + if (dev == NODEV) + return("#nodev"); if (dev->si_name[0] == '#' || dev->si_name[0] == '\0') { p = dev->si_name; len = sizeof(dev->si_name); @@ -258,3 +477,4 @@ devtoname(dev_t dev) } return (dev->si_name); } + diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 8e6d01348f..1c09cb396b 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -37,7 +37,7 @@ * * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 * $FreeBSD: src/sys/kern/kern_descrip.c,v 1.81.2.19 2004/02/28 00:43:31 tegge Exp $ - * $DragonFly: src/sys/kern/kern_descrip.c,v 1.23 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/kern_descrip.c,v 1.24 2004/05/19 22:52:58 dillon Exp $ */ #include "opt_compat.h" @@ -1717,9 +1717,11 @@ fildesc_drvinit(void *unused) { int fd; - for (fd = 0; fd < NUMFDESC; fd++) + cdevsw_add(&fildesc_cdevsw, 0, 0); + for (fd = 0; fd < NUMFDESC; fd++) { make_dev(&fildesc_cdevsw, fd, UID_BIN, GID_BIN, 0666, "fd/%d", fd); + } make_dev(&fildesc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666, "stdin"); make_dev(&fildesc_cdevsw, 1, UID_ROOT, GID_WHEEL, 0666, "stdout"); make_dev(&fildesc_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "stderr"); diff --git a/sys/kern/kern_device.c b/sys/kern/kern_device.c index cf2f4082c0..0682b2fe66 100644 --- a/sys/kern/kern_device.c +++ b/sys/kern/kern_device.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_device.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/kern_device.c,v 1.11 2004/05/19 22:52:58 dillon Exp $ */ #include #include @@ -43,11 +43,12 @@ #include #include -static struct cdevsw *cdevsw[NUMCDEVSW]; -static struct lwkt_port *cdevport[NUMCDEVSW]; +static struct cdevlink *cdevbase[NUMCDEVSW]; static int cdevsw_putport(lwkt_port_t port, lwkt_msg_t msg); +struct cdevsw dead_cdevsw; + /* * Initialize a message port to serve as the default message-handling port * for device operations. This message port provides compatibility with @@ -69,7 +70,7 @@ int cdevsw_putport(lwkt_port_t port, lwkt_msg_t lmsg) { cdevallmsg_t msg = (cdevallmsg_t)lmsg; - struct cdevsw *csw = msg->am_msg.csw; + struct cdevsw *devsw = msg->am_msg.dev->si_devsw; int error; /* @@ -78,25 +79,25 @@ cdevsw_putport(lwkt_port_t port, lwkt_msg_t lmsg) */ switch(msg->am_lmsg.ms_cmd.cm_op) { case CDEV_CMD_OPEN: - error = csw->old_open( + error = devsw->old_open( msg->am_open.msg.dev, msg->am_open.oflags, msg->am_open.devtype, msg->am_open.td); break; case CDEV_CMD_CLOSE: - error = csw->old_close( + error = devsw->old_close( msg->am_close.msg.dev, msg->am_close.fflag, msg->am_close.devtype, msg->am_close.td); break; case CDEV_CMD_STRATEGY: - csw->old_strategy(msg->am_strategy.bp); + devsw->old_strategy(msg->am_strategy.bp); error = 0; break; case CDEV_CMD_IOCTL: - error = csw->old_ioctl( + error = devsw->old_ioctl( msg->am_ioctl.msg.dev, msg->am_ioctl.cmd, msg->am_ioctl.data, @@ -104,39 +105,43 @@ cdevsw_putport(lwkt_port_t port, lwkt_msg_t lmsg) msg->am_ioctl.td); break; case CDEV_CMD_DUMP: - error = csw->old_dump(msg->am_ioctl.msg.dev); + error = devsw->old_dump( + msg->am_dump.msg.dev, + msg->am_dump.count, + msg->am_dump.blkno, + msg->am_dump.secsize); break; case CDEV_CMD_PSIZE: - msg->am_psize.result = csw->old_psize(msg->am_psize.msg.dev); + msg->am_psize.result = devsw->old_psize(msg->am_psize.msg.dev); error = 0; /* XXX */ break; case CDEV_CMD_READ: - error = csw->old_read( + error = devsw->old_read( msg->am_read.msg.dev, msg->am_read.uio, msg->am_read.ioflag); break; case CDEV_CMD_WRITE: - error = csw->old_write( + error = devsw->old_write( msg->am_read.msg.dev, msg->am_read.uio, msg->am_read.ioflag); break; case CDEV_CMD_POLL: - msg->am_poll.events = csw->old_poll( + msg->am_poll.events = devsw->old_poll( msg->am_poll.msg.dev, msg->am_poll.events, msg->am_poll.td); error = 0; break; case CDEV_CMD_KQFILTER: - msg->am_kqfilter.result = csw->old_kqfilter( + msg->am_kqfilter.result = devsw->old_kqfilter( msg->am_kqfilter.msg.dev, msg->am_kqfilter.kn); error = 0; break; case CDEV_CMD_MMAP: - msg->am_mmap.result = csw->old_mmap( + msg->am_mmap.result = devsw->old_mmap( msg->am_mmap.msg.dev, msg->am_mmap.offset, msg->am_mmap.nprot); @@ -150,40 +155,13 @@ cdevsw_putport(lwkt_port_t port, lwkt_msg_t lmsg) return(error); } -/* - * These device dispatch functions provide convenient entry points for - * any code wishing to make a dev call. - * - * YYY we ought to be able to optimize the port lookup by caching it in - * the dev_t structure itself. - */ -static __inline -struct cdevsw * -_devsw(dev_t dev) -{ - if (dev == NULL) - return(NULL); - if (dev->si_devsw) - return (dev->si_devsw); - return(cdevsw[major(dev)]); -} - static __inline lwkt_port_t _init_cdevmsg(dev_t dev, cdevmsg_t msg, int cmd) { - struct cdevsw *csw; - lwkt_initmsg_simple(&msg->msg, cmd); msg->dev = dev; - msg->csw = csw = _devsw(dev); - if (csw != NULL) { /* YYY too hackish */ - KKASSERT(csw->d_port); /* YYY too hackish */ - if (cdevport[major(dev)]) /* YYY too hackish */ - return(cdevport[major(dev)]); - return(csw->d_port); - } - return(NULL); + return(dev->si_port); } int @@ -244,6 +222,10 @@ dev_dioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td) return(lwkt_domsg(port, &msg.msg.msg)); } +/* + * note: the disk layer is expected to set count, blkno, and secsize before + * forwarding the message. + */ int dev_ddump(dev_t dev) { @@ -253,6 +235,9 @@ dev_ddump(dev_t dev) port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_DUMP); if (port == NULL) return(ENXIO); + msg.count = 0; + msg.blkno = 0; + msg.secsize = 0; return(lwkt_domsg(port, &msg.msg.msg)); } @@ -353,216 +338,30 @@ dev_dmmap(dev_t dev, vm_offset_t offset, int nprot) return(-1); } -int -dev_port_dopen(lwkt_port_t port, dev_t dev, int oflags, int devtype, thread_t td) -{ - struct cdevmsg_open msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_OPEN); - if (port == NULL) - return(ENXIO); - msg.oflags = oflags; - msg.devtype = devtype; - msg.td = td; - return(lwkt_domsg(port, &msg.msg.msg)); -} - -int -dev_port_dclose(lwkt_port_t port, dev_t dev, int fflag, int devtype, thread_t td) -{ - struct cdevmsg_close msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_CLOSE); - if (port == NULL) - return(ENXIO); - msg.fflag = fflag; - msg.devtype = devtype; - msg.td = td; - return(lwkt_domsg(port, &msg.msg.msg)); -} - -void -dev_port_dstrategy(lwkt_port_t port, dev_t dev, struct buf *bp) -{ - struct cdevmsg_strategy msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_STRATEGY); - KKASSERT(port); /* 'nostrategy' function is NULL YYY */ - msg.bp = bp; - lwkt_domsg(port, &msg.msg.msg); -} - -int -dev_port_dioctl(lwkt_port_t port, dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td) -{ - struct cdevmsg_ioctl msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_IOCTL); - if (port == NULL) - return(ENXIO); - msg.cmd = cmd; - msg.data = data; - msg.fflag = fflag; - msg.td = td; - return(lwkt_domsg(port, &msg.msg.msg)); -} - -int -dev_port_ddump(lwkt_port_t port, dev_t dev) -{ - struct cdevmsg_dump msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_DUMP); - if (port == NULL) - return(ENXIO); - return(lwkt_domsg(port, &msg.msg.msg)); -} - -int -dev_port_dpsize(lwkt_port_t port, dev_t dev) -{ - struct cdevmsg_psize msg; - int error; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_PSIZE); - if (port == NULL) - return(-1); - error = lwkt_domsg(port, &msg.msg.msg); - if (error == 0) - return(msg.result); - return(-1); -} - -int -dev_port_dread(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag) -{ - struct cdevmsg_read msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_READ); - if (port == NULL) - return(ENXIO); - msg.uio = uio; - msg.ioflag = ioflag; - return(lwkt_domsg(port, &msg.msg.msg)); -} - -int -dev_port_dwrite(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag) -{ - struct cdevmsg_write msg; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_WRITE); - if (port == NULL) - return(ENXIO); - msg.uio = uio; - msg.ioflag = ioflag; - return(lwkt_domsg(port, &msg.msg.msg)); -} - -int -dev_port_dpoll(lwkt_port_t port, dev_t dev, int events, thread_t td) -{ - struct cdevmsg_poll msg; - int error; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_POLL); - if (port == NULL) - return(ENXIO); - msg.events = events; - msg.td = td; - error = lwkt_domsg(port, &msg.msg.msg); - if (error == 0) - return(msg.events); - return(seltrue(dev, msg.events, td)); -} - -int -dev_port_dkqfilter(lwkt_port_t port, dev_t dev, struct knote *kn) -{ - struct cdevmsg_kqfilter msg; - int error; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_KQFILTER); - if (port == NULL) - return(ENXIO); - msg.kn = kn; - error = lwkt_domsg(port, &msg.msg.msg); - if (error == 0) - return(msg.result); - return(ENODEV); -} - -int -dev_port_dmmap(lwkt_port_t port, dev_t dev, vm_offset_t offset, int nprot) -{ - struct cdevmsg_mmap msg; - int error; - - _init_cdevmsg(dev, &msg.msg, CDEV_CMD_MMAP); - if (port == NULL) - return(-1); - msg.offset = offset; - msg.nprot = nprot; - error = lwkt_domsg(port, &msg.msg.msg); - if (error == 0) - return(msg.result); - return(-1); -} - const char * dev_dname(dev_t dev) { - struct cdevsw *csw; - - if ((csw = _devsw(dev)) != NULL) - return(csw->d_name); - return(NULL); + return(dev->si_devsw->d_name); } int dev_dflags(dev_t dev) { - struct cdevsw *csw; - - if ((csw = _devsw(dev)) != NULL) - return(csw->d_flags); - return(0); + return(dev->si_devsw->d_flags); } int dev_dmaj(dev_t dev) { - struct cdevsw *csw; - - if ((csw = _devsw(dev)) != NULL) - return(csw->d_maj); - return(0); + return(dev->si_devsw->d_maj); } lwkt_port_t dev_dport(dev_t dev) { - struct cdevsw *csw; - - if ((csw = _devsw(dev)) != NULL) { - if (cdevport[major(dev)]) /* YYY too hackish */ - return(cdevport[major(dev)]); - return(csw->d_port); - } - return(NULL); + return(dev->si_port); } -#if 0 -/* - * cdevsw[] array functions, moved from kern/kern_conf.c - */ -struct cdevsw * -devsw(dev_t dev) -{ - return(_devsw(dev)); -} -#endif - /* * Convert a cdevsw template into the real thing, filling in fields the * device left empty with appropriate defaults. @@ -600,67 +399,179 @@ compile_devsw(struct cdevsw *devsw) if (devsw->d_port == NULL) devsw->d_port = &devsw_compat_port; + if (devsw->d_clone == NULL) + devsw->d_clone = noclone; } /* - * Add a cdevsw entry + * This makes a cdevsw entry visible to userland (e.g /dev/). + * + * The kernel can overload a major number with multiple cdevsw's but only + * the one installed in cdevbase[] is visible to userland. make_dev() does + * not automatically call cdevsw_add() (nor do we want it to, since + * partition-managed disk devices are overloaded on top of the raw device). */ int -cdevsw_add(struct cdevsw *newentry) +cdevsw_add(struct cdevsw *devsw, u_int mask, u_int match) { - compile_devsw(newentry); - if (newentry->d_maj < 0 || newentry->d_maj >= NUMCDEVSW) { + int maj; + struct cdevlink *link; + + compile_devsw(devsw); + maj = devsw->d_maj; + if (maj < 0 || maj >= NUMCDEVSW) { printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", - newentry->d_name, newentry->d_maj); + devsw->d_name, maj); return (EINVAL); } - if (cdevsw[newentry->d_maj]) { - printf("WARNING: \"%s\" is usurping \"%s\"'s cdevsw[]\n", - newentry->d_name, cdevsw[newentry->d_maj]->d_name); + for (link = cdevbase[maj]; link; link = link->next) { + /* + * If we get an exact match we usurp the target, but we only print + * a warning message if a different device switch is installed. + */ + if (link->mask == mask && link->match == match) { + if (link->devsw != devsw) { + printf("WARNING: \"%s\" (%p) is usurping \"%s\"'s (%p)" + " cdevsw[]\n", + devsw->d_name, devsw, + link->devsw->d_name, link->devsw); + link->devsw = devsw; + ++devsw->d_refs; + } + return(0); + } + /* + * XXX add additional warnings for overlaps + */ } - cdevsw[newentry->d_maj] = newentry; - return (0); + + link = malloc(sizeof(struct cdevlink), M_DEVBUF, M_INTWAIT|M_ZERO); + link->mask = mask; + link->match = match; + link->devsw = devsw; + link->next = cdevbase[maj]; + cdevbase[maj] = link; + ++devsw->d_refs; + return(0); } /* - * Add a cdevsw entry and override the port. + * Should only be used by udev2dev(). + * + * If the minor number is -1, we match the first cdevsw we find for this + * major. + * + * Note that this function will return NULL if the minor number is not within + * the bounds of the installed mask(s). */ -lwkt_port_t -cdevsw_add_override(struct cdevsw *newentry, lwkt_port_t port) +struct cdevsw * +cdevsw_get(int x, int y) { - int error; + struct cdevlink *link; - if ((error = cdevsw_add(newentry)) == 0) - cdevport[newentry->d_maj] = port; - return(newentry->d_port); + if (x < 0 || x >= NUMCDEVSW) + return(NULL); + for (link = cdevbase[x]; link; link = link->next) { + if (y == -1 || (link->mask & y) == link->match) + return(link->devsw); + } + return(NULL); +} + +/* + * Use the passed cdevsw as a template to create our intercept cdevsw, + * and install and return ours. + */ +struct cdevsw * +cdevsw_add_override(dev_t backing_dev, u_int mask, u_int match) +{ + struct cdevsw *devsw; + struct cdevsw *bsw = backing_dev->si_devsw; + + devsw = malloc(sizeof(struct cdevsw), M_DEVBUF, M_INTWAIT|M_ZERO); + devsw->d_name = bsw->d_name; + devsw->d_maj = bsw->d_maj; + devsw->d_flags = bsw->d_flags; + compile_devsw(devsw); + cdevsw_add(devsw, mask, match); + + return(devsw); } +/* + * Override a device's port, returning the previously installed port. This + * is XXX very dangerous. + */ lwkt_port_t cdevsw_dev_override(dev_t dev, lwkt_port_t port) { - struct cdevsw *csw; + lwkt_port_t oport; - KKASSERT(major(dev) >= 0 && major(dev) < NUMCDEVSW); - if ((csw = _devsw(dev)) != NULL) { - cdevport[major(dev)] = port; - return(csw->d_port); - } - return(NULL); + oport = dev->si_port; + dev->si_port = port; + return(oport); } /* - * Remove a cdevsw entry + * Remove a cdevsw entry from the cdevbase[] major array so no new user opens + * can be performed, and destroy all devices installed in the hash table + * which are associated with this cdevsw. (see destroy_all_dev()). */ int -cdevsw_remove(struct cdevsw *oldentry) +cdevsw_remove(struct cdevsw *devsw, u_int mask, u_int match) { - if (oldentry->d_maj < 0 || oldentry->d_maj >= NUMCDEVSW) { + int maj = devsw->d_maj; + struct cdevlink *link; + struct cdevlink **plink; + + if (maj < 0 || maj >= NUMCDEVSW) { printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", - oldentry->d_name, oldentry->d_maj); + devsw->d_name, maj); return EINVAL; } - cdevsw[oldentry->d_maj] = NULL; - cdevport[oldentry->d_maj] = NULL; + if (devsw != &dead_cdevsw) + destroy_all_dev(devsw, mask, match); + for (plink = &cdevbase[maj]; (link = *plink) != NULL; plink = &link->next) { + if (link->mask == mask && link->match == match) { + if (link->devsw == devsw) + break; + printf("%s: ERROR: cannot remove from cdevsw[], its major" + " number %d was stolen by %s\n", + devsw->d_name, maj, + link->devsw->d_name + ); + } + } + if (link == NULL) { + printf("%s(%d): WARNING: cdevsw removed multiple times!\n", + devsw->d_name, maj); + } else { + *plink = link->next; + --devsw->d_refs; /* XXX cdevsw_release() / record refs */ + free(link, M_DEVBUF); + } + if (devsw->d_refs != 0) { + printf("%s: Warning: cdevsw_remove() called while %d device refs" + " still exist! (major %d)\n", + devsw->d_name, + devsw->d_refs, + maj); + } else { + printf("%s: cdevsw removed\n", devsw->d_name); + } return 0; } +/* + * Release a cdevsw entry. When the ref count reaches zero, recurse + * through the stack. + */ +void +cdevsw_release(struct cdevsw *devsw) +{ + --devsw->d_refs; + if (devsw->d_refs == 0) { + /* XXX */ + } +} + diff --git a/sys/kern/kern_memio.c b/sys/kern/kern_memio.c index ee6c697d0e..5e1423a8dd 100644 --- a/sys/kern/kern_memio.c +++ b/sys/kern/kern_memio.c @@ -39,7 +39,7 @@ * from: Utah $Hdr: mem.c 1.13 89/10/08$ * from: @(#)mem.c 7.2 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/mem.c,v 1.79.2.9 2003/01/04 22:58:01 njl Exp $ - * $DragonFly: src/sys/kern/kern_memio.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/kern_memio.c,v 1.11 2004/05/19 22:52:57 dillon Exp $ */ /* @@ -528,6 +528,7 @@ mem_drvinit(void *unused) if (mem_range_softc.mr_op != NULL) mem_range_softc.mr_op->init(&mem_range_softc); + cdevsw_add(&mem_cdevsw, 0xf0, 0); make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM, 0640, "mem"); make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM, 0640, "kmem"); make_dev(&mem_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "null"); diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index cfff488b58..49f56f5213 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -6,6 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * + * Copyright (c) 2004 Matthew Dillon. * Copyright (c) 1982, 1986, 1988, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. @@ -45,7 +46,7 @@ * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/subr_disk.c,v 1.20.2.6 2001/10/05 07:14:57 peter Exp $ * $FreeBSD: src/sys/ufs/ufs/ufs_disksubr.c,v 1.44.2.3 2001/03/05 05:42:19 obrien Exp $ - * $DragonFly: src/sys/kern/subr_disk.c,v 1.9 2004/04/20 01:52:22 dillon Exp $ + * $DragonFly: src/sys/kern/subr_disk.c,v 1.10 2004/05/19 22:52:58 dillon Exp $ */ #include @@ -75,67 +76,82 @@ static d_open_t diskopen; static d_close_t diskclose; static d_ioctl_t diskioctl; static d_psize_t diskpsize; +static d_clone_t diskclone; static int disk_putport(lwkt_port_t port, lwkt_msg_t msg); static LIST_HEAD(, disk) disklist = LIST_HEAD_INITIALIZER(&disklist); -static void -inherit_raw(dev_t pdev, dev_t dev) -{ - dev->si_disk = pdev->si_disk; - dev->si_drv1 = pdev->si_drv1; - dev->si_drv2 = pdev->si_drv2; - dev->si_iosize_max = pdev->si_iosize_max; - dev->si_bsize_phys = pdev->si_bsize_phys; - dev->si_bsize_best = pdev->si_bsize_best; -} - /* - * Create a slice and unit managed disk. The underlying raw disk device - * is specified by cdevsw. We create the device as a managed device by - * first creating it normally then overriding the message port with our - * own frontend (which will be responsible for assigning pblkno). + * Create a slice and unit managed disk. + * + * Our port layer will be responsible for assigning pblkno and handling + * high level partition operations, then forwarding the requests to the + * raw device. + * + * The raw device (based on rawsw) is returned to the caller, NOT the + * slice and unit managed cdev. The caller typically sets various + * driver parameters and IO limits on the returned rawdev which we must + * inherit when our managed device is opened. */ dev_t -disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw) +disk_create(int unit, struct disk *dp, int flags, struct cdevsw *rawsw) { - dev_t dev; + dev_t rawdev; + struct cdevsw *devsw; + + /* + * Create the raw backing device + */ + compile_devsw(rawsw); + rawdev = make_dev(rawsw, + dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART), + UID_ROOT, GID_OPERATOR, 0640, + "%s%d", rawsw->d_name, unit); + /* + * Initialize our intercept port + */ bzero(dp, sizeof(*dp)); - lwkt_initport(&dp->d_port, NULL); /* intercept port */ + lwkt_initport(&dp->d_port, NULL); dp->d_port.mp_putport = disk_putport; + dp->d_rawsw = rawsw; - dev = makedev(cdevsw->d_maj, 0); /* base device */ - dev->si_disk = dp; - /* forwarding port */ - dp->d_fwdport = cdevsw_add_override(cdevsw, &dp->d_port); - - if (bootverbose) - printf("Creating DISK %s%d\n", cdevsw->d_name, unit); - - /* - * The whole disk placemarker holds the disk structure. + /* + * We install a custom cdevsw rather then the passed cdevsw, + * and save our disk structure in d_data so we can get at it easily + * without any complex cloning code. */ - dev = make_dev(cdevsw, dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "%s%d", cdevsw->d_name, unit); - dev->si_disk = dp; - dp->d_dev = dev; + devsw = cdevsw_add_override(rawdev, dkunitmask(), dkmakeunit(unit)); + devsw->d_port = &dp->d_port; + devsw->d_data = dp; + devsw->d_clone = diskclone; + dp->d_devsw = devsw; + dp->d_rawdev = rawdev; + dp->d_cdev = make_dev(devsw, + dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART), + UID_ROOT, GID_OPERATOR, 0640, + "%s%d", devsw->d_name, unit); + dp->d_dsflags = flags; LIST_INSERT_HEAD(&disklist, dp, d_list); - return (dev); + return (dp->d_rawdev); } +/* + * This routine is called when an adapter detaches. The higher level + * managed disk device is destroyed while the lower level raw device is + * released. + */ void disk_destroy(struct disk *disk) { - dev_t dev = disk->d_dev; - - LIST_REMOVE(disk, d_list); + if (disk->d_devsw) { + cdevsw_remove(disk->d_devsw, dkunitmask(), dkunit(disk->d_cdev)); + LIST_REMOVE(disk, d_list); + } + if (disk->d_rawsw) + destroy_all_dev(disk->d_rawsw, dkunitmask(), dkunit(disk->d_rawdev)); bzero(disk, sizeof(*disk)); - dev->si_disk = NULL; - destroy_dev(dev); - /* YYY remove cdevsw entries? */ - return; } int @@ -198,7 +214,7 @@ sysctl_disks(SYSCTL_HANDLER_ARGS) } else { first = 0; } - error = SYSCTL_OUT(req, disk->d_dev->si_name, strlen(disk->d_dev->si_name)); + error = SYSCTL_OUT(req, disk->d_rawdev->si_name, strlen(disk->d_rawdev->si_name)); if (error) return error; } @@ -251,27 +267,84 @@ disk_putport(lwkt_port_t port, lwkt_msg_t lmsg) msg->am_psize.result = diskpsize(msg->am_psize.msg.dev); error = 0; /* XXX */ break; + case CDEV_CMD_READ: + error = physio(msg->am_read.msg.dev, + msg->am_read.uio, msg->am_read.ioflag); + break; + case CDEV_CMD_WRITE: + error = physio(msg->am_write.msg.dev, + msg->am_write.uio, msg->am_write.ioflag); + break; + case CDEV_CMD_POLL: + case CDEV_CMD_KQFILTER: + error = ENODEV; + case CDEV_CMD_MMAP: + error = -1; + break; + case CDEV_CMD_DUMP: + error = disk_dumpcheck(msg->am_dump.msg.dev, + &msg->am_dump.count, + &msg->am_dump.blkno, + &msg->am_dump.secsize); + if (error == 0) { + msg->am_dump.msg.dev = disk->d_rawdev; + error = lwkt_forwardmsg(disk->d_rawdev->si_port, + &msg->am_dump.msg.msg); + printf("error2 %d\n", error); + } + break; default: - error = lwkt_forwardmsg(disk->d_fwdport, &msg->am_lmsg); + error = ENOTSUP; break; } return(error); } +/* + * When new device entries are instantiated, make sure they inherit our + * si_disk structure and block and iosize limits from the raw device. + * + * This routine is always called synchronously in the context of the + * client. + * + * XXX The various io and block size constraints are not always initialized + * properly by devices. + */ +static +int +diskclone(dev_t dev) +{ + struct disk *dp; + + dp = dev->si_devsw->d_data; + KKASSERT(dp != NULL); + dev->si_disk = dp; + dev->si_iosize_max = dp->d_rawdev->si_iosize_max; + dev->si_bsize_phys = dp->d_rawdev->si_bsize_phys; + dev->si_bsize_best = dp->d_rawdev->si_bsize_best; + return(0); +} + +/* + * Open a disk device or partition. + */ static int diskopen(dev_t dev, int oflags, int devtype, struct thread *td) { - dev_t pdev; struct disk *dp; int error; + /* + * dp can't be NULL here XXX. + */ error = 0; - pdev = dkmodpart(dkmodslice(dev, WHOLE_DISK_SLICE), RAW_PART); - - dp = pdev->si_disk; + dp = dev->si_disk; if (dp == NULL) return (ENXIO); + /* + * Deal with open races + */ while (dp->d_flags & DISKFLAG_LOCK) { dp->d_flags |= DISKFLAG_WANTED; error = tsleep(dp, PCATCH, "diskopen", hz); @@ -280,14 +353,22 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td) } dp->d_flags |= DISKFLAG_LOCK; + /* + * Open the underlying raw device. + */ if (!dsisopen(dp->d_slice)) { +#if 0 if (!pdev->si_iosize_max) pdev->si_iosize_max = dev->si_iosize_max; - error = dev_port_dopen(dp->d_fwdport, pdev, oflags, devtype, td); +#endif + error = dev_dopen(dp->d_rawdev, oflags, devtype, td); } - /* Inherit properties from the whole/raw dev_t */ - inherit_raw(pdev, dev); + /* + * Inherit properties from the underlying device now that it is + * open. + */ + diskclone(dev); if (error) goto out; @@ -295,7 +376,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td) error = dsopen(dev, devtype, dp->d_dsflags, &dp->d_slice, &dp->d_label); if (!dsisopen(dp->d_slice)) - dev_port_dclose(dp->d_fwdport, pdev, oflags, devtype, td); + dev_dclose(dp->d_rawdev, oflags, devtype, td); out: dp->d_flags &= ~DISKFLAG_LOCK; if (dp->d_flags & DISKFLAG_WANTED) { @@ -306,86 +387,89 @@ out: return(error); } +/* + * Close a disk device or partition + */ static int diskclose(dev_t dev, int fflag, int devtype, struct thread *td) { struct disk *dp; int error; - dev_t pdev; error = 0; - pdev = dkmodpart(dkmodslice(dev, WHOLE_DISK_SLICE), RAW_PART); - dp = pdev->si_disk; - if (!dp) - return (ENXIO); + dp = dev->si_disk; + dsclose(dev, devtype, dp->d_slice); if (!dsisopen(dp->d_slice)) - error = dev_port_dclose(dp->d_fwdport, pdev, fflag, devtype, td); + error = dev_dclose(dp->d_rawdev, fflag, devtype, td); return (error); } +/* + * Execute strategy routine + */ static void diskstrategy(struct buf *bp) { - dev_t pdev; struct disk *dp; - pdev = dkmodpart(dkmodslice(bp->b_dev, WHOLE_DISK_SLICE), RAW_PART); - dp = pdev->si_disk; - if (dp != bp->b_dev->si_disk) - inherit_raw(pdev, bp->b_dev); + dp = bp->b_dev->si_disk; - if (!dp) { + if (dp == NULL) { bp->b_error = ENXIO; bp->b_flags |= B_ERROR; biodone(bp); return; } + KKASSERT(bp->b_dev->si_disk == dp); if (dscheck(bp, dp->d_slice) <= 0) { biodone(bp); return; } - dev_port_dstrategy(dp->d_fwdport, dp->d_dev, bp); + bp->b_dev = dp->d_rawdev; + dev_dstrategy(dp->d_rawdev, bp); } /* - * note: when forwarding the ioctl we use the original device rather then - * the whole disk slice. + * First execute the ioctl on the disk device, and if it isn't supported + * try running it on the backing device. */ static int diskioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { struct disk *dp; int error; - dev_t pdev; - pdev = dkmodpart(dkmodslice(dev, WHOLE_DISK_SLICE), RAW_PART); - dp = pdev->si_disk; - if (!dp) + dp = dev->si_disk; + if (dp == NULL) return (ENXIO); + error = dsioctl(dev, cmd, data, fflag, &dp->d_slice); if (error == ENOIOCTL) - error = dev_port_dioctl(dp->d_fwdport, dev, cmd, data, fflag, td); + error = dev_dioctl(dp->d_rawdev, cmd, data, fflag, td); return (error); } +/* + * + */ static int diskpsize(dev_t dev) { struct disk *dp; - dev_t pdev; - pdev = dkmodpart(dkmodslice(dev, WHOLE_DISK_SLICE), RAW_PART); - dp = pdev->si_disk; - if (!dp) + dp = dev->si_disk; + if (dp == NULL) return (-1); + return(dssize(dev, &dp->d_slice)); +#if 0 if (dp != dev->si_disk) { dev->si_drv1 = pdev->si_drv1; dev->si_drv2 = pdev->si_drv2; /* XXX: don't set bp->b_dev->si_disk (?) */ } - return (dssize(dev, &dp->d_slice)); +#endif } SYSCTL_DECL(_debug_sizeof); @@ -520,9 +604,7 @@ bufqdisksort(bufq, bp) * Returns NULL on success and an error string on failure. */ char * -readdisklabel(dev, lp) - dev_t dev; - struct disklabel *lp; +readdisklabel(dev_t dev, struct disklabel *lp) { struct buf *bp; struct disklabel *dlp; @@ -613,9 +695,7 @@ setdisklabel(olp, nlp, openmask) * Write disk label back to device after modification. */ int -writedisklabel(dev, lp) - dev_t dev; - struct disklabel *lp; +writedisklabel(dev_t dev, struct disklabel *lp) { struct buf *bp; struct disklabel *dlp; @@ -650,6 +730,7 @@ writedisklabel(dev, lp) *dlp = *lp; bp->b_flags &= ~(B_DONE | B_READ); bp->b_flags |= B_WRITE; + bp->b_dev = dkmodpart(dev, RAW_PART); #ifdef __alpha__ alpha_fix_srm_checksum(bp); #endif diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 0f229deed7..04c12e436b 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -32,7 +32,7 @@ * * @(#)subr_log.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/subr_log.c,v 1.39.2.2 2001/06/02 08:11:25 phk Exp $ - * $DragonFly: src/sys/kern/subr_log.c,v 1.6 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/subr_log.c,v 1.7 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -265,7 +265,7 @@ logioctl(dev_t dev, u_long com, caddr_t data, int flag, struct thread *td) static void log_drvinit(void *unused) { - + cdevsw_add(&log_cdevsw, 0, 0); make_dev(&log_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "klog"); } diff --git a/sys/kern/subr_xxx.c b/sys/kern/subr_xxx.c index 341fb9c0cf..e8ce92e88f 100644 --- a/sys/kern/subr_xxx.c +++ b/sys/kern/subr_xxx.c @@ -32,7 +32,7 @@ * * @(#)subr_xxx.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/subr_xxx.c,v 1.15.2.1 2001/02/26 04:23:16 jlemon Exp $ - * $DragonFly: src/sys/kern/Attic/subr_xxx.c,v 1.3 2003/06/23 17:55:41 dillon Exp $ + * $DragonFly: src/sys/kern/Attic/subr_xxx.c,v 1.4 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -40,15 +40,15 @@ */ #include #include +#include /* * Return error for operation not supported * on a specific object or file type. */ int -eopnotsupp() +eopnotsupp(void) { - return (EOPNOTSUPP); } @@ -57,9 +57,8 @@ eopnotsupp() * on a specific object or file type. */ int -einval() +einval(void) { - return (EINVAL); } @@ -67,9 +66,8 @@ einval() * Generic null operation, always returns success. */ int -nullop() +nullop(void) { - return (0); } @@ -81,84 +79,78 @@ nullop() */ int -noopen(dev, flags, fmt, td) - dev_t dev; - int flags; - int fmt; - struct thread *td; +noclone(dev_t dev) { + /* take no action */ + return (0); /* allow the clone */ +} +int +noopen(dev_t dev, int flags, int fmt, struct thread *td) +{ return (ENODEV); } int -noclose(dev, flags, fmt, td) - dev_t dev; - int flags; - int fmt; - struct thread *td; +noclose(dev_t dev, int flags, int fmt, struct thread *td) { - return (ENODEV); } int -noread(dev, uio, ioflag) - dev_t dev; - struct uio *uio; - int ioflag; +noread(dev_t dev, struct uio *uio, int ioflag) { - return (ENODEV); } int -nowrite(dev, uio, ioflag) - dev_t dev; - struct uio *uio; - int ioflag; +nowrite(dev_t dev, struct uio *uio, int ioflag) { - return (ENODEV); } int -noioctl(dev, cmd, data, flags, td) - dev_t dev; - u_long cmd; - caddr_t data; - int flags; - struct thread *td; +noioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td) { - return (ENODEV); } int -nokqfilter(dev, kn) - dev_t dev; - struct knote *kn; +nokqfilter(dev_t dev, struct knote *kn) { - return (ENODEV); } int -nommap(dev, offset, nprot) - dev_t dev; - vm_offset_t offset; - int nprot; +nommap(dev_t dev, vm_offset_t offset, int nprot) { - /* Don't return ENODEV. That would allow mapping address ENODEV! */ return (-1); } int -nodump(dev) - dev_t dev; +nopoll(dev_t dev, int events, d_thread_t *td) { + return(0); +} +void +nostrategy(struct buf *bp) +{ + bp->b_flags |= B_ERROR; + bp->b_error = EOPNOTSUPP; + biodone(bp); +} + +int +nopsize(dev_t dev) +{ + return(0); +} + +int +nodump(dev_t dev, u_int count, u_int blkno, u_int secsize) +{ return (ENODEV); } @@ -173,23 +165,14 @@ nodump(dev) * minor number. */ int -nullopen(dev, flags, fmt, td) - dev_t dev; - int flags; - int fmt; - struct thread *td; +nullopen(dev_t dev, int flags, int fmt, struct thread *td) { - return (0); } int -nullclose(dev, flags, fmt, td) - dev_t dev; - int flags; - int fmt; - struct thread *td; +nullclose(dev_t dev, int flags, int fmt, struct thread *td) { - return (0); } + diff --git a/sys/kern/tty_cons.c b/sys/kern/tty_cons.c index dfcbc5ecda..40a7bf6920 100644 --- a/sys/kern/tty_cons.c +++ b/sys/kern/tty_cons.c @@ -37,7 +37,7 @@ * * from: @(#)cons.c 7.2 (Berkeley) 5/9/91 * $FreeBSD: src/sys/kern/tty_cons.c,v 1.81.2.4 2001/12/17 18:44:41 guido Exp $ - * $DragonFly: src/sys/kern/tty_cons.c,v 1.12 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/tty_cons.c,v 1.13 2004/05/19 22:52:58 dillon Exp $ */ #include "opt_ddb.h" @@ -60,37 +60,30 @@ #include -static d_open_t cnopen; -static d_close_t cnclose; -static d_read_t cnread; -static d_write_t cnwrite; -static d_ioctl_t cnioctl; -static d_poll_t cnpoll; -static d_kqfilter_t cnkqfilter; +static int cnopen(struct cdevmsg_open *msg); +static int cnclose(struct cdevmsg_close *msg); +static int cnread(struct cdevmsg_read *msg); +static int cnwrite(struct cdevmsg_write *msg); +static int cnioctl(struct cdevmsg_ioctl *msg); +static int cnpoll(struct cdevmsg_poll *msg); +static int cnkqfilter(struct cdevmsg_kqfilter *msg); + static int console_putport(lwkt_port_t port, lwkt_msg_t lmsg); +static int console_interceptport(lwkt_port_t port, lwkt_msg_t lmsg); + +static struct lwkt_port cn_port; /* console device port */ +static struct lwkt_port cn_iport; /* intercept port */ #define CDEV_MAJOR 0 static struct cdevsw cn_cdevsw = { /* name */ "console", /* maj */ CDEV_MAJOR, /* flags */ D_TTY | D_KQFILTER, - /* port */ NULL, - /* clone */ NULL, - - /* open */ cnopen, - /* close */ cnclose, - /* read */ cnread, - /* write */ cnwrite, - /* ioctl */ cnioctl, - /* poll */ cnpoll, - /* mmap */ nommap, - /* strategy */ nostrategy, - /* dump */ nodump, - /* psize */ nopsize, - /* kqfilter */ cnkqfilter + /* port */ &cn_port, + /* clone */ NULL }; -static dev_t cn_dev_t; /* seems to be never really used */ +static dev_t cn_dev_t; static udev_t cn_udev_t; SYSCTL_OPAQUE(_machdep, CPU_CONSDEV, consdev, CTLFLAG_RD, &cn_udev_t, sizeof cn_udev_t, "T,dev_t", ""); @@ -112,8 +105,6 @@ static char *console_pausestr= ""; static lwkt_port_t cn_fwd_port; -static struct lwkt_port cn_port; - CONS_DRIVER(cons, NULL, NULL, NULL, NULL, NULL, NULL, NULL); SET_DECLARE(cons_set, struct consdev); @@ -128,6 +119,8 @@ cninit() */ lwkt_initport(&cn_port, NULL); cn_port.mp_putport = console_putport; + lwkt_initport(&cn_iport, NULL); + cn_iport.mp_putport = console_interceptport; /* * Find the first console with the highest priority. @@ -180,6 +173,9 @@ cninit() cn_tab = best_cp; } +/* + * Hook the open and close functions on the selected device. + */ void cninit_finish() { @@ -187,10 +183,10 @@ cninit_finish() return; /* - * Hook the open and close functions. + * Hook the open and close functions. XXX bad hack. */ - if (dev_dport(cn_tab->cn_dev)) - cn_fwd_port = cdevsw_dev_override(cn_tab->cn_dev, &cn_port); + if (dev_is_good(cn_tab->cn_dev)) + cn_fwd_port = cdevsw_dev_override(cn_tab->cn_dev, &cn_iport); cn_dev_t = cn_tab->cn_dev; cn_udev_t = dev2udev(cn_dev_t); console_pausing = 0; @@ -203,9 +199,10 @@ cnuninit(void) return; /* - * Unhook the open and close functions. + * Unhook the open and close functions. XXX bad hack */ - cdevsw_dev_override(cn_tab->cn_dev, NULL); + if (cn_fwd_port) + cdevsw_dev_override(cn_tab->cn_dev, cn_fwd_port); cn_fwd_port = NULL; cn_dev_t = NODEV; cn_udev_t = NOUDEV; @@ -230,10 +227,11 @@ sysctl_kern_consmute(SYSCTL_HANDLER_ARGS) * if the console has been openned */ cninit_finish(); - if(cn_is_open) + if (cn_is_open) { /* XXX curproc is not what we want really */ - error = cnopen(cn_dev_t, openflag, - openmode, curthread); + error = dev_dopen(cn_dev_t, openflag, + openmode, curthread); + } /* if it failed, back it out */ if ( error != 0) cnuninit(); } else if (!ocn_mute && cn_mute) { @@ -241,10 +239,12 @@ sysctl_kern_consmute(SYSCTL_HANDLER_ARGS) * going from unmuted to muted.. close the physical dev * if it's only open via /dev/console */ - if(cn_is_open) - error = cnclose(cn_dev_t, openflag, - openmode, curthread); - if ( error == 0) cnuninit(); + if (cn_is_open) { + error = dev_dclose(cn_dev_t, openflag, + openmode, curthread); + } + if (error == 0) + cnuninit(); } if (error != 0) { /* @@ -259,6 +259,38 @@ sysctl_kern_consmute(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_kern, OID_AUTO, consmute, CTLTYPE_INT|CTLFLAG_RW, 0, sizeof cn_mute, sysctl_kern_consmute, "I", ""); +/* + * We intercept the OPEN and CLOSE calls on the original device, and + * forward the rest through. + */ +static int +console_interceptport(lwkt_port_t port, lwkt_msg_t lmsg) +{ + cdevallmsg_t msg = (cdevallmsg_t)lmsg; + int error; + + switch(msg->am_lmsg.ms_cmd.cm_op) { + case CDEV_CMD_OPEN: + error = cnopen(&msg->am_open); + break; + case CDEV_CMD_CLOSE: + error = cnclose(&msg->am_close); + break; + default: + error = lwkt_forwardmsg(cn_fwd_port, &msg->am_lmsg); + break; + } + return(error); +} + +/* + * This is the port handler for /dev/console. These functions will basically + * past the request through to the actual physical device representing the + * console. + * + * Note, however, that cnopen() and cnclose() are also called from the mute + * code and the intercept code. + */ static int console_putport(lwkt_port_t port, lwkt_msg_t lmsg) { @@ -267,34 +299,60 @@ console_putport(lwkt_port_t port, lwkt_msg_t lmsg) switch(msg->am_lmsg.ms_cmd.cm_op) { case CDEV_CMD_OPEN: - error = cnopen( - msg->am_open.msg.dev, - msg->am_open.oflags, - msg->am_open.devtype, - msg->am_open.td - ); + error = cnopen(&msg->am_open); break; case CDEV_CMD_CLOSE: - error = cnclose( - msg->am_close.msg.dev, - msg->am_close.fflag, - msg->am_close.devtype, - msg->am_close.td - ); + error = cnclose(&msg->am_close); + break; + case CDEV_CMD_STRATEGY: + nostrategy(msg->am_strategy.bp); + error = 0; + break; + case CDEV_CMD_IOCTL: + error = cnioctl(&msg->am_ioctl); + break; + case CDEV_CMD_DUMP: + error = nodump(msg->am_dump.msg.dev, 0, 0, 0); + break; + case CDEV_CMD_PSIZE: + error = nopsize(msg->am_psize.msg.dev); + break; + case CDEV_CMD_READ: + error = cnread(&msg->am_read); + break; + case CDEV_CMD_WRITE: + error = cnwrite(&msg->am_write); + break; + case CDEV_CMD_POLL: + error = cnpoll(&msg->am_poll); + break; + case CDEV_CMD_KQFILTER: + error = cnkqfilter(&msg->am_kqfilter); + break; + case CDEV_CMD_MMAP: + error = nommap(msg->am_mmap.msg.dev, + msg->am_mmap.offset, + msg->am_mmap.nprot); break; default: - error = lwkt_forwardmsg(cn_fwd_port, &msg->am_lmsg); - break; + error = ENODEV; + break; } return(error); } +/* + * cnopen() is called as a port intercept function (dev will be that of the + * actual physical device representing our console), and also called from + * the muting code and from the /dev/console switch (dev will have the + * console's cdevsw). + */ static int -cnopen(dev, flag, mode, td) - dev_t dev; - int flag, mode; - struct thread *td; +cnopen(struct cdevmsg_open *msg) { + dev_t dev = msg->msg.dev; + int flag = msg->oflags; + int mode = msg->devtype; dev_t cndev, physdev; int retval = 0; @@ -302,13 +360,19 @@ cnopen(dev, flag, mode, td) return (0); cndev = cn_tab->cn_dev; physdev = (major(dev) == major(cndev) ? dev : cndev); + /* * If mute is active, then non console opens don't get here - * so we don't need to check for that. They - * bypass this and go straight to the device. + * so we don't need to check for that. They bypass this and go + * straight to the device. + * + * XXX at the moment we assume that the port forwarding function + * is synchronous for open. */ - if(!cn_mute) - retval = dev_port_dopen(cn_fwd_port, physdev, flag, mode, td); + if (!cn_mute) { + msg->msg.dev = physdev; + retval = lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg); + } if (retval == 0) { /* * check if we openned it via /dev/console or @@ -326,12 +390,16 @@ cnopen(dev, flag, mode, td) return (retval); } +/* + * cnclose() is called as a port intercept function (dev will be that of the + * actual physical device representing our console), and also called from + * the muting code and from the /dev/console switch (dev will have the + * console's cdevsw). + */ static int -cnclose(dev, flag, mode, td) - dev_t dev; - int flag, mode; - struct thread *td; +cnclose(struct cdevmsg_close *msg) { + dev_t dev = msg->msg.dev; dev_t cndev; struct tty *cn_tp; @@ -364,30 +432,33 @@ cnclose(dev, flag, mode, td) return (0); dev = cndev; } - if (cn_fwd_port) - return (dev_port_dclose(cn_fwd_port, dev, flag, mode, td)); + if (cn_fwd_port) { + msg->msg.dev = dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); + } return (0); } +/* + * The following functions are dispatched solely from the /dev/console + * port switch. Their job is primarily to forward the request through. + * If the console is not attached to anything then write()'s are sunk + * to null and reads return 0 (mostly). + */ static int -cnread(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; +cnread(struct cdevmsg_read *msg) { - if (cn_tab == NULL || cn_fwd_port == NULL) return (0); - dev = cn_tab->cn_dev; - return (dev_port_dread(cn_fwd_port, dev, uio, flag)); + msg->msg.dev = cn_tab->cn_dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); } static int -cnwrite(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; +cnwrite(struct cdevmsg_write *msg) { + struct uio *uio = msg->uio; + dev_t dev; if (cn_tab == NULL || cn_fwd_port == NULL) { uio->uio_resid = 0; /* dump the data */ @@ -398,65 +469,59 @@ cnwrite(dev, uio, flag) else dev = cn_tab->cn_dev; log_console(uio); - return (dev_port_dwrite(cn_fwd_port, dev, uio, flag)); + msg->msg.dev = dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); } static int -cnioctl(dev, cmd, data, flag, td) - dev_t dev; - u_long cmd; - caddr_t data; - int flag; - struct thread *td; +cnioctl(struct cdevmsg_ioctl *msg) { + u_long cmd = msg->cmd; int error; if (cn_tab == NULL || cn_fwd_port == NULL) return (0); - KKASSERT(td->td_proc != NULL); + KKASSERT(msg->td->td_proc != NULL); /* * Superuser can always use this to wrest control of console * output from the "virtual" console. */ if (cmd == TIOCCONS && constty) { - error = suser(td); + error = suser(msg->td); if (error) return (error); constty = NULL; return (0); } - dev = cn_tab->cn_dev; - return (dev_port_dioctl(cn_fwd_port, dev, cmd, data, flag, td)); + msg->msg.dev = cn_tab->cn_dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); } static int -cnpoll(dev, events, td) - dev_t dev; - int events; - struct thread *td; +cnpoll(struct cdevmsg_poll *msg) { if ((cn_tab == NULL) || cn_mute || cn_fwd_port == NULL) return (1); - - dev = cn_tab->cn_dev; - - return (dev_port_dpoll(cn_fwd_port, dev, events, td)); + msg->msg.dev = cn_tab->cn_dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); } static int -cnkqfilter(dev, kn) - dev_t dev; - struct knote *kn; +cnkqfilter(struct cdevmsg_kqfilter *msg) { if ((cn_tab == NULL) || cn_mute || cn_fwd_port == NULL) return (1); - - dev = cn_tab->cn_dev; - return (dev_port_dkqfilter(cn_fwd_port, dev, kn)); + msg->msg.dev = cn_tab->cn_dev; + return(lwkt_forwardmsg(cn_fwd_port, &msg->msg.msg)); } +/* + * These synchronous functions are primarily used the kernel needs to + * access the keyboard (e.g. when running the debugger), or output data + * directly to the console. + */ int -cngetc() +cngetc(void) { int c; if ((cn_tab == NULL) || cn_mute) @@ -467,7 +532,7 @@ cngetc() } int -cncheckc() +cncheckc(void) { if ((cn_tab == NULL) || cn_mute) return (-1); @@ -475,8 +540,7 @@ cncheckc() } void -cnputc(c) - int c; +cnputc(int c) { char *cp; @@ -504,8 +568,7 @@ cnputc(c) } void -cndbctl(on) - int on; +cndbctl(int on) { static int refcount; @@ -522,9 +585,9 @@ cndbctl(on) static void cn_drvinit(void *unused) { - - cn_devfsdev = make_dev(&cn_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, - "console"); + cdevsw_add(&cn_cdevsw, 0, 0); + cn_devfsdev = make_dev(&cn_cdevsw, 0, UID_ROOT, GID_WHEEL, + 0600, "console"); } SYSINIT(cndev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,cn_drvinit,NULL) diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 556418d52b..3ded00eb1d 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -32,7 +32,7 @@ * * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 * $FreeBSD: src/sys/kern/tty_pty.c,v 1.74.2.4 2002/02/20 19:58:13 dillon Exp $ - * $DragonFly: src/sys/kern/tty_pty.c,v 1.11 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/tty_pty.c,v 1.12 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -177,26 +177,29 @@ ptsopen(dev_t dev, int flag, int devtype, struct thread *td) struct tty *tp; int error; int minr; +#if 0 dev_t nextdev; +#endif struct pt_ioctl *pti; struct proc *p; p = td->td_proc; KKASSERT(p != NULL); + minr = lminor(dev); +#if 0 /* - * XXX: Gross hack for DEVFS: - * XXX: DEVFS is no more, should this be removed? - * If we openned this device, ensure we have the - * next one too, so people can open it. + * REMOVED gross hack for devfs. also note that makedev() + * no longer exists in this form and reference counting makes + * this a problem if we don't clean it out later. */ - minr = lminor(dev); if (minr < 255) { - nextdev = makedev(major(dev), minr + 1); + nextdev = make_sub_dev(dev, minr + 1); if (!nextdev->si_drv1) { ptyinit(minr + 1); } } +#endif if (!dev->si_drv1) ptyinit(minor(dev)); if (!dev->si_drv1) @@ -831,8 +834,8 @@ static void ptc_drvinit(unused) void *unused; { - cdevsw_add(&pts_cdevsw); - cdevsw_add(&ptc_cdevsw); + cdevsw_add(&pts_cdevsw, 0, 0); + cdevsw_add(&ptc_cdevsw, 0, 0); /* XXX: Gross hack for DEVFS */ /* XXX: DEVFS is no more, should this be removed? */ ptyinit(0); diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c index 3480efc1b4..15eacbe19a 100644 --- a/sys/kern/tty_tty.c +++ b/sys/kern/tty_tty.c @@ -32,7 +32,7 @@ * * @(#)tty_tty.c 8.2 (Berkeley) 9/23/93 * $FreeBSD: src/sys/kern/tty_tty.c,v 1.30 1999/09/25 18:24:24 phk Exp $ - * $DragonFly: src/sys/kern/tty_tty.c,v 1.8 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/tty_tty.c,v 1.9 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -49,6 +49,7 @@ #include static d_open_t cttyopen; +static d_close_t cttyclose; static d_read_t cttyread; static d_write_t cttywrite; static d_ioctl_t cttyioctl; @@ -64,7 +65,7 @@ struct cdevsw ctty_cdevsw = { /* clone */ NULL, /* open */ cttyopen, - /* close */ nullclose, + /* close */ cttyclose, /* read */ cttyread, /* write */ cttywrite, /* ioctl */ cttyioctl, @@ -87,28 +88,32 @@ cttyopen(dev_t dev, int flag, int mode, struct thread *td) KKASSERT(p); ttyvp = cttyvp(p); - - if (ttyvp == NULL) - return (ENXIO); - vn_lock(ttyvp, NULL, LK_EXCLUSIVE | LK_RETRY, td); -#ifdef PARANOID - /* - * Since group is tty and mode is 620 on most terminal lines - * and since sessions protect terminals from processes outside - * your session, this check is probably no longer necessary. - * Since it inhibits setuid root programs that later switch - * to another user from accessing /dev/tty, we have decided - * to delete this test. (mckusick 5/93) - */ - error = VOP_ACCESS(ttyvp, - (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, td); - if (!error) -#endif /* PARANOID */ + if (ttyvp) { + vn_lock(ttyvp, NULL, LK_EXCLUSIVE | LK_RETRY, td); error = VOP_OPEN(ttyvp, flag, NOCRED, td); - VOP_UNLOCK(ttyvp, NULL, 0, td); + VOP_UNLOCK(ttyvp, NULL, 0, td); + } else { + error = ENXIO; + } return (error); } +static int +cttyclose(dev_t dev, int fflag, int devtype, struct thread *td) +{ + struct proc *p = td->td_proc; + struct vnode *ttyvp; + int error; + + KKASSERT(p); + ttyvp = cttyvp(p); + if (ttyvp == NULL) + error = EIO; + else + error = VOP_CLOSE(ttyvp, fflag, td); + return(error); +} + /*ARGSUSED*/ static int cttyread(dev, uio, flag) @@ -201,7 +206,7 @@ static void ctty_drvinit(unused) void *unused; { - + cdevsw_add(&ctty_cdevsw, 0, 0); make_dev(&ctty_cdevsw, 0, 0, 0, 0666, "tty"); } diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index b8dae351b3..4760b58537 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -12,7 +12,7 @@ * John S. Dyson. * * $FreeBSD: src/sys/kern/vfs_bio.c,v 1.242.2.20 2003/05/28 18:38:10 alc Exp $ - * $DragonFly: src/sys/kern/vfs_bio.c,v 1.25 2004/05/13 17:40:15 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_bio.c,v 1.26 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -2753,6 +2753,10 @@ biowait(struct buf * bp) * biodone does not mess with B_INVAL, allowing the I/O routine or the * initiator to leave B_INVAL set to brelse the buffer out of existance * in the biodone routine. + * + * b_dev is required to be reinitialized prior to the top level strategy + * call in a device stack. To avoid improper reuse, biodone() sets + * b_dev to NODEV. */ void biodone(struct buf * bp) @@ -2765,6 +2769,7 @@ biodone(struct buf * bp) KASSERT(!(bp->b_flags & B_DONE), ("biodone: bp %p already done", bp)); bp->b_flags |= B_DONE; + bp->b_dev = NODEV; runningbufwakeup(bp); if (bp->b_flags & B_FREEBUF) { diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 220ed69564..c7bc1ba398 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/vfs_conf.c,v 1.49.2.5 2003/01/07 11:56:53 joerg Exp $ - * $DragonFly: src/sys/kern/vfs_conf.c,v 1.7 2004/03/01 06:33:17 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_conf.c,v 1.8 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -215,7 +215,7 @@ vfs_mountroot_try(char *mountfrom) printf("setrootbyname failed\n"); /* If the root device is a type "memory disk", mount RW */ - if (rootdev != NODEV && dev_dport(rootdev) && + if (rootdev != NODEV && dev_is_good(rootdev) && (dev_dflags(rootdev) & D_MEMDISK)) { mp->mnt_flag &= ~MNT_RDONLY; } @@ -270,8 +270,8 @@ vfs_mountroot_ask(void) if (name[0] == '?') { printf("Possibly valid devices for 'ufs' root:\n"); for (i = 0; i < NUMCDEVSW; i++) { - dev = makedev(i, 0); - if (dev_dport(dev) != NULL) + dev = udev2dev(makeudev(i, 0), 0); + if (dev_is_good(dev)) printf(" \"%s\"", dev_dname(dev)); } printf("\n"); @@ -325,10 +325,12 @@ gets(char *cp) * it refers to. */ dev_t -getdiskbyname(char *name) { +getdiskbyname(char *name) +{ char *cp; int cd, unit, slice, part; dev_t dev; + dev_t rdev; slice = 0; part = 0; @@ -347,17 +349,19 @@ getdiskbyname(char *name) { unit = *cp - '0'; *cp++ = '\0'; for (cd = 0; cd < NUMCDEVSW; cd++) { - dev = makedev(cd, 0); - if (dev_dport(dev) != NULL && - strcmp(dev_dname(dev), name) == 0) + dev = udev2dev(makeudev(cd, 0), 0); + if (dev_is_good(dev) && dev_dname(dev) && + strcmp(dev_dname(dev), name) == 0) { goto gotit; + } } printf("no such device '%s'\n", name); return (NODEV); gotit: - if (dev_dmaj(dev) == major(rootdev)) + if (dev_dmaj(dev) == major(rootdev)) { /* driver has already configured rootdev, e. g. vinum */ return (rootdev); + } if (unit == -1) { printf("missing unit number\n"); return (NODEV); @@ -376,7 +380,8 @@ gotit: printf("junk after name\n"); return (NODEV); } - return (makedev(cd, dkmakeminor(unit, slice, part))); + rdev = make_sub_dev(dev, dkmakeminor(unit, slice, part)); + return(rdev); } /* diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index 88b8d22357..7109036267 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -37,7 +37,7 @@ * * * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $ - * $DragonFly: src/sys/kern/vfs_default.c,v 1.9 2004/03/01 06:33:17 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_default.c,v 1.10 2004/05/19 22:52:58 dillon Exp $ */ #include @@ -533,8 +533,10 @@ retry: if ((error = VOP_GETATTR(vp, &vat, td)) != 0) goto retn; object = vnode_pager_alloc(vp, vat.va_size, 0, 0); - } else if (dev_dport(vp->v_rdev) != NULL) { + } else if (vp->v_rdev && dev_is_good(vp->v_rdev)) { /* + * XXX v_rdev uses NULL/non-NULL instead of NODEV + * * This simply allocates the biggest object possible * for a disk vnode. This should be fixed, but doesn't * cause any problems (yet). diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 8f9e1d6e2c..20a52a5c37 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.29 2004/04/08 17:56:48 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.30 2004/05/19 22:52:58 dillon Exp $ */ /* @@ -192,6 +192,8 @@ static void vbusy(struct vnode *vp); static void vfree(struct vnode *vp); static void vmaybefree(struct vnode *vp); +extern int dev_ref_debug; + /* * NOTE: the vnode interlock must be held on call. */ @@ -1458,7 +1460,8 @@ reassignbuf(bp, newvp) break; case VCHR: case VBLK: - if (newvp->v_specmountpoint != NULL) { + if (newvp->v_rdev && + newvp->v_rdev->si_mountpoint != NULL) { delay = metadelay; break; } @@ -1541,9 +1544,7 @@ reassignbuf(bp, newvp) * Used for mounting the root file system. */ int -bdevvp(dev, vpp) - dev_t dev; - struct vnode **vpp; +bdevvp(dev_t dev, struct vnode **vpp) { struct vnode *vp; struct vnode *nvp; @@ -1559,47 +1560,60 @@ bdevvp(dev, vpp) return (error); } vp = nvp; - vp->v_type = VBLK; - addalias(vp, dev); + vp->v_type = VCHR; + vp->v_udev = dev->si_udev; *vpp = vp; return (0); } -/* - * Add a vnode to the alias list hung off the dev_t. - * - * The reason for this gunk is that multiple vnodes can reference - * the same physical device, so checking vp->v_usecount to see - * how many users there are is inadequate; the v_usecount for - * the vnodes need to be accumulated. vcount() does that. - */ -void -addaliasu(struct vnode *nvp, udev_t nvp_rdev) +int +v_associate_rdev(struct vnode *vp, dev_t dev) { - dev_t dev; + lwkt_tokref ilock; - if (nvp->v_type != VBLK && nvp->v_type != VCHR) - panic("addaliasu on non-special vnode"); - dev = udev2dev(nvp_rdev, nvp->v_type == VBLK ? 1 : 0); - if (dev != NODEV) { - nvp->v_rdev = dev; - addalias(nvp, dev); - } else - nvp->v_rdev = NULL; + if (dev == NULL || dev == NODEV) + return(ENXIO); + if (dev_is_good(dev) == 0) + return(ENXIO); + KKASSERT(vp->v_rdev == NULL); + if (dev_ref_debug) + printf("Z1"); + vp->v_rdev = reference_dev(dev); + lwkt_gettoken(&ilock, &spechash_token); + SLIST_INSERT_HEAD(&dev->si_hlist, vp, v_specnext); + lwkt_reltoken(&ilock); + return(0); } void -addalias(struct vnode *nvp, dev_t dev) +v_release_rdev(struct vnode *vp) { lwkt_tokref ilock; + dev_t dev; - if (nvp->v_type != VBLK && nvp->v_type != VCHR) - panic("addalias on non-special vnode"); + if ((dev = vp->v_rdev) != NULL) { + lwkt_gettoken(&ilock, &spechash_token); + SLIST_REMOVE(&dev->si_hlist, vp, vnode, v_specnext); + if (dev_ref_debug) + printf("Y2"); + vp->v_rdev = NULL; + release_dev(dev); + lwkt_reltoken(&ilock); + } +} - nvp->v_rdev = dev; - lwkt_gettoken(&ilock, &spechash_token); - SLIST_INSERT_HEAD(&dev->si_hlist, nvp, v_specnext); - lwkt_reltoken(&ilock); +/* + * Add a vnode to the alias list hung off the dev_t. We only associate + * the device number with the vnode. The actual device is not associated + * until the vnode is opened (usually in spec_open()), and will be + * disassociated on last close. + */ +void +addaliasu(struct vnode *nvp, udev_t nvp_udev) +{ + if (nvp->v_type != VBLK && nvp->v_type != VCHR) + panic("addaliasu on non-special vnode"); + nvp->v_udev = nvp_udev; } /* @@ -2150,15 +2164,28 @@ vop_revoke(ap) tsleep((caddr_t)vp, 0, "vop_revokeall", 0); return (0); } - dev = vp->v_rdev; + + /* + * If the vnode has a device association, scrap all vnodes associated + * with the device. Don't let the device disappear on us while we + * are scrapping the vnodes. + */ + if (vp->v_type != VCHR && vp->v_type != VBLK) + return(0); + if ((dev = vp->v_rdev) == NULL) { + if ((dev = udev2dev(vp->v_udev, vp->v_type == VBLK)) == NODEV) + return(0); + } + reference_dev(dev); for (;;) { lwkt_gettoken(&ilock, &spechash_token); vq = SLIST_FIRST(&dev->si_hlist); lwkt_reltoken(&ilock); - if (!vq) + if (vq == NULL) break; vgone(vq); } + release_dev(dev); return (0); } @@ -2232,11 +2259,7 @@ vgonel(struct vnode *vp, lwkt_tokref_t vlock, struct thread *td) * if it is on one. */ if ((vp->v_type == VBLK || vp->v_type == VCHR) && vp->v_rdev != NULL) { - lwkt_gettoken(&ilock, &spechash_token); - SLIST_REMOVE(&vp->v_hashchain, vp, vnode, v_specnext); - freedev(vp->v_rdev); - lwkt_reltoken(&ilock); - vp->v_rdev = NULL; + v_release_rdev(vp); } /* @@ -2290,38 +2313,44 @@ vfinddev(dev, type, vpp) } /* - * Calculate the total number of references to a special device. + * Calculate the total number of references to a special device. This + * routine may only be called for VBLK and VCHR vnodes since v_rdev is + * an overloaded field. Since udev2dev can now return NODEV, we have + * to check for a NULL v_rdev. */ int -vcount(vp) - struct vnode *vp; +count_dev(dev_t dev) { lwkt_tokref ilock; - struct vnode *vq; - int count; + struct vnode *vp; + int count = 0; - count = 0; - lwkt_gettoken(&ilock, &spechash_token); - SLIST_FOREACH(vq, &vp->v_hashchain, v_specnext) - count += vq->v_usecount; - lwkt_reltoken(&ilock); - return (count); + if (SLIST_FIRST(&dev->si_hlist)) { + lwkt_gettoken(&ilock, &spechash_token); + SLIST_FOREACH(vp, &dev->si_hlist, v_specnext) { + count += vp->v_usecount; + } + lwkt_reltoken(&ilock); + } + return(count); } -/* - * Same as above, but using the dev_t as argument - */ - int -count_dev(dev) - dev_t dev; +count_udev(udev_t udev) { - struct vnode *vp; + dev_t dev; - vp = SLIST_FIRST(&dev->si_hlist); - if (vp == NULL) - return (0); - return(vcount(vp)); + if ((dev = udev2dev(udev, 0)) == NODEV) + return(0); + return(count_dev(dev)); +} + +int +vcount(struct vnode *vp) +{ + if (vp->v_rdev == NULL) + return(0); + return(count_dev(vp->v_rdev)); } /* @@ -2557,11 +2586,13 @@ SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE|CTLFLAG_RD, * Check to see if a filesystem is mounted on a block device. */ int -vfs_mountedon(vp) - struct vnode *vp; +vfs_mountedon(struct vnode *vp) { + dev_t dev; - if (vp->v_specmountpoint != NULL) + if ((dev = vp->v_rdev) == NULL) + dev = udev2dev(vp->v_udev, (vp->v_type == VBLK)); + if (dev != NODEV && dev->si_mountpoint) return (EBUSY); return (0); } @@ -3266,41 +3297,46 @@ sync_print(ap) } /* - * extract the dev_t from a VBLK or VCHR + * extract the dev_t from a VBLK or VCHR. The vnode must have been opened + * (or v_rdev might be NULL). */ dev_t -vn_todev(vp) - struct vnode *vp; +vn_todev(struct vnode *vp) { if (vp->v_type != VBLK && vp->v_type != VCHR) return (NODEV); + KKASSERT(vp->v_rdev != NULL); return (vp->v_rdev); } /* - * Check if vnode represents a disk device + * Check if vnode represents a disk device. The vnode does not need to be + * opened. */ int -vn_isdisk(vp, errp) - struct vnode *vp; - int *errp; +vn_isdisk(struct vnode *vp, int *errp) { + dev_t dev; + if (vp->v_type != VBLK && vp->v_type != VCHR) { if (errp != NULL) *errp = ENOTBLK; return (0); } - if (vp->v_rdev == NULL) { + + if ((dev = vp->v_rdev) == NULL) + dev = udev2dev(vp->v_udev, (vp->v_type == VBLK)); + if (dev == NULL || dev == NODEV) { if (errp != NULL) *errp = ENXIO; return (0); } - if (!dev_dport(vp->v_rdev)) { + if (dev_is_good(dev) == 0) { if (errp != NULL) *errp = ENXIO; return (0); } - if (!(dev_dflags(vp->v_rdev) & D_DISK)) { + if ((dev_dflags(dev) & D_DISK) == 0) { if (errp != NULL) *errp = ENOTBLK; return (0); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index fd02443b8f..eb36135dfd 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -37,7 +37,7 @@ * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 * $FreeBSD: src/sys/kern/vfs_syscalls.c,v 1.151.2.18 2003/04/04 20:35:58 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.33 2004/04/24 04:32:03 drhodus Exp $ + * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.34 2004/05/19 22:52:58 dillon Exp $ */ #include @@ -2728,7 +2728,7 @@ revoke(struct revoke_args *uap) if (p->p_ucred->cr_uid != vattr.va_uid && (error = suser_cred(p->p_ucred, PRISON_ROOT))) goto out; - if (vcount(vp) > 1) + if (count_udev(vp->v_udev) > 0) VOP_REVOKE(vp, REVOKEALL); out: vrele(vp); diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index a78a6b1ad9..3aec17efa6 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -37,7 +37,7 @@ * * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/vfs_vnops.c,v 1.87.2.13 2002/12/29 18:19:53 dillon Exp $ - * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.19 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.20 2004/05/19 22:52:58 dillon Exp $ */ #include @@ -538,9 +538,18 @@ vn_stat(struct vnode *vp, struct stat *sb, struct thread *td) if (vap->va_type == VREG) { sb->st_blksize = vap->va_blocksize; } else if (vn_isdisk(vp, NULL)) { - sb->st_blksize = vp->v_rdev->si_bsize_best; - if (sb->st_blksize < vp->v_rdev->si_bsize_phys) - sb->st_blksize = vp->v_rdev->si_bsize_phys; + /* + * XXX this is broken. If the device is not yet open (aka + * stat() call, aka v_rdev == NULL), how are we supposed + * to get a valid block size out of it? + */ + dev_t dev; + + if ((dev = vp->v_rdev) == NULL) + dev = udev2dev(vp->v_udev, vp->v_type == VBLK); + sb->st_blksize = dev->si_bsize_best; + if (sb->st_blksize < dev->si_bsize_phys) + sb->st_blksize = dev->si_bsize_phys; if (sb->st_blksize < BLKDEV_IOSIZE) sb->st_blksize = BLKDEV_IOSIZE; } else { diff --git a/sys/net/bpf.c b/sys/net/bpf.c index fe7e314efb..7647410f29 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -38,7 +38,7 @@ * @(#)bpf.c 8.2 (Berkeley) 3/28/94 * * $FreeBSD: src/sys/net/bpf.c,v 1.59.2.12 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/bpf.c,v 1.16 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/bpf.c,v 1.17 2004/05/19 22:52:59 dillon Exp $ */ #include "use_bpf.h" @@ -1397,11 +1397,9 @@ bpfdetach(ifp) static void bpf_drvinit (void *unused); static void -bpf_drvinit(unused) - void *unused; +bpf_drvinit(void *unused) { - - cdevsw_add(&bpf_cdevsw); + cdevsw_add(&bpf_cdevsw, 0, 0); } SYSINIT(bpfdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,bpf_drvinit,NULL) diff --git a/sys/net/i4b/driver/i4b_ctl.c b/sys/net/i4b/driver/i4b_ctl.c index a3cf7e73de..84c83d05f7 100644 --- a/sys/net/i4b/driver/i4b_ctl.c +++ b/sys/net/i4b/driver/i4b_ctl.c @@ -30,7 +30,7 @@ * $Id: i4b_ctl.c,v 1.37 2000/05/31 08:04:43 hm Exp $ * * $FreeBSD: src/sys/i4b/driver/i4b_ctl.c,v 1.10.2.3 2001/08/12 16:22:48 hm Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_ctl.c,v 1.8 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_ctl.c,v 1.9 2004/05/19 22:52:59 dillon Exp $ * * last edit-date: [Sat Aug 11 18:06:38 2001] * @@ -161,9 +161,9 @@ static void i4bctlinit(void *unused) { #if defined(__DragonFly__) || (defined(__FreeBSD__) && __FreeBSD__ >= 4) - cdevsw_add(&i4bctl_cdevsw); + cdevsw_add(&i4bctl_cdevsw, 0, 0); #else - dev_t dev = makedev(CDEV_MAJOR, 0); + dev_t dev = make_adhoc_dev(&i4bctl, 0); cdevsw_add(&dev, &i4bctl_cdevsw, NULL); #endif } diff --git a/sys/net/i4b/driver/i4b_rbch.c b/sys/net/i4b/driver/i4b_rbch.c index 84c6531d4a..0e4e2e9095 100644 --- a/sys/net/i4b/driver/i4b_rbch.c +++ b/sys/net/i4b/driver/i4b_rbch.c @@ -28,7 +28,7 @@ * --------------------------------------------------- * * $FreeBSD: src/sys/i4b/driver/i4b_rbch.c,v 1.10.2.3 2001/08/12 16:22:48 hm Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_rbch.c,v 1.10 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_rbch.c,v 1.11 2004/05/19 22:52:59 dillon Exp $ * * last edit-date: [Sat Aug 11 18:06:57 2001] * @@ -221,7 +221,7 @@ PSEUDO_SET(i4brbchattach, i4b_rbch); static void i4brbchinit(void *unused) { - cdevsw_add(&i4brbch_cdevsw); + cdevsw_add(&i4brbch_cdevsw, 0, 0); } SYSINIT(i4brbchdev, SI_SUB_DRIVERS, diff --git a/sys/net/i4b/driver/i4b_tel.c b/sys/net/i4b/driver/i4b_tel.c index 09d791fa1a..cc183e79fd 100644 --- a/sys/net/i4b/driver/i4b_tel.c +++ b/sys/net/i4b/driver/i4b_tel.c @@ -28,7 +28,7 @@ * -------------------------------------------- * * $FreeBSD: src/sys/i4b/driver/i4b_tel.c,v 1.10.2.4 2001/12/16 15:12:57 hm Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_tel.c,v 1.8 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_tel.c,v 1.9 2004/05/19 22:53:00 dillon Exp $ * * last edit-date: [Sat Aug 11 18:07:05 2001] * @@ -186,7 +186,7 @@ PSEUDO_SET(i4btelattach, i4b_tel); PDEVSTATIC void i4btelinit(void *unused) { - cdevsw_add(&i4btel_cdevsw); + cdevsw_add(&i4btel_cdevsw, 0, 0); } SYSINIT(i4bteldev, SI_SUB_DRIVERS, diff --git a/sys/net/i4b/driver/i4b_trace.c b/sys/net/i4b/driver/i4b_trace.c index 95fb5519b6..6a01f0bba7 100644 --- a/sys/net/i4b/driver/i4b_trace.c +++ b/sys/net/i4b/driver/i4b_trace.c @@ -30,7 +30,7 @@ * last edit-date: [Sat Aug 11 18:07:15 2001] * * $FreeBSD: src/sys/i4b/driver/i4b_trace.c,v 1.9.2.3 2001/08/12 16:22:48 hm Exp $ - * $DragonFly: src/sys/net/i4b/driver/i4b_trace.c,v 1.9 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/i4b/driver/i4b_trace.c,v 1.10 2004/05/19 22:53:00 dillon Exp $ * * NOTE: the code assumes that SPLI4B >= splimp ! * @@ -155,7 +155,7 @@ static struct cdevsw i4btrc_cdevsw = { static void i4btrcinit(void *unused) { - cdevsw_add(&i4btrc_cdevsw); + cdevsw_add(&i4btrc_cdevsw, 0, 0); } SYSINIT(i4btrcdev, SI_SUB_DRIVERS, diff --git a/sys/net/i4b/layer4/i4b_i4bdrv.c b/sys/net/i4b/layer4/i4b_i4bdrv.c index 37239a3fc0..1df035aca2 100644 --- a/sys/net/i4b/layer4/i4b_i4bdrv.c +++ b/sys/net/i4b/layer4/i4b_i4bdrv.c @@ -28,7 +28,7 @@ * -------------------------------------------- * * $FreeBSD: src/sys/i4b/layer4/i4b_i4bdrv.c,v 1.11.2.5 2001/12/16 15:12:59 hm Exp $ - * $DragonFly: src/sys/net/i4b/layer4/i4b_i4bdrv.c,v 1.9 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/i4b/layer4/i4b_i4bdrv.c,v 1.10 2004/05/19 22:53:00 dillon Exp $ * * last edit-date: [Sat Aug 11 18:08:10 2001] * @@ -204,7 +204,7 @@ static void i4b_drvinit(void *unused) { #if defined(__DragonFly__) || (defined(__FreeBSD__) && __FreeBSD__ >= 4) - cdevsw_add(&i4b_cdevsw); + cdevsw_add(&i4b_cdevsw, 0, 0); #else static int i4b_devsw_installed = 0; dev_t dev; diff --git a/sys/net/tap/if_tap.c b/sys/net/tap/if_tap.c index d4822e8327..f85a3c6723 100644 --- a/sys/net/tap/if_tap.c +++ b/sys/net/tap/if_tap.c @@ -32,7 +32,7 @@ /* * $FreeBSD: src/sys/net/if_tap.c,v 1.3.2.3 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/tap/if_tap.c,v 1.12 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/tap/if_tap.c,v 1.13 2004/05/19 22:53:00 dillon Exp $ * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $ */ @@ -144,7 +144,7 @@ tapmodevent(mod, type, data) if (attached) return (EEXIST); - cdevsw_add(&tap_cdevsw); + cdevsw_add(&tap_cdevsw, 0, 0); attached = 1; break; @@ -152,7 +152,7 @@ tapmodevent(mod, type, data) if (taprefcnt > 0) return (EBUSY); - cdevsw_remove(&tap_cdevsw); + cdevsw_remove(&tap_cdevsw, 0, 0); /* XXX: maintain tap ifs in a local list */ unit = 0; @@ -227,6 +227,7 @@ tapcreate(dev) tp->tap_dev = make_dev(&tap_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, "%s%d", name, unit); tp->tap_dev->si_drv1 = dev->si_drv1 = tp; + reference_dev(tp->tap_dev); /* so we can destroy it later */ /* generate fake MAC address: 00 bd xx xx xx unit_no */ ether_addr[0] = 0x00; diff --git a/sys/net/tun/if_tun.c b/sys/net/tun/if_tun.c index 2ba514861c..9a3af843de 100644 --- a/sys/net/tun/if_tun.c +++ b/sys/net/tun/if_tun.c @@ -14,7 +14,7 @@ * operation though. * * $FreeBSD: src/sys/net/if_tun.c,v 1.74.2.8 2002/02/13 00:43:11 dillon Exp $ - * $DragonFly: src/sys/net/tun/if_tun.c,v 1.13 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/net/tun/if_tun.c,v 1.14 2004/05/19 22:53:01 dillon Exp $ */ #include "opt_atalk.h" @@ -98,11 +98,9 @@ static struct cdevsw tun_cdevsw = { }; static void -tunattach(dummy) - void *dummy; +tunattach(void *dummy) { - - cdevsw_add(&tun_cdevsw); + cdevsw_add(&tun_cdevsw, 0, 0); } static void diff --git a/sys/netgraph/ng_device.c b/sys/netgraph/ng_device.c index 38d99126e8..a986c0f57e 100644 --- a/sys/netgraph/ng_device.c +++ b/sys/netgraph/ng_device.c @@ -29,7 +29,7 @@ * netgraph node. * * $FreeBSD: src/sys/netgraph/ng_device.c,v 1.1.2.1 2002/08/23 07:15:44 julian Exp $ - * $DragonFly: src/sys/netgraph/ng_device.c,v 1.4 2004/05/13 23:49:24 dillon Exp $ + * $DragonFly: src/sys/netgraph/ng_device.c,v 1.5 2004/05/19 22:53:01 dillon Exp $ * */ @@ -151,13 +151,14 @@ ng_device_mod_event(module_t mod, int event, void *data) switch (event) { case MOD_LOAD: + cdevsw_add(&ngd_cdevsw, 0, 0); ng_device_init(); break; case MOD_UNLOAD: /* XXX do we need to do something specific ? */ /* ng_device_breakdown */ - /* cdevsw_remove(&ngd_cdevsw);*/ + cdevsw_remove(&ngd_cdevsw, 0, 0); error = EBUSY; /* no unload! */ break; @@ -193,7 +194,6 @@ ng_device_init() return(ENXIO); } NG_NODE_SET_PRIVATE(sc->node, sc); - cdevsw_add(&ngd_cdevsw); return(0); } diff --git a/sys/netproto/smb/smb_dev.c b/sys/netproto/smb/smb_dev.c index df2f73c1fc..913c665341 100644 --- a/sys/netproto/smb/smb_dev.c +++ b/sys/netproto/smb/smb_dev.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_dev.c,v 1.2.2.1 2001/05/22 08:32:33 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.8 2004/05/13 23:49:25 dillon Exp $ + * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.9 2004/05/19 22:53:01 dillon Exp $ */ #include #include @@ -125,12 +125,13 @@ nsmb_dev_open(dev_t dev, int oflags, int devtype, d_thread_t *td) dev->si_drv1 = (void*)sdp; } /* - * XXX: this is just crazy - make a device for an already passed device... - * someone should take care of it. + * XXX: this is just crazy - make a device for an already passed + * device... someone should take care of it. */ - if ((dev->si_flags & SI_NAMED) == 0) - make_dev(&nsmb_cdevsw, minor(dev), cred->cr_uid, cred->cr_gid, 0700, - NSMB_NAME"%d", lminor(dev)); + if ((dev->si_flags & SI_NAMED) == 0) { + make_dev(&nsmb_cdevsw, minor(dev), cred->cr_uid, cred->cr_gid, + 0700, NSMB_NAME"%d", lminor(dev)); + } bzero(sdp, sizeof(*sdp)); /* STAILQ_INIT(&sdp->sd_rqlist); @@ -172,7 +173,6 @@ nsmb_dev_close(dev_t dev, int flag, int fmt, d_thread_t *td) */ dev->si_drv1 = NULL; free(sdp, M_NSMBDEV); - destroy_dev(dev); splx(s); return 0; } @@ -355,14 +355,14 @@ nsmb_dev_load(module_t mod, int cmd, void *arg) smb_sm_done(); break; } - cdevsw_add(&nsmb_cdevsw); + cdevsw_add(&nsmb_cdevsw, 0, 0); printf("netsmb_dev: loaded\n"); break; case MOD_UNLOAD: smb_iod_done(); error = smb_sm_done(); error = 0; - cdevsw_remove(&nsmb_cdevsw); + cdevsw_remove(&nsmb_cdevsw, 0, 0); printf("netsmb_dev: unloaded\n"); break; default: diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index dffe147480..9e6d24e744 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ -/* $DragonFly: src/sys/opencrypto/cryptodev.c,v 1.7 2004/05/13 23:49:25 dillon Exp $ */ +/* $DragonFly: src/sys/opencrypto/cryptodev.c,v 1.8 2004/05/19 22:53:01 dillon Exp $ */ /* $OpenBSD: cryptodev.c,v 1.52 2002/06/19 07:22:46 deraadt Exp $ */ /* @@ -763,7 +763,6 @@ static struct cdevsw crypto_cdevsw = { /* psize */ nopsize, /* kqfilter */ NULL }; -static dev_t crypto_dev; /* * Initialization code, both for static and dynamic loading. @@ -775,13 +774,13 @@ cryptodev_modevent(module_t mod, int type, void *unused) case MOD_LOAD: if (bootverbose) printf("crypto: \n"); - crypto_dev = make_dev(&crypto_cdevsw, 0, - UID_ROOT, GID_WHEEL, 0666, - "crypto"); + cdevsw_add(&crypto_cdevsw, 0, 0); + make_dev(&crypto_cdevsw, 0, UID_ROOT, GID_WHEEL, + 0666, "crypto"); return 0; case MOD_UNLOAD: /*XXX disallow if active sessions */ - destroy_dev(crypto_dev); + cdevsw_remove(&crypto_cdevsw, 0, 0); return 0; } return EINVAL; diff --git a/sys/platform/pc32/acpica/acpi_machdep.c b/sys/platform/pc32/acpica/acpi_machdep.c index fe178add63..02a8eede6b 100644 --- a/sys/platform/pc32/acpica/acpi_machdep.c +++ b/sys/platform/pc32/acpica/acpi_machdep.c @@ -22,7 +22,7 @@ * 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. - * $DragonFly: src/sys/platform/pc32/acpica/Attic/acpi_machdep.c,v 1.2 2004/02/12 23:33:26 joerg Exp $ + * $DragonFly: src/sys/platform/pc32/acpica/Attic/acpi_machdep.c,v 1.3 2004/05/19 22:52:56 dillon Exp $ */ #include @@ -320,7 +320,7 @@ apmpoll(dev_t dev, int events, d_thread_t *td) static void acpi_capm_init(struct acpi_softc *sc) { - + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); } diff --git a/sys/platform/pc32/acpica5/acpi_machdep.c b/sys/platform/pc32/acpica5/acpi_machdep.c index 31aa0b41d1..42c7ed612a 100644 --- a/sys/platform/pc32/acpica5/acpi_machdep.c +++ b/sys/platform/pc32/acpica5/acpi_machdep.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/acpica/acpi_machdep.c,v 1.15 2003/11/01 00:18:29 njl Exp $ - * $DragonFly: src/sys/platform/pc32/acpica5/acpi_machdep.c,v 1.2 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/acpica5/acpi_machdep.c,v 1.3 2004/05/19 22:52:56 dillon Exp $ */ #include @@ -303,6 +303,7 @@ apmpoll(dev_t dev, int events, d_thread_t *td) static void acpi_capm_init(struct acpi_softc *sc) { + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); } diff --git a/sys/platform/pc32/apm/apm.c b/sys/platform/pc32/apm/apm.c index 28b02b05fe..76263d9851 100644 --- a/sys/platform/pc32/apm/apm.c +++ b/sys/platform/pc32/apm/apm.c @@ -16,7 +16,7 @@ * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * * $FreeBSD: src/sys/i386/apm/apm.c,v 1.114.2.5 2002/11/02 04:41:50 iwasaki Exp $ - * $DragonFly: src/sys/platform/pc32/apm/apm.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/apm/apm.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include @@ -1118,6 +1118,7 @@ apm_attach(device_t dev) sc->initialized = 1; + cdevsw_add(&apm_cdevsw, 0, 0); make_dev(&apm_cdevsw, 0, 0, 5, 0660, "apm"); make_dev(&apm_cdevsw, 8, 0, 5, 0660, "apmctl"); return 0; diff --git a/sys/platform/pc32/gnu/isa/dgb.c b/sys/platform/pc32/gnu/isa/dgb.c index a9c26d81f3..f55cf74207 100644 --- a/sys/platform/pc32/gnu/isa/dgb.c +++ b/sys/platform/pc32/gnu/isa/dgb.c @@ -1,6 +1,6 @@ /*- * dgb.c $FreeBSD: src/sys/gnu/i386/isa/dgb.c,v 1.56.2.1 2001/02/26 04:23:09 jlemon Exp $ - * dgb.c $DragonFly: src/sys/platform/pc32/gnu/isa/dgb.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * dgb.c $DragonFly: src/sys/platform/pc32/gnu/isa/dgb.c,v 1.11 2004/05/19 22:52:57 dillon Exp $ * * Digiboard driver. * @@ -405,10 +405,7 @@ dgbprobe(dev) int i, v; u_long win_size; /* size of vizible memory window */ int unit=dev->id_unit; - static int once; - if (!once++) - cdevsw_add(&dgb_cdevsw); sc->unit=dev->id_unit; sc->port=dev->id_iobase; @@ -897,22 +894,23 @@ load_fep: port->it_out = port->it_in; /* MAX_DGB_PORTS is 32 => [0-9a-v] */ suffix = i < 10 ? '0' + i : 'a' + i - 10; - make_dev(&dgb_cdevsw, (unit*32)+i, + cdevsw_add(&dgb_cdevsw, 0xffff0000, unit << 16); + make_dev(&dgb_cdevsw, (unit<<16)+i, UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+32, + make_dev(&dgb_cdevsw, (unit<<16)+i+32, UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+64, + make_dev(&dgb_cdevsw, (unit<<16)+i+64, UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+128, + make_dev(&dgb_cdevsw, (unit<<16)+i+128, UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+160, + make_dev(&dgb_cdevsw, (unit<<16)+i+160, UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix); - make_dev(&dgb_cdevsw, (unit*32)+i+192, + make_dev(&dgb_cdevsw, (unit<<16)+i+192, UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix); } diff --git a/sys/platform/pc32/i386/autoconf.c b/sys/platform/pc32/i386/autoconf.c index ae4c5b96cf..406a851762 100644 --- a/sys/platform/pc32/i386/autoconf.c +++ b/sys/platform/pc32/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.11 2004/01/06 03:17:24 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.12 2004/05/19 22:52:57 dillon Exp $ */ /* @@ -306,8 +306,8 @@ setroot() return; } majdev = boot_translate_majdev(B_TYPE(bootdev)); - dev = makedev(majdev, 0); - if (dev_dport(dev) == NULL) + dev = udev2dev(makeudev(majdev, 0), 0); + if (!dev_is_good(dev)) return; unit = B_UNIT(bootdev); slice = B_SLICE(bootdev); @@ -330,8 +330,7 @@ setroot() part = B_PARTITION(bootdev); mindev = dkmakeminor(unit, slice, part); } - - newrootdev = makedev(majdev, mindev); + newrootdev = udev2dev(makeudev(majdev, mindev), 0); sname = dsname(newrootdev, unit, slice, part, partname); rootdevnames[0] = malloc(strlen(sname) + 6, M_DEVBUF, M_NOWAIT); sprintf(rootdevnames[0], "ufs:%s%s", sname, partname); diff --git a/sys/platform/pc32/i386/elan-mmcr.c b/sys/platform/pc32/i386/elan-mmcr.c index b8ed9fdb5a..ec35d10c06 100644 --- a/sys/platform/pc32/i386/elan-mmcr.c +++ b/sys/platform/pc32/i386/elan-mmcr.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/i386/i386/elan-mmcr.c,v 1.6.2.1 2002/09/17 22:39:53 sam Exp $ - * $DragonFly: src/sys/platform/pc32/i386/elan-mmcr.c,v 1.6 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/elan-mmcr.c,v 1.7 2004/05/19 22:52:57 dillon Exp $ * The AMD Elan sc520 is a system-on-chip gadget which is used in embedded * kind of things, see www.soekris.com for instance, and it has a few quirks * we need to deal with. @@ -147,6 +147,7 @@ elan_drvinit(void) if (elan_mmcr == NULL) return; printf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr); + cdevsw_add(&elan_cdevsw, 0, 0); make_dev(&elan_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "elan-mmcr"); return; } diff --git a/sys/platform/pc32/i386/mem.c b/sys/platform/pc32/i386/mem.c index 1bb1286215..75238c8190 100644 --- a/sys/platform/pc32/i386/mem.c +++ b/sys/platform/pc32/i386/mem.c @@ -39,7 +39,7 @@ * from: Utah $Hdr: mem.c 1.13 89/10/08$ * from: @(#)mem.c 7.2 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/mem.c,v 1.79.2.9 2003/01/04 22:58:01 njl Exp $ - * $DragonFly: src/sys/platform/pc32/i386/Attic/mem.c,v 1.10 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/Attic/mem.c,v 1.11 2004/05/19 22:52:57 dillon Exp $ */ /* @@ -528,6 +528,7 @@ mem_drvinit(void *unused) if (mem_range_softc.mr_op != NULL) mem_range_softc.mr_op->init(&mem_range_softc); + cdevsw_add(&mem_cdevsw, 0xf0, 0); make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM, 0640, "mem"); make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM, 0640, "kmem"); make_dev(&mem_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "null"); diff --git a/sys/platform/pc32/i386/perfmon.c b/sys/platform/pc32/i386/perfmon.c index d852e5d1ca..9a1e5b10bc 100644 --- a/sys/platform/pc32/i386/perfmon.c +++ b/sys/platform/pc32/i386/perfmon.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/perfmon.c,v 1.21 1999/09/25 18:24:04 phk Exp $ - * $DragonFly: src/sys/platform/pc32/i386/perfmon.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/perfmon.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include @@ -110,6 +110,9 @@ perfmon_init(void) break; } #endif /* SMP */ + + /* NOTE: really a minor of mem. perfmon gets 32-47 */ + cdevsw_add(&perfmon_cdevsw, 0xf0, 32); make_dev(&perfmon_cdevsw, 32, UID_ROOT, GID_KMEM, 0640, "perfmon"); } diff --git a/sys/platform/pc32/isa/asc.c b/sys/platform/pc32/isa/asc.c index d739840291..aa25acb01e 100644 --- a/sys/platform/pc32/isa/asc.c +++ b/sys/platform/pc32/isa/asc.c @@ -35,7 +35,7 @@ */ /* * $FreeBSD: src/sys/i386/isa/asc.c,v 1.42.2.2 2001/03/01 03:22:39 jlemon Exp $ - * $DragonFly: src/sys/platform/pc32/isa/asc.c,v 1.7 2004/05/13 23:49:23 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/isa/asc.c,v 1.8 2004/05/19 22:52:57 dillon Exp $ */ #include "use_asc.h" @@ -363,10 +363,6 @@ ascprobe (struct isa_device *isdp) int unit = isdp->id_unit; struct asc_unit *scu = unittab + unit; int stb; - static int once; - - if (!once++) - cdevsw_add(&asc_cdevsw); scu->base = isdp->id_iobase; /*** needed by the following macros ***/ scu->flags = FLAG_DEBUG; @@ -483,6 +479,7 @@ ascattach(struct isa_device *isdp) scu->selp.si_pid=(pid_t)0; #define ASC_UID 0 #define ASC_GID 13 + cdevsw_add(&asc_cdevsw, 0xc0, unit << 6); make_dev(&asc_cdevsw, unit<<6, ASC_UID, ASC_GID, 0666, "asc%d", unit); make_dev(&asc_cdevsw, ((unit<<6) + FRMT_PBM), ASC_UID, ASC_GID, 0666, "asc%dp", unit); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index b24cd250ec..bc6067c6e5 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -37,7 +37,7 @@ * * @(#)conf.h 8.5 (Berkeley) 1/9/95 * $FreeBSD: src/sys/sys/conf.h,v 1.103.2.6 2002/03/11 01:14:55 dd Exp $ - * $DragonFly: src/sys/sys/conf.h,v 1.6 2004/05/13 23:49:25 dillon Exp $ + * $DragonFly: src/sys/sys/conf.h,v 1.7 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_CONF_H_ @@ -50,6 +50,7 @@ struct tty; struct disk; struct vnode; +struct lwkt_port; struct specinfo { u_int si_flags; @@ -59,8 +60,10 @@ struct specinfo { char si_name[SPECNAMELEN + 1]; void *si_drv1; void *si_drv2; - struct cdevsw *si_devsw; /* cached */ + struct cdevsw *si_devsw; /* direct device switch */ + struct lwkt_port *si_port; /* direct port dispatch */ int si_iosize_max; /* maximum I/O size (for physio &al) */ + int si_refs; union { struct { struct tty *__sit_tty; @@ -75,6 +78,8 @@ struct specinfo { }; #define SI_STASHED 0x0001 /* created in stashed storage */ +#define SI_HASHED 0x0002 /* in (maj,min) hash table */ +#define SI_ADHOC 0x0004 /* created via make_adhoc_dev() or udev2dev() */ #define si_tty __si_u.__si_tty.__sit_tty #define si_disk __si_u.__si_disk.__sid_disk @@ -82,11 +87,7 @@ struct specinfo { #define si_bsize_phys __si_u.__si_disk.__sid_bsize_phys #define si_bsize_best __si_u.__si_disk.__sid_bsize_best -/* - * Exported shorthand - */ -#define v_hashchain v_rdev->si_hlist -#define v_specmountpoint v_rdev->si_mountpoint +#define CDEVSW_ALL_MINORS 0 /* mask of 0 always matches 0 */ /* * Special device management @@ -129,7 +130,7 @@ typedef int d_close_t (dev_t dev, int fflag, int devtype, d_thread_t *td); typedef void d_strategy_t (struct buf *bp); typedef int d_ioctl_t (dev_t dev, u_long cmd, caddr_t data, int fflag, d_thread_t *td); -typedef int d_dump_t (dev_t dev); +typedef int d_dump_t (dev_t dev, u_int count, u_int blkno, u_int secsize); typedef int d_psize_t (dev_t dev); typedef int d_read_t (dev_t dev, struct uio *uio, int ioflag); @@ -204,6 +205,19 @@ struct cdevsw { d_dump_t *old_dump; d_psize_t *old_psize; d_kqfilter_t *old_kqfilter; + void (*old_dummy1)(void); /* expansion space */ + void (*old_dummy2)(void); + void (*old_dummy3)(void); + void (*old_dummy4)(void); + int d_refs; /* ref count */ + void *d_data; /* custom driver data */ +}; + +struct cdevlink { + struct cdevlink *next; + u_int mask; + u_int match; + struct cdevsw *devsw; }; /* @@ -250,20 +264,16 @@ d_close_t noclose; d_read_t noread; d_write_t nowrite; d_ioctl_t noioctl; +d_clone_t noclone; d_mmap_t nommap; d_kqfilter_t nokqfilter; -#define nostrategy ((d_strategy_t *)NULL) -#define nopoll seltrue - +d_strategy_t nostrategy; +d_poll_t nopoll; +d_psize_t nopsize; d_dump_t nodump; #define NUMCDEVSW 256 -/* - * nopsize is little used, so not worth having dummy functions for. - */ -#define nopsize ((d_psize_t *)NULL) - d_open_t nullopen; d_close_t nullclose; @@ -287,22 +297,33 @@ static moduledata_t name##_mod = { \ }; \ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) -void compile_devsw(struct cdevsw *devsw); -int cdevsw_add (struct cdevsw *new); -struct lwkt_port *cdevsw_add_override (struct cdevsw *new, struct lwkt_port *port); +extern struct cdevsw dead_cdevsw; + +void compile_devsw(struct cdevsw *); +int cdevsw_add (struct cdevsw *, u_int mask, u_int match); +struct cdevsw *cdevsw_add_override (dev_t, u_int mask, u_int match); struct lwkt_port *cdevsw_dev_override(dev_t dev, struct lwkt_port *port); -int cdevsw_remove (struct cdevsw *old); +int cdevsw_remove (struct cdevsw *, u_int mask, u_int match); +struct cdevsw *cdevsw_get (int x, int y); +void cdevsw_release (struct cdevsw *); int count_dev (dev_t dev); +int count_udev (udev_t dev); void destroy_dev (dev_t dev); +void destroy_all_dev (struct cdevsw *, u_int mask, u_int match); +void release_dev (dev_t dev); +dev_t reference_dev (dev_t dev); struct cdevsw *devsw (dev_t dev); const char *devtoname (dev_t dev); void freedev (dev_t dev); int iszerodev (dev_t dev); dev_t make_dev (struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(6, 7); +dev_t make_adhoc_dev (struct cdevsw *devsw, int minor); +dev_t make_sub_dev (dev_t dev, int minor); int lminor (dev_t dev); void setconf (void); dev_t getdiskbyname(char *name); +int dev_is_good(dev_t dev); /* * XXX: This included for when DEVFS resurfaces diff --git a/sys/sys/device.h b/sys/sys/device.h index 018aeb44dc..9c761e51fa 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/device.h,v 1.1 2003/07/22 17:03:34 dillon Exp $ + * $DragonFly: src/sys/sys/device.h,v 1.2 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_DEVICE_H_ @@ -39,7 +39,6 @@ struct cdevmsg { lwkt_msg msg; dev_t dev; - struct cdevsw *csw; }; /* @@ -86,6 +85,9 @@ struct cdevmsg_ioctl { */ struct cdevmsg_dump { struct cdevmsg msg; + u_int count; + u_int blkno; + u_int secsize; }; /* @@ -204,18 +206,6 @@ int dev_dpoll(dev_t dev, int events, struct thread *td); int dev_dkqfilter(dev_t dev, struct knote *kn); int dev_dmmap(dev_t dev, vm_offset_t offset, int nprot); -int dev_port_dopen(lwkt_port_t port, dev_t dev, int oflags, int devtype, struct thread *td); -int dev_port_dclose(lwkt_port_t port, dev_t dev, int fflag, int devtype, struct thread *td); -void dev_port_dstrategy(lwkt_port_t port, dev_t dev, struct buf *bp); -int dev_port_dioctl(lwkt_port_t port, dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td); -int dev_port_ddump(lwkt_port_t port, dev_t dev); -int dev_port_dpsize(lwkt_port_t port, dev_t dev); -int dev_port_dread(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag); -int dev_port_dwrite(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag); -int dev_port_dpoll(lwkt_port_t port, dev_t dev, int events, struct thread *td); -int dev_port_dkqfilter(lwkt_port_t port, dev_t dev, struct knote *kn); -int dev_port_dmmap(lwkt_port_t port, dev_t dev, vm_offset_t offset, int nprot); - #endif #endif diff --git a/sys/sys/disk.h b/sys/sys/disk.h index e4691c6440..a906275883 100644 --- a/sys/sys/disk.h +++ b/sys/sys/disk.h @@ -1,4 +1,28 @@ /* + * Copyright (c) 2004 Matthew Dillon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. + * * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you @@ -7,8 +31,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/sys/disk.h,v 1.16.2.3 2001/06/20 16:11:01 scottl Exp $ - * $DragonFly: src/sys/sys/disk.h,v 1.4 2003/08/20 07:31:21 rob Exp $ - * + * $DragonFly: src/sys/sys/disk.h,v 1.5 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_DISK_H_ @@ -28,10 +51,12 @@ struct disk { struct lwkt_port d_port; /* interception port */ - struct lwkt_port *d_fwdport; /* forward to real port */ + struct cdevsw *d_devsw; /* our device switch */ + struct cdevsw *d_rawsw; /* the raw device switch */ u_int d_flags; u_int d_dsflags; - dev_t d_dev; + dev_t d_rawdev; /* backing raw device */ + dev_t d_cdev; /* special whole-disk part */ struct diskslices *d_slice; struct disklabel d_label; LIST_ENTRY(disk) d_list; @@ -40,7 +65,7 @@ struct disk { #define DISKFLAG_LOCK 0x1 #define DISKFLAG_WANTED 0x2 -dev_t disk_create (int unit, struct disk *disk, int flags, struct cdevsw *cdevsw); +dev_t disk_create (int unit, struct disk *disk, int flags, struct cdevsw *sw); void disk_destroy (struct disk *disk); int disk_dumpcheck (dev_t dev, u_int *count, u_int *blkno, u_int *secsize); struct disk *disk_enumerate (struct disk *disk); diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index f223e139e0..a98cf06770 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel.h,v 1.5 2004/03/04 01:37:57 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel.h,v 1.6 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -42,6 +42,7 @@ #include #endif #include +#include /* * Disk description table, see disktab(5) @@ -384,6 +385,19 @@ struct partinfo { (((slice) << 16) | (((unit) & 0x1e0) << 16) | \ (((unit) & 0x1f) << 3) | (part & 7) | \ ((part & 0x08) << 17)) + +static __inline u_int +dkunitmask(void) +{ + return (0x01e000f8); +} + +static __inline u_int +dkmakeunit(int unit) +{ + return(dkmakeminor(unit, 0, 0)); +} + static __inline dev_t dkmodpart(dev_t dev, int part) { @@ -393,13 +407,13 @@ dkmodpart(dev_t dev, int part) val = (part & 7); else val = (part & 7) | 0x100000; - return (makedev(major(dev), (minor(dev) & ~0x100007) | val)); + return (make_sub_dev(dev, (minor(dev) & ~0x100007) | val)); } static __inline dev_t dkmodslice(dev_t dev, int slice) { - return (makedev(major(dev), (minor(dev) & ~0x0f0000) | (slice << 16))); + return (make_sub_dev(dev, (minor(dev) & ~0x0f0000) | (slice << 16))); } static __inline int diff --git a/sys/sys/disklabel32.h b/sys/sys/disklabel32.h index 5f3d8e67d8..47c2daf230 100644 --- a/sys/sys/disklabel32.h +++ b/sys/sys/disklabel32.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel32.h,v 1.5 2004/03/04 01:37:57 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel32.h,v 1.6 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -42,6 +42,7 @@ #include #endif #include +#include /* * Disk description table, see disktab(5) @@ -384,6 +385,19 @@ struct partinfo { (((slice) << 16) | (((unit) & 0x1e0) << 16) | \ (((unit) & 0x1f) << 3) | (part & 7) | \ ((part & 0x08) << 17)) + +static __inline u_int +dkunitmask(void) +{ + return (0x01e000f8); +} + +static __inline u_int +dkmakeunit(int unit) +{ + return(dkmakeminor(unit, 0, 0)); +} + static __inline dev_t dkmodpart(dev_t dev, int part) { @@ -393,13 +407,13 @@ dkmodpart(dev_t dev, int part) val = (part & 7); else val = (part & 7) | 0x100000; - return (makedev(major(dev), (minor(dev) & ~0x100007) | val)); + return (make_sub_dev(dev, (minor(dev) & ~0x100007) | val)); } static __inline dev_t dkmodslice(dev_t dev, int slice) { - return (makedev(major(dev), (minor(dev) & ~0x0f0000) | (slice << 16))); + return (make_sub_dev(dev, (minor(dev) & ~0x0f0000) | (slice << 16))); } static __inline int diff --git a/sys/sys/odisklabel.h b/sys/sys/odisklabel.h index 2c43559486..51a2f8b681 100644 --- a/sys/sys/odisklabel.h +++ b/sys/sys/odisklabel.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/Attic/odisklabel.h,v 1.5 2004/03/04 01:37:57 dillon Exp $ + * $DragonFly: src/sys/sys/Attic/odisklabel.h,v 1.6 2004/05/19 22:53:02 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -42,6 +42,7 @@ #include #endif #include +#include /* * Disk description table, see disktab(5) @@ -384,6 +385,19 @@ struct partinfo { (((slice) << 16) | (((unit) & 0x1e0) << 16) | \ (((unit) & 0x1f) << 3) | (part & 7) | \ ((part & 0x08) << 17)) + +static __inline u_int +dkunitmask(void) +{ + return (0x01e000f8); +} + +static __inline u_int +dkmakeunit(int unit) +{ + return(dkmakeminor(unit, 0, 0)); +} + static __inline dev_t dkmodpart(dev_t dev, int part) { @@ -393,13 +407,13 @@ dkmodpart(dev_t dev, int part) val = (part & 7); else val = (part & 7) | 0x100000; - return (makedev(major(dev), (minor(dev) & ~0x100007) | val)); + return (make_sub_dev(dev, (minor(dev) & ~0x100007) | val)); } static __inline dev_t dkmodslice(dev_t dev, int slice) { - return (makedev(major(dev), (minor(dev) & ~0x0f0000) | (slice << 16))); + return (make_sub_dev(dev, (minor(dev) & ~0x0f0000) | (slice << 16))); } static __inline int diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 9714ccd85f..3f95cdc2ab 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -37,7 +37,7 @@ * * @(#)systm.h 8.7 (Berkeley) 3/29/95 * $FreeBSD: src/sys/sys/systm.h,v 1.111.2.18 2002/12/17 18:04:02 sam Exp $ - * $DragonFly: src/sys/sys/systm.h,v 1.18 2004/03/05 19:29:17 hsu Exp $ + * $DragonFly: src/sys/sys/systm.h,v 1.19 2004/05/19 22:53:03 dillon Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -363,7 +363,6 @@ void wakeup_one (void *chan); int major(dev_t x); int minor(dev_t x); -dev_t makedev(int x, int y); udev_t dev2udev(dev_t x); dev_t udev2dev(udev_t x, int b); int uminor(udev_t dev); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 179b935ad7..fb1618043d 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -32,7 +32,7 @@ * * @(#)vnode.h 8.7 (Berkeley) 2/4/94 * $FreeBSD: src/sys/sys/vnode.h,v 1.111.2.19 2002/12/29 18:19:53 dillon Exp $ - * $DragonFly: src/sys/sys/vnode.h,v 1.15 2004/04/24 04:32:03 drhodus Exp $ + * $DragonFly: src/sys/sys/vnode.h,v 1.16 2004/05/19 22:53:03 dillon Exp $ */ #ifndef _SYS_VNODE_H_ @@ -89,12 +89,16 @@ typedef int vop_t (void *); * v_flag, v_usecount, v_holdcount and v_writecount are * locked by the v_interlock token. * v_pollinfo is locked by the lock contained inside it. + * + * XXX note: v_opencount currently only used by specfs. It should be used + * universally. */ struct vnode { u_long v_flag; /* vnode flags (see below) */ int v_usecount; /* reference count of users */ int v_writecount; /* reference count of writers */ int v_holdcnt; /* page & buffer references */ + int v_opencount; /* number of explicit opens */ u_long v_id; /* capability identifier */ struct mount *v_mount; /* ptr to vfs we are in */ vop_t **v_op; /* vnode operations vector */ @@ -109,6 +113,7 @@ struct vnode { struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ struct socket *vu_socket; /* unix ipc (VSOCK) */ struct { + udev_t vu_udev; /* device number for attach */ struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ SLIST_ENTRY(vnode) vu_specnext; } vu_spec; @@ -140,6 +145,7 @@ struct vnode { }; #define v_mountedhere v_un.vu_mountedhere #define v_socket v_un.vu_socket +#define v_udev v_un.vu_spec.vu_udev #define v_rdev v_un.vu_spec.vu_specinfo #define v_specnext v_un.vu_spec.vu_specnext #define v_fifoinfo v_un.vu_fifoinfo @@ -525,8 +531,9 @@ struct vop_bwrite_args; extern int (*lease_check_hook) (struct vop_lease_args *); -void addalias (struct vnode *vp, dev_t nvp_rdev); -void addaliasu (struct vnode *vp, udev_t nvp_rdev); +void addaliasu (struct vnode *vp, udev_t nvp_udev); +int v_associate_rdev(struct vnode *vp, dev_t dev); +void v_release_rdev(struct vnode *vp); int bdevvp (dev_t dev, struct vnode **vpp); void cvtstat (struct stat *st, struct ostat *ost); void cvtnstat (struct stat *sb, struct nstat *nsb); diff --git a/sys/vfs/coda/coda_fbsd.c b/sys/vfs/coda/coda_fbsd.c index 20768c4d85..874b07af30 100644 --- a/sys/vfs/coda/coda_fbsd.c +++ b/sys/vfs/coda/coda_fbsd.c @@ -28,7 +28,7 @@ * * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD: src/sys/coda/coda_fbsd.c,v 1.18 1999/09/25 18:23:43 phk Exp $ - * $DragonFly: src/sys/vfs/coda/Attic/coda_fbsd.c,v 1.6 2004/05/13 23:49:26 dillon Exp $ + * $DragonFly: src/sys/vfs/coda/Attic/coda_fbsd.c,v 1.7 2004/05/19 22:53:03 dillon Exp $ * */ @@ -91,12 +91,12 @@ int vcdebug = 1; static int codadev_modevent(module_t mod, int type, void *data) { - switch (type) { case MOD_LOAD: - cdevsw_add(&codadevsw); + cdevsw_add(&codadevsw, 0, 0); break; case MOD_UNLOAD: + cdevsw_remove(&codadevsw, 0, 0); break; default: break; diff --git a/sys/vfs/coda/coda_vfsops.c b/sys/vfs/coda/coda_vfsops.c index 8a5f649a8c..2fb01d354c 100644 --- a/sys/vfs/coda/coda_vfsops.c +++ b/sys/vfs/coda/coda_vfsops.c @@ -28,7 +28,7 @@ * * @(#) src/sys/cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD: src/sys/coda/coda_vfsops.c,v 1.24.2.1 2001/07/26 20:36:45 iedowse Exp $ - * $DragonFly: src/sys/vfs/coda/Attic/coda_vfsops.c,v 1.13 2004/03/31 02:34:37 cpressey Exp $ + * $DragonFly: src/sys/vfs/coda/Attic/coda_vfsops.c,v 1.14 2004/05/19 22:53:04 dillon Exp $ * */ @@ -118,7 +118,7 @@ coda_mount(struct mount *vfsp, /* Allocated and initialized by mount(2) */ { struct vnode *dvp; struct cnode *cp; - dev_t dev; + udev_t udev; struct coda_mntinfo *mi; struct vnode *rootvp; ViceFid rootfid; @@ -151,7 +151,7 @@ coda_mount(struct mount *vfsp, /* Allocated and initialized by mount(2) */ NDFREE(ndp, NDF_ONLY_PNBUF); return(ENXIO); } - dev = dvp->v_rdev; + udev = dvp->v_rdev; vrele(dvp); NDFREE(ndp, NDF_ONLY_PNBUF); @@ -166,7 +166,7 @@ coda_mount(struct mount *vfsp, /* Allocated and initialized by mount(2) */ } #endif - if (minor(dev) >= NVCODA || minor(dev) < 0) { + if (uminor(udev) >= NVCODA || uminor(udev) < 0) { MARK_INT_FAIL(CODA_MOUNT_STATS); return(ENXIO); } @@ -174,7 +174,7 @@ coda_mount(struct mount *vfsp, /* Allocated and initialized by mount(2) */ /* * Initialize the mount record and link it to the vfs struct */ - mi = &coda_mnttbl[minor(dev)]; + mi = &coda_mnttbl[uminor(udev)]; if (!VC_OPEN(&mi->mi_vcomm)) { MARK_INT_FAIL(CODA_MOUNT_STATS); diff --git a/sys/vfs/gnu/ext2fs/ext2_vfsops.c b/sys/vfs/gnu/ext2fs/ext2_vfsops.c index da565f8768..113532c647 100644 --- a/sys/vfs/gnu/ext2fs/ext2_vfsops.c +++ b/sys/vfs/gnu/ext2fs/ext2_vfsops.c @@ -38,7 +38,7 @@ * * @(#)ffs_vfsops.c 8.8 (Berkeley) 4/18/94 * $FreeBSD: src/sys/gnu/ext2fs/ext2_vfsops.c,v 1.63.2.7 2002/07/01 00:18:51 iedowse Exp $ - * $DragonFly: src/sys/vfs/gnu/ext2fs/ext2_vfsops.c,v 1.14 2004/04/24 04:32:03 drhodus Exp $ + * $DragonFly: src/sys/vfs/gnu/ext2fs/ext2_vfsops.c,v 1.15 2004/05/19 22:53:04 dillon Exp $ */ #include "opt_quota.h" @@ -639,7 +639,7 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) struct buf *bp; struct ext2_sb_info *fs; struct ext2_super_block * es; - dev_t dev = devvp->v_rdev; + dev_t dev; struct partinfo dpart; int havepart = 0; int error, i, size; @@ -653,7 +653,7 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) */ if ((error = vfs_mountedon(devvp)) != 0) return (error); - if (vcount(devvp) > 1 && devvp != rootvp) + if (count_udev(devvp) > 0 && devvp != rootvp) return (EBUSY); if ((error = vinvalbuf(devvp, V_SAVE, td, 0, 0)) != 0) return (error); @@ -668,8 +668,9 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) VOP_UNLOCK(devvp, NULL, 0, td); if (error) return (error); - if (devvp->v_rdev->si_iosize_max != 0) - mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max; + dev = devvp->v_rdev; + if (dev->si_iosize_max != 0) + mp->mnt_iosize_max = dev->si_iosize_max; if (mp->mnt_iosize_max > MAXPHYS) mp->mnt_iosize_max = MAXPHYS; if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, td) != 0) @@ -751,7 +752,7 @@ ext2_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) ump->um_seqinc = EXT2_FRAGS_PER_BLOCK(fs); for (i = 0; i < MAXQUOTAS; i++) ump->um_quotas[i] = NULLVP; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; if (ronly == 0) ext2_sbupdate(ump, MNT_WAIT); return (0); @@ -809,7 +810,7 @@ ext2_unmount(struct mount *mp, int mntflags, struct thread *td) if (fs->s_block_bitmap[i]) ULCK_BUF(fs->s_block_bitmap[i]) - ump->um_devvp->v_specmountpoint = NULL; + ump->um_devvp->v_rdev->si_mountpoint = NULL; error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE, td); vrele(ump->um_devvp); bsd_free(fs->s_es, M_UFSMNT); diff --git a/sys/vfs/hpfs/hpfs_vfsops.c b/sys/vfs/hpfs/hpfs_vfsops.c index 60eed76d28..fe83989f15 100644 --- a/sys/vfs/hpfs/hpfs_vfsops.c +++ b/sys/vfs/hpfs/hpfs_vfsops.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/fs/hpfs/hpfs_vfsops.c,v 1.3.2.2 2001/12/25 01:44:45 dillon Exp $ - * $DragonFly: src/sys/vfs/hpfs/hpfs_vfsops.c,v 1.15 2004/04/24 04:32:04 drhodus Exp $ + * $DragonFly: src/sys/vfs/hpfs/hpfs_vfsops.c,v 1.16 2004/05/19 22:53:04 dillon Exp $ */ @@ -231,7 +231,7 @@ hpfs_mount(struct mount *mp, err = ENOTBLK; goto error_2; } - if (major(devvp->v_rdev) >= nblkdev) { + if (umajor(devvp->v_udev) >= nblkdev) { err = ENXIO; goto error_2; } @@ -302,7 +302,7 @@ hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp, struct hpfsmount *hpmp; struct buf *bp = NULL; struct vnode *vp; - dev_t dev = devvp->v_rdev; + dev_t dev; dprintf(("hpfs_mountfs():\n")); /* @@ -314,12 +314,12 @@ hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp, error = vfs_mountedon(devvp); if (error) return (error); - ncount = vcount(devvp); + ncount = count_udev(devvp); #if defined(__DragonFly__) if (devvp->v_object) ncount -= 1; #endif - if (ncount > 1 && devvp != rootvp) + if (ncount > 0 && devvp != rootvp) return (EBUSY); #if defined(__DragonFly__) @@ -338,6 +338,7 @@ hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp, VOP__UNLOCK(devvp, 0, td); if (error) return (error); + dev = devvp->v_rdev; /* * Do actual mount @@ -376,7 +377,7 @@ hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp, mp->mnt_data = (qaddr_t)hpmp; hpmp->hpm_devvp = devvp; - hpmp->hpm_dev = devvp->v_rdev; + hpmp->hpm_dev = dev; hpmp->hpm_mp = mp; hpmp->hpm_uid = argsp->uid; hpmp->hpm_gid = argsp->gid; @@ -410,7 +411,7 @@ hpfs_mountfs(struct vnode *devvp, struct mount *mp, struct hpfs_args *argsp, #endif mp->mnt_maxsymlinklen = 0; mp->mnt_flag |= MNT_LOCAL; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; return (0); failed: @@ -418,7 +419,7 @@ failed: brelse (bp); mp->mnt_data = (qaddr_t)NULL; #if defined(__DragonFly__) - devvp->v_specmountpoint = NULL; + dev->si_mountpoint = NULL; #else devvp->v_specflags &= ~SI_MOUNTEDON; #endif @@ -457,7 +458,7 @@ hpfs_unmount(struct mount *mp, int mntflags, struct thread *td) } #if defined(__DragonFly__) - hpmp->hpm_devvp->v_specmountpoint = NULL; + hpmp->hpm_devvp->v_rdev->si_mountpoint = NULL; #else hpmp->hpm_devvp->v_specflags &= ~SI_MOUNTEDON; #endif diff --git a/sys/vfs/isofs/cd9660/cd9660_vfsops.c b/sys/vfs/isofs/cd9660/cd9660_vfsops.c index 8fafed0375..c014603f9e 100644 --- a/sys/vfs/isofs/cd9660/cd9660_vfsops.c +++ b/sys/vfs/isofs/cd9660/cd9660_vfsops.c @@ -37,7 +37,7 @@ * * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vfsops.c,v 1.74.2.7 2002/04/08 09:39:29 bde Exp $ - * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vfsops.c,v 1.14 2004/04/24 04:32:04 drhodus Exp $ + * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vfsops.c,v 1.15 2004/05/19 22:53:04 dillon Exp $ */ #include @@ -268,7 +268,7 @@ iso_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, struct iso_mnt *isomp = (struct iso_mnt *)0; struct buf *bp = NULL; struct buf *pribp = NULL, *supbp = NULL; - dev_t dev = devvp->v_rdev; + dev_t dev; int error = EINVAL; int needclose = 0; int high_sierra = 0; @@ -293,7 +293,7 @@ iso_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, */ if ((error = vfs_mountedon(devvp))) return error; - if (vcount(devvp) > 1 && devvp != rootvp) + if (count_udev(devvp) > 0 && devvp != rootvp) return EBUSY; if ((error = vinvalbuf(devvp, V_SAVE, td, 0, 0))) return (error); @@ -303,8 +303,9 @@ iso_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, VOP_UNLOCK(devvp, NULL, 0, td); if (error) return error; - if (devvp->v_rdev->si_iosize_max != 0) - mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max; + dev = devvp->v_rdev; + if (dev->si_iosize_max != 0) + mp->mnt_iosize_max = dev->si_iosize_max; if (mp->mnt_iosize_max > MAXPHYS) mp->mnt_iosize_max = MAXPHYS; @@ -440,7 +441,7 @@ iso_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, isomp->im_dev = dev; isomp->im_devvp = devvp; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; /* Check the Rock Ridge Extention support */ if (!(argp->flags & ISOFSMNT_NORRIP)) { @@ -507,7 +508,7 @@ iso_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, return 0; out: - devvp->v_specmountpoint = NULL; + dev->si_mountpoint = NULL; if (bp) brelse(bp); if (pribp) @@ -544,7 +545,7 @@ cd9660_unmount(struct mount *mp, int mntflags, struct thread *td) isomp = VFSTOISOFS(mp); - isomp->im_devvp->v_specmountpoint = NULL; + isomp->im_devvp->v_rdev->si_mountpoint = NULL; error = VOP_CLOSE(isomp->im_devvp, FREAD, td); vrele(isomp->im_devvp); free((caddr_t)isomp, M_ISOFSMNT); diff --git a/sys/vfs/mfs/mfs_vfsops.c b/sys/vfs/mfs/mfs_vfsops.c index b6824ca869..47b429590a 100644 --- a/sys/vfs/mfs/mfs_vfsops.c +++ b/sys/vfs/mfs/mfs_vfsops.c @@ -32,7 +32,7 @@ * * @(#)mfs_vfsops.c 8.11 (Berkeley) 6/19/95 * $FreeBSD: src/sys/ufs/mfs/mfs_vfsops.c,v 1.81.2.3 2001/07/04 17:35:21 tegge Exp $ - * $DragonFly: src/sys/vfs/mfs/mfs_vfsops.c,v 1.14 2004/05/13 23:49:26 dillon Exp $ + * $DragonFly: src/sys/vfs/mfs/mfs_vfsops.c,v 1.15 2004/05/19 22:53:04 dillon Exp $ */ @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -65,8 +66,6 @@ MALLOC_DEFINE(M_MFSNODE, "MFS node", "MFS vnode private part"); -static int mfs_minor; /* used for building internal dev_t */ - extern vop_t **mfs_vnodeop_p; static int mfs_mount (struct mount *mp, @@ -77,6 +76,10 @@ static int mfs_statfs (struct mount *mp, struct statfs *sbp, struct thread *td); static int mfs_init (struct vfsconf *); +d_open_t mfsopen; +d_close_t mfsclose; +d_strategy_t mfsstrategy; + #define MFS_CDEV_MAJOR 253 static struct cdevsw mfs_cdevsw = { @@ -86,14 +89,14 @@ static struct cdevsw mfs_cdevsw = { /* port */ NULL, /* clone */ NULL, - /* open */ noopen, - /* close */ noclose, + /* open */ mfsopen, + /* close */ mfsclose, /* read */ physread, /* write */ physwrite, /* ioctl */ noioctl, /* poll */ nopoll, /* mmap */ nommap, - /* strategy */ nostrategy, + /* strategy */ mfsstrategy, /* dump */ nodump, /* psize */ nopsize }; @@ -120,6 +123,54 @@ static struct vfsops mfs_vfsops = { VFS_SET(mfs_vfsops, mfs, 0); +/* + * We allow the underlying MFS block device to be opened and read. + */ +int +mfsopen(dev_t dev, int flags, int mode, struct thread *td) +{ + if (flags & FWRITE) + return(EROFS); + if (dev->si_drv1) + return(0); + return(ENXIO); +} + +int +mfsclose(dev_t dev, int flags, int mode, struct thread *td) +{ + return(0); +} + +void +mfsstrategy(struct buf *bp) +{ + struct mfsnode *mfsp; + + if ((mfsp = bp->b_dev->si_drv1) != NULL) { + off_t boff = (off_t)bp->b_blkno << DEV_BSHIFT; + off_t eoff = boff + bp->b_bcount; + + if (eoff <= mfsp->mfs_size) { + bufq_insert_tail(&mfsp->buf_queue, bp); + wakeup((caddr_t)mfsp); + } else if (boff < mfsp->mfs_size) { + bp->b_bcount = mfsp->mfs_size - boff; + bufq_insert_tail(&mfsp->buf_queue, bp); + wakeup((caddr_t)mfsp); + } else if (boff == mfsp->mfs_size) { + bp->b_resid = bp->b_bcount; + biodone(bp); + } else { + bp->b_error = EINVAL; + biodone(bp); + } + } else { + bp->b_error = ENXIO; + bp->b_flags |= B_ERROR; + biodone(bp); + } +} /* * mfs_mount @@ -170,6 +221,7 @@ mfs_mount(struct mount *mp, char *path, caddr_t data, struct nameidata *ndp, struct mfsnode *mfsp; size_t size; int flags, err; + int minnum; dev_t dev; /* @@ -243,16 +295,23 @@ mfs_mount(struct mount *mp, char *path, caddr_t data, struct nameidata *ndp, FREE(mfsp, M_MFSNODE); goto error_1; } + + minnum = (curproc->p_pid & 0xFF) | + ((curproc->p_pid & ~0xFF) << 8); + devvp->v_type = VCHR; - dev = make_dev(&mfs_cdevsw, mfs_minor, 0, 0, 0, "MFS%d", mfs_minor); + dev = make_dev(&mfs_cdevsw, minnum, UID_ROOT, GID_WHEEL, 0600, + "MFS%d", minnum >> 16); /* It is not clear that these will get initialized otherwise */ dev->si_bsize_phys = DEV_BSIZE; dev->si_iosize_max = DFLTPHYS; - addaliasu(devvp, makeudev(253, mfs_minor++)); + dev->si_drv1 = mfsp; + addaliasu(devvp, makeudev(MFS_CDEV_MAJOR, minnum)); devvp->v_data = mfsp; mfsp->mfs_baseoff = args.base; mfsp->mfs_size = args.size; mfsp->mfs_vnode = devvp; + mfsp->mfs_dev = reference_dev(dev); mfsp->mfs_td = td; mfsp->mfs_active = 1; bufq_init(&mfsp->buf_queue); @@ -365,10 +424,12 @@ mfs_start(struct mount *mp, int flags, struct thread *td) SIGDELSET(td->td_proc->p_siglist, sig); } } - else if (tsleep((caddr_t)vp, PCATCH, "mfsidl", 0)) + else if (tsleep((caddr_t)mfsp, PCATCH, "mfsidl", 0)) gotsig++; /* try to unmount in next pass */ } PRELE(curproc); + v_release_rdev(vp); /* hack because we do not implement CLOSE */ + /* XXX destroy/release devvp */ return (0); } @@ -391,6 +452,6 @@ mfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td) static int mfs_init(struct vfsconf *vfsp) { - cdevsw_add(&mfs_cdevsw); + cdevsw_add(&mfs_cdevsw, 0, 0); return (0); } diff --git a/sys/vfs/mfs/mfs_vnops.c b/sys/vfs/mfs/mfs_vnops.c index 1a63d3357e..587d877d4f 100644 --- a/sys/vfs/mfs/mfs_vnops.c +++ b/sys/vfs/mfs/mfs_vnops.c @@ -32,7 +32,7 @@ * * @(#)mfs_vnops.c 8.11 (Berkeley) 5/22/95 * $FreeBSD: src/sys/ufs/mfs/mfs_vnops.c,v 1.47.2.1 2001/05/22 02:06:43 bp Exp $ - * $DragonFly: src/sys/vfs/mfs/mfs_vnops.c,v 1.12 2004/04/15 00:59:41 cpressey Exp $ + * $DragonFly: src/sys/vfs/mfs/mfs_vnops.c,v 1.13 2004/05/19 22:53:04 dillon Exp $ */ #include @@ -100,6 +100,10 @@ VNODEOP_SET(mfs_vnodeop_opv_desc); * validate before actual IO. Record our process identifier * so we can tell when we are doing I/O to ourself. * + * NOTE: new device sequencing. mounts check the device reference count + * before calling open, so we must associate the device in open and + * disassociate it in close rather then faking it when we created the vnode. + * * mfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred, * struct thread *a_td) */ @@ -107,10 +111,11 @@ VNODEOP_SET(mfs_vnodeop_opv_desc); static int mfs_open(struct vop_open_args *ap) { - if (ap->a_vp->v_type != VCHR) { + struct vnode *vp = ap->a_vp; + + if (vp->v_type != VCHR) panic("mfs_open not VCHR"); - /* NOTREACHED */ - } + v_associate_rdev(vp, udev2dev(vp->v_udev, 0)); return (0); } @@ -136,14 +141,11 @@ static int mfs_freeblks(struct vop_freeblks_args *ap) { struct buf *bp; - struct vnode *vp; - - if (!vfinddev(ap->a_vp->v_rdev, VCHR, &vp) || vp->v_usecount == 0) - panic("mfs_freeblks: bad dev"); + struct vnode *vp = ap->a_vp; bp = geteblk(ap->a_length); bp->b_flags |= B_FREEBUF | B_ASYNC; - bp->b_dev = ap->a_vp->v_rdev; + bp->b_dev = vp->v_rdev; bp->b_blkno = ap->a_addr; bp->b_offset = dbtob(ap->a_addr); bp->b_bcount = ap->a_length; @@ -162,13 +164,17 @@ mfs_strategy(struct vop_strategy_args *ap) { struct buf *bp = ap->a_bp; struct mfsnode *mfsp; - struct vnode *vp; struct thread *td = curthread; /* XXX */ int s; - if (!vfinddev(bp->b_dev, VCHR, &vp) || vp->v_usecount == 0) - panic("mfs_strategy: bad dev"); - mfsp = VTOMFS(vp); + bp->b_dev = ap->a_vp->v_rdev; + mfsp = bp->b_dev->si_drv1; + if (mfsp == NULL) { + bp->b_error = ENXIO; + bp->b_flags |= B_ERROR; + biodone(bp); + return(0); + } /* * splbio required for queueing/dequeueing, in case of forwarded @@ -205,7 +211,7 @@ mfs_strategy(struct vop_strategy_args *ap) * wake it up. */ bufq_insert_tail(&mfsp->buf_queue, bp); - wakeup((caddr_t)vp); + wakeup((caddr_t)mfsp); } splx(s); return (0); @@ -331,7 +337,12 @@ mfs_close(struct vop_close_args *ap) * Send a request to the filesystem server to exit. */ mfsp->mfs_active = 0; - wakeup((caddr_t)vp); + v_release_rdev(vp); + if (mfsp->mfs_dev) { + destroy_dev(mfsp->mfs_dev); + mfsp->mfs_dev = NULL; + } + wakeup((caddr_t)mfsp); return (0); } diff --git a/sys/vfs/mfs/mfsnode.h b/sys/vfs/mfs/mfsnode.h index 6799e366ca..5318a35f41 100644 --- a/sys/vfs/mfs/mfsnode.h +++ b/sys/vfs/mfs/mfsnode.h @@ -32,7 +32,7 @@ * * @(#)mfsnode.h 8.3 (Berkeley) 5/19/95 * $FreeBSD: src/sys/ufs/mfs/mfsnode.h,v 1.12.2.2 2001/07/04 17:35:21 tegge Exp $ - * $DragonFly: src/sys/vfs/mfs/mfsnode.h,v 1.3 2003/06/25 03:56:12 dillon Exp $ + * $DragonFly: src/sys/vfs/mfs/mfsnode.h,v 1.4 2004/05/19 22:53:04 dillon Exp $ */ #ifndef _UFS_MFS_MFSNODE_H_ @@ -48,6 +48,7 @@ struct mfsnode { long mfs_size; /* size of memory file system */ struct thread *mfs_td; /* supporting thread */ struct buf_queue_head buf_queue; /* list of I/O requests */ + dev_t mfs_dev; /* underlying device */ int mfs_active; long mfs_spare[1]; }; diff --git a/sys/vfs/msdosfs/msdosfs_vfsops.c b/sys/vfs/msdosfs/msdosfs_vfsops.c index f956cc59f1..3a85c142e9 100644 --- a/sys/vfs/msdosfs/msdosfs_vfsops.c +++ b/sys/vfs/msdosfs/msdosfs_vfsops.c @@ -1,5 +1,5 @@ /* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/msdosfs/Attic/msdosfs_vfsops.c,v 1.60.2.8 2004/03/02 09:43:04 tjr Exp $ */ -/* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vfsops.c,v 1.14 2004/05/03 19:08:08 cpressey Exp $ */ +/* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vfsops.c,v 1.15 2004/05/19 22:53:05 dillon Exp $ */ /* $NetBSD: msdosfs_vfsops.c,v 1.51 1997/11/17 15:36:58 ws Exp $ */ /*- @@ -362,7 +362,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp, struct thread *td, { struct msdosfsmount *pmp; struct buf *bp; - dev_t dev = devvp->v_rdev; + dev_t dev; #ifndef __DragonFly__ struct partinfo dpart; int bsize = 0, dtype = 0, tmp; @@ -384,7 +384,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp, struct thread *td, error = vfs_mountedon(devvp); if (error) return (error); - if (vcount(devvp) > 1 && devvp != rootvp) + if (count_udev(devvp) > 0 && devvp != rootvp) return (EBUSY); vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td); error = vinvalbuf(devvp, V_SAVE, td, 0, 0); @@ -398,7 +398,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp, struct thread *td, VOP_UNLOCK(devvp, NULL, 0, td); if (error) return (error); - + dev = devvp->v_rdev; bp = NULL; /* both used in error_exit */ pmp = NULL; @@ -725,7 +725,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp, struct thread *td, mp->mnt_stat.f_fsid.val[0] = dev2udev(dev); mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; mp->mnt_flag |= MNT_LOCAL; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; return 0; @@ -758,7 +758,7 @@ msdosfs_unmount(struct mount *mp, int mntflags, struct thread *td) if (error) return error; pmp = VFSTOMSDOSFS(mp); - pmp->pm_devvp->v_specmountpoint = NULL; + pmp->pm_devvp->v_rdev->si_mountpoint = NULL; #ifdef MSDOSFS_DEBUG { struct vnode *vp = pmp->pm_devvp; diff --git a/sys/vfs/nfs/nfs_subs.c b/sys/vfs/nfs/nfs_subs.c index f40f172f91..f07f7dcf96 100644 --- a/sys/vfs/nfs/nfs_subs.c +++ b/sys/vfs/nfs/nfs_subs.c @@ -35,7 +35,7 @@ * * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95 * $FreeBSD: /repoman/r/ncvs/src/sys/nfsclient/nfs_subs.c,v 1.128 2004/04/14 23:23:55 peadar Exp $ - * $DragonFly: src/sys/vfs/nfs/nfs_subs.c,v 1.16 2004/04/24 04:32:04 drhodus Exp $ + * $DragonFly: src/sys/vfs/nfs/nfs_subs.c,v 1.17 2004/05/19 22:53:05 dillon Exp $ */ /* @@ -1178,7 +1178,8 @@ nfs_loadattrcache(struct vnode **vpp, struct mbuf **mdp, caddr_t *dposp, struct nfsnode *np; int32_t t1; caddr_t cp2; - int error = 0, rdev; + int error = 0; + udev_t rdev; struct mbuf *md; enum vtype vtyp; u_short vmode; @@ -1226,7 +1227,7 @@ nfs_loadattrcache(struct vnode **vpp, struct mbuf **mdp, caddr_t *dposp, /* * Really ugly NFSv2 kludge. */ - if (vtyp == VCHR && rdev == 0xffffffff) + if (vtyp == VCHR && rdev == (udev_t)0xffffffff) vtyp = VFIFO; } diff --git a/sys/vfs/nfs/nfs_vfsops.c b/sys/vfs/nfs/nfs_vfsops.c index 45c28d84bd..41ec674f53 100644 --- a/sys/vfs/nfs/nfs_vfsops.c +++ b/sys/vfs/nfs/nfs_vfsops.c @@ -35,7 +35,7 @@ * * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95 * $FreeBSD: src/sys/nfs/nfs_vfsops.c,v 1.91.2.7 2003/01/27 20:04:08 dillon Exp $ - * $DragonFly: src/sys/vfs/nfs/nfs_vfsops.c,v 1.17 2004/05/08 04:11:48 dillon Exp $ + * $DragonFly: src/sys/vfs/nfs/nfs_vfsops.c,v 1.18 2004/05/19 22:53:05 dillon Exp $ */ #include "opt_bootp.h" @@ -566,7 +566,7 @@ nfs_mountroot(mp) vp->v_type = VREG; vp->v_flag = 0; vref(vp); - swaponvp(td, vp, NODEV, nd->swap_nblks); + swaponvp(td, vp, nd->swap_nblks); } mp->mnt_flag |= MNT_ROOTFS; diff --git a/sys/vfs/ntfs/ntfs_vfsops.c b/sys/vfs/ntfs/ntfs_vfsops.c index 918696ea02..e4136f9bbb 100644 --- a/sys/vfs/ntfs/ntfs_vfsops.c +++ b/sys/vfs/ntfs/ntfs_vfsops.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/ntfs/ntfs_vfsops.c,v 1.20.2.5 2001/12/25 01:44:45 dillon Exp $ - * $DragonFly: src/sys/vfs/ntfs/ntfs_vfsops.c,v 1.15 2004/04/24 04:32:04 drhodus Exp $ + * $DragonFly: src/sys/vfs/ntfs/ntfs_vfsops.c,v 1.16 2004/05/19 22:53:05 dillon Exp $ */ @@ -314,7 +314,7 @@ ntfs_mount(struct mount *mp, err = ENOTBLK; goto error_2; } - if (major(devvp->v_rdev) >= nblkdev) { + if (umajor(devvp->v_udev) >= nblkdev) { err = ENXIO; goto error_2; } @@ -410,7 +410,7 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, { struct buf *bp; struct ntfsmount *ntmp; - dev_t dev = devvp->v_rdev; + dev_t dev; int error, ronly, ncount, i; struct vnode *vp; struct ucred *cred; @@ -427,7 +427,7 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, error = vfs_mountedon(devvp); if (error) return (error); - ncount = vcount(devvp); + ncount = count_udev(devvp); #if defined(__DragonFly__) if (devvp->v_object) ncount -= 1; @@ -450,6 +450,7 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, VOP__UNLOCK(devvp, 0, td); if (error) return (error); + dev = devvp->v_rdev; bp = NULL; @@ -594,7 +595,7 @@ ntfs_mountfs(struct vnode *devvp, struct mount *mp, struct ntfs_args *argsp, #endif mp->mnt_maxsymlinklen = 0; mp->mnt_flag |= MNT_LOCAL; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; return (0); out1: @@ -605,7 +606,7 @@ out1: dprintf(("ntfs_mountfs: vflush failed\n")); out: - devvp->v_specmountpoint = NULL; + dev->si_mountpoint = NULL; if (bp) brelse(bp); @@ -668,7 +669,7 @@ ntfs_unmount(struct mount *mp, int mntflags, struct thread *td) * field is NULL and touching it causes null pointer derefercence. */ if (ntmp->ntm_devvp->v_type != VBAD) - ntmp->ntm_devvp->v_specmountpoint = NULL; + ntmp->ntm_devvp->v_rdev->si_mountpoint = NULL; vinvalbuf(ntmp->ntm_devvp, V_SAVE, td, 0, 0); diff --git a/sys/vfs/nullfs/null_subr.c b/sys/vfs/nullfs/null_subr.c index 92e0ab56e3..e47411c886 100644 --- a/sys/vfs/nullfs/null_subr.c +++ b/sys/vfs/nullfs/null_subr.c @@ -36,7 +36,7 @@ * @(#)null_subr.c 8.7 (Berkeley) 5/14/95 * * $FreeBSD: src/sys/miscfs/nullfs/null_subr.c,v 1.21.2.4 2001/06/26 04:20:09 bp Exp $ - * $DragonFly: src/sys/vfs/nullfs/Attic/null_subr.c,v 1.9 2004/04/24 04:32:04 drhodus Exp $ + * $DragonFly: src/sys/vfs/nullfs/Attic/null_subr.c,v 1.10 2004/05/19 22:53:05 dillon Exp $ */ #include @@ -177,7 +177,7 @@ null_node_alloc(struct mount *mp, struct vnode *lowervp, struct vnode **vpp) * This still needs to be investigated. */ if (vp->v_type == VCHR || vp->v_type == VBLK) - addalias(vp, lowervp->v_un.vu_spec.vu_specinfo); + addaliasu(vp, lowervp->v_udev); else vp->v_un = lowervp->v_un; lockinit(&xp->null_lock, 0, "nullnode", 0, LK_CANRECURSE); diff --git a/sys/vfs/specfs/spec_vnops.c b/sys/vfs/specfs/spec_vnops.c index 93ba402313..dec787c8e7 100644 --- a/sys/vfs/specfs/spec_vnops.c +++ b/sys/vfs/specfs/spec_vnops.c @@ -32,7 +32,7 @@ * * @(#)spec_vnops.c 8.14 (Berkeley) 5/21/95 * $FreeBSD: src/sys/miscfs/specfs/spec_vnops.c,v 1.131.2.4 2001/02/26 04:23:20 jlemon Exp $ - * $DragonFly: src/sys/vfs/specfs/spec_vnops.c,v 1.14 2004/05/03 18:46:34 cpressey Exp $ + * $DragonFly: src/sys/vfs/specfs/spec_vnops.c,v 1.15 2004/05/19 22:53:06 dillon Exp $ */ #include @@ -113,6 +113,8 @@ static struct vnodeopv_desc spec_vnodeop_opv_desc = VNODEOP_SET(spec_vnodeop_opv_desc); +extern int dev_ref_debug; + /* * spec_vnoperate(struct vnodeop_desc *a_desc, ...) */ @@ -135,8 +137,9 @@ static int spec_open(struct vop_open_args *ap) { struct vnode *vp = ap->a_vp; - dev_t dev = vp->v_rdev; + dev_t dev; int error; + int isblk = (vp->v_type == VBLK) ? 1 : 0; const char *cp; /* @@ -145,10 +148,40 @@ spec_open(struct vop_open_args *ap) if (vp->v_mount && (vp->v_mount->mnt_flag & MNT_NODEV)) return (ENXIO); - if (dev_dport(dev) == NULL) - return ENXIO; + /* + * Resolve the device. If the vnode is already open v_rdev may + * already be resolved. However, if the device changes out from + * under us we report it (and, for now, we allow it). + */ + if (vp->v_rdev != NULL) { + dev = udev2dev(vp->v_udev, isblk); + if (dev != vp->v_rdev) { + printf( + "Warning: spec_open: dev %s was lost", + vp->v_rdev->si_name); + v_release_rdev(vp); + error = v_associate_rdev(vp, + udev2dev(vp->v_udev, isblk)); + if (error) + printf(", reacquisition failed\n"); + else + printf(", reacquisition successful\n"); + } else { + error = 0; + } + } else { + error = v_associate_rdev(vp, udev2dev(vp->v_udev, isblk)); + } + if (error) + return(error); + + dev = vp->v_rdev; - /* Make this field valid before any I/O in ->d_open */ + /* + * Make this field valid before any I/O in ->d_open. XXX the + * device itself should probably be required to initialize + * this field in d_open. + */ if (!dev->si_iosize_max) dev->si_iosize_max = DFLTPHYS; @@ -163,35 +196,45 @@ spec_open(struct vop_open_args *ap) /* * Never allow opens for write if the device is mounted R/W */ - if (vp->v_specmountpoint != NULL && - !(vp->v_specmountpoint->mnt_flag & MNT_RDONLY)) - return (EBUSY); + if (vp->v_rdev && vp->v_rdev->si_mountpoint && + !(vp->v_rdev->si_mountpoint->mnt_flag & MNT_RDONLY)) { + error = EBUSY; + goto done; + } /* * When running in secure mode, do not allow opens * for writing if the device is mounted */ - if (securelevel >= 1 && vp->v_specmountpoint != NULL) - return (EPERM); + if (securelevel >= 1 && vfs_mountedon(vp)) { + error = EPERM; + goto done; + } /* * When running in very secure mode, do not allow * opens for writing of any devices. */ - if (securelevel >= 2) - return (EPERM); + if (securelevel >= 2) { + error = EPERM; + goto done; + } } /* XXX: Special casing of ttys for deadfs. Probably redundant */ if (dev_dflags(dev) & D_TTY) vp->v_flag |= VISTTY; + /* + * dev_dopen() is always called for each open. dev_dclose() is + * only called for the last close unless D_TRACKCLOSE is set. + */ VOP_UNLOCK(vp, NULL, 0, ap->a_td); error = dev_dopen(dev, ap->a_mode, S_IFCHR, ap->a_td); vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, ap->a_td); if (error) - return (error); + goto done; if (dev_dflags(dev) & D_TTY) { if (dev->si_tty) { @@ -215,6 +258,14 @@ spec_open(struct vop_open_args *ap) dev_dname(dev), cp); } } + ++vp->v_opencount; + if (dev_ref_debug) + printf("spec_open: %s %d\n", dev->si_name, vp->v_opencount); +done: + if (error) { + if (vp->v_opencount == 0) + v_release_rdev(vp); + } return (error); } @@ -430,7 +481,7 @@ spec_strategy(struct vop_strategy_args *ap) * and write counts for disks that have associated filesystems. */ vp = ap->a_vp; - if (vn_isdisk(vp, NULL) && (mp = vp->v_specmountpoint) != NULL) { + if (vn_isdisk(vp, NULL) && (mp = vp->v_rdev->si_mountpoint) != NULL) { if ((bp->b_flags & B_READ) == 0) { if (bp->b_lock.lk_lockholder == LK_KERNTHREAD) mp->mnt_stat.f_asyncwrites++; @@ -443,14 +494,7 @@ spec_strategy(struct vop_strategy_args *ap) mp->mnt_stat.f_syncreads++; } } -#if 0 - KASSERT(devsw(bp->b_dev) != NULL, - ("No devsw on dev %s responsible for buffer %p\n", - devtoname(bp->b_dev), bp)); - KASSERT(devsw(bp->b_dev)->d_strategy != NULL, - ("No strategy on dev %s responsible for buffer %p\n", - devtoname(bp->b_dev), bp)); -#endif + bp->b_dev = vp->v_rdev; BUF_STRATEGY(bp, 0); return (0); } @@ -520,6 +564,7 @@ spec_close(struct vop_close_args *ap) struct proc *p = ap->a_td->td_proc; struct vnode *vp = ap->a_vp; dev_t dev = vp->v_rdev; + int error; /* * Hack: a tty device that is a controlling terminal @@ -530,28 +575,41 @@ spec_close(struct vop_close_args *ap) * if the reference count is 2 (this last descriptor * plus the session), release the reference from the session. */ - if (vcount(vp) == 2 && p && (vp->v_flag & VXLOCK) == 0 && - vp == p->p_session->s_ttyvp) { + reference_dev(dev); + if (vcount(vp) == 2 && vp->v_opencount == 1 && + p && (vp->v_flag & VXLOCK) == 0 && vp == p->p_session->s_ttyvp) { vrele(vp); p->p_session->s_ttyvp = NULL; } + /* - * We do not want to really close the device if it - * is still in use unless we are trying to close it - * forcibly. Since every use (buffer, vnode, swap, cmap) - * holds a reference to the vnode, and because we mark - * any other vnodes that alias this device, when the - * sum of the reference counts on all the aliased - * vnodes descends to one, we are on last close. + * Vnodes can be opened and close multiple times. Do not really + * close the device unless (1) it is being closed forcibly, + * (2) the device wants to track closes, or (3) this is the last + * vnode doing its last close on the device. + * + * XXX the VXLOCK (force close) case can leave vnodes referencing + * a closed device. */ - if (vp->v_flag & VXLOCK) { - /* Forced close */ - } else if (dev_dflags(dev) & D_TRACKCLOSE) { - /* Keep device updated on status */ - } else if (vcount(vp) > 1) { - return (0); + if ((vp->v_flag & VXLOCK) || + (dev_dflags(dev) & D_TRACKCLOSE) || + (vcount(vp) <= 1 && vp->v_opencount == 1)) { + error = dev_dclose(dev, ap->a_fflag, S_IFCHR, ap->a_td); + } else { + error = 0; } - return (dev_dclose(dev, ap->a_fflag, S_IFCHR, ap->a_td)); + + /* + * Track the actual opens and closes on the vnode. The last close + * disassociates the rdev. + */ + KKASSERT(vp->v_opencount > 0); + if (dev_ref_debug) + printf("spec_close: %s %d\n", dev->si_name, vp->v_opencount - 1); + if (--vp->v_opencount == 0) + v_release_rdev(vp); + release_dev(dev); + return(error); } /* @@ -631,7 +689,7 @@ spec_getpages(struct vop_getpages_args *ap) * the device. i.e. it's usually '/dev'. We need the physical block * size for the device itself. * - * We can't use v_specmountpoint because it only exists when the + * We can't use v_rdev->si_mountpoint because it only exists when the * block device is mounted. However, we can use v_rdev. */ diff --git a/sys/vfs/udf/udf_vfsops.c b/sys/vfs/udf/udf_vfsops.c index 6f5c3707e5..ea37328dbe 100644 --- a/sys/vfs/udf/udf_vfsops.c +++ b/sys/vfs/udf/udf_vfsops.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/fs/udf/udf_vfsops.c,v 1.16 2003/11/05 06:56:08 scottl Exp $ - * $DragonFly: src/sys/vfs/udf/udf_vfsops.c,v 1.4 2004/04/24 04:32:05 drhodus Exp $ + * $DragonFly: src/sys/vfs/udf/udf_vfsops.c,v 1.5 2004/05/19 22:53:06 dillon Exp $ */ /* udf_vfsops.c */ @@ -225,7 +225,8 @@ udf_checktag(struct desc_tag *tag, uint16_t id) } static int -udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) { +udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) +{ struct buf *bp = NULL; struct anchor_vdp avdp; struct udf_mnt *udfmp = NULL; @@ -233,6 +234,7 @@ udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) { struct logvol_desc *lvd; struct fileset_desc *fsd; struct file_entry *root_fentry; + dev_t dev; uint32_t sector, size, mvds_start, mvds_end; uint32_t fsd_offset = 0; uint16_t part_num = 0, fsd_part = 0; @@ -246,7 +248,7 @@ udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) { */ if ((error = vfs_mountedon(devvp))) return(error); - if (vcount(devvp) > 1) + if (count_udev(devvp) > 0) return(EBUSY); if ((error = vinvalbuf(devvp, V_SAVE, td, 0, 0))) return(error); @@ -257,16 +259,17 @@ udf_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td) { if (error) return(error); needclose = 1; + dev = devvp->v_rdev; udfmp = malloc(sizeof(*udfmp), M_UDFMOUNT, M_WAITOK | M_ZERO); mp->mnt_data = (qaddr_t)udfmp; - mp->mnt_stat.f_fsid.val[0] = dev2udev(devvp->v_rdev); + mp->mnt_stat.f_fsid.val[0] = dev2udev(dev); mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; mp->mnt_maxsymlinklen = 0; mp->mnt_flag |= MNT_LOCAL; udfmp->im_mountp = mp; - udfmp->im_dev = devvp->v_rdev; + udfmp->im_dev = dev; udfmp->im_devvp = devvp; bsize = 2048; /* XXX Should probe the media for it's size */ @@ -410,7 +413,7 @@ udf_unmount(struct mount *mp, int mntflags, struct thread *td) if ((error = vflush(mp, 0, flags))) return (error); - udfmp->im_devvp->v_specmountpoint = NULL; + udfmp->im_devvp->v_rdev->si_mountpoint = NULL; error = VOP_CLOSE(udfmp->im_devvp, FREAD, td); vrele(udfmp->im_devvp); diff --git a/sys/vfs/ufs/ffs_softdep.c b/sys/vfs/ufs/ffs_softdep.c index e01d3fe4f5..7d8ea13e2c 100644 --- a/sys/vfs/ufs/ffs_softdep.c +++ b/sys/vfs/ufs/ffs_softdep.c @@ -37,7 +37,7 @@ * * from: @(#)ffs_softdep.c 9.59 (McKusick) 6/21/00 * $FreeBSD: src/sys/ufs/ffs/ffs_softdep.c,v 1.57.2.11 2002/02/05 18:46:53 dillon Exp $ - * $DragonFly: src/sys/vfs/ufs/ffs_softdep.c,v 1.14 2004/03/15 16:27:04 dillon Exp $ + * $DragonFly: src/sys/vfs/ufs/ffs_softdep.c,v 1.15 2004/05/19 22:53:06 dillon Exp $ */ /* @@ -4087,8 +4087,8 @@ softdep_sync_metadata(ap) if (!DOINGSOFTDEP(vp)) return (0); } else - if (vp->v_specmountpoint == NULL || - (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP) == 0) + if (vp->v_rdev->si_mountpoint == NULL || + (vp->v_rdev->si_mountpoint->mnt_flag & MNT_SOFTDEP) == 0) return (0); /* * Ensure that any direct block dependencies have been cleared. @@ -4311,8 +4311,9 @@ loop: * this happens rarely). */ if (vn_isdisk(vp, NULL) && - vp->v_specmountpoint && !VOP_ISLOCKED(vp, NULL) && - (error = VFS_SYNC(vp->v_specmountpoint, MNT_WAIT, ap->a_td)) != 0) + vp->v_rdev && + vp->v_rdev->si_mountpoint && !VOP_ISLOCKED(vp, NULL) && + (error = VFS_SYNC(vp->v_rdev->si_mountpoint, MNT_WAIT, ap->a_td)) != 0) return (error); return (0); } diff --git a/sys/vfs/ufs/ffs_vfsops.c b/sys/vfs/ufs/ffs_vfsops.c index 53d08dcd85..ec2711de9b 100644 --- a/sys/vfs/ufs/ffs_vfsops.c +++ b/sys/vfs/ufs/ffs_vfsops.c @@ -32,7 +32,7 @@ * * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95 * $FreeBSD: src/sys/ufs/ffs/ffs_vfsops.c,v 1.117.2.10 2002/06/23 22:34:52 iedowse Exp $ - * $DragonFly: src/sys/vfs/ufs/ffs_vfsops.c,v 1.17 2004/05/18 00:16:46 cpressey Exp $ + * $DragonFly: src/sys/vfs/ufs/ffs_vfsops.c,v 1.18 2004/05/19 22:53:06 dillon Exp $ */ #include "opt_quota.h" @@ -316,18 +316,22 @@ ffs_mount(struct mount *mp, /* mount struct pointer */ ******************** * UPDATE * If it's not the same vnode, or at least the same device - * then it's not correct. + * then it's not correct. NOTE: devvp->v_rdev may be NULL + * since we haven't opened it, so we compare udev instead. ******************** */ - if (devvp != ump->um_devvp) { - if ( devvp->v_rdev == ump->um_devvp->v_rdev) { + if (devvp->v_udev == ump->um_devvp->v_udev) { vrele(devvp); } else { + printf("cannot update mount, udev does" + " not match %08x vs %08x\n", + devvp->v_udev, ump->um_devvp->v_udev); err = EINVAL; /* needs translation */ } - } else + } else { vrele(devvp); + } /* * Update device name only on success */ @@ -459,7 +463,6 @@ ffs_reload(struct mount *mp, struct ucred *cred, struct thread *td) panic("ffs_reload: dirty1"); dev = devvp->v_rdev; - /* * Only VMIO the backing device if the backing device is a real * block device. See ffs_mountmfs() for more details. @@ -617,9 +620,7 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, int32_t *lp; u_int64_t maxfilesize; /* XXX */ size_t strsize; - int ncount; - dev = devvp->v_rdev; /* * Disallow multiple mounts of the same device. * Disallow mounting of a device that is currently in use @@ -629,9 +630,7 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, error = vfs_mountedon(devvp); if (error) return (error); - ncount = vcount(devvp); - - if (ncount > 1 && devvp != rootvp) + if (count_udev(devvp->v_udev) > 0 && devvp != rootvp) return (EBUSY); vn_lock(devvp, NULL, LK_EXCLUSIVE | LK_RETRY, td); error = vinvalbuf(devvp, V_SAVE, td, 0, 0); @@ -658,8 +657,9 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, VOP_UNLOCK(devvp, NULL, 0, td); if (error) return (error); - if (devvp->v_rdev->si_iosize_max != 0) - mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max; + dev = devvp->v_rdev; + if (dev->si_iosize_max != 0) + mp->mnt_iosize_max = dev->si_iosize_max; if (mp->mnt_iosize_max > MAXPHYS) mp->mnt_iosize_max = MAXPHYS; @@ -768,7 +768,7 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, ump->um_seqinc = fs->fs_frag; for (i = 0; i < MAXQUOTAS; i++) ump->um_quotas[i] = NULLVP; - devvp->v_specmountpoint = mp; + dev->si_mountpoint = mp; ffs_oldfscompat(fs); /* @@ -808,10 +808,10 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td, } return (0); out: - devvp->v_specmountpoint = NULL; + dev->si_mountpoint = NULL; if (bp) brelse(bp); - (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, td); + VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, td); if (ump) { free(ump->um_fs, M_UFSMNT); free(ump, M_UFSMNT); @@ -881,7 +881,7 @@ ffs_unmount(struct mount *mp, int mntflags, struct thread *td) return (error); } } - ump->um_devvp->v_specmountpoint = NULL; + ump->um_devvp->v_rdev->si_mountpoint = NULL; vinvalbuf(ump->um_devvp, V_SAVE, td, 0, 0); error = VOP_CLOSE(ump->um_devvp, fs->fs_ronly ? FREAD : FREAD|FWRITE, td); diff --git a/sys/vfs/ufs/ffs_vnops.c b/sys/vfs/ufs/ffs_vnops.c index a35670bd30..3be188aff5 100644 --- a/sys/vfs/ufs/ffs_vnops.c +++ b/sys/vfs/ufs/ffs_vnops.c @@ -32,7 +32,7 @@ * * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95 * $FreeBSD: src/sys/ufs/ffs/ffs_vnops.c,v 1.64 2000/01/10 12:04:25 phk Exp $ - * $DragonFly: src/sys/vfs/ufs/ffs_vnops.c,v 1.7 2004/05/18 00:16:46 cpressey Exp $ + * $DragonFly: src/sys/vfs/ufs/ffs_vnops.c,v 1.8 2004/05/19 22:53:06 dillon Exp $ */ #include @@ -129,8 +129,8 @@ ffs_fsync(struct vop_fsync_args *ap) wait = (ap->a_waitfor == MNT_WAIT); if (vn_isdisk(vp, NULL)) { lbn = INT_MAX; - if (vp->v_specmountpoint != NULL && - (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP)) + if (vp->v_rdev && vp->v_rdev->si_mountpoint != NULL && + (vp->v_rdev->si_mountpoint->mnt_flag & MNT_SOFTDEP)) softdep_fsync_mountdev(vp); } else { struct inode *ip; diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h index e75c496604..73463f372d 100644 --- a/sys/vm/vm_extern.h +++ b/sys/vm/vm_extern.h @@ -32,7 +32,7 @@ * * @(#)vm_extern.h 8.2 (Berkeley) 1/12/94 * $FreeBSD: src/sys/vm/vm_extern.h,v 1.46.2.3 2003/01/13 22:51:17 dillon Exp $ - * $DragonFly: src/sys/vm/vm_extern.h,v 1.11 2004/03/31 19:29:24 dillon Exp $ + * $DragonFly: src/sys/vm/vm_extern.h,v 1.12 2004/05/19 22:53:06 dillon Exp $ */ #ifndef _VM_EXTERN_H_ @@ -73,7 +73,7 @@ void kmem_init (vm_offset_t, vm_offset_t); vm_offset_t kmem_malloc (vm_map_t, vm_size_t, boolean_t); vm_map_t kmem_suballoc (vm_map_t, vm_offset_t *, vm_offset_t *, vm_size_t); void munmapfd (struct proc *, int); -int swaponvp (struct thread *, struct vnode *, dev_t , u_long); +int swaponvp (struct thread *, struct vnode *, u_long); void swapout_procs (int); int useracc (caddr_t, int, int); int vm_fault (vm_map_t, vm_offset_t, vm_prot_t, int); diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index be4b8cddf6..2c765e8cf2 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -32,7 +32,7 @@ * * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94 * $FreeBSD: src/sys/vm/vm_swap.c,v 1.96.2.2 2001/10/14 18:46:47 iedowse Exp $ - * $DragonFly: src/sys/vm/vm_swap.c,v 1.11 2004/03/23 22:54:32 dillon Exp $ + * $DragonFly: src/sys/vm/vm_swap.c,v 1.12 2004/05/19 22:53:06 dillon Exp $ */ #include "opt_swap.h" @@ -203,14 +203,14 @@ swapon(struct swapon_args *uap) vp = nd.ni_vp; if (vn_isdisk(vp, &error)) - error = swaponvp(td, vp, vp->v_rdev, 0); + error = swaponvp(td, vp, 0); else if (vp->v_type == VREG && vp->v_tag == VT_NFS && (error = VOP_GETATTR(vp, &attr, td)) == 0) { /* * Allow direct swapping to NFS regular files in the same * way that nfs_mountroot() sets up diskless swapping. */ - error = swaponvp(td, vp, NODEV, attr.va_size / DEV_BSIZE); + error = swaponvp(td, vp, attr.va_size / DEV_BSIZE); } if (error) @@ -231,16 +231,17 @@ swapon(struct swapon_args *uap) * XXX locking when multiple swapon's run in parallel */ int -swaponvp(struct thread *td, struct vnode *vp, dev_t dev, u_long nblks) +swaponvp(struct thread *td, struct vnode *vp, u_long nblks) { - int index; + u_long aligned_nblks; + struct ucred *cred; struct swdevt *sp; swblk_t vsbase; - long blk; swblk_t dvbase; + dev_t dev; + int index; int error; - u_long aligned_nblks; - struct ucred *cred; + long blk; KKASSERT(td->td_proc); cred = td->td_proc->p_ucred; @@ -269,6 +270,15 @@ swaponvp(struct thread *td, struct vnode *vp, dev_t dev, u_long nblks) if (error) return (error); + /* + * v_rdev is not valid until after the VOP_OPEN() call. dev_psize() + * must be supported if a character device has been specified. + */ + if (vp->v_type == VCHR) + dev = vp->v_rdev; + else + dev = NODEV; + if (nblks == 0 && dev != NODEV && ((nblks = dev_dpsize(dev)) == -1)) { (void) VOP_CLOSE(vp, FREAD | FWRITE, td); return (ENXIO); -- 2.41.0