forked from Rativel/BurritOS
ajout de directory.rs
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use crate::simulator::disk;
|
||||
use crate::{simulator::disk::SECTOR_SIZE, utility::bitmap::BitMap};
|
||||
pub const MAX_HEADER_SECTORS: i32 = 32;
|
||||
pub const DATAS_IN_FIRST_SECTOR: i32 = (SECTOR_SIZE - 5 * 8) /8;
|
||||
@@ -8,6 +7,11 @@ pub const MAX_FILE_LENGTH: i32 = ((MAX_DATA_SECTORS) * SECTOR_SIZE);
|
||||
|
||||
use crate::DrvDisk;
|
||||
use crate::Disk;
|
||||
use crate::OpenFile;
|
||||
|
||||
use std::mem;
|
||||
|
||||
use super::openfile::OpenFile;
|
||||
|
||||
pub struct FileHdr {
|
||||
is_dir: i32,
|
||||
@@ -20,18 +24,19 @@ pub struct FileHdr {
|
||||
|
||||
impl FileHdr {
|
||||
|
||||
//Juste histoire d'avoir un constructeur, temporaire
|
||||
pub fn new() -> FileHdr {
|
||||
FileHdr{
|
||||
is_dir : 0,
|
||||
num_bytes : 0,
|
||||
num_sectors : 0,
|
||||
data_sectors : Vec::new(),
|
||||
num_header_sectors : 0,
|
||||
header_sectors : [0 ; MAX_HEADER_SECTORS as usize]
|
||||
|
||||
pub fn init_file_hdr() -> FileHdr {
|
||||
FileHdr {
|
||||
is_dir: 0,
|
||||
num_bytes: 0,
|
||||
num_sectors: 0,
|
||||
data_sectors: Vec::new(),
|
||||
num_header_sectors: 0,
|
||||
header_sectors: [0;MAX_HEADER_SECTORS as usize],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn allocate(&mut self, mut free_map: BitMap, file_size: i32) -> bool {
|
||||
self.num_bytes = file_size;
|
||||
if file_size > MAX_FILE_LENGTH {
|
||||
@@ -96,7 +101,14 @@ impl FileHdr {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: fetchFrom WriteBack
|
||||
pub fn fetch_from(&self, file: OpenFile) {
|
||||
file.read_at(self.table,self.table_size * mem::size_of::<DirectoryEntry>() as i32);
|
||||
}
|
||||
|
||||
pub fn write_back(&self, file: OpenFile) {
|
||||
file.write_at(self.table,self.table_size * mem::size_of::<DirectoryEntry>() as i32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn byte_to_sector(&self,offset: i32) -> i32 {
|
||||
|
||||
Reference in New Issue
Block a user