diff -Naur fusd-1.10/Makefile fusd-2.6.0-fixed/Makefile --- fusd-1.10/Makefile 2001-09-29 13:23:26.000000000 -0600 +++ fusd-2.6.0-fixed/Makefile 2004-02-17 02:12:53.000000000 -0700 @@ -4,14 +4,14 @@ # # Change this to reflect where your kernel sources are -KERNEL_HOME := /usr/src/linux +KERNEL_HOME := /lib/modules/$(shell uname -r)/build ################################################################## TARGETS := \ libfusd.a \ - kfusd.o \ + kfusd.ko \ regdevice \ opentest \ simpleopen \ @@ -46,9 +46,11 @@ #################################################### +KDIR := /lib/modules/$(shell uname -r)/build -$(OBJDIR)/kfusd.o: $(MODPATH)/kfusd/kfusd.c fusd_msg.h kfusd.h - $(CC) $(KCFLAGS) -c $(MODPATH)/kfusd/kfusd.c -o $(OBJDIR)/kfusd.o +$(OBJDIR)/kfusd.ko: $(MODPATH)/kfusd/kfusd.c fusd_msg.h kfusd.h + $(MAKE) -C $(MODPATH)/kfusd +# $(CC) $(KCFLAGS) -c $(MODPATH)/kfusd/kfusd.c -o $(OBJDIR)/kfusd.o $(OBJDIR)/libfusd.a: $(OBJDIR)/libfusd.o $(AR) -cr $(OBJDIR)/libfusd.a $(OBJDIR)/libfusd.o @@ -64,3 +66,4 @@ install: cp $(OBJDIR)/libfusd.a /usr/local/lib cp include/*.h /usr/local/include + $(MAKE) -C $(MODPATH)/kfusd install diff -Naur fusd-1.10/include/kfusd.h fusd-2.6.0-fixed/include/kfusd.h --- fusd-1.10/include/kfusd.h 2003-07-11 16:29:39.000000000 -0600 +++ fusd-2.6.0-fixed/include/kfusd.h 2004-02-17 01:58:24.000000000 -0700 @@ -110,7 +110,9 @@ pid_t pid; /* PID of device driver */ char *name; /* Name of the device under devfs (/dev) */ void *private_data; /* User's private data */ - devfs_handle_t handle; /* The devfs-provided handle */ + struct cdev* handle; + dev_t dev_id; +// devfs_handle_t handle; /* The devfs-provided handle */ fusd_file_t **files; /* Array of this device's open files */ int array_size; /* Size of the array pointed to by 'files' */ diff -Naur fusd-1.10/kfusd/Makefile fusd-2.6.0-fixed/kfusd/Makefile --- fusd-1.10/kfusd/Makefile 1969-12-31 17:00:00.000000000 -0700 +++ fusd-2.6.0-fixed/kfusd/Makefile 2004-02-17 02:12:26.000000000 -0700 @@ -0,0 +1,26 @@ + + + + +ifneq ($(KERNELRELEASE),) +obj-m := kfusd.o +else +KDIR := /lib/modules/$(shell uname -r)/build +PWD := $(shell pwd) + +default: + echo EXTRA_CFLAGS=-I$(PWD)/../include + $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) EXTRA_CFLAGS=-I$(PWD)/../include modules + +install: + echo EXTRA_CFLAGS=-I$(PWD)/../include + $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) EXTRA_CFLAGS=-I$(PWD)/../include modules + mkdir -p /lib/modules/$(shell uname -r)/misc + cp kfusd.ko /lib/modules/$(shell uname -r)/misc + +clean: + rm kfusd.ko kfusd.o kfusd.mod.o kfusd.mod.c built-in.o +endif + + + diff -Naur fusd-1.10/kfusd/kfusd.c fusd-2.6.0-fixed/kfusd/kfusd.c --- fusd-1.10/kfusd/kfusd.c 2003-07-11 16:29:39.000000000 -0600 +++ fusd-2.6.0-fixed/kfusd/kfusd.c 2004-02-17 01:57:36.000000000 -0700 @@ -70,6 +70,10 @@ #include #include #include +#include +#include +#include + #include #include #include @@ -117,8 +121,14 @@ #endif /* handles that devfs gives /dev/fusd and /dev/fusd_status */ -STATIC devfs_handle_t fusd_handle = 0; -STATIC devfs_handle_t fusd_status_handle = 0; +//STATIC devfs_handle_t fusd_handle = 0; +//STATIC devfs_handle_t fusd_status_handle = 0; + +STATIC struct cdev* fusd_control_device; +STATIC struct cdev* fusd_status_device; + +STATIC dev_t control_id; +STATIC dev_t status_id; /* version number incremented for each registered device */ STATIC int last_version = 1; @@ -133,10 +143,10 @@ LIST_HEAD(fusd_devlist_head); DECLARE_MUTEX(fusd_devlist_sem); -#ifdef MODULE_LICENSE +//#ifdef MODULE_LICENSE MODULE_AUTHOR("Jeremy Elson (c)2001"); MODULE_LICENSE("GPL"); -#endif +//#endif /***************************Debugging Support*****************************/ @@ -448,7 +458,7 @@ atomic_inc_and_ret(&last_version); wake_up_interruptible(&new_device_wait); - MOD_DEC_USE_COUNT; + //MOD_DEC_USE_COUNT; return 1; } @@ -967,6 +977,22 @@ return 0; } +STATIC struct fusd_dev_t_s* find_user_device(int dev_id) +{ + struct list_head* entry; + down(&fusd_devlist_sem); + list_for_each(entry, &fusd_devlist_head) + { + fusd_dev_t *d = list_entry(entry, fusd_dev_t, devlist); + if(d->dev_id == dev_id) + { + up(&fusd_devlist_sem); + return d; + } + } + up(&fusd_devlist_sem); + return NULL; +} /* * A client has called open() has been called on a registered device. @@ -976,7 +1002,7 @@ { int retval; int device_freed = 0; - fusd_dev_t *fusd_dev = (fusd_dev_t *) file->private_data; + fusd_dev_t *fusd_dev = find_user_device(inode->i_rdev); fusd_file_t *fusd_file; fusd_msg_t fusd_msg; @@ -1003,7 +1029,7 @@ * 2) Something failed, so we are returning a failure now and no * longer need the device. * Note, open_in_progress must be protected by the global sem, not - * the device lock, due to the access of it in fusd_dev_is_valid(). + * the device lock, due to the access of it in fusd_dev_is_valid(). */ down(&fusd_devlist_sem); fusd_dev->open_in_progress--; @@ -1565,6 +1591,7 @@ { int error = 0; struct list_head *tmp; + int dev_id; /* make sure args are valid */ if (fusd_dev == NULL) { @@ -1573,8 +1600,8 @@ } /* user can only register one device per instance */ - if (fusd_dev->handle != 0) - return -EBUSY; +// if (fusd_dev->handle != 0) +// return -EBUSY; register_msg.name[FUSD_MAX_NAME_LENGTH] = '\0'; @@ -1602,17 +1629,57 @@ strcpy(fusd_dev->name, register_msg.name); /* try to register the requested device */ - fusd_dev->handle = devfs_register(NULL, register_msg.name, + /* + fusd_dev->handle = devfs_register(register_msg.name, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | register_msg.mode, &fusd_client_fops, fusd_dev); - /* make sure the registration was successful */ + */ + + dev_id = 0; + + if((error = alloc_chrdev_region(&dev_id, 0, 1, fusd_dev->name)) < 0) + { + printk("alloc_chrdev_region failed status: %d\n", error); + goto register_failed; + } + + fusd_dev->dev_id = dev_id; + + if((error = devfs_mk_cdev(dev_id, S_IFCHR | register_msg.mode, fusd_dev->name)) < 0) + { + printk("devfs_mk_cdev failed status: %d\n", error); + goto register_failed2; + } + + fusd_dev->handle = cdev_alloc(); + if(fusd_dev->handle == NULL) + { + error = -ENOMEM; + goto register_failed3; + } + + fusd_dev->handle->owner = THIS_MODULE; + fusd_dev->handle->ops = &fusd_client_fops; + + kobject_set_name(&fusd_dev->handle->kobj, fusd_dev->name); + + if((error = cdev_add(fusd_dev->handle, dev_id, 1)) < 0) + { + printk("cdev_add failed status: %d\n", error); + kobject_put(&fusd_dev->handle->kobj); + goto register_failed3; + } + + /* make sure the registration was successful */ + /* if (fusd_dev->handle == 0) { error = -EIO; goto register_failed; } + */ /* remember the user's private data so we can pass it back later */ fusd_dev->private_data = register_msg.device_info; @@ -1624,7 +1691,11 @@ wake_up_interruptible(&new_device_wait); return 0; - register_failed: +register_failed3: + devfs_remove(fusd_dev->name); +register_failed2: + unregister_chrdev_region(dev_id, 1); +register_failed: KFREE(fusd_dev->name); fusd_dev->name = NULL; return error; @@ -1643,7 +1714,7 @@ fusd_file_t **file_array = NULL; /* keep the module from being unloaded during initialization! */ - MOD_INC_USE_COUNT; + //MOD_INC_USE_COUNT; /* allocate memory for the device state */ if ((fusd_dev = KMALLOC(sizeof(fusd_dev_t), GFP_KERNEL)) == NULL) @@ -1671,7 +1742,7 @@ KFREE(fusd_dev); dev_malloc_failed: RDEBUG(1, "out of memory in fusd_open!"); - MOD_DEC_USE_COUNT; + //MOD_DEC_USE_COUNT; return -ENOMEM; } @@ -1704,6 +1775,7 @@ } #endif + /* if (fusd_dev->handle) { RDEBUG(3, "unregistering /dev/%s from pid %d", NAME(fusd_dev), fusd_dev->pid); @@ -1712,6 +1784,14 @@ } else { RDEBUG(2, "pid %d releasing without a registered device!", current->pid); } + */ + + if(fusd_dev->handle) + { + cdev_del(fusd_dev->handle); + devfs_remove(fusd_dev->name); + unregister_chrdev_region(fusd_dev->dev_id, 1); + } /* mark the driver as being gone */ zombify_dev(fusd_dev); @@ -1808,11 +1888,13 @@ } /* before device registration, the only command allowed is 'register'. */ + /* if (!fusd_dev->handle && msg->cmd != FUSD_REGISTER_DEVICE) { RDEBUG(2, "got a message other than 'register' on a new device!"); retval = -EINVAL; goto out; } + */ /* now dispatch the command to the appropriate handler */ switch (msg->cmd) { @@ -2118,7 +2200,7 @@ int error = 0; fusd_statcontext_t *fs; - MOD_INC_USE_COUNT; + //MOD_INC_USE_COUNT; if ((fs = KMALLOC(sizeof(fusd_statcontext_t), GFP_KERNEL)) == NULL) { RDEBUG(1, "yikes! kernel can't allocate memory"); @@ -2131,8 +2213,8 @@ file->private_data = (void *) fs; out: - if (error) - MOD_DEC_USE_COUNT; + //if (error) + // MOD_DEC_USE_COUNT; return error; } @@ -2147,7 +2229,7 @@ KFREE(fs); } - MOD_DEC_USE_COUNT; + //MOD_DEC_USE_COUNT; return 0; } @@ -2245,7 +2327,7 @@ len += snprintf(buf + len, buf_size - len, "\nFUSD $Revision: 1.97 $ - %d devices used by %d clients\n", total_files, total_clients); - + out: fs->last_version_seen = last_version; up(&fusd_devlist_sem); @@ -2383,13 +2465,14 @@ STATIC int init_fusd(void) { -#ifdef CONFIG_FUSD_MEMDEBUG - int retval; + int retval; +#ifdef CONFIG_FUSD_MEMDEBUG if ((retval = fusd_mem_init()) < 0) return retval; #endif + printk(KERN_INFO "fusd: starting, $Revision: 1.97 $, $Date: 2003/07/11 22:29:39 $"); #ifdef CVSTAG @@ -2401,39 +2484,125 @@ printk(", debugging messages disabled\n"); #endif + fusd_control_device = NULL; + fusd_status_device = NULL; + /* register the control channel with devfs */ + /* fusd_handle = devfs_register(NULL, FUSD_CONTROL_FILENAME, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | 0666, &fusd_fops, NULL); + if (fusd_handle == NULL) { printk("fusd: unable to register fusd control device!\n"); return -EIO; } + */ + control_id = 0; + + if((retval = alloc_chrdev_region(&control_id, 0, 1, FUSD_CONTROL_FILENAME)) < 0) + { + printk("alloc_chrdev_region failed status: %d\n", retval); + goto fail0; + } + + if((retval = devfs_mk_cdev(control_id, S_IFCHR | 0666, FUSD_CONTROL_FILENAME)) < 0) + { + printk("devfs_mk_cdev failed status: %d\n", retval); + goto fail1; + } + + fusd_control_device = cdev_alloc(); + if(fusd_control_device == NULL) + { + retval = -ENOMEM; + goto fail2; + } + + fusd_control_device->owner = THIS_MODULE; + fusd_control_device->ops = &fusd_fops; + kobject_set_name(&fusd_control_device->kobj, FUSD_CONTROL_FILENAME); + + printk("cdev control id: %d\n", control_id); + if((retval = cdev_add(fusd_control_device, control_id, 1)) < 0) + { + printk("cdev_add failed status: %d\n", retval); + kobject_put(&fusd_control_device->kobj); + goto fail2; + } /* register the status device with devfs */ + /* fusd_status_handle = devfs_register(NULL, FUSD_STATUS_FILENAME, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | 0666, &fusd_status_fops, (void *) 0); + */ + status_id = 0; - if (fusd_status_handle == NULL) - printk("fusd: warning: unable to register status device\n"); - + if((retval = alloc_chrdev_region(&status_id, 0, 1, FUSD_STATUS_FILENAME)) < 0) + { + printk("alloc_chrdev_region failed status: %d\n", retval); + goto fail3; + } + + if((retval = devfs_mk_cdev(status_id, S_IFCHR | 0666, FUSD_STATUS_FILENAME)) < 0) + { + printk("devfs_mk_cdev failed status: %d\n", retval); + goto fail4; + } + + fusd_status_device = cdev_alloc(); + if(fusd_status_device == NULL) + { + retval = -ENOMEM; + goto fail5; + } + + fusd_status_device->owner = THIS_MODULE; + fusd_status_device->ops = &fusd_status_fops; + kobject_set_name(&fusd_status_device->kobj, FUSD_STATUS_FILENAME); + + if((retval = cdev_add(fusd_status_device, status_id, 1)) < 0) + { + printk("cdev_add failed status: %d\n", retval); + kobject_put(&fusd_status_device->kobj); + goto fail5; + } RDEBUG(1, "registration successful"); return 0; + + cdev_del(fusd_status_device); +fail5: + devfs_remove(FUSD_STATUS_FILENAME); +fail4: + unregister_chrdev_region(status_id, 1); +fail3: + cdev_del(fusd_control_device); +fail2: + devfs_remove(FUSD_CONTROL_FILENAME); +fail1: + unregister_chrdev_region(control_id, 1); +fail0: + return retval; } STATIC void cleanup_fusd(void) { RDEBUG(1, "cleaning up"); - devfs_unregister(fusd_handle); + //devfs_unregister(fusd_handle); + + //if (fusd_status_handle) + // devfs_unregister(fusd_status_handle); + cdev_del(fusd_control_device); + cdev_del(fusd_status_device); - if (fusd_status_handle) - devfs_unregister(fusd_status_handle); + devfs_remove(FUSD_CONTROL_FILENAME); + devfs_remove(FUSD_STATUS_FILENAME); #ifdef CONFIG_FUSD_MEMDEBUG fusd_mem_cleanup(); diff -Naur fusd-1.10/make.include fusd-2.6.0-fixed/make.include --- fusd-1.10/make.include 2001-09-29 13:27:16.000000000 -0600 +++ fusd-2.6.0-fixed/make.include 2004-02-17 01:16:31.000000000 -0700 @@ -72,7 +72,7 @@ KERNEL_INCLUDE := $(KERNEL_HOME)/include BINSTRIP := strip -KCFLAGS += -I$(KERNEL_INCLUDE) $(INCLUDEPATH) +KCFLAGS += $(INCLUDEPATH) CFLAGS += $(INCLUDEPATH) $(LIBPATH) CCFLAGS += $(CFLAGS)