- 论坛徽章:
- 0
|
我以前写的内核写文件代码片段,你看看吧!读的话用filp->f_op->read()。
在x86 linux-2.6.18
arm920t linux-3.2.36运行过
static char data_write[10] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
static void filewrite(char* filename)
{
struct file *filp;
mm_segment_t fs;
u32 index = 0;
filp = filp_open(filename, O_RDWR| O_APPEND| O_CREAT, 0644);
if (IS_ERR(filp))
{
printk("open error...\n");
return;
}
fs=get_fs();
set_fs(KERNEL_DS);
for (index = 0; index < 10; index++)
{
memset(data_write, index, 10);
filp->f_op->write(filp, data_write, sizeof(data_write),&filp->f_pos);
}
set_fs(fs);
filp_close(filp,NULL);
}
|
|