Allow optionnal /kern regular files to have custom read methods, the same

way writes are handled: Add KERNFS_XREAD and KERNFS_FILEOP_WRITE files
operations definitions to kfsfileop, a xread function pointer to
kernfs_fileop, rename kernfs_read to kernfs_default_xread and add a
kernfs_read calling kernfs_try_fileop(KERNFS_FILEOP_READ).

Proposed on tech-kern on Feb 18 2006.
This commit is contained in:
bouyer 2006-03-14 20:47:52 +00:00
parent 0c402ec936
commit 59b64d6167
2 changed files with 29 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kernfs.h,v 1.26 2005/12/11 12:24:51 christos Exp $ */
/* $NetBSD: kernfs.h,v 1.27 2006/03/14 20:47:52 bouyer Exp $ */
/*
* Copyright (c) 1992, 1993
@ -144,11 +144,13 @@ void kernfs_revoke_sp(struct secpolicy *);
* Data types for the kernfs file operations.
*/
typedef enum {
KERNFS_XREAD,
KERNFS_XWRITE,
KERNFS_FILEOP_CLOSE,
KERNFS_FILEOP_GETATTR,
KERNFS_FILEOP_IOCTL,
KERNFS_FILEOP_OPEN,
KERNFS_FILEOP_READ,
KERNFS_FILEOP_WRITE,
} kfsfileop;
@ -158,6 +160,8 @@ struct kernfs_fileop {
union {
void *_kf_genop;
int (*_kf_vop)(void *);
int (*_kf_xread)
(const struct kernfs_node *, char *, size_t);
int (*_kf_xwrite)
(const struct kernfs_node *, char *, size_t);
} _kf_opfn;
@ -165,6 +169,7 @@ struct kernfs_fileop {
};
#define kf_genop _kf_opfn
#define kf_vop _kf_opfn._kf_vop
#define kf_xread _kf_opfn._kf_xread
#define kf_xwrite _kf_opfn._kf_xwrite
typedef struct kern_target kernfs_parentdir_t;

View File

@ -1,4 +1,4 @@
/* $NetBSD: kernfs_vnops.c,v 1.117 2006/03/01 12:38:32 yamt Exp $ */
/* $NetBSD: kernfs_vnops.c,v 1.118 2006/03/14 20:47:52 bouyer Exp $ */
/*
* Copyright (c) 1992, 1993
@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.117 2006/03/01 12:38:32 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.118 2006/03/14 20:47:52 bouyer Exp $");
#ifdef _KERNEL_OPT
#include "opt_ipsec.h"
@ -151,20 +151,25 @@ int nkern_dirs = 2;
#endif
int kernfs_try_fileop(kfstype, kfsfileop, void *, int);
int kernfs_try_xread(kfstype, const struct kernfs_node *, char *,
size_t, int);
int kernfs_try_xwrite(kfstype, const struct kernfs_node *, char *,
size_t, int);
static int kernfs_default_xread(void *v);
static int kernfs_default_xwrite(void *v);
static int kernfs_default_fileop_getattr(void *);
/* must include all fileop's */
const struct kernfs_fileop kernfs_default_fileops[] = {
{ .kf_fileop = KERNFS_XREAD },
{ .kf_fileop = KERNFS_XWRITE },
{ .kf_fileop = KERNFS_FILEOP_OPEN },
{ .kf_fileop = KERNFS_FILEOP_GETATTR,
.kf_genop = {kernfs_default_fileop_getattr} },
{ .kf_fileop = KERNFS_FILEOP_IOCTL },
{ .kf_fileop = KERNFS_FILEOP_CLOSE },
{ .kf_fileop = KERNFS_FILEOP_READ, .kf_genop = {kernfs_default_xread} },
{ .kf_fileop = KERNFS_FILEOP_WRITE, .kf_genop = {kernfs_default_xwrite} },
};
@ -910,7 +915,7 @@ kernfs_setattr(v)
}
int
kernfs_read(v)
kernfs_default_xread(v)
void *v;
{
struct vop_read_args /* {
@ -940,6 +945,21 @@ kernfs_read(v)
return (error);
}
int
kernfs_read(v)
void *v;
{
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap = v;
struct kernfs_node *kfs = VTOKERN(ap->a_vp);
return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_READ, v, 0);
}
static int
kernfs_default_xwrite(v)
void *v;