modificiation of directory
This commit is contained in:
parent
85e999a7b0
commit
69a8a0d4ea
@ -35,7 +35,6 @@ fn entries_to_bytes(entries: &Vec<DirectoryEntry>) -> Vec<u8> {
|
||||
pub struct Directory {
|
||||
table_size: i32,
|
||||
table: Vec<DirectoryEntry>,
|
||||
drv_disk: DrvDisk,
|
||||
}
|
||||
|
||||
impl Directory {
|
||||
@ -46,24 +45,23 @@ impl Directory {
|
||||
///
|
||||
/// ### Parameters
|
||||
/// - **size** is the number of entries in the directory
|
||||
pub fn init_directory(size: i32, drv_disk_: DrvDisk) -> Directory {
|
||||
let tmp:Vec<DirectoryEntry> = Vec::new();
|
||||
pub fn init_directory(size: i32) -> Directory {
|
||||
let mut tmp:Vec<DirectoryEntry> = Vec::new();
|
||||
for i in 0..size {
|
||||
tmp[i as usize].in_use = false;
|
||||
}
|
||||
Directory {
|
||||
table_size: size,
|
||||
table: tmp,
|
||||
drv_disk: drv_disk_,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_from(&self,mut file: OpenFile) {
|
||||
OpenFile::read_at(&mut self.drv_disk, &mut file, &mut entries_to_bytes(&self.table), self.table_size * mem::size_of::<DirectoryEntry>() as i32, 0);
|
||||
pub fn fetch_from(&self,mut file: OpenFile, mut drv_disk: DrvDisk) {
|
||||
OpenFile::read_at(&mut drv_disk, &mut file, &mut entries_to_bytes(&self.table), self.table_size * mem::size_of::<DirectoryEntry>() as i32, 0);
|
||||
}
|
||||
|
||||
pub fn write_back(&self,mut file: OpenFile) {
|
||||
OpenFile::write_at(&mut self.drv_disk,&mut file,&mut entries_to_bytes(&self.table),self.table_size * mem::size_of::<DirectoryEntry>() as i32,0);
|
||||
pub fn write_back(&self,mut file: OpenFile, mut drv_disk: DrvDisk) {
|
||||
OpenFile::write_at(&mut drv_disk,&mut file,&mut entries_to_bytes(&self.table),self.table_size * mem::size_of::<DirectoryEntry>() as i32,0);
|
||||
}
|
||||
|
||||
/// Look up file name in directory.
|
||||
@ -108,7 +106,7 @@ impl Directory {
|
||||
/// - **new_sector** the disk sector containing the added file's header
|
||||
///
|
||||
/// return NO_ERROR, ALREADY_IN_DIRECTORY or NOSPACE_IN_DIRECTORY.
|
||||
pub fn add(&self, name: String, new_sector: i32) -> Result<(), ErrorCode> {
|
||||
pub fn add(&mut self, name: String, new_sector: i32) -> Result<(), ErrorCode> {
|
||||
if self.find_index(name) != -1 {
|
||||
return Err(ErrorCode::AlreadyInDirectory);
|
||||
}
|
||||
@ -130,7 +128,7 @@ impl Directory {
|
||||
/// - **name** the file name to be removed
|
||||
/// return NO_ERROR, or INEXIST_DIRECTORY_ERROR
|
||||
|
||||
pub fn remove(&self, name: String) -> Result<(), ErrorCode> {
|
||||
pub fn remove(&mut self, name: String) -> Result<(), ErrorCode> {
|
||||
let i = self.find_index(name);
|
||||
if i == -1 {
|
||||
return Err(ErrorCode::InexistDirectoryError);
|
||||
@ -145,7 +143,7 @@ impl Directory {
|
||||
/// - **name** the name of the Dir to print
|
||||
/// - **depth** the depth in the recursion (to print a nice hierarchy with spaces)
|
||||
pub fn list(&self, name: char, depth: i32) {
|
||||
let dir = Directory::init_directory(NUM_DIR_ENTRIES, self.drv_disk);
|
||||
let dir = Directory::init_directory(NUM_DIR_ENTRIES);
|
||||
|
||||
for i in 0..self.table_size {
|
||||
if self.table[i as usize].in_use {
|
||||
@ -166,7 +164,7 @@ impl Directory {
|
||||
}
|
||||
|
||||
/// Return true if the directory is empty
|
||||
pub fn is_empty(self) -> bool {
|
||||
pub fn is_empty(&mut self) -> bool {
|
||||
let mut empty = true;
|
||||
for i in 0..self.table_size {
|
||||
if self.table[i as usize].in_use {
|
||||
|
Loading…
x
Reference in New Issue
Block a user