mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 01:13:23 +00:00
Fix some potential bugs of sysfs
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
01328ee404
commit
3b1248ba7c
@ -308,7 +308,10 @@ impl Inode for SysFsInode {
|
||||
}
|
||||
|
||||
fn metadata(&self) -> Metadata {
|
||||
self.metadata
|
||||
let mut metadata = self.metadata;
|
||||
metadata.mode = *self.mode.read();
|
||||
|
||||
metadata
|
||||
}
|
||||
|
||||
fn ino(&self) -> u64 {
|
||||
@ -481,12 +484,14 @@ impl Inode for SysFsInode {
|
||||
let mut count = 0;
|
||||
let mut last_ino = start_ino;
|
||||
|
||||
let iter = self.new_dentry_iter(start_ino + 1);
|
||||
let dentries = {
|
||||
let mut dentries: Vec<_> = self.new_dentry_iter(start_ino).collect();
|
||||
dentries.sort_by_key(|d| d.ino);
|
||||
dentries
|
||||
};
|
||||
|
||||
for dentry in iter {
|
||||
// The offset reported back to the caller should be the absolute position
|
||||
let next_offset = (dentry.ino + 1) as usize;
|
||||
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, next_offset);
|
||||
for dentry in dentries {
|
||||
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, dentry.ino as usize);
|
||||
|
||||
if res.is_err() {
|
||||
if count == 0 {
|
||||
@ -500,11 +505,11 @@ impl Inode for SysFsInode {
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
Ok(0)
|
||||
} else {
|
||||
// Return absolute offset instead of an increment
|
||||
Ok((last_ino + 1) as usize)
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
let next_ino = last_ino + 1;
|
||||
Ok((next_ino - start_ino) as usize)
|
||||
}
|
||||
|
||||
fn read_link(&self) -> Result<String> {
|
||||
|
Reference in New Issue
Block a user