diff --git a/12.md b/12.md index c207bae..311b0ca 100644 --- a/12.md +++ b/12.md @@ -259,6 +259,37 @@ static struct inode_operations shmem_symlink_inode_operations = { sees no difference between pages backed by a real file and those backed by virtual files. +## 12.3 Creating files in tmpfs + +* Because `tmpfs` is mounted as a proper filesystem that is visible to the user + it must support directory inode operations, as provided for by + [shmem_dir_inode_operations][shmem_dir_inode_operations], discussed in the + previous section. + +* The implementation of most of the functions used by + `shmem_dir_inode_operations` are rather small but they are all very + interconnected. + +* The majority of the inode fields provided by the VFS are filled by + [shmem_get_inode()][shmem_get_inode]. + +* When creating a new file [shmem_create()][shmem_create] is used - this is a + small wrapper around [shmem_mknod()][shmem_mknod] which is called with the + `S_IFREG` flag set so a regular file will be created. + +* Again `shmem_mknod()` is really just a wrapper around `shmem_get_inode()` + which creates an inode and fills in the [struct inode][inode] fields as + required. + +* The 3 most interesting fields that are populated are + `inode->i_mapping->a_ops`, `inode->i_op` and `inode->i_fop` fields. + +* After the inode has been created, `shmem_mknod()` updates the directory + inode's `size` and `mtime` statistics before creating the new inode. + +* Files are created differently in `shm` despite the fact the filesystems are + basically the same - this is looked at in more detail in 12.7. + [mmap]:http://man7.org/linux/man-pages/man2/mmap.2.html [fork]:http://man7.org/linux/man-pages/man2/fork.2.html [shmget]:http://man7.org/linux/man-pages/man2/shmget.2.html @@ -297,3 +328,8 @@ static struct inode_operations shmem_symlink_inode_operations = { [shmem_truncate]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L351 [shmem_notify_change]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L375 [shmem_getpage]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L583 + +[shmem_get_inode]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L809 +[shmem_create]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1164 +[shmem_mknod]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1139 +[inode]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/fs.h#L438