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是什么样的file(device file,FIFO,extn file,fat file,Yaffs2 file,proc file,sysfs 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 = {