Skip to content

Commit

Permalink
Merge pull request #390 from Thog/feature/filesystem
Browse files Browse the repository at this point in the history
Add a filesystem service
  • Loading branch information
Thomas Guillemard authored Aug 25, 2019
2 parents 5446dd9 + f9ff277 commit 19e3d1e
Show file tree
Hide file tree
Showing 37 changed files with 3,679 additions and 52 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["kernel", "bootstrap", "shell", "time", "libuser", "wall-clock", "sm", "vi", "ahci", "libutils", "libkern", "swipc-gen", "swipc-parser", "docs", "libtimezone"]
members = ["kernel", "bootstrap", "shell", "time", "libuser", "wall-clock", "sm", "vi", "ahci", "fs", "libutils", "libkern", "swipc-gen", "swipc-parser", "docs", "libtimezone", "disk-initializer"]

[profile.release]
debug = true
Expand Down
37 changes: 24 additions & 13 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,27 @@ dependencies = ["install-cargo-xbuild"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-time", "--release"]

[tasks.fs]
workspace = false
description = "Compiles sunrise-fs"
dependencies = ["install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-fs"]

[tasks.fs-release]
workspace = false
description = "Compiles sunrise-fs"
dependencies = ["install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-fs", "--release"]

[tasks.userspace]
description = "Compiles userspace apps"
dependencies = ["shell", "wall-clock", "sm", "vi", "ahci", "time"]
dependencies = ["shell", "wall-clock", "sm", "vi", "ahci", "time", "fs"]

[tasks.userspace-release]
description = "Compiles userspace apps"
dependencies = ["shell-release", "wall-clock-release", "sm-release", "vi-release", "ahci-release", "time-release"]
dependencies = ["shell-release", "wall-clock-release", "sm-release", "vi-release", "ahci-release", "time-release", "fs-release"]

[tasks.iso]
description = "Creates a bootable ISO containing the kernel and grub."
Expand All @@ -162,6 +176,7 @@ cp target/i386-unknown-none-user/debug/sunrise-wall-clock isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-sm isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-vi isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-ahci isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-fs isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]
Expand All @@ -180,22 +195,15 @@ cp target/i386-unknown-none-user/release/sunrise-wall-clock isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-sm isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-vi isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-ahci isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-fs isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]

[tasks.disk]
description = "Creates an empty disk image."
command = "dd"
# 16384 = 8MiB / 512
# 512 is the block size, 8MiB is the target disk size.
args = [ "if=/dev/zero", "of=DISK.img", "count=16384", "bs=512" ]

[tasks.disk.windows]
command = "fsutil"
# Chosen by fair dice roll.
# 8388608 = 8MiB in bytes
args = [ "file", "createnew", "DISK.img", "8388608" ]
command = "cargo"
args = ["run", "--manifest-path", "disk-initializer/Cargo.toml", "--", "DISK.img", "52428800", "external/filesystem/disk_template/"]

# because we can't have a dependency on a file ರ_ರ
[tasks.create-disk-if-not-exist]
Expand All @@ -211,6 +219,7 @@ description = "Runs the bootable ISO in qemu."
dependencies = ["iso-release", "create-disk-if-not-exist"]
command = "qemu-system-i386"
args = [
"-boot", "d",
"-cdrom", "os.iso",
"-serial", "stdio",
"-vnc", "${VNC_PORT}",
Expand All @@ -225,6 +234,7 @@ description = "Runs the bootable ISO in qemu with gdb support"
dependencies = ["iso", "create-disk-if-not-exist"]
command = "qemu-system-i386"
args = [
"-boot", "d",
"-cdrom", "os.iso",
"-serial", "stdio",
"-vnc", "${VNC_PORT}",
Expand Down Expand Up @@ -287,6 +297,7 @@ install_crate = { rustup_component_name = "clippy" }
command = "cargo"
args = ["xclippy", "--target=i386-unknown-none",
"--all", "--exclude", "swipc-gen", "--exclude", "swipc-parser",
"--exclude", "disk-initializer",
"--exclude", "docs",
"--",
"@@split(CLIPPY_RULES, )",
Expand All @@ -299,7 +310,7 @@ dependencies = ["refresh-crates"]
install_crate = { rustup_component_name = "clippy" }
command = "cargo"
args = ["clippy",
"-p", "swipc-gen", "-p", "swipc-parser", "-p", "docs",
"-p", "swipc-gen", "-p", "swipc-parser", "-p", "docs", "-p", "disk-initializer",
"--",
"@@split(CLIPPY_RULES, )",
"${@}",
Expand Down
30 changes: 15 additions & 15 deletions ahci/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use core::fmt::{self, Debug, Formatter};
use spin::Mutex;

use sunrise_libuser::error::{Error, AhciError};
use sunrise_libuser::types::SharedMemory;
use sunrise_libuser::syscalls::MemoryPermissions;
use sunrise_libuser::ahci::IDisk as IDiskInterface;
use sunrise_libuser::futures::WorkQueue;
use sunrise_libuser::zero_box::ZeroBox;
use sunrise_libuser::ahci::Block;

use crate::hba::*;


/// An AHCI Disk
///
/// Manages an AHCI port, and provides functions to read and write sectors.
Expand Down Expand Up @@ -63,6 +63,10 @@ impl Disk {
/// Reads `sector_count` sectors starting from `lba`.
#[inline(never)]
fn read_dma(&mut self, buffer: *mut u8, buffer_len: usize, lba: u64, sector_count: u64) -> Result<(), Error> {
if ((buffer as usize) % 2) != 0 {
return Err(AhciError::InvalidArg.into());
}

if (buffer_len as u64) < sector_count * 512 {
return Err(AhciError::InvalidArg.into());
}
Expand Down Expand Up @@ -104,7 +108,11 @@ impl Disk {
///
/// Writes `sector_count` sectors starting from `lba`.
#[inline(never)]
fn write_dma(&mut self, buffer: *mut u8, buffer_len: usize, lba: u64, sector_count: u64) -> Result<(), Error> {
fn write_dma(&mut self, buffer: *const u8, buffer_len: usize, lba: u64, sector_count: u64) -> Result<(), Error> {
if ((buffer as usize) % 2) != 0 {
return Err(AhciError::InvalidArg.into());
}

if (buffer_len as u64) < sector_count * 512 {
return Err(AhciError::InvalidArg.into());
}
Expand Down Expand Up @@ -186,12 +194,8 @@ impl IDiskInterface for IDisk {
/// - The passed handle points to memory that is so physically scattered it overflows
/// the PRDT. This can only happen for read/writes of 1985 sectors or more.
/// You should consider retrying with a smaller `sector_count`.
fn read_dma(&mut self, _manager: WorkQueue<'static>, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
let addr = sunrise_libuser::mem::find_free_address(mapping_size as _, 0x1000)?;
let mapped = sharedmem.map(addr, mapping_size as _, MemoryPermissions::empty())
// no need for permission, only the disk will dma to it.
.map_err(|_| AhciError::InvalidArg)?;
self.0.lock().read_dma(mapped.as_mut_ptr(), mapped.len(), lba, sector_count)
fn read_dma(&mut self, _manager: WorkQueue<'static>, address: u64, out_blocks: &mut [sunrise_libuser::ahci::Block]) -> Result<(), Error> {
self.0.lock().read_dma(out_blocks.as_mut_ptr() as *mut u8, out_blocks.len() * core::mem::size_of::<Block>(), address, out_blocks.len() as u64)
}

/// Writes sectors to disk.
Expand All @@ -209,11 +213,7 @@ impl IDiskInterface for IDisk {
/// - The passed handle points to memory that is so physically scattered it overflows
/// the PRDT. This can only happen for read/writes of 1985 sectors or more.
/// You should consider retrying with a smaller `sector_count`.
fn write_dma(&mut self, _manager: WorkQueue<'static>, sharedmem: SharedMemory, mapping_size: u64, lba: u64, sector_count: u64) -> Result<(), Error> {
let addr = sunrise_libuser::mem::find_free_address(mapping_size as _, 0x1000)?;
let mapped = sharedmem.map(addr, mapping_size as _, MemoryPermissions::empty())
// no need for permission, only the disk will dma to it.
.map_err(|_| AhciError::InvalidArg)?;
self.0.lock().write_dma(mapped.as_mut_ptr(), mapped.len(), lba, sector_count)
fn write_dma(&mut self, _manager: WorkQueue<'static>, address: u64, in_blocks: &[sunrise_libuser::ahci::Block]) -> Result<(), Error> {
self.0.lock().write_dma(in_blocks.as_ptr() as *const u8, in_blocks.len() * core::mem::size_of::<Block>(), address, in_blocks.len() as u64)
}
}
Loading

0 comments on commit 19e3d1e

Please sign in to comment.