9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c4516e51fbea7ed0aeeaca9055374cd48e884b5d
parent ceb25fe60c09727fc845457629e4c727cc0c726a
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Fri, 22 Feb 2019 07:18:25 +0000

[dev] Add rootgen() to devroot

dirread() and devwalk() can take a function pointer,
so it is better to use that functionality.

Change-Id: Ie9fc325ea5702e24730a3074cf45f94e9789347c

Diffstat:
Mdrivers/devroot.c | 37++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/devroot.c b/drivers/devroot.c @@ -23,39 +23,38 @@ static const Dirtab devfstab[] = { static Chan *bindpoint[Qmax]; static int -roottab(Qid qid, const Dirtab **tab) +rootgen(Chan *c, const Dirtab *tab, int ntab, int n, Dir *dir) { - switch (qid) { + switch (c->qid & ~CHDIR) { case Qroot: - *tab = dirtab; - return NELEM(dirtab); + tab = dirtab; + ntab = NELEM(dirtab); + break; case Qdev: - *tab = devfstab; - return NELEM(devfstab); + tab = devfstab; + ntab = NELEM(devfstab); + break; case Qdevuart: case Qrealm: - *tab = NULL; return 0; default: panic("roottab"); } + + return devgen(c, tab, ntab, n, dir); } static int rootwalk(Chan *c, const char *name) { - int n; Qid qid; Chan *mnt; - const Dirtab *tab; - - n = roottab(c->qid & ~CHDIR, &tab); - if (devwalk(c, name, tab, n, devgen) < 0) + if (devwalk(c, name, NULL, 0, rootgen) < 0) return -1; qid = c->qid & ~CHDIR; - if (qid > Qmax) + if (qid >= Qmax) panic("rootwalk"); mnt = bindpoint[qid]; @@ -72,7 +71,7 @@ rootbind(Chan *cw, Chan *cn) Chan *mnt; qid = cw->qid & ~CHDIR; - if (qid > Qmax) + if (qid >= Qmax) panic("rootbind"); mnt = bindpoint[qid]; @@ -93,15 +92,7 @@ rootattach(int dev) static int rootread(Chan *c, void *buf, int n) { - const Dirtab *tab; - int ntab; - - if ((c->qid & CHDIR) == 0) - return -1; - - ntab = roottab(c->qid & ~CHDIR, &tab); - - return dirread(c, buf, n, tab, ntab, devgen); + return dirread(c, buf, n, NULL, 0, rootgen); } static int