forked from Rativel/BurritOS
changing impl
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::drivers::drv_disk;
|
||||
use crate::filesys::openfile;
|
||||
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 ;
|
||||
@@ -43,8 +44,8 @@ impl FileHdr {
|
||||
panic!("file size is too long");
|
||||
}
|
||||
|
||||
self.num_sectors = (file_size + SECTOR_SIZE -1) / SECTOR_SIZE;
|
||||
self.num_header_sectors = ((self.num_sectors - DATAS_IN_FIRST_SECTOR)+DATAS_IN_SECTOR-1) / DATAS_IN_SECTOR;
|
||||
self.num_sectors = openfile::div_round_up(file_size, SECTOR_SIZE);
|
||||
self.num_header_sectors = openfile::div_round_up(self.num_sectors-DATAS_IN_FIRST_SECTOR, DATAS_IN_SECTOR);
|
||||
|
||||
// Check if there is enough free sectors for both of them
|
||||
if free_map.num_clear() < (self.num_sectors + self.num_header_sectors) as i32 {
|
||||
@@ -63,11 +64,14 @@ impl FileHdr {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn re_allocate(&mut self, mut free_map: BitMap, old_file_size: i32, new_file_size: i32) -> bool {
|
||||
let mut new_num_sectors = ((new_file_size + SECTOR_SIZE -1) / SECTOR_SIZE) - self.num_sectors;
|
||||
pub fn re_allocate(&mut self, free_map: &mut BitMap, old_file_size: i32, new_file_size: i32) -> bool {
|
||||
|
||||
openfile::div_round_up(1,1);
|
||||
|
||||
let mut new_num_sectors = openfile::div_round_up(new_file_size, SECTOR_SIZE) - self.num_sectors;
|
||||
self.num_bytes = new_file_size;
|
||||
|
||||
let mut new_num_header_sectors = (((self.num_sectors - DATAS_IN_FIRST_SECTOR)+DATAS_IN_SECTOR-1) / DATAS_IN_SECTOR) - self.num_header_sectors;
|
||||
let mut new_num_header_sectors = openfile::div_round_up(self.num_sectors-DATAS_IN_FIRST_SECTOR, DATAS_IN_SECTOR) - self.num_header_sectors;
|
||||
|
||||
assert!(new_file_size <= MAX_FILE_LENGTH);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user