Skip to content

Commit 9a6f991

Browse files
committed
Apply editorial changes
1 parent 9a44a32 commit 9a6f991

File tree

8 files changed

+100
-112
lines changed

8 files changed

+100
-112
lines changed

bitmap.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#define SIMPLEFS_BITMAP_H
33

44
#include <linux/bitmap.h>
5+
56
#include "simplefs.h"
67

7-
/*
8-
* Return the first bit we found and clear the the following `len` consecutive
8+
/* Return the first bit we found and clear the the following 'len' consecutive
99
* free bit(s) (set to 1) in a given in-memory bitmap spanning over multiple
1010
* blocks. Return 0 if no enough free bit(s) were found (we assume that the
1111
* first bit is never free because of the superblock and the root inode, thus
@@ -28,8 +28,7 @@ static inline uint32_t get_first_free_bits(unsigned long *freemap,
2828
return 0;
2929
}
3030

31-
/*
32-
* Return an unused inode number and mark it used.
31+
/* Return an unused inode number and mark it used.
3332
* Return 0 if no free inode was found.
3433
*/
3534
static inline uint32_t get_free_inode(struct simplefs_sb_info *sbi)
@@ -40,8 +39,7 @@ static inline uint32_t get_free_inode(struct simplefs_sb_info *sbi)
4039
return ret;
4140
}
4241

43-
/*
44-
* Return `len` unused block(s) number and mark it used.
42+
/* Return 'len' unused block(s) number and mark it used.
4543
* Return 0 if no enough free block(s) were found.
4644
*/
4745
static inline uint32_t get_free_blocks(struct simplefs_sb_info *sbi,
@@ -54,7 +52,7 @@ static inline uint32_t get_free_blocks(struct simplefs_sb_info *sbi,
5452
}
5553

5654

57-
/* Mark the `len` bit(s) from i-th bit in freemap as free (i.e. 1) */
55+
/* Mark the 'len' bit(s) from i-th bit in freemap as free (i.e. 1) */
5856
static inline int put_free_bits(unsigned long *freemap,
5957
unsigned long size,
6058
uint32_t i,

dir.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
#include "simplefs.h"
99

10-
/*
11-
* Iterate over the files contained in dir and commit them in ctx.
10+
/* Iterate over the files contained in dir and commit them in ctx.
1211
* This function is called by the VFS while ctx->pos changes.
1312
* Return 0 on success.
1413
*/
@@ -28,8 +27,7 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
2827
if (!S_ISDIR(inode->i_mode))
2928
return -ENOTDIR;
3029

31-
/*
32-
* Check that ctx->pos is not bigger than what we can handle (including
30+
/* Check that ctx->pos is not bigger than what we can handle (including
3331
* . and ..)
3432
*/
3533
if (ctx->pos > SIMPLEFS_MAX_SUBFILES + 2)
@@ -46,15 +44,14 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
4644
eblock = (struct simplefs_file_ei_block *) bh->b_data;
4745

4846
ei = (ctx->pos - 2) / SIMPLEFS_FILES_PER_EXT;
49-
bi = (ctx->pos - 2) % SIMPLEFS_FILES_PER_EXT
50-
/ SIMPLEFS_FILES_PER_BLOCK;
47+
bi = (ctx->pos - 2) % SIMPLEFS_FILES_PER_EXT / SIMPLEFS_FILES_PER_BLOCK;
5148
fi = (ctx->pos - 2) % SIMPLEFS_FILES_PER_BLOCK;
5249

5350
/* Iterate over the index block and commit subfiles */
5451
for (; ei < SIMPLEFS_MAX_EXTENTS; ei++) {
55-
if (eblock->extents[ei].ee_start == 0) {
52+
if (eblock->extents[ei].ee_start == 0)
5653
break;
57-
}
54+
5855
/* Iterate over blocks in one extent */
5956
for (; bi < eblock->extents[ei].ee_len; bi++) {
6057
bh2 = sb_bread(sb, eblock->extents[ei].ee_start + bi);
@@ -63,14 +60,15 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
6360
goto release_bh;
6461
}
6562
dblock = (struct simplefs_dir_block *) bh2->b_data;
66-
if (dblock->files[0].inode == 0) {
63+
if (dblock->files[0].inode == 0)
6764
break;
68-
}
65+
6966
/* Iterate every file in one block */
7067
for (; fi < SIMPLEFS_FILES_PER_BLOCK; fi++) {
7168
f = &dblock->files[fi];
72-
if (f->inode && !dir_emit(ctx, f->filename, SIMPLEFS_FILENAME_LEN,
73-
f->inode, DT_UNKNOWN))
69+
if (f->inode &&
70+
!dir_emit(ctx, f->filename, SIMPLEFS_FILENAME_LEN, f->inode,
71+
DT_UNKNOWN))
7472
break;
7573
ctx->pos++;
7674
}

extent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include "simplefs.h"
55

6-
/*
7-
* Search the extent which contain the target block.
6+
/* Search the extent which contain the target block.
87
* Return the first unused file index if not found.
98
* Return -1 if it is out of range.
109
* TODO: use binary search.
@@ -20,5 +19,6 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index,
2019
(iblock >= block && iblock < block + len))
2120
return i;
2221
}
22+
2323
return -1;
2424
}

file.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "bitmap.h"
1010
#include "simplefs.h"
1111

12-
/*
13-
* Map the buffer_head passed in argument with the iblock-th block of the file
12+
/* Map the buffer_head passed in argument with the iblock-th block of the file
1413
* represented by inode. If the requested block is not allocated and create is
1514
* true, allocate a new block on disk and map it.
1615
*/
@@ -44,8 +43,7 @@ static int simplefs_file_get_block(struct inode *inode,
4443
goto brelse_index;
4544
}
4645

47-
/*
48-
* Check if iblock is already allocated. If not and create is true,
46+
/* Check if iblock is already allocated. If not and create is true,
4947
* allocate it. Else, get the physical block number.
5048
*/
5149
if (index->extents[extent].ee_start == 0) {
@@ -56,6 +54,7 @@ static int simplefs_file_get_block(struct inode *inode,
5654
ret = -ENOSPC;
5755
goto brelse_index;
5856
}
57+
5958
index->extents[extent].ee_start = bno;
6059
index->extents[extent].ee_len = 8;
6160
index->extents[extent].ee_block =
@@ -77,8 +76,7 @@ static int simplefs_file_get_block(struct inode *inode,
7776
return ret;
7877
}
7978

80-
/*
81-
* Called by the page cache to read a page from the physical disk and map it in
79+
/* Called by the page cache to read a page from the physical disk and map it in
8280
* memory.
8381
*/
8482
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
@@ -93,17 +91,15 @@ static int simplefs_readpage(struct file *file, struct page *page)
9391
}
9492
#endif
9593

96-
/*
97-
* Called by the page cache to write a dirty page to the physical disk (when
94+
/* Called by the page cache to write a dirty page to the physical disk (when
9895
* sync is called or when memory is needed).
9996
*/
10097
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
10198
{
10299
return block_write_full_page(page, simplefs_file_get_block, wbc);
103100
}
104101

105-
/*
106-
* Called by the VFS when a write() syscall occurs on file before writing the
102+
/* Called by the VFS when a write() syscall occurs on file before writing the
107103
* data in the page cache. This functions checks if the write will be able to
108104
* complete and allocates the necessary blocks through block_write_begin().
109105
*/
@@ -131,6 +127,7 @@ static int simplefs_write_begin(struct file *file,
131127
/* Check if the write can be completed (enough space?) */
132128
if (pos + len > SIMPLEFS_MAX_FILESIZE)
133129
return -ENOSPC;
130+
134131
nr_allocs = max(pos + len, file->f_inode->i_size) / SIMPLEFS_BLOCK_SIZE;
135132
if (nr_allocs > file->f_inode->i_blocks - 1)
136133
nr_allocs -= file->f_inode->i_blocks - 1;
@@ -139,7 +136,7 @@ static int simplefs_write_begin(struct file *file,
139136
if (nr_allocs > sbi->nr_free_blocks)
140137
return -ENOSPC;
141138

142-
/* prepare the write */
139+
/* prepare the write */
143140
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
144141
err = block_write_begin(mapping, pos, len, pagep, simplefs_file_get_block);
145142
#else
@@ -152,8 +149,7 @@ static int simplefs_write_begin(struct file *file,
152149
return err;
153150
}
154151

155-
/*
156-
* Called by the VFS after writing data from a write() syscall to the page
152+
/* Called by the VFS after writing data from a write() syscall to the page
157153
* cache. This functions updates inode metadata and truncates the file if
158154
* necessary.
159155
*/
@@ -216,6 +212,7 @@ static int simplefs_write_end(struct file *file,
216212
index = (struct simplefs_file_ei_block *) bh_index->b_data;
217213

218214
first_ext = simplefs_ext_search(index, inode->i_blocks - 1);
215+
219216
/* Reserve unused block in last extent */
220217
if (inode->i_blocks - 1 != index->extents[first_ext].ee_block)
221218
first_ext++;

0 commit comments

Comments
 (0)