Subject: Re: README: VFS change, breakings LKMs
To: Hal Murray <murray@pa.dec.com>
From: Jaromir Dolecek <dolecek@ics.muni.cz>
List: current-users
Date: 03/17/2000 09:06:38
Hal Murray wrote:
> 
> > As usual, when the kernel version gets bumped,. you really should
> > re-compile all lkm's.
> 
> Sorry, I should have been more specific.
> 
> I was thinking of a run-time (load time?) check to make sure that 
> the module had been recompiled correctly. 

What about this ?

XXXXX
Index: sys/mount.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/mount.h,v
retrieving revision 1.82
diff -u -p -r1.82 mount.h
--- mount.h	2000/03/16 18:08:17	1.82
+++ mount.h	2000/03/17 08:04:00
@@ -344,6 +344,12 @@ struct vfsops {
 #endif /* _KERNEL */
 
 /*
+ * VFS interface version number.
+ */
+#define	VFS_VERSION	0x01
+int	vfs_check_version __P((int));
+
+/*
  * Flags for various system call interfaces.
  *
  * waitfor flags to vfs_sync() and getfsstat()
Index: sys/lkm.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/lkm.h,v
retrieving revision 1.17
diff -u -p -r1.17 lkm.h
--- lkm.h	1999/01/13 23:06:28	1.17
+++ lkm.h	2000/03/17 08:04:02
@@ -67,7 +67,7 @@ typedef enum loadmod {
 struct lkm_syscall {
 	MODTYPE	lkm_type;
 	int	lkm_ver;
-	char	*lkm_name;
+	const char *lkm_name;
 	u_long	lkm_offset;		/* save/assign area */
 	struct sysent	*lkm_sysent;
 	struct sysent	lkm_oldent;	/* save area for unload */
@@ -79,7 +79,7 @@ struct lkm_syscall {
 struct lkm_vfs {
 	MODTYPE	lkm_type;
 	int	lkm_ver;
-	char	*lkm_name;
+	const char *lkm_name;
 	u_long	lkm_offset;
 	struct vfsops	*lkm_vfsops;
 };
@@ -98,7 +98,7 @@ typedef enum devtype {
 struct lkm_dev {
 	MODTYPE	lkm_type;
 	int	lkm_ver;
-	char	*lkm_name;
+	const char *lkm_name;
 	u_long	lkm_offset;
 	DEVTYPE	lkm_devtype;
 	union {
@@ -118,7 +118,7 @@ struct lkm_dev {
 struct lkm_strmod {
 	MODTYPE	lkm_type;
 	int	lkm_ver;
-	char	*lkm_name;
+	const char *lkm_name;
 	u_long	lkm_offset;
 	/*
 	 * Removed: future release
@@ -131,7 +131,7 @@ struct lkm_strmod {
 struct lkm_exec {
 	MODTYPE	lkm_type;
 	int	lkm_ver;
-	char	*lkm_name;
+	const char *lkm_name;
 	u_long	lkm_offset;
 	struct execsw	*lkm_exec;
 	struct execsw	lkm_oldexec;
@@ -265,6 +265,8 @@ extern int	lkmdispatch __P((struct lkm_t
 #define	DISPATCH(lkmtp,cmd,ver,load,unload,stat)			\
 	if (ver != LKM_VERSION)						\
 		return EINVAL;	/* version mismatch */			\
+	if (cmd == LM_VFS && !vfs_check_version(VFS_VERSION))		\
+		return EFTYPE;	/* VFS version mismatch */		\
 	switch (cmd) {							\
 	int	error;							\
 	case LKM_E_LOAD:						\
Index: kern/vfs_subr.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/vfs_subr.c,v
retrieving revision 1.121
diff -u -p -r1.121 vfs_subr.c
--- vfs_subr.c	2000/03/16 18:08:20	1.121
+++ vfs_subr.c	2000/03/17 08:04:12
@@ -2516,3 +2516,13 @@ vfs_detach(vfs)
 	vfs_opv_free(vfs->vfs_opv_descs);
 	return (0);
 }
+
+/*
+ * Check if given version matches the version of kernel's VFS interface.
+ */
+int
+vfs_check_version(version)
+	int version;
+{
+	return (version == VFS_VERSION);
+}
XXXX

-- 
Jaromir Dolecek <jdolecek@NetBSD.org>      http://www.ics.muni.cz/~dolecek/
@@@@  Wanna a real operating system ? Go and get NetBSD, damn!  @@@@