Add file and directory management functions to EXT2 filesystem - #6
Merged
Conversation
lassedtu
commented
Aug 7, 2026
Owner
- Extend EXT2_VOLUME structure to include superblock and additional metadata
- Implement functions for creating and removing files and directories in the EXT2 filesystem
- Add support for renaming files and directories
- Introduce fs_stat function to retrieve file metadata, including inode information and timestamps
- Update VFS layer to provide high-level interfaces for the new file and directory operations: create, remove, rename, and stat
- Extend EXT2_VOLUME structure to include superblock and additional metadata - Implement functions for creating and removing files and directories in the EXT2 filesystem - Add support for renaming files and directories - Introduce fs_stat function to retrieve file metadata, including inode information and timestamps - Updated VFS layer to provide high-level interfaces for the new file and directory operations: create, remove, rename, and stat
There was a problem hiding this comment.
Pull request overview
This PR extends the kernel VFS/FS layers and the EXT2 driver to support filesystem mutation and metadata querying (create/remove/mkdir/rmdir/rename/stat), and adds block-device write support end-to-end (ATA + partition wrapper) so EXT2 can persist changes to disk.
Changes:
- Added VFS and FS APIs for create/mkdir/remove/rmdir/rename/stat, including an
FS_STAT/VFS_STATmetadata struct. - Extended the EXT2 volume state (cached superblock + counts) and implemented EXT2 mutation helpers for file/dir create/remove/rename.
- Introduced block-device write plumbing (
block_device_write) and implemented ATA + partition write backends.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/kernel/vfs/vfs.h | Adds VFS-level APIs for create/mkdir/remove/rmdir/rename/stat and VFS_STAT alias. |
| src/kernel/vfs/vfs.c | Implements VFS wrappers that dispatch to FS layer for new operations. |
| src/kernel/fs/fs.h | Adds FS_STAT and declares new FS-level create/mkdir/remove/rmdir/rename/stat APIs. |
| src/kernel/fs/fs.c | Implements FS wrappers mapping new operations to EXT2 driver functions; implements fs_stat. |
| src/fs/ext2/ext2.h | Extends EXT2_VOLUME with cached superblock/counts and declares EXT2 mutation APIs. |
| src/fs/ext2/ext2.c | Implements EXT2 on-disk mutation primitives (alloc/free, dir entry ops) and create/remove/rename. |
| src/drivers/disk/partition.c | Adds partition-level write implementation and wires it into the partition block device. |
| src/drivers/disk/block_device.h | Extends BLOCK_DEVICE with a write callback and declares block_device_write. |
| src/drivers/disk/block_device.c | Implements block_device_write dispatcher with basic validation. |
| src/drivers/disk/ata.h | Updates ATA init documentation to reflect write capability. |
| src/drivers/disk/ata.c | Implements ATA LBA28 write path and wires it into the ATA block device. |
Suppressed comments (1)
src/fs/ext2/ext2.c:1912
- EXT2_CreateDir sets the parent directory’s mtime/ctime to 0 before writing the inode. This permanently overwrites on-disk timestamps with epoch values. If the kernel doesn’t yet have a real time source, avoid clobbering these fields and just update the link count.
parent_inode.i_links_count++;
parent_inode.i_mtime = 0;
parent_inode.i_ctime = 0;
if (!write_inode(volume, parent_inode_number, &parent_inode))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1828
to
+1831
| parent_inode.i_mtime = 0; | ||
| parent_inode.i_ctime = 0; | ||
| write_inode(volume, parent_inode_number, &parent_inode); | ||
| return true; |
Comment on lines
+2021
to
+2022
| update_group_and_super_counts(volume, child_group, 0, 0, -1); | ||
| return true; |
Comment on lines
+1917
to
+1918
| update_group_and_super_counts(volume, child_group, 0, 0, 1); | ||
| return true; |
Comment on lines
+1008
to
+1020
| entry = (EXT2_DIR_ENTRY *)(g_block_buffer + ext2_dir_entry_size(1u)); | ||
| if (entry->name_len != 2u) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (memcmp((uint8_t *)entry + header_size, "..", 2u) != 0) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| entry->inode = parent_inode_number; | ||
| return write_block(volume, dir_inode.i_block[0], g_block_buffer); |
Comment on lines
+16
to
+18
| static bool inode_is_dir(const EXT2_INODE *inode); | ||
| static bool inode_is_regular(const EXT2_INODE *inode); | ||
| static bool inode_is_directory(const EXT2_INODE *inode); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.