Skip to content

Commit e2ae639

Browse files
feat(ext2): fill in the timestamp fields for stat
Signed-off-by: Anhad Singh <[email protected]>
1 parent a758ca8 commit e2ae639

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/aero_kernel/src/arch/x86_64/apic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub fn init() -> ApicType {
450450

451451
log::debug!("apic: detected APIC (addr={address_phys:?}, type={apic_type:?})");
452452

453-
let address_virt = unsafe { PHYSICAL_MEMORY_OFFSET } + address_phys.as_u64();
453+
let address_virt = address_phys.as_hhdm_virt();
454454
let mut local_apic = LocalApic::new(address_virt, apic_type);
455455

456456
local_apic.init();

src/aero_kernel/src/fs/ext2/disk.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717

18+
use core::time::Duration;
19+
1820
use bit_field::BitField;
1921

2022
use crate::fs::inode;
@@ -199,10 +201,10 @@ impl From<FileType> for inode::FileType {
199201
pub struct INode {
200202
type_and_perm: u16,
201203
pub user_id: u16,
202-
pub size_lower: u32,
203-
pub last_access: u32,
204+
size_lower: u32,
205+
last_access: u32,
204206
pub creation_time: u32,
205-
pub last_modification: u32,
207+
last_modification: u32,
206208
pub deletion_time: u32,
207209
pub group_id: u16,
208210
pub hl_count: u16,
@@ -253,6 +255,21 @@ impl INode {
253255
_ => FileType::Unknown,
254256
}
255257
}
258+
259+
#[inline]
260+
pub fn last_access(&self) -> Duration {
261+
Duration::from_secs(self.last_access as u64)
262+
}
263+
264+
#[inline]
265+
pub fn last_modification(&self) -> Duration {
266+
Duration::from_secs(self.last_modification as u64)
267+
}
268+
269+
#[inline]
270+
pub fn creation_time(&self) -> Duration {
271+
Duration::from_secs(self.creation_time as u64)
272+
}
256273
}
257274

258275
const_assert_eq!(core::mem::size_of::<INode>(), 128);

src/aero_kernel/src/fs/ext2/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl INodeInterface for INode {
380380
let inode = self.inode.read();
381381

382382
let filesystem = self.fs.upgrade().unwrap();
383-
let filetype = self.metadata()?.file_type();
383+
let filetype = inode.file_type().into();
384384

385385
let mut mode = Mode::empty();
386386

@@ -401,6 +401,10 @@ impl INodeInterface for INode {
401401
st_size: inode.size() as _,
402402
st_mode: mode,
403403

404+
st_atim: inode.last_access().into(),
405+
st_mtim: inode.last_modification().into(),
406+
st_ctim: inode.creation_time().into(),
407+
404408
..Default::default()
405409
})
406410
}

src/aero_syscall/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub mod time;
3232

3333
pub type Result<T> = core::result::Result<T, SyscallError>;
3434

35+
use core::time::Duration;
36+
3537
use byte_endian::BigEndian;
3638

3739
pub use crate::syscall::*;
@@ -272,6 +274,16 @@ pub struct TimeSpec {
272274
pub tv_nsec: isize,
273275
}
274276

277+
impl From<Duration> for TimeSpec {
278+
#[inline]
279+
fn from(value: Duration) -> Self {
280+
TimeSpec {
281+
tv_sec: value.as_secs() as isize,
282+
tv_nsec: value.subsec_nanos() as isize,
283+
}
284+
}
285+
}
286+
275287
#[repr(usize)]
276288
#[derive(Debug, Copy, Clone)]
277289
pub enum SeekWhence {

0 commit comments

Comments
 (0)