update to new vfs interface.

This commit is contained in:
chopps 1994-06-17 20:06:05 +00:00
parent ab119e2183
commit 61e3e83691
5 changed files with 816 additions and 989 deletions

View File

@ -27,11 +27,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: adlookup.c,v 1.4 1994/06/02 23:40:56 chopps Exp $
* $Id: adlookup.c,v 1.5 1994/06/17 20:06:05 chopps Exp $
*/
#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/namei.h>
#include <sys/mount.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <adosfs/adosfs.h>
@ -51,89 +52,82 @@
* LOOKUP always unlocks parent if last element. (not now!?!?)
*/
int
adosfs_lookup(pvp, ndp, p)
struct vnode *pvp;
struct nameidata *ndp;
struct proc *p;
adosfs_lookup(sp)
struct vop_lookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
} */ *sp;
{
int lockp, wantp, flag, error, last, cvalid, nocache, i;
struct amount *amp;
struct anode *pap, *ap;
struct buf *bp;
char *pelt;
int nameiop, last, lockp, wantp, flags, error, vpid, nocache, i;
struct componentname *cnp;
struct vnode **vpp; /* place to store result */
struct anode *ap; /* anode to find */
struct vnode *vdp; /* vnode of search dir */
struct anode *adp; /* anode of search dir */
struct ucred *ucp; /* lookup credentials */
u_long bn, plen, hval;
char *pelt;
#ifdef ADOSFS_DIAGNOSTIC
printf("(adlookup ");
advopprint(sp);
#endif
ndp->ni_dvp = pvp;
ndp->ni_vp = NULL;
pap = VTOA(pvp);
amp = pap->amp;
lockp = ndp->ni_nameiop & LOCKPARENT;
wantp = ndp->ni_nameiop & (LOCKPARENT | WANTPARENT);
flag = ndp->ni_nameiop & OPMASK;
pelt = ndp->ni_ptr;
plen = ndp->ni_namelen;
last = (*ndp->ni_next == 0);
cnp = sp->a_cnp;
vdp = sp->a_dvp;
adp = VTOA(vdp);
vpp = sp->a_vpp;
*vpp = NULL;
ucp = cnp->cn_cred;
nameiop = cnp->cn_nameiop;
flags = cnp->cn_flags;
last = flags & ISLASTCN;
lockp = flags & LOCKPARENT;
wantp = flags & (LOCKPARENT | WANTPARENT);
pelt = cnp->cn_nameptr;
plen = cnp->cn_namelen;
nocache = 0;
/*
* check that:
* pvp is a dir, and that the user has rights to access
*/
if (pvp->v_type != VDIR) {
#ifdef ADOSFS_DIAGNOSTIC
printf("ENOTDIR)");
#endif
return(ENOTDIR);
}
if (error = VOP_ACCESS(pvp, VEXEC, ndp->ni_cred, p)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[VOP_ACCESS] %d)", error);
#endif
return(error);
}
if (vdp->v_type != VDIR)
return (ENOTDIR);
if (error = VOP_ACCESS(vdp, VEXEC, ucp, cnp->cn_proc))
return (error);
/*
* cache lookup algorithm borrowed from ufs_lookup()
* its not consistent with otherthings in this function..
*/
if (error = cache_lookup(ndp)) {
if (error == ENOENT) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[cache_lookup] %d)", error);
#endif
return(error);
}
if (error = cache_lookup(vdp, vpp, cnp)) {
if (error == ENOENT)
return (error);
ap = VTOA(ndp->ni_vp);
cvalid = ndp->ni_vp->v_id;
if (ap == pap) {
VREF(pvp);
vpid = (*vpp)->v_id;
if (vdp == *vpp) {
VREF(vdp);
error = 0;
} else if (ndp->ni_isdotdot) {
AUNLOCK(pap); /* race */
error = vget(ATOV(ap), 1);
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(vdp); /* race */
error = vget(*vpp, 1);
if (error == 0 && lockp && last)
ALOCK(pap);
error = VOP_LOCK(vdp);
} else {
error = vget(ATOV(ap), 1);
if (lockp == 0 || error || last)
AUNLOCK(pap);
error = vget(*vpp, 1);
/* if (lockp == 0 || error || last) */
if (lockp == 0 || error || last == 0)
VOP_UNLOCK(vdp);
}
if (error == 0) {
if (cvalid == ATOV(ap)->v_id) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[cache_lookup] 0)\n");
#endif
return(0);
}
aput(ap);
if (lockp && pap != ap && last)
AUNLOCK(pap);
if (vpid == vdp->v_id)
return (0);
vput(*vpp);
if (lockp && vdp != *vpp && last)
VOP_UNLOCK(vdp);
}
ALOCK(pap);
ndp->ni_vp = NULL;
*vpp = NULL;
if (error = VOP_LOCK(vdp))
return (error);
}
/*
@ -141,32 +135,39 @@ adosfs_lookup(pvp, ndp, p)
*/
if (plen == 1 && pelt[0] == '.') {
/* see special cases in prologue. */
ap = pap;
*vpp = vdp;
goto found;
}
/*
* fake a ".."
*/
if (ndp->ni_isdotdot) {
if (pap->type == AROOT)
if (flags & ISDOTDOT) {
if (vdp->v_type == VDIR && (vdp->v_flag & VROOT))
panic("adosfs .. attemped through root");
/*
* cannot get previous entry while later is locked
* eg procA holds lock on previous and wats for pap
* we wait for previous and hold lock on pap. deadlock.
* becuase pap may have been acheived through symlink
* cannot get `..' while `vdp' is locked
* e.g. procA holds lock on `..' and waits for `vdp'
* we wait for `..' and hold lock on `vdp'. deadlock.
* becuase `vdp' may have been acheived through symlink
* fancy detection code that decreases the race
* window size is not reasonably possible.
*
* basically unlock the parent, try and lock the child (..)
* if that fails relock the parent (ignoring error) and
* fail. Otherwise we have the child (..) if this is the
* last and the caller requested LOCKPARENT, attempt to
* relock the parent. If that fails unlock the child (..)
* and fail. Otherwise we have succeded.
*
*/
AUNLOCK(pap); /* race */
error = aget(amp->mp, pap->pblock, &ap);
if (error || (last && lockp))
ALOCK(pap);
VOP_UNLOCK(vdp); /* race */
if (error = VFS_VGET(vdp->v_mount, (ino_t)adp->pblock, vpp))
VOP_LOCK(vdp);
else if (last && lockp && (error = VOP_LOCK(vdp)))
vput(*vpp);
if (error) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[..] %d)", error);
#endif
return(error);
*vpp = NULL;
return (error);
}
goto found_lockdone;
}
@ -176,102 +177,93 @@ adosfs_lookup(pvp, ndp, p)
* then walk the chain. if chain has not been fully
* walked before, track the count in `tabi'
*/
hval = adoshash(pelt, plen, pap->ntabent);
bn = pap->tab[hval];
i = min(pap->tabi[hval], 0);
hval = adoshash(pelt, plen, adp->ntabent);
bn = adp->tab[hval];
i = min(adp->tabi[hval], 0);
while (bn != 0) {
if (error = aget(amp->mp, bn, &ap)) {
if (error = VFS_VGET(vdp->v_mount, (ino_t)bn, vpp)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[aget] %d)", error);
#endif
/* XXX check to unlock parent possibly? */
return(error);
}
ap = VTOA(*vpp);
if (i <= 0) {
if (--i < pap->tabi[hval])
pap->tabi[hval] = i;
if (--i < adp->tabi[hval])
adp->tabi[hval] = i;
/*
* last header in chain lock count down by
* negating it to positive
*/
if (ap->hashf == 0) {
#ifdef DEBUG
if (i != pap->tabi[hval])
if (i != adp->tabi[hval])
panic("adlookup: wrong chain count");
#endif
pap->tabi[hval] = -pap->tabi[hval];
adp->tabi[hval] = -adp->tabi[hval];
}
}
#ifdef ADOSFS_DIAGNOSTIC
printf("%s =? %s", pelt, ap->name);
#endif
if (strmatch(pelt, plen, ap->name, strlen(ap->name)))
goto found;
bn = ap->hashf;
aput(ap);
vput(*vpp);
}
*vpp = NULL;
/*
* not found
*/
if ((flag == CREATE || flag == RENAME) && last) {
if (error = VOP_ACCESS(pvp, VWRITE, ndp->ni_cred, p)) {
if ((nameiop == CREATE || nameiop == RENAME) && last) {
if (error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("[VOP_ACCESS] %d)", error);
#endif
return(error);
return (error);
}
if (lockp == 0)
AUNLOCK(pap);
ndp->ni_nameiop |= SAVENAME;
VOP_UNLOCK(vdp);
cnp->cn_nameiop |= SAVENAME;
#ifdef ADOSFS_DIAGNOSTIC
printf("EJUSTRETURN)");
#endif
return(EJUSTRETURN);
}
if (ndp->ni_makeentry && flag != CREATE)
cache_enter(ndp);
if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
cache_enter(vdp, NULL, cnp);
#ifdef ADOSFS_DIAGNOSTIC
printf("ENOENT)");
#endif
return(ENOENT);
found:
if (last && flag == DELETE) {
if (error = VOP_ACCESS(pvp, VWRITE, ndp->ni_cred, p)) {
if (pap != ap)
aput(ap);
#ifdef ADOSFS_DIAGNOSTIC
printf("[VOP_ACCESS] %d)", error);
#endif
return(error);
if (nameiop == DELETE && last) {
if (error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) {
if (vdp != *vpp)
vput(*vpp);
*vpp = NULL;
return (error);
}
nocache = 1;
}
if (last && flag == RENAME && wantp) {
if (pap == ap) {
#ifdef ADOSFS_DIAGNOSTIC
printf("EISDIR)");
#endif
if (nameiop == RENAME && wantp && last) {
if (vdp == *vpp)
return(EISDIR);
if (error = VOP_ACCESS(vdp, VWRITE, ucp, cnp->cn_proc)) {
vput(*vpp);
*vpp = NULL;
return (error);
}
if (error = VOP_ACCESS(pvp, VWRITE, ndp->ni_cred, p)) {
aput(ap);
#ifdef ADOSFS_DIAGNOSTIC
printf("[VOP_ACCESS] %d)", error);
#endif
return(error);
}
ndp->ni_nameiop |= SAVENAME;
cnp->cn_flags |= SAVENAME;
nocache = 1;
}
if (ap == pap)
VREF(pvp);
if (vdp == *vpp)
VREF(vdp);
else if (lockp == 0 || last == 0)
AUNLOCK(pap);
VOP_UNLOCK(vdp);
found_lockdone:
ndp->ni_vp = ATOV(ap);
if ((cnp->cn_flags & MAKEENTRY) && nocache == 0)
cache_enter(vdp, *vpp, cnp);
if (ndp->ni_makeentry && nocache == 0)
cache_enter(ndp);
#ifdef ADOSFS_DIAGNOSTIC
printf("0)\n");
#endif

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: adosfs.h,v 1.1 1994/05/11 18:49:10 chopps Exp $
* $Id: adosfs.h,v 1.2 1994/06/17 20:06:08 chopps Exp $
*/
/*
@ -72,11 +72,6 @@ struct anode {
int adprot; /* (d/f) amigados protection bits */
int flags; /* misc flags */
char *slinkto; /* name of file or dir */
#ifdef DIAGNOSTIC
struct proc *plock; /* process holding the lock */
const char *whereat; /* where lock was obtained */
int line; /* line where lock obtained */
#endif
};
#define VTOA(vp) ((struct anode *)(vp)->v_data)
#define ATOV(ap) ((ap)->vp)
@ -123,26 +118,12 @@ struct amount {
*/
long adoswordn __P((struct buf *, int));
long adoscksum __P((struct buf *, long));
void aput __P((struct anode *));
int aget __P((struct mount *, u_long, struct anode **));
int adoshash __P((const char *, int, int));
#ifdef DIAGNOSTIC
int atrylock __P((struct anode *, const char *, int));
void alock __P((struct anode *, const char *,int));
#ifdef __GNUC__
#define ALOCK(ap) alock((ap), __FUNCTION__ ":" __FILE__, __LINE__)
#define ATRYLOCK(ap) atrylock((ap), __FUNCTION__ ":" __FILE__, __LINE__)
#else /* !__GNUC__ */
#define ALOCK(ap) alock((ap), __FILE__, __LINE__)
#define ATRYLOCK(ap) atrylock((ap), __FILE__, __LINE__)
#endif /* !__GNUC__ */
#else /* !DIAGNOSTIC */
int atrylock __P((struct anode *));
void alock __P((struct anode *));
#define ALOCK(ap) alock((ap))
#define ATRYLOCK(ap) atrylock((ap))
#endif /* !DIAGNOSTIC */
void aunlock __P((struct anode *));
#define AUNLOCK(ap) aunlock(ap)
struct vnode *adosfs_ahashget __P((struct mount *, ino_t));
void adosfs_ainshash __P((struct amount *, struct anode *));
void adosfs_aremhash __P((struct anode *));
int adosfs_lookup __P((struct vop_lookup_args *));
int (**adosfs_vnodeop_p)();

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: adutil.c,v 1.2 1994/06/02 23:42:19 chopps Exp $
* $Id: adutil.c,v 1.3 1994/06/17 20:06:09 chopps Exp $
*/
#include <sys/param.h>
#include <sys/vnode.h>
@ -43,11 +43,11 @@
* look for anode in the mount's hash table, return locked.
*/
#define AHASH(an) ((an) & (ANODEHASHSZ - 1))
int
ahashget(mp, an, app)
struct vnode *
adosfs_ahashget(mp, an)
struct mount *mp;
u_long an;
struct anode **app;
ino_t an;
{
struct anodechain *hp;
struct anode *ap;
@ -59,363 +59,74 @@ start_over:
if (ap->block != an)
continue;
if (ap->flags & ALOCKED) {
#ifdef DIAGNOSTIC
if (ap->plock == curproc) {
printf("deadlock: proc: %x, alock()\n"
"first:%s:%d\nsecond:%s:%d\n", ap->plock,
ap->whereat, ap->line, "ahashget():"
__FILE__, __LINE__);
panic("alock(), deadlock");
}
#endif
ap->flags |= AWANT;
tsleep((caddr_t)ap, PINOD, "alock", 0);
tsleep(ap, PINOD, "ahashget", 0);
goto start_over;
}
if (vget(ATOV(ap), 1))
goto start_over;
*app = ap;
return(1);
return (ATOV(ap));
}
return(0);
}
/*
* lookup an anode, check mount's hash table if not found, create
* return locked
*/
int
aget(mp, an, app)
struct mount *mp;
u_long an;
struct anode **app;
{
extern struct vnodeops adosfs_vnodeops;
struct amount *amp;
struct vnode *vp;
struct anode *ap;
struct buf *bp;
char *nam, *tmp;
int namlen, error, tmplen;
#ifdef ADOSFS_DIAGNOSTIC
printf("(aget [0x%x %d 0x%x]", mp, an, app);
#endif
error = 0;
bp = NULL;
*app = NULL;
/*
* check hash table.
*/
if (ahashget(mp, an, app))
goto reterr;
if (error = getnewvnode(VT_ADOSFS, mp, &adosfs_vnodeops, &vp))
goto reterr;
/*
* setup minimal; put in table and lock before doing io.
*/
amp = VFSTOADOSFS(mp);
ap = VTOA(vp);
ap->amp = amp;
ap->vp = vp;
ap->block = an;
ap->nwords = amp->nwords;
LIST_INSERT_HEAD(&amp->anodetab[AHASH(an)], ap, link);
ALOCK(ap);
if (error = bread(amp->devvp, an, amp->bsize, NOCRED, &bp))
goto fail;
if (adoscksum(bp, amp->nwords)) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: cksum of blk %d failed\n", an);
#endif
error = EINVAL;
goto fail;
}
/*
* now check primary block type.
*/
if (adoswordn(bp, 0) != BPT_SHORT) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: bad primary type blk %d\n", an);
#endif
error = EINVAL;
goto fail;
}
/*
* get type and fill rest in based on that.
*/
switch (adoswordn(bp, ap->nwords - 1)) {
case BST_RDIR: /* root block */
if (amp->rootb != an) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: rootblk mismatch %x\n", an);
#endif
error = EINVAL;
break;
}
vp->v_type = VDIR;
vp->v_flag |= VROOT;
ap->type = AROOT;
ap->mtimev.days = adoswordn(bp, ap->nwords - 10);
ap->mtimev.mins = adoswordn(bp, ap->nwords - 9);
ap->mtimev.ticks = adoswordn(bp, ap->nwords - 8);
ap->created.days = adoswordn(bp, ap->nwords - 7);
ap->created.mins = adoswordn(bp, ap->nwords - 6);
ap->created.ticks = adoswordn(bp, ap->nwords - 5);
/* XXX load bmap */
break;
case BST_LDIR: /* hard link to dir */
vp->v_type = VDIR;
ap->type = ALDIR;
break;
case BST_UDIR: /* user dir */
vp->v_type = VDIR;
ap->type = ADIR;
break;
case BST_LFILE: /* hard link to file */
vp->v_type = VREG;
ap->type = ALFILE;
ap->fsize = adoswordn(bp, ap->nwords - 47);
break;
case BST_FILE: /* file header */
vp->v_type = VREG;
ap->type = AFILE;
ap->fsize = adoswordn(bp, ap->nwords - 47);
break;
case BST_SLINK: /* XXX soft link */
vp->v_type = VLNK;
ap->type = ASLINK;
/*
* convert from BCPL string and
* from: "part:dir/file" to: "/part/dir/file"
*/
nam = bp->b_un.b_addr + (6 * sizeof(long));
tmplen = namlen = *(u_char *)nam++;
tmp = nam;
while (tmplen-- && *tmp != ':')
tmp++;
if (*tmp == 0) {
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
bcopy(nam, ap->slinkto, namlen);
} else if (*nam == ':') {
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
bcopy(nam, ap->slinkto, namlen);
ap->slinkto[0] = '/';
} else {
ap->slinkto = malloc(namlen + 2, M_ANODE, M_WAITOK);
ap->slinkto[0] = '/';
bcopy(nam, &ap->slinkto[1], namlen);
ap->slinkto[tmp - nam + 1] = '/';
namlen++;
}
ap->slinkto[namlen] = 0;
break;
default:
#ifdef DIAGNOSTIC
printf("aodsfs: aget: unknown secondary type blk %d\n", an);
#endif
error = EINVAL;
break;
}
if (error)
goto fail;
/*
* if dir alloc hash table and copy it in
*/
if (vp->v_type == VDIR) {
int i;
ap->tab = malloc(ANODETABSZ(ap) * 2, M_ANODE, M_WAITOK);
ap->ntabent = ANODETABENT(ap);
ap->tabi = (int *)&ap->tab[ap->ntabent];
bzero(ap->tabi, ANODETABSZ(ap));
for (i = 0; i < ap->ntabent; i++)
ap->tab[i] = adoswordn(bp, i + 6);
}
/*
* misc.
*/
ap->pblock = adoswordn(bp, ap->nwords - 3);
ap->hashf = adoswordn(bp, ap->nwords - 4);
ap->linknext = adoswordn(bp, ap->nwords - 10);
ap->linkto = adoswordn(bp, ap->nwords - 11);
if (ap->type == AROOT)
ap->adprot = 0;
else
ap->adprot = adoswordn(bp, ap->nwords - 48);
ap->mtime.days = adoswordn(bp, ap->nwords - 23);
ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
/*
* copy in name
*/
nam = bp->b_un.b_addr + (ap->nwords - 20) * sizeof(long);
namlen = *(u_char *)nam++;
if (namlen > 30) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: name length too long blk %d\n", an);
#endif
error = EINVAL;
goto fail;
}
bcopy(nam, ap->name, namlen);
ap->name[namlen] = 0;
brelse(bp);
*app = ap;
if (0) {
fail:
if (bp)
brelse(bp);
LIST_REMOVE(ap, link);
aput(ap);
}
reterr:
#ifdef ADOSFS_DIAGNOSTIC
printf(" %d)", error);
#endif
return(error);
}
void
aput(ap)
struct anode *ap;
{
#ifdef ADOSFS_DIAGNOSTIC
printf("(aput [0x%x]", ap);
#endif
AUNLOCK(ap);
vrele(ATOV(ap));
#ifdef ADOSFS_DIAGNOSTIC
printf(")");
#endif
return (NULL);
}
/*
* the kernel wants its vnode back.
* no lock needed we are being called from vclean()
* insert in hash table and lock
*/
int
adosfs_reclaim(vp)
struct vnode *vp;
{
struct anodechain *hp;
void
adosfs_ainshash(amp, ap)
struct amount *amp;
struct anode *ap;
{
LIST_INSERT_HEAD(&amp->anodetab[AHASH(ap->block)], ap, link);
ap->flags |= ALOCKED;
}
#ifdef ADOSFS_DIAGNOSTIC
printf("(reclaim 0)");
#endif
ap = VTOA(vp);
void
adosfs_aremhash(ap)
struct anode *ap;
{
LIST_REMOVE(ap, link);
if (vp->v_type == VDIR)
free(ap->tab, M_ANODE);
else if (vp->v_type == VLNK)
free(ap->slinkto, M_ANODE);
cache_purge(vp);
return(0);
}
#ifdef DIAGNOSTIC
int
atrylock(ap, whereat, line)
struct anode *ap;
const char *whereat;
int line;
{
if (ap->flags & ALOCKED)
return(0);
ap->flags |= ALOCKED;
ap->plock = curproc;
ap->whereat = whereat;
ap->line = line;
return(1);
}
void
alock(ap, whereat, line)
struct anode *ap;
const char *whereat;
int line;
{
while (ap->flags & ALOCKED) {
if (ap->plock == curproc) {
printf("deadlock: proc: %x, alock()\nfirst:%s:%d\n"
"second:%s:%d\n", ap->plock, ap->whereat,
ap->line, whereat, line);
panic("alock(), deadlock");
}
ap->flags |= AWANT;
tsleep((caddr_t)ap, PINOD, "alock", 0);
}
ap->flags |= ALOCKED;
ap->plock = curproc;
ap->whereat = whereat;
ap->line = line;
}
void
aunlock(ap)
struct anode *ap;
{
if ((ap->flags & ALOCKED) == 0)
panic("aunlock: not locked");
ap->flags &= ~ALOCKED;
ap->plock = NULL;
ap->whereat = NULL;
ap->line = 0;
if (ap->flags & AWANT) {
ap->flags &= ~AWANT;
wakeup((caddr_t)ap);
}
}
#else /* !DIAGNOSTIC */
int
atrylock(ap)
struct anode *ap;
adosfs_getblktype(amp, bp)
struct amount *amp;
struct buf *bp;
{
if (ap->flags & ALOCKED)
return(0);
ap->flags |= ALOCKED;
return(1);
}
void
alock(ap)
struct anode *ap;
{
while (ap->flags & ALOCKED) {
ap->flags |= AWANT;
tsleep((caddr_t)ap, PINOD, "alock", 0);
if (adoscksum(bp, amp->nwords)) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: cksum of blk %d failed\n", bp->b_blkno);
#endif
return (-1);
}
ap->flags |= ALOCKED;
}
void
aunlock(ap)
struct anode *ap;
{
if ((ap->flags & ALOCKED) == 0)
panic("aunlock: not locked");
ap->flags &= ~ALOCKED;
if (ap->flags & AWANT) {
ap->flags &= ~AWANT;
wakeup((caddr_t)ap);
/*
* check primary block type
*/
if (adoswordn(bp, 0) != BPT_SHORT) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: bad primary type blk %d\n", bp->b_blkno);
#endif
return (-1);
}
switch (adoswordn(bp, amp->nwords - 1)) {
case BST_RDIR: /* root block */
return (AROOT);
case BST_LDIR: /* hard link to dir */
return (ALDIR);
case BST_UDIR: /* user dir */
return (ADIR);
case BST_LFILE: /* hard link to file */
return (ALFILE);
case BST_FILE: /* file header */
return (AFILE);
case BST_SLINK: /* soft link */
return (ASLINK);
}
return (-1);
}
#endif /* !DIAGNOSTIC */
int
adunixprot(adprot)
@ -441,7 +152,7 @@ adoscksum(bp, n)
{
long sum, *lp;
lp = (long *)bp->b_un.b_addr;
lp = (long *)bp->b_data;
sum = 0;
while (n--)
@ -490,5 +201,5 @@ adoswordn(bp, wn)
/*
* ados stored in network (big endian) order
*/
return(ntohl(*((long *)bp->b_un.b_addr + wn)));
return(ntohl(*((long *)bp->b_data + wn)));
}

View File

@ -27,12 +27,13 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: advfsops.c,v 1.1 1994/05/11 18:49:15 chopps Exp $
* $Id: advfsops.c,v 1.2 1994/06/17 20:06:12 chopps Exp $
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/time.h>
#include <sys/malloc.h>
#include <sys/disklabel.h>
@ -72,43 +73,37 @@ adosfs_mount(mp, path, data, ndp, p)
/*
* lookup blkdev name and validate.
*/
ndp->ni_nameiop = LOOKUP | FOLLOW;
ndp->ni_segflg = UIO_USERSPACE;
ndp->ni_dirp = args.fspec;
if (error = namei(ndp, p)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("adosfs_mount: namei() failed\n");
#endif
return(error);
}
NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
if (error = namei(ndp))
return (error);
bdvp = ndp->ni_vp;
if (bdvp->v_type != VBLK) {
vrele(bdvp);
return(ENOTBLK);
return (ENOTBLK);
}
if (major(bdvp->v_rdev) >= nblkdev) {
vrele(bdvp);
return(ENXIO);
return (ENXIO);
}
if (error = mountadosfs(mp, path, bdvp, &args, p))
if (error = adosfs_mountfs(mp, path, bdvp, &args, p))
vrele(bdvp);
return(error);
}
int
mountadosfs(mp, path, bdvp, args, p)
adosfs_mountfs(mp, path, bdvp, args, p)
struct mount *mp;
char *path;
struct vnode *bdvp;
struct adosfs_args *args;
struct proc *p;
{
extern struct vnodeops adosfs_vnodeops;
struct disklabel dl;
struct partition *parp;
struct amount *amp;
struct statfs *sfp;
struct anode *rap;
struct vnode *rvp;
int error, nl, part, i;
#ifdef DISKPART
@ -117,60 +112,27 @@ mountadosfs(mp, path, bdvp, args, p)
part = minor(bdvp->v_rdev) % MAXPARTITIONS;
#error just_for_now
#endif
amp = NULL;
/*
* anything mounted on blkdev?
*/
if (error = mountedon(bdvp)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("mountadosfs: mountedon() failed\n");
#endif
return(error);
}
/*
* XXX device currently in use? fail unless it is root XXX
*/
#if yes_do_this
if (error = vfs_mountedon(bdvp))
return (error);
if (vcount(bdvp) > 1 && bdvp != rootvp)
return(EBUSY);
#endif
vinvalbuf(bdvp, 1);
return (EBUSY);
if (error = vinvalbuf(bdvp, V_SAVE, p->p_ucred, p, 0, 0))
return (error);
/*
* opend blkdev and read root block
* open blkdev and read root block
*/
if (error = VOP_OPEN(bdvp, FREAD, NOCRED, p)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("mountadosfs: VOP_OPEN() failed\n");
#endif
return(error);
}
amp = malloc(sizeof(struct amount), M_ADOSFSMNT, M_WAITOK);
if (error = VOP_IOCTL(bdvp,DIOCGDINFO,(caddr_t)&dl, FREAD, NOCRED, p)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("mountadosfs: VOP_IOCTL() failed\n");
#endif
if (error = VOP_OPEN(bdvp, FREAD, NOCRED, p))
return (error);
if (error = VOP_IOCTL(bdvp, DIOCGDINFO,(caddr_t)&dl, FREAD, NOCRED, p))
goto fail;
}
if (part >= dl.d_npartitions) {
#ifdef DIAGNOSTIC
printf("adosfs_mount: %n with only %d partitions on drive\n",
part, dl.d_npartitions);
#endif
error = EINVAL; /* XXX correct? */
goto fail;
}
if (dl.d_partitions[part].p_fstype != FS_ADOS) {
#ifdef DIAGNOSTIC
printf("adosfs_mount: not an ados partition\n");
#endif
error = EINVAL;
goto fail;
}
parp = &dl.d_partitions[part];
amp = malloc(sizeof(struct amount), M_ADOSFSMNT, M_WAITOK);
amp->mp = mp;
amp->startb = parp->p_offset;
amp->endb = parp->p_offset + parp->p_size;
@ -211,20 +173,16 @@ mountadosfs(mp, path, bdvp, args, p)
/*
* get the root anode, if not a valid fs this will fail.
*/
if (error = aget(mp, amp->rootb, &rap)) {
#ifdef ADOSFS_DIAGNOSTIC
printf("mountadosfs: aget() failed\n");
#endif
if (error = VFS_ROOT(mp, &rvp))
goto fail;
}
amp->rootvp = ATOV(rap);
AUNLOCK(rap);
(void)adosfs_statfs(mp, &mp->mnt_stat, p);
vput(rvp);
(void)adosfs_statfs(mp, &mp->mnt_stat, p);
return(0);
fail:
VOP_CLOSE(bdvp, FREAD, NOCRED, p);
free(amp, M_ADOSFSMNT);
if (amp)
free(amp, M_ADOSFSMNT);
return(error);
}
@ -234,9 +192,6 @@ adosfs_start(mp, flags, p)
int flags;
struct proc *p;
{
#ifdef ADOSFS_DIAGNOSTIC
printf("adstart(%x, %x, %x)\n", mp, flags, p);
#endif
return(0);
}
@ -255,36 +210,32 @@ adosfs_unmount(mp, flags, p)
printf("adumount(%x, %x, %x)\n", mp, flags, p);
#endif
amp = VFSTOADOSFS(mp);
rvp = amp->rootvp;
bdvp = amp->devvp;
if (flags & MNT_FORCE) {
if (doforce == 0)
if (mp->mnt_flag & MNT_ROOTFS)
return(EINVAL); /*XXX*/
flags |= FORCECLOSE;
if (doforce)
flags |= FORCECLOSE;
else
flags &= ~FORCECLOSE;
}
/*
* clean out cached stuff
*/
mntflushbuf(mp, 0);
if (mntinvalbuf(mp))
return(EBUSY);
if (rvp->v_usecount > 1)
return(EBUSY);
error = vflush(mp, rvp, flags);
if (error)
return(error);
if (error = vflush(mp, rvp, flags))
return (error);
/*
* release block device we are mounted on.
*/
bdvp->v_specflags &= ~SI_MOUNTEDON;
VOP_CLOSE(bdvp, FREAD, NOCRED, p);
error = VOP_CLOSE(bdvp, FREAD, NOCRED, p);
vrele(amp->devvp);
free(amp, M_ADOSFSMNT);
mp->mnt_data = 0;
return(0);
mp->mnt_flag &= ~MNT_LOCAL;
return (error);
}
int
@ -292,30 +243,13 @@ adosfs_root(mp, vpp)
struct mount *mp;
struct vnode **vpp;
{
struct vnode *rvp;
struct vnode *nvp;
int error;
#ifdef ADOSFS_DIAGNOSTIC
printf("adroot(%x, %x)\n", mp, vpp);
#endif
rvp = VFSTOADOSFS(mp)->rootvp;
VREF(rvp);
VOP_LOCK(rvp);
*vpp = rvp;
return(0);
}
int
adosfs_quotactl(mp, cmds, uid, arg, p)
struct mount *mp;
int cmds;
uid_t uid;
caddr_t arg;
struct proc *p;
{
#ifdef ADOSFS_DIAGNOSTIC
printf("adquatactl(%x, %x, %x, %x, %x)\n", mp, cmds, uid, arg, p);
#endif
return(EOPNOTSUPP);
if (error = VFS_VGET(mp, (ino_t)VFSTOADOSFS(mp)->rootb, &nvp))
return (error);
*vpp = nvp;
return (0);
}
int
@ -348,15 +282,160 @@ adosfs_statfs(mp, sbp, p)
return(0);
}
/*
* lookup an anode, check mount's hash table if not found, create
* return locked and referenced al la vget(vp, 1);
*/
int
adosfs_sync(mp, waitfor)
adosfs_vget(mp, an, vpp)
struct mount *mp;
int waitfor;
ino_t an;
struct vnode **vpp;
{
#ifdef ADOSFS_DIAGNOSTIC
printf("ad_sync(%x, %x)\n", mp, waitfor);
struct amount *amp;
struct vnode *vp;
struct anode *ap;
struct buf *bp;
char *nam, *tmp;
int namlen, error, tmplen;
error = 0;
amp = VFSTOADOSFS(mp);
bp = NULL;
/*
* check hash table. we are done if found
*/
if (*vpp = adosfs_ahashget(mp, an))
return (0);
if (error = getnewvnode(VT_ADOSFS, mp, adosfs_vnodeop_p, &vp))
return (error);
/*
* setup, insert in hash, and lock before io.
*/
vp->v_data = ap = malloc(sizeof(struct anode), M_ANODE, M_WAITOK);
bzero(ap, sizeof(struct anode));
ap->vp = vp;
ap->amp = amp;
ap->block = an;
ap->nwords = amp->nwords;
adosfs_ainshash(amp, ap);
if (error = bread(amp->devvp, an, amp->bsize, NOCRED, &bp)) {
vput(vp);
return (error);
}
/*
* get type and fill rest in based on that.
*/
switch (ap->type = adosfs_getblktype(amp, bp)) {
case AROOT:
vp->v_type = VDIR;
vp->v_flag |= VROOT;
ap->mtimev.days = adoswordn(bp, ap->nwords - 10);
ap->mtimev.mins = adoswordn(bp, ap->nwords - 9);
ap->mtimev.ticks = adoswordn(bp, ap->nwords - 8);
ap->created.days = adoswordn(bp, ap->nwords - 7);
ap->created.mins = adoswordn(bp, ap->nwords - 6);
ap->created.ticks = adoswordn(bp, ap->nwords - 5);
break;
case ALDIR:
vp->v_type = VDIR;
break;
case ADIR:
vp->v_type = VDIR;
break;
case ALFILE:
vp->v_type = VREG;
ap->fsize = adoswordn(bp, ap->nwords - 47);
break;
case AFILE:
vp->v_type = VREG;
ap->fsize = adoswordn(bp, ap->nwords - 47);
break;
case ASLINK: /* XXX soft link */
vp->v_type = VLNK;
/*
* convert from BCPL string and
* from: "part:dir/file" to: "/part/dir/file"
*/
nam = bp->b_data + (6 * sizeof(long));
tmplen = namlen = *(u_char *)nam++;
tmp = nam;
while (tmplen-- && *tmp != ':')
tmp++;
if (*tmp == 0) {
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
bcopy(nam, ap->slinkto, namlen);
} else if (*nam == ':') {
ap->slinkto = malloc(namlen + 1, M_ANODE, M_WAITOK);
bcopy(nam, ap->slinkto, namlen);
ap->slinkto[0] = '/';
} else {
ap->slinkto = malloc(namlen + 2, M_ANODE, M_WAITOK);
ap->slinkto[0] = '/';
bcopy(nam, &ap->slinkto[1], namlen);
ap->slinkto[tmp - nam + 1] = '/';
namlen++;
}
ap->slinkto[namlen] = 0;
break;
default:
brelse(bp);
vput(vp);
return (EINVAL);
}
/*
* if dir alloc hash table and copy it in
*/
if (vp->v_type == VDIR) {
int i;
ap->tab = malloc(ANODETABSZ(ap) * 2, M_ANODE, M_WAITOK);
ap->ntabent = ANODETABENT(ap);
ap->tabi = (int *)&ap->tab[ap->ntabent];
bzero(ap->tabi, ANODETABSZ(ap));
for (i = 0; i < ap->ntabent; i++)
ap->tab[i] = adoswordn(bp, i + 6);
}
/*
* misc.
*/
ap->pblock = adoswordn(bp, ap->nwords - 3);
ap->hashf = adoswordn(bp, ap->nwords - 4);
ap->linknext = adoswordn(bp, ap->nwords - 10);
ap->linkto = adoswordn(bp, ap->nwords - 11);
if (ap->type == AROOT)
ap->adprot = 0;
else
ap->adprot = adoswordn(bp, ap->nwords - 48);
ap->mtime.days = adoswordn(bp, ap->nwords - 23);
ap->mtime.mins = adoswordn(bp, ap->nwords - 22);
ap->mtime.ticks = adoswordn(bp, ap->nwords - 21);
/*
* copy in name
*/
nam = bp->b_data + (ap->nwords - 20) * sizeof(long);
namlen = *(u_char *)nam++;
if (namlen > 30) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: name length too long blk %d\n", an);
#endif
return(0);
brelse(bp);
vput(vp);
return (EINVAL);
}
bcopy(nam, ap->name, namlen);
ap->name[namlen] = 0;
*vpp = vp; /* return vp */
brelse(bp); /* release buffer */
return (0);
}
int
@ -383,14 +462,33 @@ adosfs_vptofh(vp, fhp)
}
int
adosfs_init()
adosfs_quotactl(mp, cmds, uid, arg, p)
struct mount *mp;
int cmds;
uid_t uid;
caddr_t arg;
struct proc *p;
{
return(EOPNOTSUPP);
}
int
adosfs_sync(mp, waitfor)
struct mount *mp;
int waitfor;
{
#ifdef ADOSFS_DIAGNOSTIC
printf("adinit()\n");
printf("ad_sync(%x, %x)\n", mp, waitfor);
#endif
return(0);
}
int
adosfs_init()
{
return(0);
}
/*
* vfs generic function call table
*/
@ -403,8 +501,8 @@ struct vfsops adosfs_vfsops = {
adosfs_quotactl,
adosfs_statfs,
adosfs_sync,
adosfs_vget,
adosfs_fhtovp,
adosfs_vptofh,
adosfs_init,
};

File diff suppressed because it is too large Load Diff