Compare commits

...

15 Commits

Author SHA1 Message Date
able 1702ce23ed fic? 2024-02-10 16:24:37 -06:00
able ef114de438 Fix Broken deps for ableos 2024-02-10 16:13:39 -06:00
able c990d07298 VFS: Updated the API and worked on some implementation 2023-09-13 05:31:35 -05:00
able 74eee90af0 Bare metal test 2023-09-13 05:31:08 -05:00
able a45a19c6b7 reworking system_config to better build an ableOS file tree 2023-05-23 06:39:19 -05:00
able fdd7f5c1d8 update formating rules 2023-05-23 06:38:42 -05:00
able cef2af2278 nixOS support 2023-05-23 06:38:17 -05:00
Able 0f55b5907c prelim VFS work 2023-05-09 01:07:52 -05:00
Able f433484f2f add log and try debugging the BB 2023-05-08 22:31:10 -05:00
Able 94c231bffc add back buffer support to agl 2023-05-08 21:56:10 -05:00
Able 70a65fc10d update v2 2023-05-06 05:13:52 -05:00
Able e3cc98495d make things public *Bleh* 2023-05-06 04:39:09 -05:00
Able 59e723a6f1 public display 2023-05-06 04:37:34 -05:00
Able f5c3852ade graphics lib update 2023-05-06 04:35:44 -05:00
Able 3cbe1571ff update 2023-05-04 02:38:55 -05:00
30 changed files with 570 additions and 282 deletions

103
Cargo.lock generated
View File

@ -6,6 +6,8 @@ version = 3
name = "able_graphics_library"
version = "0.1.2"
dependencies = [
"embedded-graphics",
"log",
"versioning",
]
@ -35,7 +37,7 @@ dependencies = [
name = "aidl"
version = "0.1.0"
dependencies = [
"logos 0.13.0",
"logos",
]
[[package]]
@ -76,6 +78,12 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
name = "axel2wat"
version = "0.1.0"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]]
name = "base64"
version = "0.13.1"
@ -98,6 +106,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -110,7 +124,7 @@ version = "0.1.0"
dependencies = [
"hashbrown 0.13.1",
"log",
"toml 0.5.9 (git+https://git.ablecorp.us/theoddgarlic/toml-rs)",
"toml 0.5.9 (git+https://git.ablecorp.us/asya/toml-rs)",
]
[[package]]
@ -139,6 +153,38 @@ dependencies = [
name = "derelict_microarchitecture"
version = "0.1.0"
[[package]]
name = "embedded-graphics"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "750082c65094fbcc4baf9ba31583ce9a8bb7f52cadfb96f6164b1bc7f922f32b"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b1239db5f3eeb7e33e35bd10bd014e7b2537b17e071f726a09351431337cfa"
dependencies = [
"az",
"byteorder",
]
[[package]]
name = "float-cmp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4"
dependencies = [
"num-traits",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -225,22 +271,13 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "logos"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
dependencies = [
"logos-derive 0.12.1",
]
[[package]]
name = "logos"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
dependencies = [
"logos-derive 0.13.0",
"logos-derive",
]
[[package]]
@ -257,20 +294,6 @@ dependencies = [
"syn 2.0.15",
]
[[package]]
name = "logos-derive"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
"syn 1.0.105",
]
[[package]]
name = "logos-derive"
version = "0.13.0"
@ -295,10 +318,25 @@ dependencies = [
"versioning",
]
[[package]]
name = "micromath"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc4010833aea396656c2f91ee704d51a6f1329ec2ab56ffd00bfd56f7481ea94"
[[package]]
name = "no_video"
version = "0.1.0"
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
@ -520,7 +558,7 @@ dependencies = [
[[package]]
name = "toml"
version = "0.5.9"
source = "git+https://git.ablecorp.us/theoddgarlic/toml-rs#34db433429f3ad38921d13ac9aba74c8a706f376"
source = "git+https://git.ablecorp.us/asya/toml-rs#34db433429f3ad38921d13ac9aba74c8a706f376"
dependencies = [
"hashbrown 0.12.3",
"serde",
@ -590,7 +628,7 @@ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
name = "uri"
version = "0.1.0"
dependencies = [
"logos 0.13.0",
"logos",
]
[[package]]
@ -606,6 +644,13 @@ dependencies = [
"serde",
]
[[package]]
name = "vfs"
version = "0.1.0"
dependencies = [
"std",
]
[[package]]
name = "vgable"
version = "0.1.0"
@ -631,7 +676,7 @@ dependencies = [
name = "wat2wasm"
version = "0.1.0"
dependencies = [
"logos 0.12.1",
"logos",
]
[[package]]

View File

@ -11,6 +11,8 @@ members = [
"drivers/graphics/novideo",
"drivers/graphics/vgable",
"drivers/vfs",
"drivers/keyboards/ps2_keyboard",
"drivers/mice/ps2_mouse",

9
drivers/vfs/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "vfs"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# std = { path = "../../libraries/std" }

42
drivers/vfs/src/cache.rs Normal file
View File

@ -0,0 +1,42 @@
pub struct Cache {
// A limit on how many open files can be in this cache
// Usefull to prevent hundreds of processes caching thousands of files
// 0 == No Limit
file_id_limit: u64,
// Total bytes allowed to be cached before a file is pushed out of the cache
total_byte_size: u64,
current_byte_size: u64,
cache: Vec<(FileID, Vec<u8>)>,
}
impl Cache {
fn default() -> Self {
Self {
file_id_limit: 1024,
total_byte_size: 1024 * 16,
current_byte_size: 0,
cache: Vec::new(),
}
}
fn recalculate_cache(&mut self) {
let mut current: u64 = 0;
for (_, file) in &self.cache {
current += file.len() as u64;
}
self.current_byte_size = current;
}
}
#[test]
fn recalc_cache_test() {
let mut cache = Cache::default();
let mut temp_file_vec: Vec<u8> = Vec::new();
for x in 0u64..=10 {
temp_file_vec.push(x.try_into().unwrap());
let file = (x, temp_file_vec.clone());
cache.cache.push(file);
}
cache.recalculate_cache();
assert_eq!(cache.current_byte_size, 66);
}

105
drivers/vfs/src/main.rs Normal file
View File

@ -0,0 +1,105 @@
// #![no_std]
#![feature(async_fn_in_trait)]
pub mod cache;
extern crate alloc;
use alloc::vec::Vec;
pub type Path = String;
fn main() {
let vfs = VFS::new();
// TODO: load config for the vfs
// advertise the VFS service
// wait on proccesses to subscribe and send messages
}
// NOTE: in the implementation this should be a basevalue of some randomized value to
// prevent the ability to check how many files are open on the system
pub type FileID = u64;
pub trait FileIO {
// Store the FileID in the VFS to allow multiple programs to have a FileID without conflicting
fn s_open(path: Path) -> Result<FileID, FileIOError>;
async fn a_open(path: Path) -> Result<FileID, FileIOError>;
// Close the file and flush changes to disk
fn s_close(file_id: FileID) -> Result<(), FileIOError>;
async fn a_close(file_id: FileID) -> Result<(), FileIOError>;
// Offset into the file to allow for things like reading a specific value
// Length from the offset
fn s_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError>;
async fn a_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError>;
// Offset into the file to allow for things like reading a specific value
fn s_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError>;
async fn a_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError>;
}
pub enum FileIOError {
NoMountPoint,
}
pub struct MountPoint {
mount: Path,
// Use this to send the file requests to the right filesystem driver
filesystem_proc_id: u64,
}
pub struct VFS {
// If a file is used twice move it from first cache to second cache
// This is under the assumption that if you write to a file twice you will write again
first_layer: Cache,
second_layer: Cache,
mount_point_list: Vec<MountPoint>,
}
impl VFS {
fn new() -> Self {
Self {
first_layer: Cache::default(),
second_layer: Cache::default(),
mount_point_list: Vec::new(),
}
}
fn resolve_mountpoint(self, path: Path) -> Result<MountPoint, FileIOError> {
return Err(FileIOError::NoMountPoint);
}
}
impl FileIO for VFS {
fn s_open(path: Path) -> Result<FileID, FileIOError> {
// Break up the path into a mountpoint and a path fragment
todo!()
}
async fn a_open(path: Path) -> Result<FileID, FileIOError> {
todo!()
}
fn s_close(file_id: FileID) -> Result<(), FileIOError> {
todo!()
}
async fn a_close(file_id: FileID) -> Result<(), FileIOError> {
todo!()
}
fn s_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError> {
todo!()
}
async fn a_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError> {
todo!()
}
fn s_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError> {
todo!()
}
async fn a_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError> {
todo!()
}
}

View File

@ -7,3 +7,5 @@ edition = "2021"
[dependencies]
versioning = { path = "../versioning" }
embedded-graphics = "0.7.1"
log = "*"

View File

@ -6,8 +6,6 @@ use alloc::vec::Vec;
use super::error::GPUError;
pub type VertexBuffer = Vec<u8>;
#[repr(C)]
pub struct XYZ {
x: f64,
@ -22,28 +20,3 @@ pub struct XYZW {
z: f64,
w: f64,
}
pub struct GraphicsEngine {
vertex_buffer_attributes_editable: bool,
vertex_buffer: VertexBuffer,
vertex_size: usize,
}
impl GraphicsEngine {
pub fn new() -> Self {
Self {
vertex_buffer_attributes_editable: true,
vertex_buffer: Vec::new(),
vertex_size: 0,
}
}
pub fn append_vertex(&mut self, mut vertex: Vec<u8>) -> Result<(), GPUError> {
if self.vertex_buffer_attributes_editable {
return Err(GPUError::EngineNotInitialized);
}
if !vertex.len() == self.vertex_size {
return Err(GPUError::ImproperVertexSize);
}
self.vertex_buffer.append(&mut vertex);
Ok(())
}
}

View File

@ -1,21 +0,0 @@
pub struct Color3 {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Color3 {
/// Usage
/// The alpha value is a number between 0.0 and 1.0, which represents the transparency
/// or translucency of the other color.
pub fn blend(&self, other: &Self, alpha: f32) -> Self {
let r = (1.0 - alpha) * f32::from(self.r) + alpha * f32::from(other.r);
let g = (1.0 - alpha) * f32::from(self.g) + alpha * f32::from(other.g);
let b = (1.0 - alpha) * f32::from(self.b) + alpha * f32::from(other.b);
Self {
r: r as u8,
g: g as u8,
b: b as u8,
}
}
}

View File

@ -1,35 +0,0 @@
use alloc::vec::Vec;
pub enum DisplayError {
InvalidFormat,
InvalidWidth,
InvalidHeight,
InvalidBPP,
InvalidFPS,
}
pub fn parse_display_string(s: &str) -> Result<(u32, u32, u32, u32), DisplayError> {
let parts: Vec<&str> = s.split('x').collect();
if parts.len() != 3 {
return Err(DisplayError::InvalidFormat);
}
let width = parts[0]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidWidth)?;
let height = parts[1]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidHeight)?;
let bits: Vec<&str> = parts[2].split('@').collect();
if bits.len() != 2 {
return Err(DisplayError::InvalidFormat);
}
let bpp = bits[0]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidBPP)?;
let fps = bits[1]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidFPS)?;
Ok((width, height, bpp, fps))
}

View File

@ -1,4 +0,0 @@
pub enum GPUError {
ImproperVertexSize = 10,
EngineNotInitialized = 100,
}

View File

@ -1,54 +0,0 @@
use core::ptr;
use alloc::vec::Vec;
use super::color::Color3;
/// NOTE: Assumes the layout of RGBA
pub struct FrameBuffer {
pub width: u32,
pub height: u32,
pub data: Vec<u32>,
}
impl FrameBuffer {
pub fn new(width: u32, height: u32) -> Self {
let data = vec![0; (width * height) as usize];
FrameBuffer {
width,
height,
data,
}
}
/// WARNING: Slow
pub fn set_pixel(&mut self, x: u32, y: u32, color: u32) {
let index = (y * self.width + x) as usize;
self.data[index] = color;
}
/// WARNING: Slow
pub fn get_pixel(&self, x: u32, y: u32) -> u32 {
let index = (y * self.width + x) as usize;
self.data[index]
}
/// Quickly writes the provided color to the whole framebuffer
pub fn clear(&mut self, color: Color3) {
unsafe {
// TODO: properly clear instead of only copying red
ptr::write_bytes(self.data.as_mut_ptr(), color.r, self.data.len());
}
}
// TODO(Able): Test preformance of clear2
#[allow(dead_code)]
fn clear2(&mut self, color: u32) {
self.data.fill(color);
}
/// Check the size of one framebuffer vs the other.
/// NOTE: Just because this returns false does not mean that something is wrong
/// there are cases that this makes sense
pub fn check_size(&self, other: &FrameBuffer) -> bool {
self.width == other.width && self.height == other.height
}
}

View File

@ -1,5 +1 @@
pub mod buffer;
pub mod color;
pub mod display;
pub mod error;
pub mod framebuffer;
pub mod vertex;

View File

@ -0,0 +1,48 @@
use alloc::vec::Vec;
pub type VertexBuffer = Vec<u8>;
pub struct GraphicsEngine {
vertex_buffer_attributes_editable: bool,
vertex_buffer: VertexBuffer,
vertex_size: usize,
}
impl GraphicsEngine {
pub fn new() -> Self {
Self {
vertex_buffer_attributes_editable: true,
vertex_buffer: Vec::new(),
vertex_size: 0,
}
}
pub fn append_vertex(&mut self, mut vertex: Vec<u8>) -> Result<(), GPUError> {
if self.vertex_buffer_attributes_editable {
return Err(GPUError::EngineNotInitialized);
}
if !vertex.len() == self.vertex_size {
return Err(GPUError::ImproperVertexSize);
}
self.vertex_buffer.append(&mut vertex);
Ok(())
}
}
#[repr(C)]
pub struct XYZ {
x: f64,
y: f64,
z: f64,
}
#[repr(C)]
pub struct XYZW {
x: f64,
y: f64,
z: f64,
w: f64,
}
pub enum GPUError {
ImproperVertexSize,
EngineNotInitialized,
}

View File

@ -0,0 +1 @@
pub mod x86;

View File

@ -0,0 +1,90 @@
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::{DrawTarget, IntoStorage, OriginDimensions, PixelColor, Point, Size},
primitives::{Line, Primitive, PrimitiveStyle},
Drawable, Pixel,
};
pub struct Display {
pub fb: *mut u32,
// Back buffer
pub bb: *mut u32,
pub size: Size,
pub color: Rgb888,
}
impl Display {
pub fn set_color(&mut self, color: Rgb888) {
self.color = color;
}
pub fn swap_buffers(&mut self) {
let size: usize = (self.size.height * self.size.width).try_into().unwrap();
unsafe {
let dst_ptr = self.fb;
let src_ptr = self.bb;
core::ptr::copy_nonoverlapping(src_ptr, dst_ptr, size);
}
log::trace!("Update");
}
pub fn line(
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
thickness: u32,
) -> Result<(), BlitOutOfBoundsError> {
let color = self.color;
let style = PrimitiveStyle::with_stroke(color, thickness);
Line::new(Point::new(x1, y1), Point::new(x2, y2))
.into_styled(style)
.draw(&mut *self)?;
Ok(())
}
}
unsafe impl Send for Display {}
impl DrawTarget for Display {
type Color = Rgb888;
type Error = BlitOutOfBoundsError;
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Pixel<Self::Color>>,
{
for Pixel(pos, rgb) in pixels {
let pos_x = u32::try_from(pos.x).map_err(|_| BlitOutOfBoundsError)?;
let pos_y = u32::try_from(pos.y).map_err(|_| BlitOutOfBoundsError)?;
unsafe {
if pos_x >= self.size.width || pos_y >= self.size.height {
return Err(BlitOutOfBoundsError);
}
self.bb
.add(
(pos_y * self.size.width + pos_x)
.try_into()
.map_err(|_| BlitOutOfBoundsError)?,
)
.write_volatile(rgb.into_storage());
}
}
Ok(())
}
}
impl OriginDimensions for Display {
#[inline]
fn size(&self) -> Size {
self.size
}
}
#[derive(Debug)]
pub struct BlitOutOfBoundsError;

View File

@ -1,18 +1,9 @@
mod arch;
use core::fmt::Error;
use alloc::vec::Vec;
pub struct Color {
r: u8,
g: u8,
b: u8,
a: u8,
}
pub use arch::x86::Display;
pub struct PixelBuffer {
width: usize,
height: usize,
data: Vec<Color>,
}
impl PixelBuffer {
pub fn xy_calc(x: usize, y: isize) {}
pub fn blit(&mut self, x: isize, y: isize, buff: PixelBuffer) {}
}
use self::arch::x86::BlitOutOfBoundsError;

View File

@ -0,0 +1,5 @@
Type Coordinate = i32;
Type Coordinates = (Coordinate, Coordinate);
Function line Takes(Coordinates, Coordinates) Returns(Nothing);

View File

@ -15,7 +15,7 @@ hashbrown = "*"
[dependencies.toml]
git = "https://git.ablecorp.us:443/theoddgarlic/toml-rs"
git = "https://git.ablecorp.us:443/asya/toml-rs"
# version = "0.5.8"
default-features = false

View File

@ -5,7 +5,7 @@ type Handle = i64;
#[repr(C)]
pub struct OSString {
pub address: i32,
pub length: i32,
pub length: i32,
}
extern "C" {
@ -21,6 +21,10 @@ pub enum ExternErrors {
#[repr(C)]
pub struct Result<T> {
pub ok: T,
pub ok: T,
pub err: ExternErrors,
}
pub struct Path {
parts: OSString,
}

View File

@ -0,0 +1,16 @@
use alloc::alloc::{GlobalAlloc, Layout};
struct MyAllocator;
unsafe impl GlobalAlloc for MyAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
panic!();
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
panic!();
}
}
#[global_allocator]
static GLOBAL: MyAllocator = MyAllocator;

View File

@ -1,12 +1,3 @@
pub enum IOErrors {
UnknownError,
}
// pub struct Port<T> {
// inner: T,
// }
// impl<T> Port<T> {
// pub fn read(&self) -> Result<T, IOErrors> {
// Ok(self.inner)
// }
// }

View File

@ -9,6 +9,7 @@ pub mod env;
pub mod exit;
pub mod io;
pub mod allocator;
#[cfg(not(test))]
pub mod panic;
@ -23,6 +24,8 @@ pub mod prelude;
use versioning::Version;
pub mod path;
pub const VERSION: Version = Version::new(0, 1, 0);
// extern crate alloc;
@ -61,7 +64,7 @@ pub struct LocationInFile<'a> {
// TODO: replace &str with ableOS path
file_path: &'a str,
line: u16,
line: u16,
column: u16,
}
impl<'a> Display for LocationInFile<'a> {

18
libraries/std/src/path.rs Normal file
View File

@ -0,0 +1,18 @@
use alloc::string::{String, ToString};
pub struct Path {
pub path: Vec<String>,
}
impl Path {
pub fn new(path: String) -> Self {
let mut path_vec_string = alloc::vec![];
for part in path.split(&['\\', '/'][..]) {
path_vec_string.push(part.to_string());
}
Path {
path: path_vec_string,
}
}
}

View File

@ -6,3 +6,6 @@ pub use crate::print_char;
pub use core::panic;
pub use versioning;
extern crate alloc;
pub use alloc::vec::Vec;

View File

@ -47,16 +47,18 @@ enum Token {
#[regex(r"//[ a-zA-Z!-+]+", |lex| lex.slice().parse().ok())]
Comment(String),
#[regex("[0-9]+", |lex| lex.slice().parse().ok())]
Number(String),
}
fn main() {
let mut lex = Token::lexer(include_str!("../../../programs/aidl/assets/vfs.idl"));
for token in lex {
// let ok_token = token.ok();
// if ok_token.is_some() {
// println!("{:?}", ok_token.unwrap());
// }
println!("{:?}", token);
let ok_token = token.ok();
if ok_token.is_some() {
println!("{:?}", ok_token.unwrap());
}
}
}

0
programs/std_test/run.sh Executable file → Normal file
View File

View File

@ -20,37 +20,42 @@ resolution = "1024x768x24"
core = "https://git.ablecorp.us/AbleOS/core"
userspace = "https://git.ablecorp.us/AbleOS/ableos_userland"
[packages]
[packages.list_files]
[apps]
[apps.list_files]
version = "0.1.1"
hash = ""
repo = "userspace"
authors = []
[packages.list_files.configuration]
[users]
[users.able]
home = "/home/able/"
password_hash = "abc123"
[users.able.repositories]
able_repo = "https://git.ablecorp.us/able/ableos_packages"
[users.able.packages]
[users.able.packages.ablecraft]
able_repo = "https://git.ablecorp.us/able/ableos_apps"
[users.able.apps]
[users.able.apps.able_editor]
version = "1.0"
[users.able.apps.able_editor.plugins.rustfmt]
version = "1.0"
hash = ""
repo = "default"
[users.able.apps.able_editor.plugins.repositories]
default = ["https://github.com/able_editor/plugins"]
[users.able.apps.ablecraft]
version = "0.1.1"
hash = ""
repo = "able_repo"
[users.able.packages.ablecraft.configuration]
[users.able.packages.list_files.configuration]
# [users.able.apps.ablecraft.configuration]
[users.able.apps.list_files.configuration]
use_color = true
[users.able.packages.list_files.permissions]
[users.able.apps.list_files.permissions]
file_paths = ["/"]
[users.chad]
home = "/chad/"
password_hash = "abc123"
[users.chad.repositories]
[users.chad.packages]

View File

@ -1,20 +1,25 @@
use std::{
env,
error::Error,
fmt::format,
fs::{self, File},
io::{Read, Write},
path,
use {
std::{
env,
error::Error,
fs::{self, File},
io::{Read, Write},
},
toml::{self, Table, Value},
};
use toml::Table;
use toml::{self, Value};
fn main() -> Result<(), Box<dyn Error>> {
let mut args: Vec<String> = env::args().collect();
// #[cfg(target_os="linux")]
if args.len() == 1 {
println!("Pass a file");
}
args.remove(0);
let file_path = &args[0];
println!("{}", file_path);
println!("configuration path - {}", file_path);
let mut file = File::open(file_path).expect("Unable to open the file");
let mut file = File::open(file_path).unwrap(); //.expect("Unable to open the file");
let mut contents = String::new();
file.read_to_string(&mut contents)
@ -28,7 +33,8 @@ fn main() -> Result<(), Box<dyn Error>> {
// HANDLE repolist
{
let repolist = value.get("repositories").unwrap();
let ret = make_repolist("repolist.toml".to_string(), repolist);
fs::create_dir("disk/System")?;
let ret = make_repolist("System/repolist.toml".to_string(), repolist);
println!("making repolist {:?}", ret);
}
@ -55,7 +61,8 @@ fn main() -> Result<(), Box<dyn Error>> {
for user in users_table.keys() {
let ut = users_table.get(user).unwrap();
let home_path = ut.get("home").unwrap();
// let home_path = ut.get("home").unwrap();
let home_path = format!("/Users/{}", user);
let pass_hash = ut.get("password_hash").unwrap();
passhash_list.push((user.to_string(), pass_hash.to_string()));
@ -63,54 +70,63 @@ fn main() -> Result<(), Box<dyn Error>> {
let ret = make_user(home_path.to_string());
println!("making user return {:?}", ret);
// Handle homepath generation of USER
{
let mut hp = home_path.clone().to_string();
hp.remove(0);
hp.remove(0);
hp.remove(hp.len() - 1);
hp.remove(hp.len() - 1);
for package in ut.get("packages").unwrap().as_table().unwrap().keys() {
let pack_folder: String = format!("disk/{}/{}", hp, package);
let pack_config: String = format!("disk/{}/{}/config.toml", hp, package);
let hp = home_path.clone().to_string();
let apps = ut.get("apps");
fs::create_dir_all(format!("disk/{}/Apps/", hp))?;
fs::create_dir(pack_folder)?;
let mut file = File::create(pack_config)?;
// repo_list_str.as_bytes()
let abc = ut
.get("packages")
.unwrap()
.get(package)
.unwrap()
.get("configuration")
.unwrap();
let mut abc = abc.to_string();
if abc.len() > 2 {
abc.remove(0);
abc.remove(0);
abc.remove(abc.len() - 1);
abc.remove(abc.len() - 1);
}
if abc.len() == 2 {
abc.remove(0);
abc.remove(0);
}
println!("ok");
if apps.is_some() {
let apps = apps.unwrap();
for app in apps.as_table().unwrap().keys() {
let pack_folder: String = format!("disk/{}/Apps/{}", hp, app);
let pack_config: String = format!("disk/{}/Apps/{}/config.toml", hp, app);
file.write_all(abc.as_bytes())?;
fs::create_dir_all(pack_folder)?;
let mut file = File::create(pack_config)?;
// repo_list_str.as_bytes()
let abc = apps.get(app).unwrap().get("configuration");
let tab = match abc {
Some(val) => val.clone(),
None => {
let tab = Table::new();
Value::Table(tab)
}
};
// .unwrap_or(&Value::Table(Table::new()));
let mut abc = tab.to_string();
if abc.len() > 2 {
abc.remove(0);
abc.remove(0);
abc.remove(abc.len() - 1);
abc.remove(abc.len() - 1);
}
if abc.len() == 2 {
abc.remove(0);
abc.remove(0);
}
file.write_all(abc.as_bytes())?;
}
}
}
{
let repolist = ut.get("repositories").unwrap();
let mut hp = home_path.clone().to_string();
hp.remove(0);
hp.remove(0);
hp.remove(hp.len() - 1);
hp.remove(hp.len() - 1);
let repolist = ut.get("repositories");
let hp = home_path.clone().to_string();
let user_path_repolist = format!("{}/repolist.toml", hp.to_string());
println!("{}", user_path_repolist);
match repolist {
Some(repolist) => {
let ret = make_repolist(user_path_repolist, repolist);
println!("making repolist {:?}", ret);
}
None => {
let repolist = Table::new();
let user_path_repolist = format!("{}/repolist.toml", hp.to_string());
println!("{}", user_path_repolist);
let ret = make_repolist(user_path_repolist, repolist);
println!("making repolist {:?}", ret);
let ret = make_repolist(user_path_repolist, &Value::Table(repolist));
println!("making repolist {:?}", ret);
}
}
}
@ -118,6 +134,9 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("making password hashlist {:?}", ret);
}
// TODO: Handle system wide things like repolist and Apps/
{}
// let mut file = File::create("disk/foo.txt")?;
// file.write_all(b"Hello, world!")?;
@ -192,10 +211,7 @@ TERM_BACKDROP={}
Ok(())
}
pub fn make_user(mut home_path: String) -> std::io::Result<()> {
home_path.remove(0);
home_path.remove(home_path.len() - 1);
pub fn make_user(home_path: String) -> std::io::Result<()> {
let path = format!("disk/{}", home_path);
fs::create_dir_all(path)?;
Ok(())
@ -203,6 +219,7 @@ pub fn make_user(mut home_path: String) -> std::io::Result<()> {
pub fn make_repolist(path: String, repolist: &Value) -> std::io::Result<()> {
let path = format!("disk/{}", path);
let mut file = File::create(path)?;
let mut repo_list_str = String::new();
for (repo_name, repo_url) in repolist.as_table().unwrap() {

3
rustfmt.toml Normal file
View File

@ -0,0 +1,3 @@
hex_literal_case = "Upper"
imports_granularity = "One"
struct_field_align_threshold = 5

31
shell.nix Normal file
View File

@ -0,0 +1,31 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell rec {
buildInputs = with pkgs; [ clang llvmPackages.bintools rustup ];
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
# https://github.com/rust-lang/rust-bindgen#environment-variables
LIBCLANG_PATH =
pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
shellHook = ''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
'';
# Add precompiled library to rustc search path
RUSTFLAGS = (builtins.map (a: "-L ${a}/lib") [
# add libraries here (e.g. pkgs.libvmi)
]);
# Add glibc, clang, glib and other headers to bindgen search path
BINDGEN_EXTRA_CLANG_ARGS =
# Includes with normal include path
(builtins.map (a: ''-I"${a}/include"'') [
# add dev libraries here (e.g. pkgs.libvmi.dev)
pkgs.glibc.dev
])
# Includes with special directory paths
++ [
''
-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
''-I"${pkgs.glib.dev}/include/glib-2.0"''
"-I${pkgs.glib.out}/lib/glib-2.0/include/"
];
}