Skip to content

Commit

Permalink
add clear
Browse files Browse the repository at this point in the history
  • Loading branch information
buhe committed Nov 29, 2021
1 parent e4ec97a commit 23d366b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
10 changes: 8 additions & 2 deletions fs-fat-fuse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ fn easy_fs_pack() -> std::io::Result<()> {
let mut all_data: Vec<u8> = Vec::new();
host_file.read_to_end(&mut all_data).unwrap();
// create a file in easy-fs
// todo
let inode = root_inode.create(app.as_str(), ATTRIBUTE_ARCHIVE);
// write data to easy-fs
match inode {
Some(i) => {i.write_at(0, all_data.as_slice());},
None => {},
None => {println!("Not create app.")},
}

}
Expand All @@ -107,6 +106,13 @@ fn easy_fs_pack() -> std::io::Result<()> {
let hello_app = root_inode.find("hello").unwrap();
hello_app.read_at(0, &mut cache);
println!("hello app data {:?}", cache);
hello_app.clear();
println!("clear hello app");
let hello_clear = root_inode.find("hello");
match hello_clear {
Some(_) => {},
None => {println!("can not found hello..")},
}
Ok(())
}

Expand Down
16 changes: 16 additions & 0 deletions fs-fat/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,22 @@ impl Inode {

}

pub fn clear(&self){
let first_cluster:u32 = self.first_cluster();
if self.is_dir() || first_cluster == 0 {
return;
}
self.modify_dir_entry(|short_ent:&mut ShortDirEntry|{
short_ent.clear();
});
let fs = self.fs.lock();
let all_clusters = fs
.get_fat()
.get_all_cluster_of(first_cluster, self.block_device.clone());
fs.dealloc_cluster(all_clusters);
}


// pub fn read_at(&self, offset: usize, buf: &mut [u8]) -> usize {
// let _fs = self.fs.lock();
// self.read_disk_inode(|disk_inode| {
Expand Down
4 changes: 2 additions & 2 deletions os/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ k210-soc = { git = "https://github.com/buguOS/k210-soc" }
libm = "0.1"
infrared = "0.13.0"
nom = { version = "5", default-features = false, features = [] }
fs-demo = { path = "../fs-demo" }
fs-fat = { path = "../fs-fat" }
2 changes: 1 addition & 1 deletion os/src/driver/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod sdcard;

use lazy_static::*;
use alloc::sync::Arc;
use fs_demo::BlockDevice;
use fs_fat::BlockDevice;

type BlockDeviceImpl = sdcard::SDCardWrapper;

Expand Down
13 changes: 7 additions & 6 deletions os/src/fs/inode.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fs_demo::{
EasyFileSystem,
use fs_fat::{
ATTRIBUTE_ARCHIVE,
FatFileSystem,
Inode,
};
use crate::driver::BLOCK_DEVICE;
Expand Down Expand Up @@ -55,15 +56,15 @@ impl OSInode {

lazy_static! {
pub static ref ROOT_INODE: Arc<Inode> = {
let efs = EasyFileSystem::open(BLOCK_DEVICE.clone());
Arc::new(EasyFileSystem::root_inode(&efs))
let efs = FatFileSystem::open(BLOCK_DEVICE.clone());
Arc::new(FatFileSystem::root_inode(&efs))
};
}

pub fn list_apps() {
println!("/**** APPS ****");
for app in ROOT_INODE.ls() {
println!("{}", app);
println!("{}", app.0);
}
println!("**************/");
}
Expand Down Expand Up @@ -105,7 +106,7 @@ pub fn open_file(name: &str, flags: OpenFlags) -> Option<Arc<OSInode>> {
)))
} else {
// create file
ROOT_INODE.create(name)
ROOT_INODE.create(name, ATTRIBUTE_ARCHIVE)
.map(|inode| {
Arc::new(OSInode::new(
readable,
Expand Down

0 comments on commit 23d366b

Please sign in to comment.