Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加入索引缓存、引入路径抽象crate、重构ramfs #669

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
80bcf02
update .gitignore
Samuka007 Feb 29, 2024
cd9e85a
优化inode索引
Samuka007 Feb 29, 2024
5636dec
rubust link
Samuka007 Feb 29, 2024
451ff37
暂时保存
Samuka007 Mar 2, 2024
d6a968e
完成缓存初步设计
Samuka007 Mar 2, 2024
e6d14de
通过编译 未能启动
Samuka007 Mar 2, 2024
9b2784f
暂时保存同步
Samuka007 Mar 3, 2024
3900275
RamFS重构成Entry-Inode结构,未测试
Samuka007 Mar 5, 2024
8992a96
整合
Samuka007 Mar 5, 2024
27fd9c0
修复一些循环依赖问题,通过编译,未能启动。
Samuka007 Mar 5, 2024
0397ac3
Keyer 复制比较,牺牲性能换取成功进入系统()
Samuka007 Mar 6, 2024
a530778
Merge branch 'DragonOS-Community:master' into master
Samuka007 Mar 6, 2024
45ad814
明晰了要做的地方,设计好了api(虽然很丑
Samuka007 Mar 6, 2024
4806431
Keyer引用比较的修复
Samuka007 Mar 7, 2024
f4308d0
cache 设计完毕,开始设计api
Samuka007 Mar 8, 2024
2ac1e9c
finish cache
Samuka007 Mar 9, 2024
f323dfd
vfs cache编译通过且不影响运行
Samuka007 Mar 9, 2024
7fe7ac0
commit tests
Samuka007 Mar 10, 2024
3e18200
Merge branch 'master' of github.com:Samuka007/DragonOS
Samuka007 Mar 10, 2024
6f3c0a9
sync ignore
Samuka007 Mar 10, 2024
0dac25d
update test
Samuka007 Mar 10, 2024
3931293
Merge branch 'master' into fs-cache
Samuka007 Mar 10, 2024
91d8ada
clean
Samuka007 Mar 12, 2024
979814e
删除不必要注释
Samuka007 Mar 12, 2024
4beaa3c
Merge branch 'DragonOS-Community:master' into fs-cache
Samuka007 Mar 12, 2024
939eeff
一些边缘工作
Samuka007 Mar 12, 2024
4deb2f8
补充stage
Samuka007 Mar 12, 2024
2778cae
删除无用import
Samuka007 Mar 12, 2024
90d5e74
remove a problem todo!
Samuka007 Mar 12, 2024
e38c5c2
tmp
Samuka007 Mar 13, 2024
4534d44
tmp'
Samuka007 Mar 13, 2024
ce93f53
tmp3
Samuka007 Mar 13, 2024
29d40f6
优化
Samuka007 Mar 13, 2024
cb81a1f
make even more changes in fs
Samuka007 Mar 14, 2024
c46f601
tmp save
Samuka007 Mar 18, 2024
8d46789
runable
Samuka007 Mar 19, 2024
743b60b
Merge branch 'master' of github.com:Samuka007/DragonOS into fs-cache
Samuka007 Mar 19, 2024
e3dc30e
跑通了!!!
Samuka007 Mar 20, 2024
6093e51
基本完成功能,功能测试通过;性能待测试
Samuka007 Mar 20, 2024
2ce5753
一些收尾工作
Samuka007 Mar 20, 2024
b803ac7
after merge
Samuka007 Mar 20, 2024
46c713a
fix unstable problem, sqlite3 test success
Samuka007 Mar 21, 2024
82324bc
fmt
Samuka007 Mar 22, 2024
7d08f35
去除了一个无用api
Samuka007 Mar 24, 2024
a4f52a9
merge clippy patch
Samuka007 Mar 24, 2024
06637e8
支持装载
Samuka007 Mar 24, 2024
ae3ea1f
使用path_base重构FS
Samuka007 Mar 25, 2024
4c59305
fix bugs, now partly able to run test_ramfs v2
Samuka007 Mar 25, 2024
467e0a2
clean uneccesary debug msg
Samuka007 Mar 25, 2024
fd1fe90
增强稳定性,修复路径索引bug
Samuka007 Mar 26, 2024
726b700
merge mainline
Samuka007 Mar 26, 2024
47792ad
tmp
Samuka007 Mar 26, 2024
debbd14
tmp2
Samuka007 Mar 26, 2024
242d770
fix conflicts
Samuka007 Mar 26, 2024
fcbd86c
clean patch
Samuka007 Mar 26, 2024
7042327
make fmt
Samuka007 Mar 26, 2024
110daa1
修复bug,我这辈子就是被clippy害了.jpg
Samuka007 Mar 27, 2024
3448cec
fmt code
Samuka007 Mar 27, 2024
5787cb8
clean code
Samuka007 Mar 27, 2024
b069f23
Merge remote-tracking branch 'origin/fs-cache-patch' into fs-cache-patch
Samuka007 Mar 27, 2024
eadd0b3
1
fslongjin Apr 4, 2024
ab791ab
patch
Samuka007 Apr 6, 2024
6250b71
merge
Samuka007 Apr 6, 2024
b128b9e
优化接口设计,完善注释
Samuka007 Apr 7, 2024
0ad027c
merge
Samuka007 Apr 7, 2024
46ec842
美化import项
Samuka007 Apr 7, 2024
de0ec89
修复了一个可能导致未定义行为的bug
Samuka007 Apr 7, 2024
bc7af85
rename vfs::cache -> vfs::dcache
Samuka007 Apr 7, 2024
b0caae5
riscv fmt check
Samuka007 Apr 7, 2024
8ac0b18
修改,使之可读性与可维护性提高
Samuka007 Apr 8, 2024
c3d0907
优化dcache, 但先把接口合并吧,dcache转为使用hashbrown还需要一点时间
Samuka007 Apr 8, 2024
aeb1757
将dentry层缝到了mountfs中
Samuka007 Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ida = { path = "src/libs/ida" }
intertrait = { path = "src/libs/intertrait" }
kdepends = { path = "crates/kdepends" }
klog_types = { path = "crates/klog_types" }
path_base = { path = "crates/path_base" }
linkme = "=0.2"
num = { version = "=0.4.0", default-features = false }
num-derive = "=0.3"
Expand Down
6 changes: 6 additions & 0 deletions kernel/crates/path_base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "path_base"
version = "0.1.0"
edition = "2021"

[dependencies]
266 changes: 266 additions & 0 deletions kernel/crates/path_base/src/clean_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
#![forbid(unsafe_code)]

//! `clean-path` is a safe fork of the
//! [`path-clean`](https://crates.io/crates/path-clean) crate.
//!
//! # About
//!
//! This fork aims to provide the same utility as
//! [`path-clean`](https://crates.io/crates/path-clean), without using unsafe. Additionally, the api
//! is improved ([`clean`] takes `AsRef<Path>` instead of just `&str`) and `Clean` is implemented on
//! `Path` in addition to just `PathBuf`.
//!
//! The main cleaning procedure is implemented using the methods provided by `PathBuf`, thus it should
//! bring portability benefits over [`path-clean`](https://crates.io/crates/path-clean) w.r.t. correctly
//! handling cross-platform filepaths. However, the current implementation is not highly-optimized, so
//! if performance is top-priority, consider using [`path-clean`](https://crates.io/crates/path-clean)
//! instead.
//!
//! # Specification
//!
//! The cleaning works as follows:
//! 1. Reduce multiple slashes to a single slash.
//! 2. Eliminate `.` path name elements (the current directory).
//! 3. Eliminate `..` path name elements (the parent directory) and the non-`.` non-`..`, element that precedes them.
//! 4. Eliminate `..` elements that begin a rooted path, that is, replace `/..` by `/` at the beginning of a path.
//! 5. Leave intact `..` elements that begin a non-rooted path.
//!
//! If the result of this process is an empty string, return the
//! string `"."`, representing the current directory.
//!
//! This transformation is performed lexically, without touching the filesystem. Therefore it doesn't do
//! any symlink resolution or absolute path resolution. For more information you can see ["Getting
//! Dot-Dot Right"](https://9p.io/sys/doc/lexnames.html).
//!
//! This functionality is exposed in the [`clean`] function and [`Clean`] trait implemented for
//! [`crate::PathBuf`] and [`crate::Path`].
//!
//!
//! # Example
//!
//! ```rust
//! use path_base::{Path, PathBuf};
//! use path_base::clean_path::{clean, Clean};
//!
//! assert_eq!(clean("foo/../../bar"), PathBuf::from("../bar"));
//! assert_eq!(Path::new("hello/world/..").clean(), PathBuf::from("hello"));
//! assert_eq!(
//! PathBuf::from("/test/../path/").clean(),
//! PathBuf::from("/path")
//! );
//! ```

use crate::{Path, PathBuf};

/// The Clean trait implements the `clean` method.
pub trait Clean {
fn clean(&self) -> PathBuf;
}

/// Clean implemented for PathBuf
impl Clean for PathBuf {
fn clean(&self) -> PathBuf {
clean(self)
}
}

/// Clean implemented for PathBuf
impl Clean for Path {
fn clean(&self) -> PathBuf {
clean(self)
}
}

/**
Clean the given path to according to a set of rules:
1. Reduce multiple slashes to a single slash.
2. Eliminate `.` path name elements (the current directory).
3. Eliminate `..` path name elements (the parent directory) and the non-`.` non-`..`, element that precedes them.
4. Eliminate `..` elements that begin a rooted path, that is, replace `/..` by `/` at the beginning of a path.
5. Leave intact `..` elements that begin a non-rooted path.

If the result of this process is an empty string, return the string `"."`, representing the current directory.

Note that symlinks and absolute paths are not resolved.

# Example

```rust
# use path_base::PathBuf;
# use path_base::clean_path::{clean, Clean};
assert_eq!(clean("foo/../../bar"), PathBuf::from("../bar"));
```
*/
pub fn clean<P: AsRef<Path>>(path: P) -> PathBuf {
let path = path.as_ref();
clean_internal(path)
}

/// The core implementation.
fn clean_internal(path: &Path) -> PathBuf {
// based off of github.com/rust-lang/cargo/blob/fede83/src/cargo/util/paths.rs#L61
use crate::Component;

let mut components = path.components().peekable();
let mut cleaned = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();
PathBuf::from(c.as_os_str())
} else {
PathBuf::new()
};

// amount of leading parentdir components in `cleaned`
let mut dotdots = 0;
// amount of components in `cleaned`
// invariant: component_count >= dotdots
let mut component_count = 0;

for component in components {
match component {
Component::Prefix(..) => unreachable!(),
Component::RootDir => {
cleaned.push(component.as_os_str());
component_count += 1;
}
Component::CurDir => {}
Component::ParentDir if component_count == 1 && cleaned.is_absolute() => {}
Component::ParentDir if component_count == dotdots => {
cleaned.push("..");
dotdots += 1;
component_count += 1;
}
Component::ParentDir => {
cleaned.pop();
component_count -= 1;
}
Component::Normal(c) => {
cleaned.push(c);
component_count += 1;
}
}
}

if component_count == 0 {
cleaned.push(".");
}

cleaned
}

#[cfg(test)]
mod tests {
use alloc::vec;

use super::{clean, Clean};
use crate::PathBuf;

#[test]
fn test_empty_path_is_current_dir() {
assert_eq!(clean(""), PathBuf::from("."));
}

#[test]
fn test_clean_paths_dont_change() {
let tests = vec![(".", "."), ("..", ".."), ("/", "/")];

for test in tests {
assert_eq!(
clean(test.0),
PathBuf::from(test.1),
"clean({}) == {}",
test.0,
test.1
);
}
}

#[test]
fn test_replace_multiple_slashes() {
let tests = vec![
("/", "/"),
("//", "/"),
("///", "/"),
(".//", "."),
("//..", "/"),
("..//", ".."),
("/..//", "/"),
("/.//./", "/"),
("././/./", "."),
("path//to///thing", "path/to/thing"),
("/path//to///thing", "/path/to/thing"),
];

for test in tests {
assert_eq!(
clean(test.0),
PathBuf::from(test.1),
"clean({}) == {}",
test.0,
test.1
);
}
}

#[test]
fn test_eliminate_current_dir() {
let tests = vec![
("./", "."),
("/./", "/"),
("./test", "test"),
("./test/./path", "test/path"),
("/test/./path/", "/test/path"),
("test/path/.", "test/path"),
];

for test in tests {
assert_eq!(
clean(test.0),
PathBuf::from(test.1),
"clean({}) == {}",
test.0,
test.1
);
}
}

#[test]
fn test_eliminate_parent_dir() {
let tests = vec![
("/..", "/"),
("/../test", "/test"),
("test/..", "."),
("test/path/..", "test"),
("test/../path", "path"),
("/test/../path", "/path"),
("test/path/../../", "."),
("test/path/../../..", ".."),
("/test/path/../../..", "/"),
("/test/path/../../../..", "/"),
("test/path/../../../..", "../.."),
("test/path/../../another/path", "another/path"),
("test/path/../../another/path/..", "another"),
("../test", "../test"),
("../test/", "../test"),
("../test/path", "../test/path"),
("../test/..", ".."),
];

for test in tests {
assert_eq!(
clean(test.0),
PathBuf::from(test.1),
"clean({}) == {}",
test.0,
test.1
);
}
}

#[test]
fn test_trait() {
assert_eq!(
PathBuf::from("/test/../path/").clean(),
PathBuf::from("/path")
);
}
}
Loading
Loading