forked from AbleOS/ableos
filesystem implementation
This commit is contained in:
parent
5ea5172cae
commit
f61d4fe9e7
38
ableos/Cargo.lock
generated
38
ableos/Cargo.lock
generated
|
@ -30,8 +30,10 @@ dependencies = [
|
|||
"acpi",
|
||||
"bootloader",
|
||||
"cpuio",
|
||||
"ext2",
|
||||
"externc-libm",
|
||||
"facepalm",
|
||||
"genfs",
|
||||
"hashbrown",
|
||||
"lazy_static",
|
||||
"linked_list_allocator",
|
||||
|
@ -46,7 +48,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"shadeable",
|
||||
"smoltcp",
|
||||
"spin",
|
||||
"spin 0.5.2",
|
||||
"uart_16550",
|
||||
"unicode-width",
|
||||
"vga",
|
||||
|
@ -178,6 +180,17 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
||||
|
||||
[[package]]
|
||||
name = "ext2"
|
||||
version = "0.1.1"
|
||||
source = "git+https://git.ablecorp.us/able/ext2-rs.git#220f66a156bfd5033eecac20372368860749c304"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"genfs",
|
||||
"rlibc",
|
||||
"spin 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "externc-libm"
|
||||
version = "0.1.0"
|
||||
|
@ -199,6 +212,12 @@ version = "0.3.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e"
|
||||
|
||||
[[package]]
|
||||
name = "genfs"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65b9e52a0ffd4c2f11f9f84e8885a40cb99f490971eee78bbd7ddffd6ac023d6"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.4"
|
||||
|
@ -240,7 +259,7 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
dependencies = [
|
||||
"spin",
|
||||
"spin 0.5.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -489,6 +508,12 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rlibc"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
|
||||
|
||||
[[package]]
|
||||
name = "rsdp"
|
||||
version = "2.0.0"
|
||||
|
@ -590,6 +615,15 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spinning_top"
|
||||
version = "0.2.4"
|
||||
|
|
|
@ -57,6 +57,8 @@ unicode-width = "0.1.7"
|
|||
picorand = "*"
|
||||
# watson = "0.4"
|
||||
|
||||
genfs = "0.1.0"
|
||||
|
||||
|
||||
acpi = "4.1.0"
|
||||
|
||||
|
@ -94,6 +96,8 @@ features = ["log", "proto-ipv4"]
|
|||
|
||||
[dependencies.y-compositor-protocol]
|
||||
git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
|
||||
[dependencies.ext2]
|
||||
git = "https://git.ablecorp.us:443/able/ext2-rs.git"
|
||||
|
||||
[dependencies.shadeable]
|
||||
path = "../shadeable"
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
use alloc::string::{String, ToString};
|
||||
|
||||
pub enum FileSystemStates {
|
||||
Null = 0,
|
||||
Clean = 1,
|
||||
Error = 2,
|
||||
}
|
||||
|
||||
pub enum ErrorHandleMethod {
|
||||
Null = 0,
|
||||
Ignore = 1,
|
||||
RemountFileSystem = 2,
|
||||
Panic = 3,
|
||||
}
|
||||
|
||||
/// Used by ableOS to identify the creator of the file system
|
||||
#[repr(C)]
|
||||
pub enum CreatorOperatingSystemID {
|
||||
Linux = 0,
|
||||
GNU_HURD = 1,
|
||||
// 2 MASIX (an operating system developed by Rémy Card, one of the developers of ext2)
|
||||
MASIX = 2,
|
||||
// 3 FreeBSD
|
||||
FreeBsd = 3,
|
||||
// 4 Other "Lites" (BSD4.4-Lite derivatives such as NetBSD, OpenBSD, XNU/Darwin, etc.)
|
||||
LITES = 4,
|
||||
|
||||
AbleOS = 5,
|
||||
Unknown = 6,
|
||||
}
|
||||
|
||||
impl CreatorOperatingSystemID {
|
||||
pub fn to_string(&self) -> String {
|
||||
match self {
|
||||
&CreatorOperatingSystemID::Linux => "Linux".to_string(),
|
||||
&CreatorOperatingSystemID::GNU_HURD => "GNU_HURD".to_string(),
|
||||
&CreatorOperatingSystemID::MASIX => "MASIX".to_string(),
|
||||
&CreatorOperatingSystemID::FreeBsd => "FREE_BSD".to_string(),
|
||||
&CreatorOperatingSystemID::LITES => "LITES".to_string(),
|
||||
&CreatorOperatingSystemID::AbleOS => "ABLEOS".to_string(),
|
||||
&CreatorOperatingSystemID::Unknown => "Unknown".to_string(),
|
||||
}
|
||||
}
|
||||
pub fn match_to_int(id: CreatorOperatingSystemID) -> u8 {
|
||||
match id {
|
||||
Self::Linux => 0,
|
||||
Self::GNU_HURD => 1,
|
||||
Self::MASIX => 2,
|
||||
Self::FreeBsd => 3,
|
||||
Self::LITES => 4,
|
||||
Self::AbleOS => 5,
|
||||
_ => 6,
|
||||
}
|
||||
}
|
||||
pub fn match_to_enum(id: u8) -> CreatorOperatingSystemID {
|
||||
match id {
|
||||
0 => Self::Linux,
|
||||
1 => Self::GNU_HURD,
|
||||
2 => Self::MASIX,
|
||||
3 => Self::FreeBsd,
|
||||
4 => Self::LITES,
|
||||
5 => Self::AbleOS,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
0x001 00001 Other—execute permission
|
||||
0x002 00002 Other—write permission
|
||||
0x004 00004 Other—read permission
|
||||
0x008 00010 Group—execute permission
|
||||
0x010 00020 Group—write permission
|
||||
0x020 00040 Group—read permission
|
||||
0x040 00100 User—execute permission
|
||||
0x080 00200 User—write permission
|
||||
0x100 00400 User—read permission
|
||||
0x200 01000 Sticky Bit
|
||||
0x400 02000 Set group ID
|
||||
0x800 04000 Set user ID*/
|
||||
pub struct FilePermissions(pub u16);
|
||||
|
||||
/*
|
||||
0x1000 FIFO
|
||||
0x2000 Character device
|
||||
0x4000 Directory
|
||||
0x6000 Block device
|
||||
0x8000 Regular file
|
||||
0xA000 Symbolic link
|
||||
0xC000 Unix socket
|
||||
*/
|
||||
|
||||
pub struct InodeType(pub u16);
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use acpi::AcpiTables;
|
||||
|
||||
use crate::scratchpad;
|
||||
|
||||
use {
|
||||
crate::{
|
||||
arch::{init, sloop},
|
||||
|
@ -83,7 +85,7 @@ pub fn kernel_main() -> ! {
|
|||
}
|
||||
|
||||
start_facepalm();
|
||||
|
||||
scratchpad();
|
||||
sloop()
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ pub mod arch;
|
|||
|
||||
#[macro_use]
|
||||
pub mod print;
|
||||
pub mod ext2fs;
|
||||
|
||||
#[macro_use]
|
||||
pub extern crate log;
|
||||
|
@ -91,3 +90,6 @@ pub mod tests;
|
|||
pub use tests::*;
|
||||
pub mod syscalls;
|
||||
pub use syscalls::*;
|
||||
|
||||
pub mod scratchpad;
|
||||
pub use scratchpad::*;
|
||||
|
|
59
ableos/src/scratchpad.rs
Normal file
59
ableos/src/scratchpad.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
use alloc::{string::String, vec::Vec};
|
||||
use ext2::{
|
||||
fs::{sync::Synced, Ext2},
|
||||
sector::Size1024,
|
||||
};
|
||||
|
||||
/// Experimental scratchpad for testing.
|
||||
pub fn scratchpad() {
|
||||
let mut fs = load_fs();
|
||||
{
|
||||
let found = fs.open(b"/home/able/kernel.md", &OpenOptions::new());
|
||||
|
||||
assert!(found.is_ok());
|
||||
let inode = found.unwrap();
|
||||
let mut vec = Vec::new();
|
||||
assert!(inode.read_to_end(&mut vec).is_ok());
|
||||
|
||||
println!("{}", String::from_utf8_lossy(&vec));
|
||||
}
|
||||
|
||||
// let x = fs.create_dir(b"/config/", &DirOptions::new());
|
||||
}
|
||||
|
||||
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
||||
let file = include_bytes!("../../userland/root_rs/ext2.img");
|
||||
|
||||
let mut volume = Vec::new();
|
||||
volume.extend_from_slice(file);
|
||||
|
||||
/*
|
||||
let fs = Ext2::<Size512, _>::new(volume);
|
||||
|
||||
match fs {
|
||||
Ok(filesystem) => {
|
||||
info!("{}", filesystem.total_inodes_count());
|
||||
|
||||
let vers = filesystem.version();
|
||||
info!("version: {}.{}", vers.0, vers.1);
|
||||
}
|
||||
|
||||
Err(_) => todo!(),
|
||||
}
|
||||
|
||||
*/
|
||||
// let abc: Result<, _> = Synced::new(volume);
|
||||
|
||||
let fs = Synced::<Ext2<Size1024, _>>::new(volume);
|
||||
assert!(
|
||||
fs.is_ok(),
|
||||
"Err({:?})",
|
||||
fs.err().unwrap_or_else(|| unreachable!()),
|
||||
);
|
||||
|
||||
let fs = fs.unwrap();
|
||||
|
||||
fs
|
||||
}
|
||||
|
||||
use genfs::{DirOptions, Fs, OpenOptions};
|
BIN
userland/root_rs/ext2.img
Normal file
BIN
userland/root_rs/ext2.img
Normal file
Binary file not shown.
1
userland/root_rs/mnt/home/able/kernel.md
Normal file
1
userland/root_rs/mnt/home/able/kernel.md
Normal file
|
@ -0,0 +1 @@
|
|||
Hi there :>$RED$
|
Loading…
Reference in a new issue