-/* $OpenBSD: dev.c,v 1.115 2024/05/24 15:16:09 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.116 2024/05/24 15:21:35 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
int
dev_open(struct dev *d)
{
+ struct opt *o;
+
d->mode = d->reqmode;
d->round = d->reqround;
d->bufsz = d->reqbufsz;
return 0;
d->pstate = DEV_INIT;
+
+ /* add server.device if device is opened after opt_ref() call */
+ for (o = opt_list; o != NULL; o = o->next) {
+ if (o->refcnt > 0 && !ctl_find(CTL_OPT_DEV, o, d)) {
+ ctl_new(CTL_OPT_DEV, o, d,
+ CTL_SEL, dev_getdisplay(d),
+ o->name, "server", -1, "device",
+ d->name, -1, 1, o->dev == d);
+ d->refcnt++;
+ }
+ }
+
return 1;
}
void
dev_close(struct dev *d)
{
+ struct opt *o;
+
+ /* remove server.device entries */
+ for (o = opt_list; o != NULL; o = o->next) {
+ if (ctl_del(CTL_OPT_DEV, o, d))
+ d->refcnt--;
+ }
+
d->pstate = DEV_CFG;
dev_sio_close(d);
dev_freebufs(d);
-/* $OpenBSD: opt.c,v 1.11 2024/05/24 15:16:09 ratchov Exp $ */
+/* $OpenBSD: opt.c,v 1.12 2024/05/24 15:21:35 ratchov Exp $ */
/*
* Copyright (c) 2008-2011 Alexandre Ratchov <alex@caoua.org>
*
void
opt_init(struct opt *o)
{
- struct dev *d;
-
- if (strcmp(o->name, o->dev->name) != 0) {
- for (d = dev_list; d != NULL; d = d->next) {
- ctl_new(CTL_OPT_DEV, o, d,
- CTL_SEL, "", o->name, "server", -1, "device",
- d->name, -1, 1, o->dev == d);
- }
- }
}
void
/* if device changed, move everything to the new one */
if (d != o->dev)
opt_setdev(o, d);
+
+ /* create server.device control */
+ for (d = dev_list; d != NULL; d = d->next) {
+ d->refcnt++;
+ if (d->pstate == DEV_CFG)
+ dev_open(d);
+ ctl_new(CTL_OPT_DEV, o, d,
+ CTL_SEL, dev_getdisplay(d),
+ o->name, "server", -1, "device",
+ d->name, -1, 1, o->dev == d);
+ }
}
}
void
opt_unref(struct opt *o)
{
+ struct dev *d;
+
o->refcnt--;
- if (o->refcnt == 0)
+ if (o->refcnt == 0) {
+ /* delete server.device control */
+ for (d = dev_list; d != NULL; d = d->next) {
+ if (ctl_del(CTL_OPT_DEV, o, d))
+ dev_unref(d);
+ }
dev_unref(o->dev);
+ }
}