Skip to content

Commit b8b8944

Browse files
committed
page_cache
1 parent 77e4d9f commit b8b8944

File tree

14 files changed

+297
-194
lines changed

14 files changed

+297
-194
lines changed

api/src/file/fs.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
use core::{any::Any, ffi::c_int, sync::atomic::{AtomicUsize, Ordering}};
2-
3-
use alloc::{string::String, sync::{Arc, Weak}};
1+
use core::{
2+
any::Any,
3+
ffi::c_int,
4+
sync::atomic::{AtomicUsize, Ordering},
5+
};
6+
7+
use alloc::{
8+
string::String,
9+
sync::{Arc, Weak},
10+
};
411
use axerrno::{LinuxError, LinuxResult};
512
use axfs::fops::DirEntry;
613
use axio::PollState;
14+
use axio::SeekFrom;
715
use axsync::{Mutex, MutexGuard};
816
use linux_raw_sys::general::S_IFDIR;
9-
use axio::SeekFrom;
1017

11-
12-
use super::{get_file_like, page_cache::{PageCache, page_cache_manager}, FileLike, Kstat};
18+
use super::{
19+
FileLike, Kstat, get_file_like,
20+
page_cache::{PageCache, page_cache_manager},
21+
};
1322

1423
/// File wrapper for `axfs::fops::File`.
1524
pub struct File {
@@ -24,9 +33,9 @@ pub struct File {
2433
impl File {
2534
pub fn new(
2635
inner: Option<Arc<Mutex<axfs::fops::File>>>,
27-
path: String,
36+
path: String,
2837
is_direct: bool,
29-
cache: Weak<PageCache>
38+
cache: Weak<PageCache>,
3039
) -> Self {
3140
debug!("Starry-api open file {}", path);
3241
let size = {
@@ -84,7 +93,8 @@ impl File {
8493
SeekFrom::Start(pos) => Some(pos),
8594
SeekFrom::Current(off) => offset.checked_add_signed(off),
8695
SeekFrom::End(off) => size.checked_add_signed(off),
87-
}.unwrap();
96+
}
97+
.unwrap();
8898
self.offset.store(new_offset as usize, Ordering::SeqCst);
8999
Ok(new_offset as isize)
90100
}
@@ -101,7 +111,7 @@ impl File {
101111
if self.is_direct {
102112
return Ok(self.inner().read_at(offset as u64, buf)?);
103113
}
104-
114+
105115
let cache = self.get_cache();
106116
Ok(cache.read_at(offset, buf))
107117
}
@@ -110,7 +120,7 @@ impl File {
110120
if self.is_direct {
111121
return Ok(self.inner().write_at(offset as u64, buf)?);
112122
}
113-
123+
114124
let cache = self.get_cache();
115125
Ok(cache.write_at(offset, buf))
116126
}
@@ -140,7 +150,7 @@ impl FileLike for File {
140150
if self.is_direct {
141151
return Ok(self.inner().read(buf)?);
142152
}
143-
153+
144154
let cache = self.get_cache();
145155
let offset = self.offset.load(Ordering::SeqCst);
146156
let len = cache.write_at(offset, buf);
@@ -152,7 +162,7 @@ impl FileLike for File {
152162
if self.is_direct {
153163
return Ok(self.inner().write(buf)?);
154164
}
155-
165+
156166
let cache = self.get_cache();
157167
let offset = self.offset.load(Ordering::SeqCst);
158168
let len = cache.write_at(offset, buf);
@@ -166,7 +176,7 @@ impl FileLike for File {
166176
let cache = self.get_cache();
167177
return cache.stat();
168178
}
169-
179+
170180
let metadata = self.inner().get_attr()?;
171181
let ty = metadata.file_type() as u8;
172182
let perm = metadata.perm().bits() as u32;

api/src/file/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod fs;
22
mod net;
3+
mod page_cache;
34
mod pipe;
45
mod stdio;
5-
mod page_cache;
66

77
use core::{any::Any, ffi::c_int};
88

@@ -17,8 +17,8 @@ use spin::RwLock;
1717
pub use self::{
1818
fs::{Directory, File},
1919
net::Socket,
20-
pipe::Pipe,
2120
page_cache::page_cache_manager,
21+
pipe::Pipe,
2222
};
2323

2424
pub const AX_FILE_LIMIT: usize = 1024;

0 commit comments

Comments
 (0)