feat: add ext2 write support - #33
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements write-path functionality for the ext2 filesystem, including inode/block allocation, directory entry mutation, truncate/unlink support, and syscall-level O_TRUNC handling to enable basic POSIX file updates.
Changes:
- Add ext2 write support (block/inode allocation, file writes, truncate, create, unlink) and wire new ops into mount/inode creation.
- Refactor ext2 low-level utilities (block/group desc I/O, inode sizing helpers, directory entry helpers) to support the write path.
- Add a userspace ext2 write/truncate/unlink regression test.
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libk/utils/cache.c | Fix cache commit to pass the correct cached value to commit handler. |
| kernel/syscalls/257_openat.c | Add O_TRUNC handling via vfs_truncate() for regular files opened for write. |
| kernel/fs/ext2/utils/ext2_inode.c | Implement inode allocation/free and block-mapping based inode data read/write/free. |
| kernel/fs/ext2/utils/ext2_dir.c | Add helpers to add/remove directory entries and map dirent types. |
| kernel/fs/ext2/utils/ext2_block.c | Add block alloc/free, superblock/group-desc read/write, and harden block I/O with validation + error returns. |
| kernel/fs/ext2/ext2.h | Add layout asserts, inode size helpers, and expose new ext2 utility APIs + ops. |
| kernel/fs/ext2/ext2_write.c | Rewrite ext2 write logic to allocate blocks on demand and support holes. |
| kernel/fs/ext2/ext2_unlink.c | Add ext2 unlink implementation for regular files. |
| kernel/fs/ext2/ext2_umount.c | Ensure ext2 block cache is destroyed on unmount. |
| kernel/fs/ext2/ext2_truncate.c | Add ext2 truncate implementation (grow with zero-fill, shrink freeing blocks). |
| kernel/fs/ext2/ext2_setattr.c | Enforce read-only mounts and commit inode metadata updates via ext2 icache commit. |
| kernel/fs/ext2/ext2_readlink.c | Update to new inode-data API and add ext2 lock around on-disk readlink path. |
| kernel/fs/ext2/ext2_readdir.c | Rewrite readdir to robustly parse entries and emit multiple results per call. |
| kernel/fs/ext2/ext2_read.c | Rewrite read path to new inode-data API with locking and bounds checks. |
| kernel/fs/ext2/ext2_mount.c | Add feature validation, compute group counts safely, and wire in setattr/creat/unlink ops and caches. |
| kernel/fs/ext2/ext2_getattr.c | Fix time fields and use unified inode size getter; set blksize from statvfs. |
| kernel/fs/ext2/ext2_fsync.c | Flush inode cache and forward fsync to underlying device inode. |
| kernel/fs/ext2/ext2_finddir.c | Add shared inode creation helper and harden directory parsing/search logic. |
| kernel/fs/ext2/ext2_creat.c | Add ext2 create implementation for regular files (alloc inode + add dir entry). |
| kernel/fs/ext2/ext2_cache.c | Make inode cache allocate ext2 inode-sized entries and persist on commit when writable. |
| drivers/dev/block/main.c | Invalidate per-device block cache at start of write path. |
| apps/test/ext2-write-test/Makefile | Add build rules for a new ext2 write regression test app. |
| apps/test/ext2-write-test/main.c | Add userspace test covering write patterns, holes, truncate grow/shrink, O_TRUNC, and unlink. |
| .gitignore | Ignore AGENTS.md and normalize .pdb ignore line formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+52
to
54
| if (unlikely(pos < 0 || (uint64_t)pos > UINT64_MAX - len)) | ||
| return errno = EINVAL, -1; | ||
|
|
| } | ||
| } | ||
|
|
||
| ext2_inode_set_size(ext2, node, new_size); |
Comment on lines
+108
to
+109
| if (!result) | ||
| errno = errno == EIO ? EIO : ENOENT; |
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.
No description provided.