diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-05-15 01:15:00 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-05-15 01:15:00 +0000 |
commit | f077699e3c77321235c007ec7e47e066ed55ca68 (patch) | |
tree | 48a3322ed6d363dbd2155d8e19470797301a8d77 | |
parent | 53b54f664ed2b4630c23cacc9e216a6a5935b57f (diff) |
s5 fixes!
-rw-r--r-- | kernel/fs/open.c | 2 | ||||
-rw-r--r-- | kernel/fs/s5fs/s5fs_subr.c | 41 | ||||
-rw-r--r-- | kernel/main/kmain.c | 2 | ||||
-rw-r--r-- | kernel/proc/proc.c | 3 | ||||
-rw-r--r-- | kernel/vm/shadow.c | 1 | ||||
-rw-r--r-- | kernel/vm/vmmap.c | 3 |
6 files changed, 39 insertions, 13 deletions
diff --git a/kernel/fs/open.c b/kernel/fs/open.c index 8f0d893..e8945de 100644 --- a/kernel/fs/open.c +++ b/kernel/fs/open.c @@ -144,9 +144,7 @@ long do_open(const char *filename, int oflags) // Truncate the file if O_TRUNC is specified if (oflags & O_TRUNC && S_ISREG(res_vnode->vn_mode)) { - vlock(res_vnode); res_vnode->vn_ops->truncate_file(res_vnode); - vunlock(res_vnode); } // Create the file descriptor 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. diff --git a/kernel/main/kmain.c b/kernel/main/kmain.c index c835275..c4b64b4 100644 --- a/kernel/main/kmain.c +++ b/kernel/main/kmain.c @@ -170,9 +170,11 @@ static void *initproc_run(long arg1, void *arg2) // dbg(DBG_PROC, "%s", "In main thread!\n"); +#ifdef __VM__ char *const argv[] = {NULL}; char *const envp[] = {NULL}; kernel_execve("/sbin/init", argv, envp); +#endif #ifdef __DRIVERS__ // driverstest_main(0, NULL); diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index 2ade163..cfaa2b3 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -296,7 +296,10 @@ void proc_cleanup(long status) do_close(fd); } vput(&curproc->p_cwd); + +#ifdef __VM__ vmmap_destroy(&curproc->p_vmmap); +#endif if (curproc->p_pid == PID_INIT) { diff --git a/kernel/vm/shadow.c b/kernel/vm/shadow.c index 4883160..bf04bc9 100644 --- a/kernel/vm/shadow.c +++ b/kernel/vm/shadow.c @@ -119,6 +119,7 @@ void shadow_collapse(mobj_t *o) NOT_YET_IMPLEMENTED("VM: shadow_collapse"); } + /* * Obtain the desired pframe from the given mobj, traversing its shadow chain if * necessary. This is where copy-on-write logic happens! diff --git a/kernel/vm/vmmap.c b/kernel/vm/vmmap.c index 5f8e575..34dfaa5 100644 --- a/kernel/vm/vmmap.c +++ b/kernel/vm/vmmap.c @@ -302,13 +302,14 @@ vmmap_t *vmmap_clone(vmmap_t *map) // NOT_YET_IMPLEMENTED("VM: vmmap_clone"); // Create a new vmmap - // vmmap_collapse(map); vmmap_t *new_vmmap = vmmap_create(); if (new_vmmap == NULL) { return NULL; } + vmmap_collapse(map); + // Iterate over the list of vmareas list_iterate(&map->vmm_list, vma, vmarea_t, vma_plink) { |