-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "ramfs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[features] | ||
|
||
|
||
|
||
|
||
[dependencies] | ||
axstd = { path = "../../../ulib/axstd", optional = true, features = ["paging"] } | ||
axtask = { path = "../../../modules/axtask" } | ||
axalloc = { path = "../../../modules/axalloc" } | ||
axfs = { path = "../../../modules/axfs"} | ||
axio = { path = "../../../crates/axio", features = ["alloc"] } | ||
axdriver = { path = "../../../modules/axdriver", features = ["block", "ramdisk"]} | ||
driver_block = { path = "../../../crates/driver_block", features = ["ramdisk"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# From https://github.com/rafalh/rust-fatfs/blob/master/scripts/create-test-img.sh | ||
|
||
CUR_DIR=`dirname $0` | ||
|
||
echo $OUT_DIR | ||
|
||
create_test_img() { | ||
local name=$1 | ||
local blkcount=$2 | ||
local fatSize=$3 | ||
dd if=/dev/zero of="$name" bs=1024 count=$blkcount | ||
mkfs.vfat -s 1 -F $fatSize -n "Test!" -i 12345678 "$name" | ||
mkdir -p mnt | ||
sudo mount -o loop "$name" mnt -o rw,uid=$USER,gid=$USER | ||
for i in $(seq 1 1000); do | ||
echo "Rust is cool!" >>"mnt/long.txt" | ||
done | ||
echo "Rust is cool!" >>"mnt/short.txt" | ||
mkdir -p "mnt/very/long/path" | ||
echo "Rust is cool!" >>"mnt/very/long/path/test.txt" | ||
mkdir -p "mnt/very-long-dir-name" | ||
echo "Rust is cool!" >>"mnt/very-long-dir-name/very-long-file-name.txt" | ||
|
||
sudo umount mnt | ||
} | ||
|
||
create_test_img "$CUR_DIR/fat16.img" 2500 16 | ||
create_test_img "$CUR_DIR/fat32.img" 34000 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.align 4 | ||
.section .data | ||
.global fs_ | ||
fs_: | ||
.quad 2 | ||
.quad fs_start | ||
|
||
.section .data | ||
.global fs_start | ||
.global fs_end | ||
fs_start: | ||
.incbin "apps/fs/ramfs/fat32.img" | ||
fs_end: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![cfg_attr(feature = "axstd", no_std)] | ||
#![cfg_attr(feature = "axstd", no_main)] | ||
|
||
#[cfg(feature = "axstd")] | ||
use axstd::println; | ||
|
||
#[macro_use] | ||
extern crate alloc; | ||
|
||
use core::arch::global_asm; | ||
global_asm!(include_str!("link_fs.S")); | ||
|
||
use axdriver::AxDeviceContainer; | ||
use axfs::api as fs; | ||
use axio as io; | ||
use driver_block::ramdisk::RamDisk; | ||
|
||
use io::Result; | ||
|
||
fn test_read_dir() -> Result<()> { | ||
let dir = "/././//./"; | ||
println!("list directory {:?}:", dir); | ||
for entry in fs::read_dir(dir)? { | ||
let entry = entry?; | ||
println!(" {}", entry.file_name()); | ||
} | ||
println!("test_read_dir() OK!"); | ||
Ok(()) | ||
} | ||
|
||
|
||
#[cfg_attr(feature = "axstd", no_mangle)] | ||
fn main() { | ||
println!("Hello, world!"); | ||
|
||
extern "C" { | ||
fn fs_(); | ||
fn fs_start(); | ||
fn fs_end(); | ||
} | ||
println!("fs addr {:#x?}", fs_ as usize); | ||
println!("fs_start {:#x?}", fs_start as usize); | ||
println!("fs_start {:#x?}", fs_end as usize); | ||
|
||
let fs_data: &[u8] = unsafe { | ||
core::slice::from_raw_parts(fs_start as *mut u8, fs_end as usize - fs_start as usize) | ||
}; | ||
|
||
let ramdisk = RamDisk::from(&fs_data); | ||
axfs::init_filesystems(AxDeviceContainer::from_one(ramdisk)); | ||
|
||
test_read_dir().expect("test_read_dir() failed"); | ||
} |