Skip to content

Commit 9f2299f

Browse files
committed
Refine comments
1 parent e4f76f2 commit 9f2299f

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

bitmap.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include "simplefs.h"
77

8-
/* Return the first bit we found and clear the the following 'len' consecutive
9-
* free bit(s) (set to 1) in a given in-memory bitmap spanning over multiple
10-
* blocks. Return 0 if no enough free bit(s) were found (we assume that the
11-
* first bit is never free because of the superblock and the root inode, thus
12-
* allowing us to use 0 as an error value).
8+
/* Returns the first bit found and clears the following 'len' consecutive
9+
* free bits (sets them to 1) in a given in-memory bitmap spanning multiple
10+
* blocks. Returns 0 if an adequate number of free bits were not found.
11+
* Assumes the first bit is never free (reserved for the superblock and the
12+
* root inode), allowing the use of 0 as an error value.
1313
*/
1414
static inline uint32_t get_first_free_bits(unsigned long *freemap,
1515
unsigned long size,
@@ -51,7 +51,6 @@ static inline uint32_t get_free_blocks(struct simplefs_sb_info *sbi,
5151
return ret;
5252
}
5353

54-
5554
/* Mark the 'len' bit(s) from i-th bit in freemap as free (i.e. 1) */
5655
static inline int put_free_bits(unsigned long *freemap,
5756
unsigned long size,

dir.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
#include "simplefs.h"
99

10-
/* Iterate over the files contained in dir and commit them in ctx.
11-
* This function is called by the VFS while ctx->pos changes.
12-
* Return 0 on success.
10+
/* Iterate over the files contained in dir and commit them to @ctx.
11+
* This function is called by the VFS as ctx->pos changes.
12+
* Returns 0 on success.
1313
*/
1414
static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
1515
{

extent.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#include "simplefs.h"
55

6-
/* Search the extent which contain the target block.
7-
* Return the first unused file index if not found.
8-
* Return -1 if it is out of range.
9-
* TODO: use binary search.
6+
/* Search for the extent containing the target block.
7+
* Returns the first unused file index if not found.
8+
* Returns -1 if the target block is out of range.
9+
* TODO: Implement binary search for efficiency.
1010
*/
1111
uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
1212
uint32_t iblock)

file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static int simplefs_file_get_block(struct inode *inode,
7878
return ret;
7979
}
8080

81-
/* Called by the page cache to read a page from the physical disk and map it in
82-
* memory.
81+
/* Called by the page cache to read a page from the physical disk and map it
82+
* into memory.
8383
*/
8484
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
8585
static void simplefs_readahead(struct readahead_control *rac)
@@ -101,9 +101,9 @@ static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
101101
return block_write_full_page(page, simplefs_file_get_block, wbc);
102102
}
103103

104-
/* Called by the VFS when a write() syscall occurs on file before writing the
105-
* data in the page cache. This functions checks if the write will be able to
106-
* complete and allocates the necessary blocks through block_write_begin().
104+
/* Called by the VFS when a write() syscall is made on a file, before writing
105+
* the data into the page cache. This function checks if the write operation
106+
* can complete and allocates the necessary blocks through block_write_begin().
107107
*/
108108
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
109109
static int simplefs_write_begin(struct file *file,
@@ -152,7 +152,7 @@ static int simplefs_write_begin(struct file *file,
152152
}
153153

154154
/* Called by the VFS after writing data from a write() syscall to the page
155-
* cache. This functions updates inode metadata and truncates the file if
155+
* cache. This function updates inode metadata and truncates the file if
156156
* necessary.
157157
*/
158158
static int simplefs_write_end(struct file *file,

inode.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
9696
return ERR_PTR(ret);
9797
}
9898

99-
/* Look for dentry in dir.
100-
* Fill dentry with NULL if not in dir, with the corresponding inode if found.
101-
* Returns NULL on success.
99+
/* Searches for a dentry in dir.
100+
* Fills dentry with NULL if not found in dir, or with the corresponding inode
101+
* if found.
102+
* Returns NULL on success, indicating the dentry was successfully filled or
103+
* confirmed absent.
102104
*/
103105
static struct dentry *simplefs_lookup(struct inode *dir,
104106
struct dentry *dentry,
@@ -554,10 +556,11 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
554556
return ret;
555557
}
556558

557-
/* Cleanup pointed blocks if unlinking a file. If we fail to read the
558-
* index block, cleanup inode anyway and lose this file's blocks
559-
* forever. If we fail to scrub a data block, don't fail (too late
560-
* anyway), just put the block and continue.
559+
/* Cleans up pointed blocks when unlinking a file. If reading the index
560+
* block fails, the inode is cleaned up regardless, resulting in the
561+
* permanent loss of this file's blocks. If scrubbing a data block fails,
562+
* do not terminate the operation (as it is already too late); instead,
563+
* release the block and proceed.
561564
*/
562565
bno = SIMPLEFS_INODE(inode)->ei_block;
563566
bh = sb_bread(sb, bno);

0 commit comments

Comments
 (0)