热门关键字:  PHP  Cisco  seo  网络广告 虚拟主机 中文域名
当前位置 :| 主页>服务器>Linux服务器>

Linux系统下设备驱动的安全端口分配

来源:赛迪网技术社区 作者:tanktang 时间:2006-09-20 点击:

当模块从内核移出时,端口应当被释放以便为其它设备使用,为此我们在 cleanup_module ( )中 使用release_region ( ) 函数。 函数的语法如下:

void release_region ( unsigned long start, unsigned long len);

两个参数的解释和前面一致。 以上的3个函数实际上是宏定义,定义于

设备端口分配的驱动代码例子

下面的程序说明了动态加载设备的端口分配与回收:

#include <linux/fs。h。>
#include <linux/ioport。h。>
 
struct file_operations fops;
unsigned long start, len;
 
int init_module (void)
{
 int status;
 start = 0xff90;
 len   = 0x90;
 
 register_chrdev(254,"your_device",&fops);
 
 status = check_region (start, len);
 if (status == 0) {
     printk ("The ports are available in that range。
");
     request_region(start,len,"your_device");
 } else {
     printk ("The ports are already in use。 Try other range。
");
     return (status);
 }
 return 0;
}
 
void cleanup_module (void)
{
 release_region(start, len);
 printk (" ports are freed successfully
");
 unregister_chrdev(254,"your_device");}
 printk (" your device is unregistered
");
}

为了避免混淆,例子代码中去掉了错误检查和和主(设备)号的动态分配。 当端口分配成功时,我们可以在proc目录中检查:

$cat /proc/ioports

 


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
赞助商连接