added num_dir_entries & directory_file_size in filesys.rs
This commit is contained in:
parent
d620822d97
commit
4633c512bd
@ -2,9 +2,11 @@ use crate::{simulator::disk, utility::bitmap::BitMap, kernel::mgerror::ErrorCode
|
||||
|
||||
use super::filehdr::FileHdr;
|
||||
|
||||
const ERROR : i32 = -1;
|
||||
const FREE_MAP_SECTOR : i32 = 0;
|
||||
const DIRECTORY_SECTOR : i32 = 1;
|
||||
pub const ERROR : i32 = -1;
|
||||
pub const FREE_MAP_SECTOR : i32 = 0;
|
||||
pub const DIRECTORY_SECTOR : i32 = 1;
|
||||
pub const NUM_DIR_ENTRIES : i32 = 10;
|
||||
pub const DIRECTORY_FILE_SIZE : i32 = 100; //std::mem::size_of<Directory>() * NUM_DIR_ENTRIES;
|
||||
|
||||
pub struct Filesys {
|
||||
pub free_map_file : OpenFile, //Bit map of free disk blocks, represented as a file
|
||||
@ -27,7 +29,7 @@ impl Filesys {
|
||||
pub fn init_filesys(format : bool) -> Filesys {
|
||||
if format {
|
||||
let free_map = BitMap::init_bitmap(disk::NUM_SECTORS as usize);
|
||||
let directory = Directory::init_directory(num_dir_entries);
|
||||
let directory = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
|
||||
free_map.mark(FREE_MAP_SECTOR as usize);
|
||||
free_map.mark(DIRECTORY_SECTOR as usize);
|
||||
@ -36,7 +38,7 @@ impl Filesys {
|
||||
let dir_header : FileHdr;
|
||||
|
||||
map_header.allocate(free_map, FREE_MAP_SECTOR);
|
||||
dir_header.allocate(free_map, directory_file_size);
|
||||
dir_header.allocate(free_map, DIRECTORY_FILE_SIZE);
|
||||
|
||||
dir_header.set_dir();
|
||||
|
||||
@ -97,7 +99,7 @@ impl Filesys {
|
||||
}
|
||||
|
||||
let dir_file = OpenFile::init_open_file(dir_sector);
|
||||
let directory = Directory::init_directory(num_dir_entries);
|
||||
let directory = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
directory.fetch_from(&dir_file);
|
||||
|
||||
if directory.find(name) != ERROR {
|
||||
@ -163,7 +165,7 @@ impl Filesys {
|
||||
|
||||
// Read the directory from disk
|
||||
let dir_file = OpenFile::init_open_file(dir_sector);
|
||||
let directory = Directory::init_directory(num_dir_entries);
|
||||
let directory = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
directory.fetch_from(&directory);
|
||||
|
||||
// Find the file in the directory
|
||||
@ -201,7 +203,7 @@ impl Filesys {
|
||||
|
||||
// Fetch the directory from the disk
|
||||
let dir_file = OpenFile::init_open_file(dir_sector);
|
||||
let directory = Directory::init_directory(num_dir_entries);
|
||||
let directory = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
directory.fetch_from(&dir_file);
|
||||
|
||||
// Look for the file in the directory
|
||||
@ -283,7 +285,7 @@ impl Filesys {
|
||||
|
||||
// Fetch it from disk
|
||||
let parent_dir_file = OpenFile::init_open_file(parent_sector);
|
||||
let parent_dir = Directory::init_directory(num_dir_entries);
|
||||
let parent_dir = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
parent_dir.fetch_from(parent_dir_file);
|
||||
|
||||
// Check that the directory does not exit yet
|
||||
@ -303,7 +305,7 @@ impl Filesys {
|
||||
|
||||
// Allocate free sectors for the directory contents
|
||||
let hdr : FileHdr;
|
||||
if !hdr.allocate(free_map, directory_file_size) {
|
||||
if !hdr.allocate(free_map, DIRECTORY_FILE_SIZE) {
|
||||
return Err(ErrorCode::OutOfDisk);
|
||||
}
|
||||
|
||||
@ -322,7 +324,7 @@ impl Filesys {
|
||||
|
||||
// New directory (initially empty)
|
||||
let new_dir_file = OpenFile::init_open_file(hdr_sector as usize);
|
||||
let new_dir = Directory::init_directory(num_dir_entries);
|
||||
let new_dir = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
new_dir.write_back(new_dir_file);
|
||||
|
||||
// Parent directory
|
||||
@ -354,7 +356,7 @@ impl Filesys {
|
||||
|
||||
// Fetch it from disk
|
||||
let parent_dir_file = OpenFile::init_open_file(parent_sector);
|
||||
let parent_dir = Directory::init_directory(num_dir_entries);
|
||||
let parent_dir = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
parent_dir.fetch_from(parent_dir_file);
|
||||
|
||||
// Check that the directory to be removed exist
|
||||
@ -374,7 +376,7 @@ impl Filesys {
|
||||
|
||||
// Fetch its contents from the disk
|
||||
let the_dir_file = OpenFile::init_open_file(the_dir_sector);
|
||||
let the_dir = Directory::init_directory(num_dir_entries);
|
||||
let the_dir = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
the_dir.fetch_from(the_dir_file);
|
||||
|
||||
// Check that is is empty
|
||||
|
Loading…
x
Reference in New Issue
Block a user