Commit graph

71 commits

Author SHA1 Message Date
Andreas Kling
05f18febb6 Ext2FS: Delete inodes when their link count goes to zero. 2019-01-22 16:34:24 +01:00
Andreas Kling
bda0c935c2 Add unlink() syscall and /bin/rm.
This patch adds most of the plumbing for working file deletion in Ext2FS.
Directory entries are removed and inode link counts updated.
We don't yet update the inode or block bitmaps, I will do that separately.
2019-01-22 07:03:44 +01:00
Andreas Kling
f70136a324 Kernel: Support open() with O_CREAT.
It's now possible to create zero-length files! :^)
Also hook up the new functionality in /bin/touch.
2019-01-22 00:58:56 +01:00
Andreas Kling
b75ee4aacb Coding style fixes in AK. 2019-01-19 22:53:05 +01:00
Andreas Kling
0d36281162 Refactor FS::find_parent_of_inode() into Inode::parent().
This way, Ext2FSInode can cache its parent inode index. This makes absolute
path lookups dramatically faster.
SynthFSInode is also simplified greatly.
2019-01-04 18:37:58 +01:00
Andreas Kling
eb78238032 Ext2FS: Don't worry about updating lookup caches in write_ext2_inode().
Instead, have Ext2FSInode worry about that when flushing.
Also tidy up in the inode bitmap accessors at the same time for some reason.
2019-01-01 03:55:43 +01:00
Andreas Kling
8f9542174f Ext2FS: Don't cache a full Ext2FSInode object for non-existent inodes.
This was a bit silly. We were always creating Ext2FSInode objects when
Ext2FSInode::get_inode() was called. They'd then sit and fatten up the
inode cache forever, despite not representing allocated inodes.

This patch consults the inode bitmap and if get_inode() is called with
an unallocated inode index, we simply cache a nullptr to represent the
fact that this index is unused.

This could be a lot better optimized, it will currently hit the disk for
every new inode index encountered.
2019-01-01 03:37:27 +01:00
Andreas Kling
d07b08a287 FS: Don't default to having a full InodeMetadata in every Inode.
This allows Ext2FS to keep its own ext2_inode around instead.
2019-01-01 03:16:36 +01:00
Andreas Kling
0cb074dc73 Ext2FS: On second thought, let's not uncache the Ext2FSInodes today.. 2019-01-01 02:52:21 +01:00
Andreas Kling
741349502f Ext2FS: Free Ext2FSInodes when the last user releases them.
The inode cache was keeping these alive forever. Added a cute little magic
trick to Retainable that calls T::one_retain_left() when the retain count
is decremented to 1.
2019-01-01 02:38:09 +01:00
Andreas Kling
eed6031064 Fix EXT2_DEBUG build. 2018-12-29 03:36:22 +01:00
Andreas Kling
079889050e Merge lookup_ext2_inode() into Ext2FS::get_inode(). 2018-12-25 00:32:57 +01:00
Andreas Kling
6451b98ad4 Refactor FS::add_inode_to_directory() into Inode::add_child(). 2018-12-25 00:27:39 +01:00
Andreas Kling
4f142b86ec Refactor FS::write_inode() into Inode::write(). 2018-12-25 00:10:32 +01:00
Andreas Kling
b0db0e5de0 Get rid of Ext2FS::modify_link_count() in favor of Inode accessors. 2018-12-24 23:58:00 +01:00
Andreas Kling
673870563d Convert some FS methods to return RetainPtr<Inode>. 2018-12-24 23:45:09 +01:00
Andreas Kling
1e07ead119 Get rid of Ext2FS::is_directory_inode().
This was only used for assertions and will be factored out in favor of
Inode metadata checks eventually.
2018-12-24 23:38:15 +01:00
Andreas Kling
04ee693925 Get rid of FS::inode_metadata() since we use Inode::metadata() everywhere. 2018-12-21 17:32:18 +01:00
Andreas Kling
8a71303827 Get rid of FS::read_inode_bytes() and use Inode::read_bytes() everywhere. 2018-12-21 17:28:16 +01:00
Andreas Kling
ec1c487dcd Yet another pass of style fixes. 2018-12-21 02:10:45 +01:00
Andreas Kling
ed7ae6c02c Add sync() syscall and a /bin/sync.
It walks all the live Inode objects and flushes pending metadata changes
wherever needed.

This could be optimized by keeping a separate list of dirty Inodes,
but let's not get ahead of ourselves.
2018-12-20 00:39:29 +01:00
Andreas Kling
d0f06e5f3f Automatically call Inode::flush_metadata() before an Inode is destroyed.
Use a little template magic to have Retainable::release() call out to
T::will_be_destroyed() if such a function exists before actually calling
the destructor. This gives us full access to virtual functions in the
pre-destruction code.
2018-12-19 22:28:09 +01:00
Andreas Kling
1f44cd9dd9 Reworked Inode to have a dirty bit and subclass-implemented flush_metadata().
This way we can defer disk writes as long as we like. There's no automatic
flushing happening just yet.
2018-12-19 21:56:45 +01:00
Andreas Kling
d506c857ab Rename CoreInode to Inode.
I don't know what I was thinking here. Clearly Inode is the right name.
2018-12-19 21:18:28 +01:00
Andreas Kling
038d8641f9 Implement utime() along with a naive /bin/touch.
This synchronous approach to inodes is silly, obviously. I need to rework
it so that the in-memory CoreInode object is the canonical inode, and then
we just need a sync() that flushes pending changes to disk.
2018-12-19 21:14:55 +01:00
Andreas Kling
ca6847b5bb Import a simple text editor I started working on. 2018-12-04 00:27:16 +01:00
Andreas Kling
aff89d2fd7 Yet more coding style fixes. 2018-12-03 01:38:22 +01:00
Andreas Kling
d824442e3e Get rid of deprecated_enumerateDirectoryInode.
This was a vestige from the pre-CoreInode implementation of Ext2FS.
2018-12-03 00:26:39 +01:00
Andreas Kling
407bb3e76e Some coding style fixes. I'm getting more comfortable with this style. 2018-12-03 00:20:00 +01:00
Andreas Kling
85b886c2e0 Make it possible to build the Kernel on a macOS host.
It still requires an ELF compiler and linker, but at least it builds.
I need to get rid of the "Unix" namespace. This does a lot of that.
2018-12-02 23:34:50 +01:00
Andreas Kling
f5a0b6961c Fix mkdir with relative paths. 2018-11-18 23:28:43 +01:00
Andreas Kling
de4604ac95 Finally hook up the mkdir code to a syscall.
Added a /bin/mkdir that makes directories. How very neat :^)
There are various limitations because of missing functionality.
2018-11-18 15:02:16 +01:00
Andreas Kling
2529925fe9 Some more renaming:
FileSystem -> FS
SyntheticFileSystem -> SynthFS
ProcFileSystem -> ProcFS
Ext2FileSystem -> Ext2FS
Ext2Inode -> Ext2FSInode
2018-11-15 17:13:10 +01:00
Andreas Kling
eced5f11e3 Add CoreInode::reverse_lookup().
Getting the absolute path of an ext2fs inode now uses the lookup cache
which makes it a lot faster.
2018-11-15 17:04:55 +01:00
Andreas Kling
5f434bc00b Add CoreInode::lookup() for directory lookups.
Also add a name-to-inode lookup cache to Ext2Inode. This seems like a great
speedup for filesystem traversal.
2018-11-15 16:38:43 +01:00
Andreas Kling
8fa2d7104a More VFS cleanup. 2018-11-15 16:04:25 +01:00
Andreas Kling
396a32835b A pass of style/naming cleanup in VFS. 2018-11-15 15:10:30 +01:00
Andreas Kling
c735c56e4c More work on CoreInode. 2018-11-13 23:44:54 +01:00
Andreas Kling
26852a8363 Add metadata to CoreInode. 2018-11-13 13:32:16 +01:00
Andreas Kling
10c470e95f Make page_in_from_vnode 2x faster.
...by adding a new class called Ext2Inode that inherits CoreInode.
The idea is that a vnode will wrap a CoreInode rather than InodeIdentifier.
Each CoreInode subclass can keep whatever caches they like.

Right now, Ext2Inode caches the list of block indices since it can be very
expensive to retrieve.
2018-11-13 13:02:39 +01:00
Andreas Kling
19b9401487 Reduce kmalloc() traffic in directory iteration.
Pass the file name in a stack-allocated buffer instead of using an AK::String
when iterating directories. This dramatically reduces the amount of cycles
spent traversing the filesystem.
2018-11-13 00:17:30 +01:00
Andreas Kling
ebf308d413 Make kernel build with clang.
It's a bit faster than g++ and seems to generate perfectly fine code.
The kernel is also roughly 10% smaller(!)
2018-11-09 12:22:31 +01:00
Andreas Kling
03a8357e84 Implement sending signals to blocked-in-kernel processes.
This is dirty but pretty cool! If we have a pending, unmasked signal for
a process that's blocked inside the kernel, we set up alternate stacks
for that process and unblock it to execute the signal handler.

A slightly different return trampoline is used here: since we need to
get back into the kernel, a dedicated syscall is used (sys$sigreturn.)

This restores the TSS contents of the process to the state it was in
while we were originally blocking in the kernel.

NOTE: There's currently only one "kernel resume TSS" so signal nesting
definitely won't work.
2018-11-07 21:19:47 +01:00
Andreas Kling
83172e6a4b Rename FileHandle to FileDescriptor. 2018-11-07 11:37:54 +01:00
Andreas Kling
8f6998c902 Add SpinLock to IDE disk access.
This forces serialization of accesses. This driver needs to be redesigned.
2018-10-31 21:33:27 +01:00
Andreas Kling
dec5683e9c Snazz up the kprintf() output a bit by giving it its own color. 2018-10-31 20:14:23 +01:00
Andreas Kling
8e640539ef Add an inode metadata cache to the ext2fs implementation. 2018-10-29 23:45:34 +01:00
Andreas Kling
b1ff62f605 Okay let's just not have this broken locking at all right now.
I think I should just protect access to shared data structures
and eventually do read/write atomicity locks at the inode level.
2018-10-29 22:43:39 +01:00
Andreas Kling
e6284a8774 Fix broken SpinLock.
The SpinLock was all backwards and didn't actually work. Fixing it exposed
how wrong most of the locking here is.

I need to come up with a better granularity here.
2018-10-29 22:04:26 +01:00
Andreas Kling
1d4af51250 Add a VFS::absolutePath(InodeIdentifier).
This is pretty inefficient for ext2fs. We walk the entire block group
containing the inode, searching through every directory for an entry
referencing this inode.

It might be a good idea to cache this information somehow. I'm not sure
how often we'll be searching for it.

Obviously there are multiple caching layers missing in the file system.
2018-10-28 12:20:25 +01:00