建体彩网|中彩网双色球连号|
?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

亞博國際首頁登入:VFS層攔截readwrite fileoperations函數無效

?

改變read,write,readdir,open,release等函數指針,發明readdir可以正常得到目錄名,open,release只能截獲目錄的操作, read,write完全截獲不了任何操作。 討教各位大年夜蝦有碰到類似問題嗎。現在感到上是對目錄的操作都能截獲,然則對文件操作的就完全沒有。

readdir(事情正常) 和 read 代碼如下

int my_readdir(struct file *fp, void *buf, filldir_t filldir)

{

char *path = (char*)kmalloc(MAX_DIR_LENTH);

unsigned int offset = MAX_DIR_LENTH-1;

struct dentry* cwd = fp->f_dentry;

int rs;

path[MAX_DIR_LENTH-1] = '\0';

// path add one slash in the end

path[--offset] = '/';

while( cwd->d_parent != cwd ) {

offset -= cwd->d_name.len;

strncpy(path + offset, cwd->d_name.name, cwd->d_name.len);

path[--offset] = '/';

cwd = cwd->d_parent;

}

if (offset == MAX_DIR_LENTH-1) path[--offset] = '/';

printk(" Read Dir %s\n", path+offset);

kfree(path);

if (orig_readdir == NULL) {

printk(" orig read dir function is NULL\n");

return -1;

}亞博國際首頁登入

rs = orig_readdir(fp, buf, filldir);

return rs;

}

ssize_t my_read (struct file *fp, char *buf, size_t len, loff_t *off)

{

int rs;

printk(" enter my read \n");//這也沒有輸出

char *path = (char*)kmalloc(MAX_DIR_LENTH);

unsigned int offset = MAX_DIR_LENTH-1;

struct dentry* cwd = fp->f_dentry;

path[MAX_DIR_LENTH-1] = '\0';

while( cwd->d_parent != cwd ) {

offset -= cwd->d_name.len;

strncpy(path + offset, cwd->d_name.name, cwd->d_name.len);

path[--offset] = '/';

cwd = cwd->d_parent;

}

printk(" Read file %s\n", path+offset);

kfree(path);

if (orig_read == N亞博國際首頁登入ULL) {

printk(" orig read function is NULL\n");

return -1;

}

rs = orig_read(fp, buf, len, off);

return rs;

}

調換file_operations,打開一個文件(我打開的是/),獲得該fs的file_operations指針,調換。

下面是代碼。

int patch_vfs(const char* p)

{

struct file* filep;

filep = filp_open(p, O_RDONLY, 0);

if (IS_ERR(filep)){

printk(" can not open file\n");

return -1;

}

orig_read = filep->f_op->read;

orig_write = filep->f_op->write;

orig_readdir = filep->f_op->readdir;

orig_ioctl = filep->f_op->ioctl;

orig_open = filep->f_op->open;

orig_lock = filep->f_op->lock;

orig_mmap = filep->f_op->mmap;

orig_release = filep->f_op->release;

filep->f_op->read = my_read;

filep->f_op->write = my亞博國際首頁登入_write;

filep->f_op->readdir = my_readdir;

filep->f亞博國際首頁登入_op->ioctl = my_ioctl;

filep->f_op->open = my_open;

filep->f_op->lock = my_lock;

filep->f_op->mmap = my_mmap;

filep->f_op->release = my_release;

filp_clo亞博國際首頁登入se(filep, 0);

return 0;

}

static int patch_init(void)

{

if (patch_vfs(root_fs) != 0) return -1;

printk(" VFS patched\n");

return 0;

}

module_init(patch_init);

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

建体彩网
快乐十分软件 腾讯捕鱼来了贴吧 pc蛋蛋预测神器 法甲女足积分榜 湖北11选5 香港赛马会摩星岭青年旅舍 喜乐彩 河北福彩快三遗漏号 安徽11选5任选5单试票 顶呱刮彩票在线