Skip to content

Commit e12af34

Browse files
Merge pull request #258 from arihant2math/ext4plus-update
Update ext4plus to 0.1.0-alpha.5
2 parents 5becb38 + 654b31e commit e12af34

File tree

6 files changed

+60
-41
lines changed

6 files changed

+60
-41
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libkernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2024"
66
[dependencies]
77
async-trait = { workspace = true }
88
bitflags = { workspace = true }
9-
ext4plus = "0.1.0-alpha.2"
9+
ext4plus = "0.1.0-alpha.5"
1010
intrusive-collections = { version = "0.10.0", default-features = false }
1111
log = { workspace = true }
1212
object = { version = "0.38.0", default-features = false, features = ["core", "elf", "read_core"] }

libkernel/src/fs/filesystems/ext4/mod.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ use core::marker::PhantomData;
3131
use core::num::NonZeroU32;
3232
use core::ops::{Deref, DerefMut};
3333
use core::time::Duration;
34-
use ext4plus::{
35-
AsyncIterator, AsyncSkip, Dir, DirEntryName, Ext4, Ext4Read, Ext4Write, File, FollowSymlinks,
36-
InodeCreationOptions, InodeFlags, InodeMode, Metadata, ReadDir, write_at,
34+
use ext4plus::prelude::{
35+
AsyncIterator, AsyncSkip, Dir, DirEntryName, Ext4, Ext4Error, Ext4Read, Ext4Write, File,
36+
FollowSymlinks, Inode as ExtInode, InodeCreationOptions, InodeFlags, InodeMode, Metadata,
37+
PathBuf as ExtPathBuf, ReadDir, write_at,
3738
};
3839
use log::error;
3940

@@ -59,13 +60,13 @@ impl Ext4Write for BlockBuffer {
5960
}
6061
}
6162

62-
impl From<ext4plus::Ext4Error> for KernelError {
63-
fn from(err: ext4plus::Ext4Error) -> Self {
63+
impl From<Ext4Error> for KernelError {
64+
fn from(err: Ext4Error) -> Self {
6465
match err {
65-
ext4plus::Ext4Error::NotFound => KernelError::Fs(FsError::NotFound),
66-
ext4plus::Ext4Error::NotADirectory => KernelError::Fs(FsError::NotADirectory),
67-
ext4plus::Ext4Error::AlreadyExists => KernelError::Fs(FsError::AlreadyExists),
68-
ext4plus::Ext4Error::Corrupt(c) => {
66+
Ext4Error::NotFound => KernelError::Fs(FsError::NotFound),
67+
Ext4Error::NotADirectory => KernelError::Fs(FsError::NotADirectory),
68+
Ext4Error::AlreadyExists => KernelError::Fs(FsError::AlreadyExists),
69+
Ext4Error::Corrupt(c) => {
6970
error!("Corrupt EXT4 filesystem: {c}, likely a bug");
7071
KernelError::Fs(FsError::InvalidFs)
7172
}
@@ -143,34 +144,33 @@ impl DirStream for ReadDirWrapper {
143144
}
144145
}
145146

146-
#[expect(clippy::large_enum_variant)]
147147
enum InodeInner {
148148
Regular(File),
149149
Directory(Dir),
150-
Other(ext4plus::Inode),
150+
Other(ExtInode),
151151
}
152152

153153
impl InodeInner {
154-
async fn new(inode: ext4plus::Inode, fs: &Ext4) -> Self {
154+
async fn new(inode: ExtInode, fs: &Ext4) -> Self {
155155
match inode.file_type() {
156156
ext4plus::FileType::Regular => {
157157
InodeInner::Regular(File::open_inode(fs, inode).unwrap())
158158
}
159159
ext4plus::FileType::Directory => {
160-
InodeInner::Directory(Dir::open(fs.clone(), inode).await.unwrap())
160+
InodeInner::Directory(Dir::open_inode(fs, inode).await.unwrap())
161161
}
162162
_ => InodeInner::Other(inode),
163163
}
164164
}
165165
}
166166

167167
impl Deref for InodeInner {
168-
type Target = ext4plus::Inode;
168+
type Target = ExtInode;
169169

170170
fn deref(&self) -> &Self::Target {
171171
match self {
172172
InodeInner::Regular(f) => f.inode(),
173-
InodeInner::Directory(d) => d.as_ref(),
173+
InodeInner::Directory(d) => d.inode(),
174174
InodeInner::Other(i) => i,
175175
}
176176
}
@@ -180,7 +180,7 @@ impl DerefMut for InodeInner {
180180
fn deref_mut(&mut self) -> &mut Self::Target {
181181
match self {
182182
InodeInner::Regular(f) => f.inode_mut(),
183-
InodeInner::Directory(d) => d.as_mut(),
183+
InodeInner::Directory(d) => d.inode_mut(),
184184
InodeInner::Other(i) => i,
185185
}
186186
}
@@ -190,7 +190,7 @@ pub struct Ext4Inode<CPU: CpuOps> {
190190
fs_ref: Weak<Ext4Filesystem<CPU>>,
191191
id: NonZeroU32,
192192
inner: Mutex<InodeInner, CPU>,
193-
path: ext4plus::PathBuf,
193+
path: ExtPathBuf,
194194
}
195195

196196
#[async_trait]
@@ -311,6 +311,7 @@ where
311311
name: &str,
312312
file_type: FileType,
313313
permissions: FilePermissions,
314+
time: Option<Duration>,
314315
) -> Result<Arc<dyn Inode>> {
315316
let fs = self.fs_ref.upgrade().unwrap();
316317
let mut inner = self.inner.lock().await;
@@ -326,14 +327,14 @@ where
326327
mode: InodeMode::S_IFREG | InodeMode::from_bits(permissions.bits()).unwrap(),
327328
uid: 0,
328329
gid: 0,
329-
time: Default::default(),
330+
time: time.unwrap_or_default(),
330331
flags: InodeFlags::empty(),
331332
})
332333
.await?;
333334
InodeInner::Regular(File::open_inode(&fs.inner, inode)?)
334335
} else if matches!(file_type, FileType::Directory) {
335-
let old_links_count = inner_dir.as_ref().links_count();
336-
inner_dir.as_mut().set_links_count(old_links_count + 1);
336+
let old_links_count = inner_dir.inode().links_count();
337+
inner_dir.inode_mut().set_links_count(old_links_count + 1);
337338
let inode = fs
338339
.inner
339340
.create_inode(InodeCreationOptions {
@@ -377,7 +378,7 @@ where
377378
if inode.id().fs_id() != fs.id() {
378379
return Err(KernelError::Fs(FsError::CrossDevice));
379380
}
380-
let mut other_inode = ext4plus::Inode::read(
381+
let mut other_inode = ExtInode::read(
381382
&fs.inner,
382383
(inode.id().inode_id() as u32).try_into().unwrap(),
383384
)
@@ -445,12 +446,12 @@ where
445446
let old_parent_id = old_parent.id();
446447
let fs = self.fs_ref.upgrade().unwrap();
447448

448-
let old_parent_inode = ext4plus::Inode::read(
449+
let old_parent_inode = ExtInode::read(
449450
&fs.inner,
450451
(old_parent_id.inode_id() as u32).try_into().unwrap(),
451452
)
452453
.await?;
453-
let old_parent_dir = Dir::open(fs.inner.clone(), old_parent_inode).await?;
454+
let old_parent_dir = Dir::open_inode(&fs.inner, old_parent_inode).await?;
454455

455456
let inner = self.inner.lock().await;
456457
let inner_dir = match &*inner {
@@ -548,7 +549,7 @@ where
548549
.symlink(
549550
inner_dir,
550551
DirEntryName::try_from(name.as_bytes()).unwrap(),
551-
ext4plus::PathBuf::new(target.as_str().as_bytes()),
552+
ExtPathBuf::new(target.as_str().as_bytes()),
552553
0,
553554
0,
554555
Duration::from_secs(0),
@@ -618,7 +619,7 @@ where
618619
fs_ref: self.this.clone(),
619620
id: root.index,
620621
inner: Mutex::new(InodeInner::new(root, &self.inner).await),
621-
path: ext4plus::PathBuf::new("/"),
622+
path: ExtPathBuf::new("/"),
622623
}))
623624
}
624625

libkernel/src/fs/filesystems/tmpfs.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use alloc::{
2323
vec::Vec,
2424
};
2525
use async_trait::async_trait;
26+
use core::time::Duration;
2627
use core::{
2728
cmp::min,
2829
marker::PhantomData,
@@ -423,6 +424,7 @@ where
423424
name: &str,
424425
file_type: FileType,
425426
mode: FilePermissions,
427+
_time: Option<Duration>,
426428
) -> Result<Arc<dyn Inode>> {
427429
let mut entries = self.entries.lock_save_irq();
428430

@@ -988,6 +990,7 @@ mod tests {
988990
"test_file.txt",
989991
FileType::File,
990992
FilePermissions::from_bits_retain(0),
993+
None,
991994
)
992995
.await
993996
.expect("Create failed");
@@ -1006,12 +1009,17 @@ mod tests {
10061009
let fs = setup_fs();
10071010
let root = fs.root_inode().await.unwrap();
10081011

1009-
root.create("dup", FileType::File, FilePermissions::from_bits_retain(0))
1010-
.await
1011-
.unwrap();
1012+
root.create(
1013+
"dup",
1014+
FileType::File,
1015+
FilePermissions::from_bits_retain(0),
1016+
None,
1017+
)
1018+
.await
1019+
.unwrap();
10121020

10131021
let res = root
1014-
.create("dup", FileType::File, FilePermissions::empty())
1022+
.create("dup", FileType::File, FilePermissions::empty(), None)
10151023
.await;
10161024
assert!(res.is_err(), "Should not allow duplicate file creation");
10171025
}
@@ -1023,13 +1031,18 @@ mod tests {
10231031

10241032
// Create /subdir
10251033
let subdir = root
1026-
.create("subdir", FileType::Directory, FilePermissions::empty())
1034+
.create(
1035+
"subdir",
1036+
FileType::Directory,
1037+
FilePermissions::empty(),
1038+
None,
1039+
)
10271040
.await
10281041
.unwrap();
10291042

10301043
// Create /subdir/inner
10311044
let inner = subdir
1032-
.create("inner", FileType::File, FilePermissions::empty())
1045+
.create("inner", FileType::File, FilePermissions::empty(), None)
10331046
.await
10341047
.unwrap();
10351048

@@ -1045,13 +1058,13 @@ mod tests {
10451058
let root = fs.root_inode().await.unwrap();
10461059

10471060
// Create files in "random" order
1048-
root.create("c.txt", FileType::File, FilePermissions::empty())
1061+
root.create("c.txt", FileType::File, FilePermissions::empty(), None)
10491062
.await
10501063
.unwrap();
1051-
root.create("a.txt", FileType::File, FilePermissions::empty())
1064+
root.create("a.txt", FileType::File, FilePermissions::empty(), None)
10521065
.await
10531066
.unwrap();
1054-
root.create("b.dir", FileType::Directory, FilePermissions::empty())
1067+
root.create("b.dir", FileType::Directory, FilePermissions::empty(), None)
10551068
.await
10561069
.unwrap();
10571070

@@ -1076,11 +1089,11 @@ mod tests {
10761089
let root = fs.root_inode().await.unwrap();
10771090

10781091
let f1 = root
1079-
.create("f1", FileType::File, FilePermissions::empty())
1092+
.create("f1", FileType::File, FilePermissions::empty(), None)
10801093
.await
10811094
.unwrap();
10821095
let f2 = root
1083-
.create("f2", FileType::File, FilePermissions::empty())
1096+
.create("f2", FileType::File, FilePermissions::empty(), None)
10841097
.await
10851098
.unwrap();
10861099

libkernel/src/fs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use alloc::vec::Vec;
3030
use alloc::{boxed::Box, string::String, sync::Arc};
3131
use async_trait::async_trait;
3232
use attr::{FileAttr, FilePermissions};
33+
use core::time::Duration;
3334

3435
bitflags::bitflags! {
3536
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -256,6 +257,7 @@ pub trait Inode: Send + Sync + Any {
256257
_name: &str,
257258
_file_type: FileType,
258259
_permissions: FilePermissions,
260+
_time: Option<Duration>,
259261
) -> Result<Arc<dyn Inode>> {
260262
Err(KernelError::NotSupported)
261263
}

src/fs/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::clock::realtime::date;
12
use crate::{
23
drivers::{DM, Driver},
34
process::Task,
@@ -351,7 +352,9 @@ impl VFS {
351352
return Err(FsError::NotADirectory.into());
352353
}
353354

354-
parent_inode.create(file_name, FileType::File, mode).await?
355+
parent_inode
356+
.create(file_name, FileType::File, mode, Some(date()))
357+
.await?
355358
} else {
356359
// O_CREAT was not specified, so NotFound is the correct error.
357360
return Err(FsError::NotFound.into());
@@ -455,7 +458,7 @@ impl VFS {
455458

456459
// Delegate the creation to the filesystem-specific inode.
457460
parent_inode
458-
.create(dir_name, FileType::Directory, mode)
461+
.create(dir_name, FileType::Directory, mode, Some(date()))
459462
.await?;
460463

461464
Ok(())

0 commit comments

Comments
 (0)