Linux Kernel 之AP读写Nand Flash上的Yaffs2文件的全过程浅析

本文深入剖析了Linux内核如何处理应用程序(AP)读写Nand Flash上的Yaffs2文件的过程。从`open`系统调用开始,介绍了`fill_inode_from_object`函数的角色,以及`file_operations`和`address_space_operations`的设置。接着详细讲解了`read`过程,涉及page cache、address space的概念,以及从硬件层面的Nand Flash读取数据。最后,文章预告了对AP写文件过程的分析。
摘要由CSDN通过智能技术生成

1.1                   top-down的方法分析AP一个Nand Flash上的file的全过程

我先简单看一个例子,看User Application如何打开一个Yaffs2 file并读写之:

int main (int argc, char* argv[])

{

  /* Open the file for reading.  */

  int fd = open (argv[1], O_RDONLY);

  do {

    bytes_read = read (fd, buffer, sizeof (buffer));

    offset += bytes_read;

  }

  close (fd);

  return 0;

}

1.1.1               int fd = open (argv[1], O_RDONLY)的来龙去脉

APP打开一个file的时候,无论该file是什么样的filedevice fileFIFOextn filefat fileYaffs2 fileproc filesysfs file等等)其前半部分是完成一致的,这个过程我们已经在4.3中已经分析过,由于我们现在以打开一个regular Yaffs2 file为例子来进行分析,所以我们从yaffs_FillInodeFromObject function开始作为入口了:

static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)

{

             。。。。。。

             case S_IFREG:     /* file */

                    inode->i_op = &yaffs_file_inode_operations;

                    inode->i_fop = &yaffs_file_operations;

                    inode->i_mapping->a_ops = &yaffs_file_address_operations;

                    break;

。。。。。。。

}

而:

static struct file_operations yaffs_file_operations = {

   .read = do_sync_read,

   .write = do_sync_write,

   .aio_read = generic_file_aio_read,

   .aio_write = generic_file_aio_write,

   .mmap = generic_file_mmap,

   .flush = yaffs_file_flush,

   .fsync = yaffs_sync_object,

   .splice_read = generic_file_splice_read,

   .splice_write = generic_file_splice_write,

};

 

static struct address_space_operations yaffs_file_address_operations = {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值