From f1631e52a46ecdbac7e360fe1dbf52d8e7140f97 Mon Sep 17 00:00:00 2001 From: nat Date: Fri, 9 Dec 2016 19:13:47 +0000 Subject: [PATCH] Add functions to access device flags. This restores simultaneous audio open/close. OK hannken@ christos@ --- sys/kern/subr_devsw.c | 24 ++++++++++++++++++++++-- sys/miscfs/specfs/spec_vnops.c | 6 +++--- sys/sys/conf.h | 4 +++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/sys/kern/subr_devsw.c b/sys/kern/subr_devsw.c index 0bfd02eb1d67..2823bea80410 100644 --- a/sys/kern/subr_devsw.c +++ b/sys/kern/subr_devsw.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_devsw.c,v 1.34 2016/02/01 05:05:43 riz Exp $ */ +/* $NetBSD: subr_devsw.c,v 1.35 2016/12/09 19:13:47 nat Exp $ */ /*- * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34 2016/02/01 05:05:43 riz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.35 2016/12/09 19:13:47 nat Exp $"); #ifdef _KERNEL_OPT #include "opt_dtrace.h" @@ -795,6 +795,16 @@ bdev_dump(dev_t dev, daddr_t addr, void *data, size_t sz) return rv; } +int +bdev_flags(dev_t dev) +{ + const struct bdevsw *d; + + if ((d = bdevsw_lookup(dev)) == NULL) + return 0; + return d->d_flag & ~D_TYPEMASK; +} + int bdev_type(dev_t dev) { @@ -1025,6 +1035,16 @@ cdev_discard(dev_t dev, off_t pos, off_t len) return rv; } +int +cdev_flags(dev_t dev) +{ + const struct cdevsw *d; + + if ((d = cdevsw_lookup(dev)) == NULL) + return 0; + return d->d_flag & ~D_TYPEMASK; +} + int cdev_type(dev_t dev) { diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 2b7b4a36293e..87bd8250801a 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: spec_vnops.c,v 1.166 2016/12/08 10:28:44 nat Exp $ */ +/* $NetBSD: spec_vnops.c,v 1.167 2016/12/09 19:13:47 nat Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.166 2016/12/08 10:28:44 nat Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.167 2016/12/09 19:13:47 nat Exp $"); #include #include @@ -1227,7 +1227,7 @@ spec_close(void *v) sd->sd_bdevvp = NULL; mutex_exit(&device_lock); - if (count != 0 && (vp->v_type != VCHR || cdev_type(dev) != D_MCLOSE)) + if (count != 0 && (vp->v_type != VCHR || !(cdev_flags(dev) & D_MCLOSE))) return 0; /* diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 41c41d21512c..dc24f00e2218 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -1,4 +1,4 @@ -/* $NetBSD: conf.h,v 1.148 2016/12/08 20:53:12 nat Exp $ */ +/* $NetBSD: conf.h,v 1.149 2016/12/09 19:13:47 nat Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -175,7 +175,9 @@ dev_type_kqfilter(cdev_kqfilter); dev_type_discard(cdev_discard); int cdev_type(dev_t); +int cdev_flags(dev_t); int bdev_type(dev_t); +int bdev_flags(dev_t); /* symbolic sleep message strings */ extern const char devopn[], devio[], devwait[], devin[], devout[];