Read file operation

JFFS2 uses jffs2_lookup() to determinate the inode number of the file by its name. If the jffs2_lookup() finds the inode then iget() it. iget() calls jffs2_read_inode() to read the inode. jffs2_read_inode() gets the inode info and the sb info from the inode parameter. Then initializes the inode info and calls jffs2_do_read_inode() to fill up the structures. jffs2_do_read_inode() asks for the inodecache of the inode by jffs2_get_ino_cache() If it has inode cache then it can do three different cases depending on the status of the inode cache.
The state of the inode cache is: If it hasn't got inode cache and the inode number is 1 which is the root node then it allocates a new one for it and sets the parameters (ino, nodes, state). Then adds the inode cache to the inode cache list. If it hasn't got inocache yet then returns with error otherwise it returns with the return value of the called jffs2_do_read_inode_internal(). jffs2_do_read_inode_internal() gets all the relevant nodes of this inode by calling
jffs2_get_inode_nodes(). jffs2_get_inode_nodes() allocates a buffer where the nodes can be loaded. It walks through the inode's next_in_ino list and if the current raw reference is valid then it reads it.
If the type of the read node is: jffs2_get_inode_nodes() returns. If the node is a data node then it builds up the fragtree of the inode in inode info and frees the jffs2_tmp_dnode_info structures during the fragtree building. It sets the inode info dents pointer equal to fd_list (fd_list is a pointer parameter of jffs2_get_inode_nodes() and if the node was a directory inode then its children are listed in fd_list. Then it reads the latest node, checks its CRC and does some modification on structures depending on the type of the node (truncate fragtree, modify mctime, ...). If the state field of the inode cache of the inode is INO_STATE_READING then it sets the status to INO_STATE_PRESENT. And finally it returns.

If jffs2_do_read_inode() returns with error then marks the inode bad and returns, otherwise the inode structure are actualized by the values of the latest_node (mode, uid, gid, etc.). The operations of the inode (inode, file, mapping) are set dependings on the mode of the inode.

Havasi Ferenc 2005-12-22