summaryrefslogtreecommitdiff
path: root/Kernel/Storage/StorageDevice.cpp
AgeCommit message (Collapse)Author
2022-08-14Kernel/Storage: Remove InterfaceType enumLiav A
This enum was created to help put distinction between the commandset and the interface type, as ATAPI devices are simply ATA devices utilizing the SCSI commandset. Because we don't support ATAPI, putting such type of distinction is pointless, so let's remove this for now.
2022-07-24Kernel/SysFS: Fix parent directory hierarchy with symbolic linksLiav A
We should actually start counting from the parent directory and not from the symbolic link as it will represent a wrong count of hops from the actual mountpoint. The symlinks in /sys/dev/block and /sys/dev/char worked only by luck, because I have set it to the wrong parent directory which is the /sys/dev directory, so with the symlink it was 3 hops to /sys, together with the root directory, therefore, everything seemed to work. Now that the device symlinks in /sys/dev/block and /sys/dev/char are set to the right parent directory and we start measure hops from root directory with the parent directory of a symlink, everything seem to work correctly now.
2022-07-19Kernel/Devices: Abstract SysFS Device add/remove methods more properlyLiav A
It is starting to get a little messy with how each device can try to add or remove itself to either /sys/dev/block or /sys/dev/char directories. To better do this, we introduce 4 virtual methods to take care of that, so until we ensure all nodes in /sys/dev/block and /sys/dev/char are actual symlinks, we allow the Device base class to call virtual methods upon insertion or before being destroying, so it add itself elegantly to either of these directories or remove itself when needed. For special cases where we need to create symlinks, we have two virtual methods to be called otherwise to do almost the same thing mentioned before, but to use symlinks instead.
2022-07-15Kernel/SysFS: Add /sys/devices/storage directoryLiav A
This change in fact does the following: 1. Use support for symlinks between /sys/dev/block/ storage device identifier nodes and devices in /sys/devices/storage/{LUN}. 2. Add basic nodes in a /sys/devices/storage/{LUN} directory, to let userspace to know about the device and its details.
2022-07-15Kernel/Storage: Add LUN address to each StorageDeviceLiav A
LUN address is essentially how people used to address SCSI devices back in the day we had these devices more in use. However, SCSI was taken as an abstraction layer for many Unix and Unix-like systems, so it still common to see LUN addresses in use. In Serenity, we don't really provide such abstraction layer, and therefore until now, we didn't use LUNs too. However (again), this changes, as we want to let users to address their devices under SysFS easily. LUNs make sense in that regard, because they can be easily adapted to different interfaces besides SCSI. For example, for legacy ATA hard drive being connected to the first IDE controller which was enumerated on the PCI bus, and then to the primary channel as slave device, the LUN address would be 0:0:1. To make this happen, we add unique ID number to each StorageController, which increments by 1 for each new instance of StorageController. Then, we adapt the ATA and NVMe devices to use these numbers and generate LUN in the construction time.
2022-07-15Kernel: Export both interface type and command set of a StorageDeviceLiav A
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-30Kernel: Fix storage device read/write for request length < block sizePankaj Raghav
The current implementation of read/write will fail in StorageDevice when the request length is less than the block size of the underlying device. Fix it by calculating the offset within a block for such cases and using it for copying data from the bounce buffer.
2022-01-29Kernel: Optimize StorageDevice read and write functionPankaj Raghav
Use shift operator with log size instead of division while calculating the index and len.
2022-01-29Kernel: Cache blocks_per_page in StorageDevice classPankaj Raghav
Instead of calculating blocks_per_page in every IO, cache it to save CPU cycles as that value will not change after initialization.
2022-01-26Kernel: Make StorageDevice partial block writes OOM-fallibleIdan Horowitz
2022-01-25Kernel: Use u64 instead of size_t in the STORAGE_DEVICE_GET_SIZE ioctlIdan Horowitz
This ensures the device size doesn't get truncated on i686.
2022-01-25Kernel: Use u64 instead of u32 and u16 in StorageDevice::{read, write}Idan Horowitz
This ensures offsets will not be truncated on large filesystems on i686
2022-01-25Kernel: Use u64 instead of size_t for File::can_write offsetIdan Horowitz
This ensures offsets will not be truncated on large files on i686.
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2021-12-23Kernel: Make major and minor numbers to be DistinctNumericsLiav A
This helps avoid confusion in general, and make constructors, methods and code patterns much more clean and understandable.
2021-11-16Kernel: Use static_ptr_cast to convert between Userspace<T*> typesAndrew Kaster
Some calls of copy_to_user were converting Userspace<T*> to Userspace<U*> via the implicit conversion to FlatPtr. Change them to use the static_ptr_cast overload that is designed to express this conversion
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-10-09Kernel: Add ioctl request for getting a storage device's block sizeDavid Isaksson
2021-10-09Kernel: Add STORAGE_DEVICE_GET_SIZE ioctl requestDavid Isaksson
This ioctl request makes it possible to get the size of a storage device that has not yet been mounted.
2021-10-09Kernel/Storage: Unify all ATA devicesLiav A
There's basically no real difference in software between a SATA harddisk and IDE harddisk. The difference in the implementation is for the host bus adapter protocol and registers layout. Therefore, there's no point in putting a distinction in software to these devices. This change also greatly simplifies and removes stale APIs and removes unnecessary parameters in constructor calls, which tighten things further everywhere.
2021-10-03Kernel: Remove now unused StorageDevice constructorBrian Gianforcaro
2021-10-03Kernel: Remove most String usage from storage_name() APIBrian Gianforcaro
This change is another minor step towards removing `AK::String` from the Kernel. Instead of dynamically allocating the storage_name we can instead allocate it via a KString in the factory for each device, and then push the device name down into the StorageDevice base class. We don't have a way of doing `AK::String::formatted(..)` with a KString at the moment, so cleaning that up will be left for a later day.
2021-10-03Kernel: Use `operator ""sv` in all class_name() implementationsBrian Gianforcaro
Previously there was a mix of returning plain strings and returning explicit string views using `operator ""sv`. This change switches them all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-09-07Kernel: Make Device request creation return KResultOrAndreas Kling
This allows us to propagate errors in a bunch of new places.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-07-11Kernel: Make various T::class_name() and similar return StringViewAndreas Kling
Instead of returning char const*, we can also give you a StringView.
2021-06-16Kernel: Remove various other uses of ssize_tGunnar Beutner
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-17Kernel: Refactor storage stack with u64 as file operations offsetJean-Baptiste Boric
2021-03-17Kernel: Refactor storage stack with u64 as number of blocksJean-Baptiste Boric
2021-03-12Kernel: Convert klog() => AK::Format in StorageAndreas Kling
2021-03-05Kernel: Use global mechanism to determine minor number of Storage DeviceLiav A
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-20Kernel+LibC: Turn errno codes into a strongly typed enumAndreas Kling
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
2020-12-21Kernel: Introduce the new Storage subsystemLiav A
This new subsystem is somewhat replacing the IDE disk code we had with a new flexible design. StorageDevice is a generic class that represent a generic storage device. It is meant that specific storage hardware will override the interface. StorageController is a generic class that represent a storage controller that can be found in a machine. The IDEController class governs two IDEChannels. An IDEChannel is responsible to manage the master & slave devices of the channel, therefore an IDEChannel is an IRQHandler.