* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)mfs_vnops.c 7.22 (Berkeley) %G%
#include "machine/vmparam.h"
#include "machine/mtpr.h"
#if !defined(hp300) && !defined(i386)
static int mfsmap_want
; /* 1 => need kernel I/O resources */
struct map mfsmap
[MFS_MAPSIZE
];
struct vnodeops mfs_vnodeops
= {
mfs_getattr
, /* getattr */
mfs_setattr
, /* setattr */
mfs_symlink
, /* symlink */
mfs_readdir
, /* readdir */
mfs_readlink
, /* readlink */
mfs_abortop
, /* abortop */
mfs_inactive
, /* inactive */
mfs_reclaim
, /* reclaim */
mfs_strategy
, /* strategy */
mfs_islocked
, /* islocked */
mfs_advlock
, /* advlock */
* Open called to allow memory filesystem to initialize and
* validate before actual IO. Record our process identifier
* so we can tell when we are doing I/O to ourself.
mfs_open(vp
, mode
, cred
, p
)
register struct vnode
*vp
;
if (vp
->v_type
!= VBLK
) {
panic("mfs_ioctl not VBLK");
mfs_ioctl(vp
, com
, data
, fflag
, cred
, p
)
* Pass I/O requests to the memory filesystem process.
register struct mfsnode
*mfsp
;
struct proc
*p
= curproc
; /* XXX */
if (vfinddev(bp
->b_dev
, VBLK
, &vp
) || vp
->v_usecount
== 0)
panic("mfs_strategy: bad dev");
if (mfsp
->mfs_pid
== p
->p_pid
) {
mfs_doio(bp
, mfsp
->mfs_baseoff
);
bp
->av_forw
= mfsp
->mfs_buflist
;
#if defined(vax) || defined(tahoe)
* Memory file system I/O.
* Essentially play ubasetup() and disk interrupt service routine by
* doing the copies to or from the memfs process. If doing physio
* (i.e. pagein), we must map the I/O through the kernel virtual
register struct pte
*pte
, *ppte
;
caddr_t kernaddr
, offset
;
* For phys I/O, map the b_addr into kernel virtual space using
if ((bp
->b_flags
& B_PHYS
) == 0) {
kernaddr
= bp
->b_un
.b_addr
;
if (bp
->b_flags
& (B_PAGET
| B_UAREA
| B_DIRTY
))
off
= (int)bp
->b_un
.b_addr
& PGOFSET
;
npf
= btoc(bp
->b_bcount
+ off
);
* Get some mapping page table entries
while ((reg
= rmalloc(mfsmap
, (long)npf
)) == 0) {
sleep((caddr_t
)&mfsmap_want
, PZERO
-1);
pte
= vtopte(bp
->b_proc
, btop(bp
->b_un
.b_addr
));
* Do vmaccess() but with the Mfsiomap page table.
vaddr
= &mfsiobuf
[reg
* NBPG
];
for (npf2
= npf
; npf2
; npf2
--) {
mapin(ppte
, (u_int
)vaddr
, pte
->pg_pfnum
,
if ((bp
->b_flags
& B_READ
) == 0)
offset
= base
+ (bp
->b_blkno
<< DEV_BSHIFT
);
if (bp
->b_flags
& B_READ
)
bp
->b_error
= copyin(offset
, kernaddr
, bp
->b_bcount
);
bp
->b_error
= copyout(kernaddr
, offset
, bp
->b_bcount
);
* Release pte's used by physical I/O.
if (bp
->b_flags
& B_PHYS
) {
rmfree(mfsmap
, (long)npf
, (long)++reg
);
wakeup((caddr_t
)&mfsmap_want
);
#endif /* vax || tahoe */
#if defined(hp300) || defined(i386)
* Memory file system I/O.
* Trivial on the HP since buffer has already been mapping into KVA space.
base
+= (bp
->b_blkno
<< DEV_BSHIFT
);
if (bp
->b_flags
& B_READ
)
bp
->b_error
= copyin(base
, bp
->b_un
.b_addr
, bp
->b_bcount
);
bp
->b_error
= copyout(bp
->b_un
.b_addr
, base
, bp
->b_bcount
);
* This is a noop, simply returning what one has been given.
mfs_bmap(vp
, bn
, vpp
, bnp
)
* Memory filesystem close routine
mfs_close(vp
, flag
, cred
, p
)
register struct vnode
*vp
;
register struct mfsnode
*mfsp
= VTOMFS(vp
);
* Finish any pending I/O requests.
while (bp
= mfsp
->mfs_buflist
) {
mfsp
->mfs_buflist
= bp
->av_forw
;
mfs_doio(bp
, mfsp
->mfs_baseoff
);
* On last close of a memory filesystem
* we must invalidate any in core blocks, so that
* we can, free up its vnode.
* There should be no way to have any more uses of this
* vnode, so if we find any other uses, it is a panic.
printf("mfs_close: ref count %d > 1\n", vp
->v_usecount
);
if (vp
->v_usecount
> 1 || mfsp
->mfs_buflist
)
* Send a request to the filesystem server to exit.
mfsp
->mfs_buflist
= (struct buf
*)(-1);
* Memory filesystem inactive routine
if (VTOMFS(vp
)->mfs_buflist
!= (struct buf
*)(-1))
panic("mfs_inactive: not inactive");
* Print out the contents of an mfsnode.
register struct mfsnode
*mfsp
= VTOMFS(vp
);
printf("tag VT_MFS, pid %d, base %d, size %d\n", mfsp
->mfs_pid
,
mfsp
->mfs_baseoff
, mfsp
->mfs_size
);
* Block device bad operation
panic("mfs_badop called\n");
* Memory based filesystem initialization.
#if !defined(hp300) && !defined(i386)
rminit(mfsmap
, (long)MFS_MAPREG
, (long)1, "mfs mapreg", MFS_MAPSIZE
);