I ported cpuid for kernel version 2.4.2 to devfs. It now creates
the /dev/cpu/%d/cpuid devices. The changes are straightforward.
Duncan Sands.
--- arch/i386/kernel/cpuid.c.orig Mon Mar 19 17:57:24 2001
+++ arch/i386/kernel/cpuid.c Mon Mar 19 16:13:14 2001
@@ -35,12 +35,15 @@
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/major.h>
+#include <linux/devfs_fs_kernel.h>
#include <asm/processor.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/system.h>
+static devfs_handle_t dir_handle; /* For the directory */
+
#ifdef CONFIG_SMP
struct cpuid_command {
@@ -142,18 +145,38 @@
int __init cpuid_init(void)
{
- if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
+ if (devfs_register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
CPUID_MAJOR);
return -EBUSY;
}
+ dir_handle = devfs_mk_dir(NULL, "cpu", NULL);
+ devfs_register_series(dir_handle, "%u/cpuid", smp_num_cpus, DEVFS_FL_DEFAULT,
+ CPUID_MAJOR, 0,
+ S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
+ &cpuid_fops, NULL);
+
return 0;
}
void __exit cpuid_exit(void)
{
- unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
+ char devname[16];
+ devfs_handle_t handle;
+ unsigned int minor;
+
+#ifdef CONFIG_DEVFS_FS
+ for (minor=0; minor < smp_num_cpus; ++minor)
+ {
+ sprintf(devname, "%u/cpuid", minor);
+ handle = devfs_find_handle(dir_handle, devname, CPUID_MAJOR, minor,
+ DEVFS_SPECIAL_CHR, 0);
+ devfs_unregister(handle);
+ }
+#endif /* CONFIG_DEVFS_FS */
+
+ devfs_unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
}
module_init(cpuid_init);
|