linux合併fa檔案 linux 混雜裝置模型

2021-10-13 12:27:46 字數 2723 閱讀 1921

在linux系統中,存在一類字元裝置,他們共享乙個主裝置號(10),但此裝置號不同,我們稱這類裝置為混雜裝置(miscdeivce),檢視/proc/device中可以看到乙個名為misc的主裝置號為10.所有的混雜裝置形成乙個鍊錶,對裝置訪問時核心根據次裝置號找到對應的miscdevice裝置。

linux核心使用struct miscdeivce來描述乙個混雜裝置

struct miscdevice  {

int minor;

const char *name;

const struct file_operations *fops;

struct list_head list;

struct device *parent;

struct device *this_device;

const char *nodename;

mode_t mode;

minor是這個混雜裝置的次裝置號,若由系統自動配置,則可以設定為misc_dynanic_minor,name是裝置名.使用時只需填寫minor次裝置號,*name裝置名,*fops檔案操作函式集即可。

linux核心使用misc_register函式註冊乙個混雜裝置,使用misc_deregister移除乙個混雜裝置。註冊成功後,linux核心為自動為該裝置建立裝置節點,在/dev/下會產生相應的節點。

註冊函式:

int misc_register(struct miscdevice * misc)

輸入引數:struct miscdevice

返回值:

表示註冊成功。

負數 表示未成功。

解除安裝函式:

intmisc_deregister(struct miscdevice *misc)

0表示成功。

負數 表示失敗。

下面是基於linux 混雜裝置模型的乙個簡單示例:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define device_name "bell-control"

volatile unsigned long *gpbcon = null ;

volatile unsigned long *gpbdat = null ;

volatile unsigned long *gpbup = null ;

static int bell_drv_open(struct inode *inode, struct file *file)

*gpbcon &= ~(0x3<

*gpbcon |= (0x1<

*gpbup = 0x0;

printk("first_drv_open\n");

return 0;

static ssize_t bell_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)

int val;

copy_from_user(&val, buf, count) ;

if (val == 1)

*gpbdat &= ~(1<<0);

printk("first_drv_write 1111111\n");

else

*gpbdat |= (1<<0);

printk("first_drv_write 00000\n");

return 0;

static struct file_operations bell_drv_fops = {

.owner = this_module, /* 這是乙個巨集,推向編譯模組時自動建立的__this_module變數 */

.open = bell_drv_open,

.write = bell_drv_write,

//註冊混雜裝置,每乙個misc驅動會自動出現在/sys/class/misc/下

static struct miscdevice misc = {

.minor =misc_dynamic_minor,

.name = device_name,

.fops = &bell_drv_fops,

static int bell_drv_init(void)

int result;

result = misc_register(&misc);

printk (""device_name" initialized\n");

gpbcon = (volatile unsigned long *)ioremap(0x56000010, 16);

gpbdat = gpbcon + 1;

gpbup = gpbcon + 2;

return 0;

static void bell_drv_exit(void)

misc_deregister(&misc);

iounmap(gpbcon);

module_init(bell_drv_init);

module_exit(bell_drv_exit);

module_license("gpl");

linux合併fa檔案 linux本地化blast

1.軟體安裝 解壓 base fyx huangji 5885h v5 biosoft tar zxvf ncbi blast 2.10.1 x64 linux.tar.gz base fyx huangji 5885h v5 biosoft ncbi blast 2.10.1 bin ls bla...

Linu檔案處理命令

命令格式 命令 選項 引數 例如 ls la etc 多個選項可以寫在一起,個別命令不遵循此格式,簡化選項只用乙個 完整選項需要寫兩個 a等於 all 1.命令格式與目錄處理命令ls ls功能描述 顯示目錄檔案 執行許可權 所有使用者 位於 bin ls 選項 常用的是 a和 l a 所有檔案,包括...

LInux 分割合併檔案

有兩種方式,第一種使用dd命令 第二種使用split dd命令是linux下乙個非常有用的磁碟命令。它可以將指定大小的塊拷貝成乙個檔案,並在拷貝的同時執行指定的轉換。unix已經提供了檔案切割功能,能完成這個功能的unix命令就是dd。要切割的大檔案為dgjd,共98336321位元組,則 dd i...