From 09d3f77cd82947d8c039cbc29efd32207922ba77 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 24 Feb 2025 19:54:45 -0500 Subject: [PATCH] ext2: add locking --- fs/ext2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext2.c b/fs/ext2.c index d8270d1..4062728 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -655,6 +655,7 @@ static int ext2_ino_del_dirent(struct ext2fs *fs, struct ext2_inode *ino, const struct ext2_dir_entry *cur = NULL; struct ext2_dir_entry *prev = NULL; + spinlock_acquire(&fs->lock); while (cur && offset < fs->block_size * n_blocks && cur->inode) { cur = (struct ext2_dir_entry *)((char *)entry + offset); @@ -682,10 +683,10 @@ static int ext2_ino_del_dirent(struct ext2fs *fs, struct ext2_inode *ino, const /* write all the blocks */ uint32_t starting_block = offset / fs->block_size; - for (int i = starting_block; i < n_blocks; i++) { + for (int i = starting_block; i < n_blocks; i++) ext2_ino_write_block(fs, ino, ((char *)entry) + i * fs->block_size, i); - } + spinlock_release(&fs->lock); return 0; } @@ -693,6 +694,7 @@ static int ext2_ino_del_dirent(struct ext2fs *fs, struct ext2_inode *ino, const offset += cur->rec_len; } + spinlock_release(&fs->lock); return -ENOENT; }