Clean up my source tree to avoid getting hit too badly by the next KSE or

whatever mega-commit.  This goes some way towards adding support for
writeable files (needed by procfs).
This commit is contained in:
des 2001-09-25 13:25:30 +00:00
parent 38da189563
commit 2462e13fc4
2 changed files with 67 additions and 6 deletions

View File

@ -48,6 +48,15 @@ typedef enum {
pfstype_procdir
} pfs_type_t;
/*
* Flags
*/
#define PFS_RDONLY 0x0000 /* read-only (default) */
#define PFS_WRONLY 0x0001 /* write-only */
#define PFS_RDWR 0x0002 /* read-write */
#define PFS_RAWRD 0x0004 /* raw reader */
#define PFS_RAWWR 0x0008 /* raw writer */
/*
* Data structures
*/
@ -56,7 +65,8 @@ struct pfs_node;
struct pfs_bitmap;
#define PFS_FILL_ARGS \
struct thread *td, struct proc *p, struct pfs_node *pn, struct sbuf *sb
struct thread *td, struct proc *p, struct pfs_node *pn, \
struct sbuf *sb, struct uio *uio
#define PFS_FILL_PROTO(name) \
int name(PFS_FILL_ARGS);
typedef int (*pfs_fill_t)(PFS_FILL_ARGS);
@ -134,7 +144,7 @@ int pfs_uninit (struct pfs_info *pi, struct vfsconf *vfc);
/*
* Now for some initialization magic...
*/
#define PSEUDOFS(name, root) \
#define PSEUDOFS(name, root, version) \
\
static struct pfs_info name##_info = { \
#name, \
@ -174,6 +184,7 @@ static struct vfsops name##_vfsops = { \
vfs_stdextattrctl, \
}; \
VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC); \
MODULE_VERSION(name, version); \
MODULE_DEPEND(name, pseudofs, 1, 1, 1);
#endif

View File

@ -216,12 +216,22 @@ pfs_read(struct vop_read_args *va)
if (vn->v_type != VREG)
return (EINVAL);
if (pn->pn_flags & PFS_WRONLY)
return (EBADF);
if (pvd->pvd_pid != NO_PID) {
if ((proc = pfind(pvd->pvd_pid)) == NULL)
return (EIO);
_PHOLD(proc);
PROC_UNLOCK(proc);
}
if (pn->pn_flags & PFS_RAWRD) {
error = (pn->pn_func)(curproc, proc, pn, NULL, uio);
if (proc != NULL)
PRELE(proc);
return (error);
}
sb = sbuf_new(sb, NULL, uio->uio_offset + uio->uio_resid, 0);
if (sb == NULL) {
@ -230,7 +240,7 @@ pfs_read(struct vop_read_args *va)
return (EIO);
}
error = (pn->pn_func)(curthread, proc, pn, sb);
error = (pn->pn_func)(curthread, proc, pn, sb, uio);
if (proc != NULL)
PRELE(proc);
@ -392,7 +402,7 @@ pfs_readlink(struct vop_readlink_args *va)
/* sbuf_new() can't fail with a static buffer */
sbuf_new(&sb, buf, sizeof buf, 0);
error = (pn->pn_func)(curthread, proc, pn, &sb);
error = (pn->pn_func)(curthread, proc, pn, &sb, NULL);
if (proc != NULL)
PRELE(proc);
@ -434,8 +444,48 @@ pfs_setattr(struct vop_setattr_args *va)
}
/*
* Dummy operations
* Read from a file
*/
static int
pfs_write(struct vop_read_args *va)
{
struct vnode *vn = va->a_vp;
struct pfs_vdata *pvd = (struct pfs_vdata *)vn->v_data;
struct pfs_node *pn = pvd->pvd_pn;
struct uio *uio = va->a_uio;
struct proc *proc = NULL;
int error;
if (vn->v_type != VREG)
return (EINVAL);
if (pn->pn_flags & PFS_RDONLY)
return (EBADF);
if (pvd->pvd_pid != NO_PID) {
if ((proc = pfind(pvd->pvd_pid)) == NULL)
return (EIO);
_PHOLD(proc);
PROC_UNLOCK(proc);
}
if (pn->pn_flags & PFS_RAWWR) {
error = (pn->pn_func)(curproc, proc, pn, NULL, uio);
if (proc != NULL)
PRELE(proc);
return (error);
}
/*
* We currently don't support non-raw writers. It's not very
* hard to do, but it probably requires further changes to the
* sbuf API.
*/
return (EIO);
}
/*
* Dummy operations */
static int pfs_erofs(void *va) { return (EROFS); }
#if 0
static int pfs_null(void *va) { return (0); }
@ -464,7 +514,7 @@ static struct vnodeopv_entry_desc pfs_vnodeop_entries[] = {
{ &vop_rmdir_desc, (vop_t *)pfs_erofs },
{ &vop_setattr_desc, (vop_t *)pfs_setattr },
{ &vop_symlink_desc, (vop_t *)pfs_erofs },
{ &vop_write_desc, (vop_t *)pfs_erofs },
{ &vop_write_desc, (vop_t *)pfs_write },
/* XXX I've probably forgotten a few that need pfs_erofs */
{ NULL, (vop_t *)NULL }
};