From 106eacf796dc15d1256aa92ee4ded216d0e6f29c Mon Sep 17 00:00:00 2001 From: sotech117 Date: Fri, 26 Apr 2024 08:06:23 +0000 Subject: finish s5, but no clean halt --- kernel/fs/s5fs/s5fs.c | 79 ++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 36 deletions(-) (limited to 'kernel/fs/s5fs/s5fs.c') diff --git a/kernel/fs/s5fs/s5fs.c b/kernel/fs/s5fs/s5fs.c index 819b106..602c7aa 100644 --- a/kernel/fs/s5fs/s5fs.c +++ b/kernel/fs/s5fs/s5fs.c @@ -218,25 +218,28 @@ static void s5fs_read_vnode(fs_t *fs, vnode_t *vn) // Get the inode s5_inode_t *s5_inode = &s5_node->inode; KASSERT(s5_inode); - // Update linkcount - s5_inode->s5_linkcount++; // Get the page frame for the inode pframe_t *pf; - long err = s5fs_get_pframe(vn, &vn->vn_mobj, 0, &pf); - // Check if the page frame was not found - if (err < 0) - { - return; - } + s5_get_meta_disk_block(FS_TO_S5FS(fs), S5_INODE_BLOCK(vn->vn_vno), 0, &pf); + // // Check if the page frame was not found + // if (err < 0) + // { + // return; + // } // Copy the inode from the page frame - memcpy(s5_inode, pf->pf_addr, sizeof(s5_inode_t)); + memcpy( + s5_inode, + (s5_inode_t *)pf->pf_addr + S5_INODE_OFFSET(vn->vn_vno), + sizeof(s5_inode_t) + ); // Release the disk block s5_release_disk_block(&pf); // Initialize the dirtied_inode field s5_node->dirtied_inode = 0; + s5_node->vnode = *vn; // Initialize the vnode fields // lan and inode trivial @@ -290,9 +293,6 @@ static void s5fs_delete_vnode(fs_t *fs, vnode_t *vn) s5_inode_t *s5_inode = &s5_node->inode; KASSERT(s5_inode); - // Update linkcount - s5_inode->s5_linkcount--; - // Check if the inode is no longer in use if (s5_inode->s5_linkcount == 0) { @@ -306,14 +306,18 @@ static void s5fs_delete_vnode(fs_t *fs, vnode_t *vn) { // Write the inode back to disk and return pframe_t *pf; - long err = s5fs_get_pframe(vn, &vn->vn_mobj, 1, &pf); - // Check if the page frame was not found - if (err < 0) - { - return; - } + s5_get_meta_disk_block(FS_TO_S5FS(fs), S5_INODE_BLOCK(vn->vn_vno), 0, &pf); + // // Check if the page frame was not found + // if (err < 0) + // { + // return; + // } // Copy the inode to the page frame - memcpy(pf->pf_addr, s5_inode, sizeof(s5_inode_t)); + memcpy( + (s5_inode_t *)pf->pf_addr + S5_INODE_OFFSET(vn->vn_vno), + s5_inode, + sizeof(s5_inode_t) + ); s5_release_disk_block(&pf); return; } @@ -429,7 +433,7 @@ static long s5fs_mknod(struct vnode *dir, const char *name, size_t namelen, // NOT_YET_IMPLEMENTED("S5FS: s5fs_mknod"); // Check if the mode is not supported - if (mode != S_IFCHR && mode != S_IFBLK && mode != S_IFREG) + if (!(S_ISCHR(mode) || S_ISBLK(mode) || S_ISREG(mode))) { return -ENOTSUP; } @@ -456,7 +460,7 @@ static long s5fs_mknod(struct vnode *dir, const char *name, size_t namelen, // Allocate the inode s5_inode_t *s5_inode; - long inode_num = s5_alloc_inode(s5fs, type, &s5_inode); + long inode_num = s5_alloc_inode(s5fs, type, devid); // Check if the inode allocation failed if (inode_num < 0) { @@ -464,7 +468,7 @@ static long s5fs_mknod(struct vnode *dir, const char *name, size_t namelen, } // Create the new vnode - vnode_t *new_vnode = vget(dir->vn_fs, inode_num); + vnode_t *new_vnode = vget(s5fs->s5f_fs, inode_num); // Check if the vnode creation failed if (!new_vnode) { @@ -472,15 +476,12 @@ static long s5fs_mknod(struct vnode *dir, const char *name, size_t namelen, return -ENOMEM; } - // Set the devid for the new inode - s5_inode->s5_indirect_block = devid; - // Link the new inode/vnode to the parent directory - long link = s5_link(dir, name, namelen, new_vnode); + long link = s5_link(dir, name, namelen, VNODE_TO_S5NODE(new_vnode)); // Check if the link operation failed if (link < 0) { - vput(new_vnode); + vput(&new_vnode); s5_free_inode(s5fs, inode_num); return link; } @@ -527,7 +528,6 @@ long s5fs_lookup(vnode_t *dir, const char *name, size_t namelen, return 0; } - // If not, get the found vnode vnode_t *found_vnode = vget(dir->vn_fs, ino); // Check if the vnode creation failed @@ -590,11 +590,11 @@ static long s5fs_unlink(vnode_t *dir, const char *name, size_t namelen) } // Get the found vnode - vnode_t *child = vget_locked(dir->vn_fs, ino); + vnode_t *child = vget_locked(VNODE_TO_S5FS(dir)->s5f_fs, ino); KASSERT(!S_ISDIR(child->vn_mode) && "should be handled at the VFS level"); // Remove the directory entry - s5_remove_dirent(s5_node, name, namelen, filepos); + s5_remove_dirent(s5_node, name, namelen, VNODE_TO_S5NODE(child)); // Check to see if this failed (TODO: ask in hours) // Release the vnode @@ -797,7 +797,9 @@ static long s5fs_mkdir(vnode_t *dir, const char *name, size_t namelen, } // Create the "." entry + vlock(new_vnode); long link = s5_link(VNODE_TO_S5NODE(new_vnode), ".", 1, VNODE_TO_S5NODE(new_vnode)); + vunlock(new_vnode); // Check if the link operation failed if (link < 0) { @@ -807,7 +809,9 @@ static long s5fs_mkdir(vnode_t *dir, const char *name, size_t namelen, } // Create the ".." entry + vlock(new_vnode); long link2 = s5_link(VNODE_TO_S5NODE(new_vnode), "..", 2, VNODE_TO_S5NODE(dir)); + vunlock(new_vnode); // Check if the link operation failed if (link2 < 0) { @@ -818,7 +822,12 @@ static long s5fs_mkdir(vnode_t *dir, const char *name, size_t namelen, } // Link the new directory to the parent + vlock(dir); + + dbg(DBG_PRINT, "LINKING DIR TO NAME %s\n\n", name); + long link3 = s5_link(VNODE_TO_S5NODE(dir), name, namelen, VNODE_TO_S5NODE(new_vnode)); + vunlock(dir); // Check if the link operation failed if (link3 < 0) { @@ -866,8 +875,6 @@ static long s5fs_rmdir(vnode_t *parent, const char *name, size_t namelen) // Get the found vnode vnode_t *child = vget_locked(parent->vn_fs, ino); - KASSERT(S_ISDIR(child->vn_mode) && "should be handled at the VFS level"); - // Check if this is a directory if (!S_ISDIR(child->vn_mode)) { @@ -883,14 +890,14 @@ static long s5fs_rmdir(vnode_t *parent, const char *name, size_t namelen) } // Remove the "." entry - s5_remove_dirent(VNODE_TO_S5NODE(child), ".", 1, 0); + s5_remove_dirent(VNODE_TO_S5NODE(child), ".", 1, VNODE_TO_S5NODE(child)); // Check if this failed (TODO: ask in hours) // Remove the ".." entry - s5_remove_dirent(VNODE_TO_S5NODE(child), "..", 2, 0); + s5_remove_dirent(VNODE_TO_S5NODE(child), "..", 2, VNODE_TO_S5NODE(parent)); // Remove the directory entry - s5_remove_dirent(s5_node, name, namelen, filepos); + s5_remove_dirent(s5_node, name, namelen, VNODE_TO_S5NODE(child)); // Check if this failed (TODO: ask in hours) // Release the vnode @@ -962,7 +969,7 @@ static long s5fs_stat(vnode_t *vnode, stat_t *ss) s5_inode_t *s5_inode = &VNODE_TO_S5NODE(vnode)->inode; // Initialize the stat struct - ss->st_blocks = s5_inode_blocks(s5_inode); + ss->st_blocks = s5_inode_blocks(vnode); ss->st_mode = vnode->vn_mode; ss->st_rdev = vnode->vn_devid; ss->st_ino = s5_inode->s5_number; -- cgit v1.2.3-70-g09d2