mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-24 02:16:19 +04:00
Added more FS stuff.
This commit is contained in:
parent
e033feee2b
commit
61d8ace581
@ -6,11 +6,35 @@
|
|||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
|
||||||
pub trait FileSystem {
|
pub trait FileSystem {
|
||||||
fn open(path: &String) -> Option<Descriptor>;
|
fn init(bdev: usize) -> bool;
|
||||||
|
fn open(path: &String) -> Result<Descriptor, FsError>;
|
||||||
fn read(desc: &Descriptor, buffer: *mut u8, offset: u32, size: u32) -> u32;
|
fn read(desc: &Descriptor, buffer: *mut u8, offset: u32, size: u32) -> u32;
|
||||||
|
fn write(desc: &Descriptor, buffer: *const u8, offset: u32, size: u32) -> u32;
|
||||||
|
fn close(desc: &mut Descriptor);
|
||||||
|
fn stat(desc: &Descriptor) -> Stat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stats on a file. This generally mimics an inode
|
||||||
|
/// since that's the information we want anyway.
|
||||||
|
/// However, inodes are filesystem specific, and we
|
||||||
|
/// want a more generic stat.
|
||||||
|
pub struct Stat {
|
||||||
|
pub mode: u16,
|
||||||
|
pub size: u32,
|
||||||
|
pub uid: u16,
|
||||||
|
pub gid: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A file descriptor
|
/// A file descriptor
|
||||||
pub struct Descriptor {
|
pub struct Descriptor {
|
||||||
|
blockdev: usize,
|
||||||
|
inode: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum FsError {
|
||||||
|
Success,
|
||||||
|
FileNotFound,
|
||||||
|
Permission,
|
||||||
|
IsFile,
|
||||||
|
IsDirectory,
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,74 @@
|
|||||||
// Stephen Marz
|
// Stephen Marz
|
||||||
// 16 March 2020
|
// 16 March 2020
|
||||||
|
|
||||||
use crate::fs::{Descriptor, FileSystem};
|
use crate::fs::{Descriptor, FileSystem, Stat, FsError};
|
||||||
|
use alloc::string::String;
|
||||||
|
|
||||||
pub struct MinixFileSystem {
|
pub const MAGIC: u16 = 0x4d5a;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct SuperBlock {
|
||||||
|
ninodes: u32,
|
||||||
|
pad0: u16,
|
||||||
|
imap_blocks: u16,
|
||||||
|
zmap_blocks: u16,
|
||||||
|
first_data_zone: u16,
|
||||||
|
log_zone_size: u16,
|
||||||
|
pad1: u16,
|
||||||
|
max_size: u32,
|
||||||
|
zones: u32,
|
||||||
|
magic: u16,
|
||||||
|
pad2: u16,
|
||||||
|
block_size: u16,
|
||||||
|
disk_version: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Inode {
|
||||||
|
mode: u16,
|
||||||
|
nlinks: u16,
|
||||||
|
uid: u16,
|
||||||
|
gid: u16,
|
||||||
|
size: u32,
|
||||||
|
atime: u32,
|
||||||
|
mtime: u32,
|
||||||
|
ctime: u32,
|
||||||
|
zones: [u32; 10],
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct DirEntry {
|
||||||
|
inode: u32,
|
||||||
|
name: [u8; 60],
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MinixFileSystem {
|
||||||
|
sb: SuperBlock
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileSystem for MinixFileSystem {
|
||||||
|
fn init(bdev: usize) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
fn open(path: &String) -> Result<Descriptor, FsError> {
|
||||||
|
Err(FsError::FileNotFound)
|
||||||
|
}
|
||||||
|
fn read(desc: &Descriptor, buffer: *mut u8, offset: u32, size: u32) -> u32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
fn write(desc: &Descriptor, buffer: *const u8, offset: u32, size: u32) -> u32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
fn close(desc: &mut Descriptor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
fn stat(desc: &Descriptor) -> Stat {
|
||||||
|
Stat {
|
||||||
|
mode: 0,
|
||||||
|
size: 0,
|
||||||
|
uid: 0,
|
||||||
|
gid: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ pub fn dealloc(ptr: *mut u8) {
|
|||||||
HEAP_START + (ptr as usize - ALLOC_START) / PAGE_SIZE;
|
HEAP_START + (ptr as usize - ALLOC_START) / PAGE_SIZE;
|
||||||
// Make sure that the address makes sense. The address we
|
// Make sure that the address makes sense. The address we
|
||||||
// calculate here is the page structure, not the HEAP address!
|
// calculate here is the page structure, not the HEAP address!
|
||||||
assert!(addr >= HEAP_START && addr < HEAP_START + HEAP_SIZE);
|
assert!(addr >= HEAP_START && addr < ALLOC_START);
|
||||||
let mut p = addr as *mut Page;
|
let mut p = addr as *mut Page;
|
||||||
// Keep clearing pages until we hit the last page.
|
// Keep clearing pages until we hit the last page.
|
||||||
while (*p).is_taken() && !(*p).is_last() {
|
while (*p).is_taken() && !(*p).is_last() {
|
||||||
|
Loading…
Reference in New Issue
Block a user