⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liskmod.c

📁 7号信令功能代码,为开源代码
💻 C
字号:
/*************************************************************************                      LiS Kernel Module                                ***************************************************************************									** Some versions of the kernel do not export all the functions that	** the more advanced releases of LiS need.  We do not want to patch	** the kernel -- users these days like to load external modules against	** unmodified kernels from distributions.  We also don't want to 	** duplicate kernel code inside LiS for licensing reasons.  Importing	** full GNU license code into LiS, which is GNU Library license, would	** probably render all of LiS full GNU, which we, the authors of LiS,	** explicitly do not want to do so as to encourage the porting of	** STREAMS drivers from other platforms such as Solaris and SCO.		**									** So, we have created this little module which contains code snippets	** shamelessly lifted from the kernel source.  The "liskmod" then	** exports these routines itself to the rest of the world, including	** LiS.									**									** So, the code in this module, unlike almost all the rest of the code	** under LiS, is full GNU license, and not GNU Library.			**									** Here are the functions that we are exporting.				**									** put_unused_fd								**	Exported in kernels >= 2.2.18 and 2.4.?.  For earlier		**	kernels we need to provide it here.				**									*************************************************************************/#ident "@(#) LiS liskmod.c 1.7 05/07/02 20:41:46 "#include <linux/version.h>#include <linux/config.h>#ifdef CONFIG_MODVERSIONS#include <linux/modversions.h>#endif#include <linux/module.h>#if   LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)#define KERNEL_2_0#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)#define KERNEL_2_2#else#define	KERNEL_2_4#endif#include <linux/kernel.h>			/* for printk */#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)#include <linux/sched.h>#include <linux/fs.h>#endif/* * Do not include <sys/osif.h> in this module.  It would create * circular dependencies on streams.o. *//*************************************************************************                       Module Init and Cleanup                         ***************************************************************************									** Functions called at module load/unload time.				**									*************************************************************************/int	init_module(void){    printk("LiS Kernel Module Loaded\n") ;    return(0) ;			/* if we're here, we're OK */}void	cleanup_module(void){    printk("LiS Kernel Module Unloading\n") ;}/*************************************************************************                        put_unused_fd                                  ***************************************************************************									** If the kernel version is early enough, include this function.		**									*************************************************************************/#if   defined(KERNEL_2_2)# if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,6)	/* inexact version test */void put_unused_fd(unsigned int fd){        FD_CLR(fd, &current->files->open_fds);}# elif LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)void put_unused_fd(unsigned int fd){        FD_CLR(fd, current->files->open_fds);        if (fd < current->files->next_fd)                current->files->next_fd = fd;}# else	/* kernel version 2.2.17 should have this visible */# endif#elif defined(KERNEL_2_4)# if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)inline void __put_unused_fd(struct files_struct *files, unsigned int fd){        FD_CLR(fd, files->open_fds);        if (fd < files->next_fd)                files->next_fd = fd;}void put_unused_fd(unsigned int fd){        struct files_struct *files = current->files;        write_lock(&files->file_lock);        __put_unused_fd(files, fd);        write_unlock(&files->file_lock);}# else	/* kernel version 2.4.1 should have this visible */# endif#endif/*************************************************************************                           igrab                                       ***************************************************************************									** Kernels before about 2.2.12 did not have this function.		**									*************************************************************************/#if   defined(KERNEL_2_2)# if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,12)/* * The following code was lifted from 2.2.12. */static void __wait_on_inode(struct inode * inode){        struct wait_queue wait = { current, NULL };        add_wait_queue(&inode->i_wait, &wait);repeat:        current->state = TASK_UNINTERRUPTIBLE;        if (inode->i_state & I_LOCK) {                schedule();                goto repeat;        }        remove_wait_queue(&inode->i_wait, &wait);        current->state = TASK_RUNNING;}static inline void wait_on_inode(struct inode *inode){        if (inode->i_state & I_LOCK)                __wait_on_inode(inode);}/* * A slight problem here is that we don't have access to "inode_lock" * since it is not exported.  So we just have to risk bumping the * count without holding the lock. */struct inode *igrab(struct inode *inode){        /* spin_lock(&inode_lock); */        if (inode->i_state & I_FREEING)                inode = NULL;        else                inode->i_count++;        /* spin_unlock(&inode_lock); */        if (inode)                wait_on_inode(inode);        return inode;}# endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -