aboutsummaryrefslogtreecommitdiff
path: root/kernel/fs/s5fs
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/fs/s5fs')
-rw-r--r--kernel/fs/s5fs/s5fs_subr.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/kernel/fs/s5fs/s5fs_subr.c b/kernel/fs/s5fs/s5fs_subr.c
index f092d0a..55dd932 100644
--- a/kernel/fs/s5fs/s5fs_subr.c
+++ b/kernel/fs/s5fs/s5fs_subr.c
@@ -116,17 +116,17 @@ static inline void s5_release_file_block(pframe_t **pfp)
* - Use s5_alloc_block to allocate blocks.
* - Be sure to mark the inode as dirty when appropriate, i.e. when you are
* making changes to the actual s5_inode_t struct. Hint: Does allocating a
- * direct block dirty the inode? What about allocating the indirect block?
- * Finally, what about allocating a block pointed to by the indirect block?
+ * direct block dirty the inode?(yes) What about allocating the indirect block?(yes)
+ * Finally, what about allocating a block pointed to by the indirect block?(no)
* - Cases to consider:
- * 1) file_blocknum < S_NDIRECT_BLOCKS
- * 2) Indirect block is not allocated but alloc is set. Be careful not to
+ * - 1) file_blocknum < S_NDIRECT_BLOCKS
+ * - 2) Indirect block is not allocated but alloc is set. Be careful not to
* leak a block in an error case!
- 2a) Make sure you allocate the indirect block on disk and create a
+ - 2a) Make sure you allocate the indirect block on disk and create a
corresponding pframe_t on the mobj (Hint: see s5_cache_and_clear_block).
- * 3) Indirect block is allocated. The desired block may be sparse, and you
+ * - 3) Indirect block is allocated. The desired block may be sparse, and you
* may have to allocate it.
- * 4) The indirect block has not been allocated and alloc is clear.
+ * - 4) The indirect block has not been allocated and alloc is clear.
*/
long s5_file_block_to_disk_block(s5_node_t *sn, size_t file_blocknum,
int alloc, int *newp)
@@ -341,6 +341,7 @@ ssize_t s5_read_file(s5_node_t *sn, size_t pos, char *buf, size_t len)
return bytes_read;
}
+
/* Write to a file.
*
* sn - The s5_node representing the file to write to
@@ -491,7 +492,7 @@ static long s5_alloc_block(s5fs_t *s5fs)
// Collapse the next node of the free list into the super block
pframe_t *pf;
- s5_get_meta_disk_block(s5fs, new_block_num, 1, &pf);
+ s5_get_meta_disk_block(s5fs, new_block_num, 0, &pf);
memcpy(s->s5s_free_blocks, pf->pf_addr, sizeof(s->s5s_free_blocks));
s5_release_disk_block(&pf);
@@ -511,6 +512,11 @@ static long s5_alloc_block(s5fs_t *s5fs)
pframe_t *pf;
s5_get_meta_disk_block(s5fs, new_block_num, 1, &pf);
memset(pf->pf_addr, 0, PAGE_SIZE);
+
+ // Flush the pframe
+ mobj_lock(&s5fs->s5f_mobj);
+ mobj_flush_pframe(&s5fs->s5f_mobj, pf);
+ mobj_unlock(&s5fs->s5f_mobj);
s5_release_disk_block(&pf);
// Unlock the super block
@@ -795,7 +801,7 @@ void s5_remove_dirent(s5_node_t *sn, const char *name, size_t namelen,
// Truncate the length of the directory by sizeof(s5_dirent_t)
inode->s5_un.s5_size -= sizeof(s5_dirent_t);
dir->vn_len -= sizeof(s5_dirent_t);
- sn->dirtied_inode = 1;
+ // sn->dirtied_inode = 1;
// Decrement the child's linkcount
child->inode.s5_linkcount--;
@@ -927,7 +933,7 @@ long s5_link(s5_node_t *dir, const char *name, size_t namelen,
}
/* Return the number of file blocks allocated for sn. This means any
- * file blocks that are not sparse, direct or indirect. If the indirect
+ * direct or indirect file blocks that are not sparse. If the indirect
* block itself is allocated, that must also count. This function should not
* fail.
*
@@ -964,11 +970,26 @@ long s5_inode_blocks(s5_node_t *sn)
if (inode->s5_indirect_block)
{
num_file_blocks++;
+
+ pframe_t *pf;
+ s5_get_meta_disk_block(VNODE_TO_S5FS(&sn->vnode), inode->s5_indirect_block, 0, &pf);
+ uint32_t *blocknum_ptr = pf->pf_addr;
+
+ for (unsigned i = 0; i < S5_NIDIRECT_BLOCKS; i++)
+ {
+ if (blocknum_ptr[i])
+ {
+ num_file_blocks++;
+ }
+ }
+
+ s5_release_disk_block(&pf);
}
return num_file_blocks;
}
+
/**
* Given a s5_node_t, frees the associated direct blocks and
* the indirect blocks if they exist.