Skip to content

Commit 5929c20

Browse files
committed
Add comments
1 parent e302ed2 commit 5929c20

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

inode.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
static const struct inode_operations simplefs_inode_ops;
1212
static const struct inode_operations symlink_inode_ops;
1313

14-
/* Get inode ino from disk */
14+
/* Either return the inode that corresponds to a given inode number (ino), if
15+
* it is already in the cache, or create a new inode object if it is not in the
16+
* cache.
17+
*
18+
* Note that this function is very similar to simplefs_new_inode, except that
19+
* the requested inode is supposed to be allocated on-disk already. So do not
20+
* use this to create a completely new inode that has not been allocated on
21+
* disk.
22+
*/
1523
struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
1624
{
1725
struct inode *inode = NULL;
@@ -181,7 +189,17 @@ static struct dentry *simplefs_lookup(struct inode *dir,
181189
return NULL;
182190
}
183191

184-
/* Create a new inode in dir */
192+
/* Find and construct a new inode.
193+
*
194+
* @dir: the inode of the parent directory where the new inode is supposed to
195+
* be attached to.
196+
* @mode: the mode information of the new inode
197+
*
198+
* This is a helper function for the inode operation "create" (implemented in
199+
* simplefs_create()). It takes care of reserving an inode block on disk (by
200+
* modifying the inode bitmap), creating a VFS inode object (in memory), and
201+
* attaching filesystem-specific information to that VFS inode.
202+
*/
185203
static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
186204
{
187205
struct inode *inode;

simplefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct simplefs_sb_info {
8080
#define SIMPLEFS_AT_LEAST(major, minor, rev) \
8181
LINUX_VERSION_CODE >= KERNEL_VERSION(major, minor, rev)
8282

83+
/* A 'container' structure that keeps the VFS inode and additional on-disk
84+
* data.
85+
*/
8386
struct simplefs_inode_info {
8487
uint32_t ei_block; /* Block with list of extents for this file */
8588
char i_data[32];
@@ -132,6 +135,7 @@ extern uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
132135

133136
/* Getters for superblock and inode */
134137
#define SIMPLEFS_SB(sb) (sb->s_fs_info)
138+
/* Extract a simplefs_inode_info object from a VFS inode */
135139
#define SIMPLEFS_INODE(inode) \
136140
(container_of(inode, struct simplefs_inode_info, vfs_inode))
137141
#endif /* __KERNEL__ */

super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ struct dentry *simplefs_mount(struct file_system_type *fs_type,
1616
void simplefs_kill_sb(struct super_block *sb);
1717
static struct kmem_cache *simplefs_inode_cache;
1818

19+
/* Needed to initiate the inode cache, to allow us to attach
20+
* filesystem-specific inode information.
21+
*/
1922
int simplefs_init_inode_cache(void)
2023
{
2124
simplefs_inode_cache = kmem_cache_create_usercopy(
@@ -26,6 +29,7 @@ int simplefs_init_inode_cache(void)
2629
return 0;
2730
}
2831

32+
/* De-allocate the inode cache */
2933
void simplefs_destroy_inode_cache(void)
3034
{
3135
kmem_cache_destroy(simplefs_inode_cache);

0 commit comments

Comments
 (0)