Skip to content

Commit

Permalink
Merge pull request #56 from yuoo655/starry
Browse files Browse the repository at this point in the history
add ext4-fs on rust for Starry
  • Loading branch information
Azure-stars authored Jun 1, 2024
2 parents cd24ded + 5c00793 commit 3d93061
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fs = ["alloc", "paging", "axdriver/virtio-blk", "dep:axfs", "axruntime/fs"] # TO
fatfs = ["axfs/fatfs"]
ext4fs = ["axfs/ext4fs"]
myfs = ["axfs?/myfs"]
ext4_rs = ["axfs/ext4_rs"]

# Networking
net = ["alloc", "paging", "axdriver/virtio-net", "dep:axnet", "axruntime/net"]
Expand Down
2 changes: 2 additions & 0 deletions modules/axfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ myfs = ["dep:crate_interface"]
use-ramdisk = []
monolithic = []
fatfs = ["dep:fatfs"]
ext4_rs = ["dep:ext4_rs", "devfs", "ramfs", "procfs", "sysfs"]
ext4fs = ["dep:lwext4_rust", "devfs", "ramfs", "procfs", "sysfs",]
default = ["devfs", "ramfs", "fatfs", "procfs", "sysfs"]

Expand All @@ -33,6 +34,7 @@ axconfig = { path = "../axconfig", optional = true }
axfs_vfs = { path = "../../crates/axfs_vfs" }
axfs_devfs = { path = "../../crates/axfs_devfs", optional = true }
axfs_ramfs = { path = "../../crates/axfs_ramfs", optional = true }
ext4_rs = { git = "https://github.com/yuoo655/ext4_rs.git", rev= "6bcc7f5", optional = true }
lwext4_rust = { git = "https://github.com/elliott10/lwext4_rust.git", rev = "f3048f87", optional = true }
axdriver = { path = "../axdriver", features = ["block"] }
axsync = { path = "../axsync" }
Expand Down
22 changes: 22 additions & 0 deletions modules/axfs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ impl Disk {
};
Ok(write_size)
}

/// Read a single block starting from the specified offset.
pub fn read_offset(&mut self, offset: usize) -> [u8; BLOCK_SIZE] {
let block_id = offset / BLOCK_SIZE;
let mut block_data = [0u8; BLOCK_SIZE];
self.dev
.read_block(block_id as u64, &mut block_data)
.unwrap();
block_data
}

/// Write single block starting from the specified offset.
pub fn write_offset(&mut self, offset: usize, buf: &[u8]) -> DevResult<usize> {
assert!(
buf.len() == BLOCK_SIZE,
"Buffer length must be equal to BLOCK_SIZE"
);
assert!(offset % BLOCK_SIZE == 0);
let block_id = offset / BLOCK_SIZE;
self.dev.write_block(block_id as u64, buf).unwrap();
Ok(buf.len())
}
}
Loading

0 comments on commit 3d93061

Please sign in to comment.