I'm reading in Understanding the Linux Kernel, 3rd Edition on how to create a new regular file on ext2fs.
(Book is available online at multiple places: not sure as to their legalities. A later version of just the relevant chapter is at O'reilly's site - but it does not have all the relevant data)
As I see it, the Linux kernel has to create a new inode, and to allocate the necessary blocks to it.
The book outlines the following procedures:
Creating inodes
(p. 758)Allocating a Data Block
(p. 764)
What I don't understand is when does the kernel allocate the new inode's data blocks.
Near the end (para. 14) of the Creating inodes
procedure, I see the following:
Invokes
ext2_preread_inode()
to read from disk the block containing the inode and to put the block in the page cache. This type of read-ahead is done because it is likely that a recently created inode will be written back soon.
So, just prior to that - seems to me a logical place to allocate the inode's blocks. However, It may be that the ext2 architects decided to do the allocation at a different time.
Does anyone know when is storage allocated for a newly created ext2 inode?