Subject: Re: kernfs and read()
To: None <tech-kern@NetBSD.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 02/18/2006 15:50:57
--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Sun, Feb 12, 2006 at 09:53:37PM +0100, Manuel Bouyer wrote:
> Hi,
> if I want to add a port-dependant regular file to /kern (say,
> /kern/xen/xenbus) which has read and write methods, should I add a
> KERNFS_XREAD and KERNFS_FILEOP_READ to kfsfileop, and the associated glue ?
Here is a diff for this. Is is OK to commit ?
--
Manuel Bouyer <bouyer@antioche.eu.org>
NetBSD: 26 ans d'experience feront toujours la difference
--
--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff
Index: kernfs.h
===================================================================
RCS file: /cvsroot/src/sys/miscfs/kernfs/kernfs.h,v
retrieving revision 1.26
diff -u -r1.26 kernfs.h
--- kernfs.h 11 Dec 2005 12:24:51 -0000 1.26
+++ kernfs.h 18 Feb 2006 14:50:02 -0000
@@ -144,11 +144,13 @@
* 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 @@
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 @@
};
#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;
Index: kernfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/kernfs/kernfs_vnops.c,v
retrieving revision 1.116
diff -u -r1.116 kernfs_vnops.c
--- kernfs_vnops.c 24 Dec 2005 20:45:09 -0000 1.116
+++ kernfs_vnops.c 18 Feb 2006 14:50:02 -0000
@@ -151,20 +151,25 @@
#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 @@
}
int
-kernfs_read(v)
+kernfs_default_xread(v)
void *v;
{
struct vop_read_args /* {
@@ -940,6 +945,21 @@
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;
--azLHFNyN32YCQGCU--