fully functional squashfs driver!! + gen code cleanup

This commit is contained in:
Zoe
2024-03-19 03:58:47 -05:00
parent 1791b693ac
commit 952620d905
9 changed files with 944 additions and 288 deletions

View File

@@ -78,7 +78,7 @@ copy-initramfs-files:
echo "Hello World from Initramfs" > ${INITRAMFS_PATH}/example.txt echo "Hello World from Initramfs" > ${INITRAMFS_PATH}/example.txt
echo "Second file for testing" > ${INITRAMFS_PATH}/example2.txt echo "Second file for testing" > ${INITRAMFS_PATH}/example2.txt
mkdir -p ${INITRAMFS_PATH}/firstdir/seconddirbutlonger/ mkdir -p ${INITRAMFS_PATH}/firstdir/seconddirbutlonger/
echo "Hell yeah, we getting a working initramfs using a custom squashfs driver!!" > ${INITRAMFS_PATH}/firstdir/seconddirbutlonger/yeah.txt echo "Nexted file reads!!" > ${INITRAMFS_PATH}/firstdir/seconddirbutlonger/yeah.txt
compile-initramfs: copy-initramfs-files compile-initramfs: copy-initramfs-files
# Make squashfs without compression temporaily so I can get it working before I have to write a gzip driver # Make squashfs without compression temporaily so I can get it working before I have to write a gzip driver
@@ -100,7 +100,7 @@ endif
python scripts/font.py python scripts/font.py
mv scripts/font.psf ${INITRAMFS_PATH}/ mv scripts/font.psf ${INITRAMFS_PATH}/
# python scripts/initramfs-test.py 1000 ${INITRAMFS_PATH}/ python scripts/initramfs-test.py 100 ${INITRAMFS_PATH}/
copy-iso-files: copy-iso-files:
# Limine files # Limine files

View File

@@ -511,21 +511,18 @@ impl FatFs {
} }
impl FsOps for FatFs { impl FsOps for FatFs {
fn mount(&self, path: &str, data: &mut *mut u8, vfsp: *const super::vfs::Vfs) { fn mount(&mut self, _path: &str, data: &mut *mut u8, _vfsp: *const super::vfs::Vfs) {
// TODO: load the FAT into memory here // TODO: load the FAT into memory here
*data = core::ptr::addr_of!(*self) as *mut u8; *data = core::ptr::addr_of!(*self) as *mut u8;
// *data = unsafe { alloc::alloc::alloc(alloc::alloc::Layout::new::<Option<VNode>>()) };
// unsafe { *data.cast::<Option<VNode>>() = None };
} }
fn unmount(&self, vfsp: *const super::vfs::Vfs) { fn unmount(&mut self, _vfsp: *const super::vfs::Vfs) {
// TODO: unload the FAT form memory // TODO: unload the FAT form memory
} }
fn root(&self, vfsp: *const super::vfs::Vfs) -> super::vfs::VNode { fn root(&mut self, vfsp: *const super::vfs::Vfs) -> super::vfs::VNode {
let mut root_cluster = match self.fat_type { let root_cluster = match self.fat_type {
FatType::Fat32(ebpb) => ebpb.root_dir_cluster as usize, FatType::Fat32(ebpb) => ebpb.root_dir_cluster as usize,
_ => self.sector_to_cluster( _ => self.sector_to_cluster(
self.bpb.reserved_sectors as usize self.bpb.reserved_sectors as usize
@@ -535,7 +532,6 @@ impl FsOps for FatFs {
let file = File::Dir(FatDirectory { let file = File::Dir(FatDirectory {
directory_cluster: root_cluster, directory_cluster: root_cluster,
// fat_fs: self,
}); });
return super::vfs::VNode { return super::vfs::VNode {
@@ -552,19 +548,23 @@ impl FsOps for FatFs {
}; };
} }
fn fid(&self, path: &str, vfsp: *const super::vfs::Vfs) -> Option<super::vfs::FileId> { fn fid(&mut self, _path: &str, _vfsp: *const super::vfs::Vfs) -> Option<super::vfs::FileId> {
todo!("FAT FID"); todo!("FAT FID");
} }
fn statfs(&self, vfsp: *const super::vfs::Vfs) -> super::vfs::StatFs { fn statfs(&mut self, _vfsp: *const super::vfs::Vfs) -> super::vfs::StatFs {
todo!("FAT STATFS"); todo!("FAT STATFS");
} }
fn sync(&self, vfsp: *const super::vfs::Vfs) { fn sync(&mut self, _vfsp: *const super::vfs::Vfs) {
todo!("FAT SYNC"); todo!("FAT SYNC");
} }
fn vget(&self, fid: super::vfs::FileId, vfsp: *const super::vfs::Vfs) -> super::vfs::VNode { fn vget(
&mut self,
_fid: super::vfs::FileId,
_vfsp: *const super::vfs::Vfs,
) -> super::vfs::VNode {
todo!("FAT VGET"); todo!("FAT VGET");
} }
@@ -607,64 +607,71 @@ enum File {
} }
impl<'a> VNodeOperations for File { impl<'a> VNodeOperations for File {
fn access(&self, m: u32, c: super::vfs::UserCred, vp: *const VNode) { fn access(&mut self, _m: u32, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn bmap(&self, block_number: u32, bnp: (), vp: *const VNode) -> super::vfs::VNode { fn bmap(&mut self, _block_number: u32, _bnp: (), _vp: *const VNode) -> super::vfs::VNode {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn bread(&self, block_number: u32, vp: *const VNode) -> Arc<[u8]> { fn bread(&mut self, _block_number: u32, _vp: *const VNode) -> Arc<[u8]> {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn close(&self, f: u32, c: super::vfs::UserCred, vp: *const VNode) { fn close(&mut self, _f: u32, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn create( fn create(
&self, &mut self,
nm: &str, _nm: &str,
va: super::vfs::VAttr, _va: super::vfs::VAttr,
e: u32, _e: u32,
m: u32, _m: u32,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) -> Result<super::vfs::VNode, ()> { ) -> Result<super::vfs::VNode, ()> {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn fsync(&self, c: super::vfs::UserCred, vp: *const VNode) { fn fsync(&mut self, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn getattr(&self, c: super::vfs::UserCred, vp: *const VNode) -> super::vfs::VAttr { fn getattr(&mut self, _c: super::vfs::UserCred, _vp: *const VNode) -> super::vfs::VAttr {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn inactive(&self, c: super::vfs::UserCred, vp: *const VNode) { fn inactive(&mut self, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn ioctl(&self, com: u32, d: *mut u8, f: u32, c: super::vfs::UserCred, vp: *const VNode) { fn ioctl(
&mut self,
_com: u32,
_d: *mut u8,
_f: u32,
_c: super::vfs::UserCred,
_vp: *const VNode,
) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn link( fn link(
&self, &mut self,
target_dir: *mut super::vfs::VNode, _target_dir: *mut super::vfs::VNode,
target_name: &str, _target_name: &str,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) { ) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn lookup( fn lookup(
&self, &mut self,
nm: &str, nm: &str,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, vp: *const VNode,
) -> Result<super::vfs::VNode, ()> { ) -> Result<super::vfs::VNode, ()> {
let fat_fs = unsafe { (*(*vp).parent).data.cast::<FatFs>() }; let fat_fs = unsafe { (*(*vp).parent).data.cast::<FatFs>() };
@@ -708,16 +715,21 @@ impl<'a> VNodeOperations for File {
} }
fn mkdir( fn mkdir(
&self, &mut self,
nm: &str, _nm: &str,
va: super::vfs::VAttr, _va: super::vfs::VAttr,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) -> Result<super::vfs::VNode, ()> { ) -> Result<super::vfs::VNode, ()> {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn open(&self, f: u32, c: super::vfs::UserCred, vp: *const VNode) -> Result<Arc<[u8]>, ()> { fn open(
&mut self,
_f: u32,
_c: super::vfs::UserCred,
vp: *const VNode,
) -> Result<Arc<[u8]>, ()> {
match self { match self {
File::Archive(archive) => { File::Archive(archive) => {
let fat_fs = unsafe { (*(*vp).parent).data.cast::<FatFs>() }; let fat_fs = unsafe { (*(*vp).parent).data.cast::<FatFs>() };
@@ -780,59 +792,67 @@ impl<'a> VNodeOperations for File {
} }
_ => panic!("Cannot open non archives"), _ => panic!("Cannot open non archives"),
} }
todo!("VNODE OPERATIONS");
} }
fn rdwr( fn rdwr(
&self, &mut self,
uiop: *const super::vfs::UIO, _uiop: *const super::vfs::UIO,
direction: super::vfs::IODirection, _direction: super::vfs::IODirection,
f: u32, _f: u32,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) { ) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn readdir(&self, uiop: *const super::vfs::UIO, c: super::vfs::UserCred, vp: *const VNode) { fn readdir(
&mut self,
_uiop: *const super::vfs::UIO,
_c: super::vfs::UserCred,
_vp: *const VNode,
) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn readlink(&self, uiop: *const super::vfs::UIO, c: super::vfs::UserCred, vp: *const VNode) { fn readlink(
&mut self,
_uiop: *const super::vfs::UIO,
_c: super::vfs::UserCred,
_vp: *const VNode,
) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn rename( fn rename(
&self, &mut self,
nm: &str, _nm: &str,
target_dir: *mut super::vfs::VNode, _target_dir: *mut super::vfs::VNode,
target_name: &str, _target_name: &str,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) { ) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn select(&self, w: super::vfs::IODirection, c: super::vfs::UserCred, vp: *const VNode) { fn select(&mut self, _w: super::vfs::IODirection, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn setattr(&self, va: super::vfs::VAttr, c: super::vfs::UserCred, vp: *const VNode) { fn setattr(&mut self, _va: super::vfs::VAttr, _c: super::vfs::UserCred, _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn strategy(&self, bp: (), vp: *const VNode) { fn strategy(&mut self, _bp: (), _vp: *const VNode) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }
fn symlink( fn symlink(
&self, &mut self,
link_name: &str, _link_name: &str,
va: super::vfs::VAttr, _va: super::vfs::VAttr,
target_name: &str, _target_name: &str,
c: super::vfs::UserCred, _c: super::vfs::UserCred,
vp: *const VNode, _vp: *const VNode,
) { ) {
todo!("VNODE OPERATIONS"); todo!("VNODE OPERATIONS");
} }

View File

@@ -36,25 +36,28 @@ pub enum CompressionErrors {
// RFC 1950: "ZLIB Compressed Data Format Specification" // RFC 1950: "ZLIB Compressed Data Format Specification"
// RFC 1951: "DEFLATE Compressed Data Format Specification" // RFC 1951: "DEFLATE Compressed Data Format Specification"
pub fn uncompress_data(bytes: &[u8]) -> Result<Arc<[u8]>, CompressionErrors> { pub fn uncompress_data(bytes: &[u8]) -> Result<Vec<u8>, ()> {
assert!(bytes.len() > 2); assert!(bytes.len() > 2);
// Compression Method and flags // Compression Method and flags
let cmf = bytes[0]; let cmf = bytes[0];
if (cmf & 0x0F) != 0x08 { if (cmf & 0x0F) != 0x08 {
return Err(CompressionErrors::NotDeflate); return Err(());
// return Err(CompressionErrors::NotDeflate);
} }
let window_log2 = cmf >> 4 & 0x0F; let window_log2 = cmf >> 4 & 0x0F;
if window_log2 > 0x07 { if window_log2 > 0x07 {
return Err(CompressionErrors::UnsupportedWindowSize); return Err(());
// return Err(CompressionErrors::UnsupportedWindowSize);
} }
let flags = bytes[1]; let flags = bytes[1];
if (cmf as u32 * 256 + flags as u32) % 31 != 0 { if (cmf as u32 * 256 + flags as u32) % 31 != 0 {
return Err(CompressionErrors::FCheckFailed); return Err(());
// return Err(CompressionErrors::FCheckFailed);
} }
let present_dictionary = flags >> 5 & 0x01 != 0; let present_dictionary = flags >> 5 & 0x01 != 0;
@@ -62,7 +65,8 @@ pub fn uncompress_data(bytes: &[u8]) -> Result<Arc<[u8]>, CompressionErrors> {
if present_dictionary { if present_dictionary {
// cry // cry
return Err(CompressionErrors::UnsupportedDictionary); return Err(());
// return Err(CompressionErrors::UnsupportedDictionary);
} }
let mut inflate_context = InflateContext::new(&bytes[2..bytes.len() - 4]); let mut inflate_context = InflateContext::new(&bytes[2..bytes.len() - 4]);
@@ -70,7 +74,8 @@ pub fn uncompress_data(bytes: &[u8]) -> Result<Arc<[u8]>, CompressionErrors> {
let data = inflate_context.decompress(); let data = inflate_context.decompress();
if data.is_err() { if data.is_err() {
return Err(CompressionErrors::FailedCompression); return Err(());
// return Err(CompressionErrors::FailedCompression);
} }
let data = data.unwrap(); let data = data.unwrap();
@@ -79,7 +84,8 @@ pub fn uncompress_data(bytes: &[u8]) -> Result<Arc<[u8]>, CompressionErrors> {
let checksum = u32::from_le_bytes(bytes[bytes.len() - 4..].try_into().unwrap()); let checksum = u32::from_le_bytes(bytes[bytes.len() - 4..].try_into().unwrap());
if adler32(&data) != checksum { if adler32(&data) != checksum {
return Err(CompressionErrors::FailedChecksum); return Err(());
// return Err(CompressionErrors::FailedChecksum);
} }
return Ok(data); return Ok(data);
@@ -178,7 +184,7 @@ impl InflateContext {
return (base + if num != 0 { self.get_bits(num) } else { 0 } as usize) as u32; return (base + if num != 0 { self.get_bits(num) } else { 0 } as usize) as u32;
} }
pub fn decompress(&mut self) -> Result<Arc<[u8]>, ()> { pub fn decompress(&mut self) -> Result<Vec<u8>, ()> {
build_fixed(); build_fixed();
loop { loop {
@@ -205,7 +211,7 @@ impl InflateContext {
} }
} }
return Ok(Arc::from(self.output_buf.clone())); return Ok(self.output_buf.clone());
} }
fn decode(&mut self, huff: &mut Huff) -> u32 { fn decode(&mut self, huff: &mut Huff) -> u32 {

File diff suppressed because it is too large Load Diff

View File

@@ -110,15 +110,15 @@ impl Vfs {
pub trait FsOps { pub trait FsOps {
// yes, the vfsp was the best solution I could come up with // yes, the vfsp was the best solution I could come up with
fn mount(&self, path: &str, data: &mut *mut u8, vfsp: *const Vfs); fn mount(&mut self, path: &str, data: &mut *mut u8, vfsp: *const Vfs);
fn unmount(&self, vfsp: *const Vfs); fn unmount(&mut self, vfsp: *const Vfs);
fn root(&self, vfsp: *const Vfs) -> VNode; fn root(&mut self, vfsp: *const Vfs) -> VNode;
fn statfs(&self, vfsp: *const Vfs) -> StatFs; fn statfs(&mut self, vfsp: *const Vfs) -> StatFs;
fn sync(&self, vfsp: *const Vfs); fn sync(&mut self, vfsp: *const Vfs);
fn fid(&self, path: &str, vfsp: *const Vfs) -> Option<FileId>; fn fid(&mut self, path: &str, vfsp: *const Vfs) -> Option<FileId>;
// idk how the fuck you're supposed to accomplish this // idk how the fuck you're supposed to accomplish this
// good luck I guess. // good luck I guess.
fn vget(&self, fid: FileId, vfsp: *const Vfs) -> VNode; fn vget(&mut self, fid: FileId, vfsp: *const Vfs) -> VNode;
} }
pub struct FileId { pub struct FileId {
@@ -208,17 +208,24 @@ pub struct UIO {
} }
pub trait VNodeOperations { pub trait VNodeOperations {
fn open(&self, f: u32, c: UserCred, vp: *const VNode) -> Result<Arc<[u8]>, ()>; fn open(&mut self, f: u32, c: UserCred, vp: *const VNode) -> Result<Arc<[u8]>, ()>;
fn close(&self, f: u32, c: UserCred, vp: *const VNode); fn close(&mut self, f: u32, c: UserCred, vp: *const VNode);
fn rdwr(&self, uiop: *const UIO, direction: IODirection, f: u32, c: UserCred, vp: *const VNode); fn rdwr(
fn ioctl(&self, com: u32, d: *mut u8, f: u32, c: UserCred, vp: *const VNode); &mut self,
fn select(&self, w: IODirection, c: UserCred, vp: *const VNode); uiop: *const UIO,
fn getattr(&self, c: UserCred, vp: *const VNode) -> VAttr; direction: IODirection,
fn setattr(&self, va: VAttr, c: UserCred, vp: *const VNode); f: u32,
fn access(&self, m: u32, c: UserCred, vp: *const VNode); c: UserCred,
fn lookup(&self, nm: &str, c: UserCred, vp: *const VNode) -> Result<VNode, ()>; vp: *const VNode,
);
fn ioctl(&mut self, com: u32, d: *mut u8, f: u32, c: UserCred, vp: *const VNode);
fn select(&mut self, w: IODirection, c: UserCred, vp: *const VNode);
fn getattr(&mut self, c: UserCred, vp: *const VNode) -> VAttr;
fn setattr(&mut self, va: VAttr, c: UserCred, vp: *const VNode);
fn access(&mut self, m: u32, c: UserCred, vp: *const VNode);
fn lookup(&mut self, nm: &str, c: UserCred, vp: *const VNode) -> Result<VNode, ()>;
fn create( fn create(
&self, &mut self,
nm: &str, nm: &str,
va: VAttr, va: VAttr,
e: u32, e: u32,
@@ -226,24 +233,31 @@ pub trait VNodeOperations {
c: UserCred, c: UserCred,
vp: *const VNode, vp: *const VNode,
) -> Result<VNode, ()>; ) -> Result<VNode, ()>;
fn link(&self, target_dir: *mut VNode, target_name: &str, c: UserCred, vp: *const VNode); fn link(&mut self, target_dir: *mut VNode, target_name: &str, c: UserCred, vp: *const VNode);
fn rename( fn rename(
&self, &mut self,
nm: &str, nm: &str,
target_dir: *mut VNode, target_dir: *mut VNode,
target_name: &str, target_name: &str,
c: UserCred, c: UserCred,
vp: *const VNode, vp: *const VNode,
); );
fn mkdir(&self, nm: &str, va: VAttr, c: UserCred, vp: *const VNode) -> Result<VNode, ()>; fn mkdir(&mut self, nm: &str, va: VAttr, c: UserCred, vp: *const VNode) -> Result<VNode, ()>;
fn readdir(&self, uiop: *const UIO, c: UserCred, vp: *const VNode); fn readdir(&mut self, uiop: *const UIO, c: UserCred, vp: *const VNode);
fn symlink(&self, link_name: &str, va: VAttr, target_name: &str, c: UserCred, vp: *const VNode); fn symlink(
fn readlink(&self, uiop: *const UIO, c: UserCred, vp: *const VNode); &mut self,
fn fsync(&self, c: UserCred, vp: *const VNode); link_name: &str,
fn inactive(&self, c: UserCred, vp: *const VNode); va: VAttr,
fn bmap(&self, block_number: u32, bnp: (), vp: *const VNode) -> VNode; target_name: &str,
fn strategy(&self, bp: (), vp: *const VNode); c: UserCred,
fn bread(&self, block_number: u32, vp: *const VNode) -> Arc<[u8]>; vp: *const VNode,
);
fn readlink(&mut self, uiop: *const UIO, c: UserCred, vp: *const VNode);
fn fsync(&mut self, c: UserCred, vp: *const VNode);
fn inactive(&mut self, c: UserCred, vp: *const VNode);
fn bmap(&mut self, block_number: u32, bnp: (), vp: *const VNode) -> VNode;
fn strategy(&mut self, bp: (), vp: *const VNode);
fn bread(&mut self, block_number: u32, vp: *const VNode) -> Arc<[u8]>;
} }
pub struct VAttr { pub struct VAttr {
@@ -267,7 +281,9 @@ pub struct VAttr {
pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> { pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> {
let layout = alloc::alloc::Layout::new::<Vfs>(); let layout = alloc::alloc::Layout::new::<Vfs>();
let vfs = unsafe { alloc(layout).cast::<Vfs>() }; // TODO: investigate why on earth this gives me an allocation error
// let vfs = unsafe { alloc(layout).cast::<Vfs>() };
let vfs = PHYSICAL_MEMORY_MANAGER.alloc(1).unwrap().cast::<Vfs>();
let vfs = unsafe { &mut *vfs }; let vfs = unsafe { &mut *vfs };
@@ -286,7 +302,7 @@ pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> {
(*vfs) (*vfs)
.ops .ops
.as_ref() .as_mut()
.unwrap() .unwrap()
.mount(mount_point, &mut vfs.data, vfsp); .mount(mount_point, &mut vfs.data, vfsp);
} }
@@ -302,8 +318,8 @@ pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> {
let target_vfs = unsafe { ROOT_VFS.next.unwrap() }; let target_vfs = unsafe { ROOT_VFS.next.unwrap() };
let binding = unsafe { &(*target_vfs).ops }; let binding = unsafe { &mut (*target_vfs).ops };
let mut cur_vnode = binding.as_ref().unwrap().root(target_vfs); let mut cur_vnode = binding.as_mut().unwrap().root(target_vfs);
let parts = mount_point.split('/').collect::<Vec<&str>>(); let parts = mount_point.split('/').collect::<Vec<&str>>();
@@ -329,7 +345,7 @@ pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> {
(*vfs) (*vfs)
.ops .ops
.as_ref() .as_mut()
.unwrap() .unwrap()
.mount(mount_point, &mut vfs.data, vfsp); .mount(mount_point, &mut vfs.data, vfsp);
} }
@@ -342,8 +358,8 @@ pub fn add_vfs(mount_point: &str, fs_ops: Box<dyn FsOps>) -> Result<(), ()> {
pub fn vfs_open(path: &str) -> Result<VNode, ()> { pub fn vfs_open(path: &str) -> Result<VNode, ()> {
let parts = path.split('/').collect::<Vec<&str>>(); let parts = path.split('/').collect::<Vec<&str>>();
let target_vfs = unsafe { ROOT_VFS.next.unwrap() }; let target_vfs = unsafe { ROOT_VFS.next.unwrap() };
let binding = unsafe { &(*target_vfs).ops }; let binding = unsafe { &mut (*target_vfs).ops };
let mut cur_vnode = binding.as_ref().unwrap().root(target_vfs); let mut cur_vnode = binding.as_mut().unwrap().root(target_vfs);
for part in parts { for part in parts {
if part.is_empty() { if part.is_empty() {

View File

@@ -21,6 +21,10 @@ impl<T> Cell<T> {
return unsafe { &*self.value.get() }; return unsafe { &*self.value.get() };
} }
pub fn get_mut(&self) -> &mut T {
return unsafe { &mut *self.value.get() };
}
pub fn set(&self, new_value: T) { pub fn set(&self, new_value: T) {
unsafe { *self.value.get() = new_value }; unsafe { *self.value.get() = new_value };
} }

89
src/libs/math.rs Normal file
View File

@@ -0,0 +1,89 @@
pub fn abs(x: f64) -> f64 {
return f64::from_bits(x.to_bits() & (u64::MAX / 2));
}
const TOINT: f64 = 1. / f64::EPSILON;
pub fn floor(x: f64) -> f64 {
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_feature = "sse2")
))]
{
if abs(x).to_bits() < 4503599627370496.0_f64.to_bits() {
let truncated = x as i64 as f64;
if truncated > x {
return truncated - 1.0;
} else {
return truncated;
}
} else {
return x;
}
}
let ui = x.to_bits();
let e = ((ui >> 52) & 0x7FF) as i32;
if (e >= 0x3FF + 52) || (x == 0.) {
return x;
}
let y = if (ui >> 63) != 0 {
x - TOINT + TOINT - x
} else {
x + TOINT + TOINT - x
};
if e < 0x3FF {
return if (ui >> 63) != 0 { -1. } else { 0. };
}
if y > 0. {
return x + y - 1.;
} else {
return x + y;
}
}
pub fn ceil(x: f64) -> f64 {
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_feature = "sse2")
))]
{
if abs(x).to_bits() < 4503599627370496.0_f64.to_bits() {
let truncated = x as i64 as f64;
if truncated < x {
return truncated + 1.0;
} else {
return truncated;
}
} else {
return x;
}
}
let u: u64 = x.to_bits();
let e: i64 = (u >> 52 & 0x7ff) as i64;
if e >= 0x3ff + 52 || x == 0. {
return x;
}
let y = if (u >> 63) != 0 {
x - TOINT + TOINT - x
} else {
x + TOINT - TOINT - x
};
if e < 0x3ff {
return if (u >> 63) != 0 { -0. } else { 1. };
}
if y < 0. {
return x + y + 1.;
} else {
return x + y;
}
}

View File

@@ -1,3 +1,4 @@
pub mod cell; pub mod cell;
pub mod math;
pub mod sync; pub mod sync;
pub mod uuid; pub mod uuid;

View File

@@ -9,10 +9,12 @@
use core::ffi::CStr; use core::ffi::CStr;
use alloc::{format, vec::Vec}; use alloc::{format, vec::Vec};
use drivers::serial::{read_serial, write_serial};
use limine::KernelFileRequest; use limine::KernelFileRequest;
use crate::drivers::fs::vfs::{vfs_open, UserCred}; use crate::drivers::fs::{
initramfs,
vfs::{vfs_open, UserCred},
};
extern crate alloc; extern crate alloc;
@@ -30,24 +32,38 @@ pub extern "C" fn _start() -> ! {
drivers::serial::init_serial(); drivers::serial::init_serial();
// let squashfs = initramfs::init();
// crate::println!("{:?}", squashfs.superblock);
let _ = drivers::fs::vfs::add_vfs("/", alloc::boxed::Box::new(initramfs::init()));
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
drivers::pci::enumerate_pci_bus(); drivers::pci::enumerate_pci_bus();
drivers::storage::ide::init(); let mut file = vfs_open("/firstdir/seconddirbutlonger/yeah.txt").unwrap();
let nested_file = vfs_open("/boot/limine/limine.cfg").unwrap(); // drivers::storage::ide::init();
// let nested_file = vfs_open("/boot/limine/limine.cfg").unwrap();
// crate::println!(
// "{:X?}",
// nested_file
// .ops
// .open(0, UserCred { uid: 0, gid: 0 }, nested_file.as_ptr())
// );
// let file = vfs_open("/example.txt").unwrap();
crate::println!( crate::println!(
"{:X?}", "{:X?}",
nested_file core::str::from_utf8(
&file
.ops .ops
.open(0, UserCred { uid: 0, gid: 0 }, nested_file.as_ptr()) .open(0, UserCred { uid: 0, gid: 0 }, file.as_ptr())
); .unwrap()
)
let file = vfs_open("/example.txt").unwrap(); .unwrap()
crate::println!(
"{:X?}",
file.ops.open(0, UserCred { uid: 0, gid: 0 }, file.as_ptr())
); );
let fb = drivers::video::get_framebuffer().unwrap(); let fb = drivers::video::get_framebuffer().unwrap();
@@ -72,23 +88,23 @@ pub extern "C" fn _start() -> ! {
fb.blit_screen(buffer, None); fb.blit_screen(buffer, None);
loop { // loop {
let ch = read_serial(); // let ch = read_serial();
if ch == b'\x00' { // if ch == b'\x00' {
continue; // continue;
} // }
if ch == b'\x08' { // if ch == b'\x08' {
write_serial(b'\x08'); // write_serial(b'\x08');
write_serial(b' '); // write_serial(b' ');
write_serial(b'\x08'); // write_serial(b'\x08');
} // }
if ch > 0x20 && ch < 0x7F { // if ch > 0x20 && ch < 0x7F {
write_serial(ch); // write_serial(ch);
} // }
} // }
hcf(); hcf();
} }