mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 09:23:25 +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 {
|
fn metadata(&self) -> Metadata {
|
||||||
self.metadata
|
let mut metadata = self.metadata;
|
||||||
|
metadata.mode = *self.mode.read();
|
||||||
|
|
||||||
|
metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ino(&self) -> u64 {
|
fn ino(&self) -> u64 {
|
||||||
@ -481,12 +484,14 @@ impl Inode for SysFsInode {
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut last_ino = start_ino;
|
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 {
|
for dentry in dentries {
|
||||||
// The offset reported back to the caller should be the absolute position
|
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, dentry.ino as usize);
|
||||||
let next_offset = (dentry.ino + 1) as usize;
|
|
||||||
let res = visitor.visit(&dentry.name, dentry.ino, dentry.type_, next_offset);
|
|
||||||
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
@ -500,11 +505,11 @@ impl Inode for SysFsInode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
Ok(0)
|
return Ok(0);
|
||||||
} else {
|
|
||||||
// Return absolute offset instead of an increment
|
|
||||||
Ok((last_ino + 1) as usize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let next_ino = last_ino + 1;
|
||||||
|
Ok((next_ino - start_ino) as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_link(&self) -> Result<String> {
|
fn read_link(&self) -> Result<String> {
|
||||||
|
Reference in New Issue
Block a user