File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use alloc::sync::Arc;
99use alloc:: vec:: Vec ;
1010use async_trait:: async_trait;
1111use core:: ffi:: c_char;
12- use libkernel:: fs:: OpenFlags ;
12+ use libkernel:: fs:: { OpenFlags , SeekFrom } ;
1313use libkernel:: memory:: address:: { TUA , UA } ;
1414
1515pub struct MemFd {
@@ -70,6 +70,25 @@ impl FileOps for MemFd {
7070 data. resize ( new_size, 0 ) ;
7171 Ok ( ( ) )
7272 }
73+
74+ async fn seek ( & mut self , ctx : & mut FileCtx , pos : SeekFrom ) -> libkernel:: error:: Result < u64 > {
75+ fn saturating_add_signed ( u : u64 , i : i64 ) -> u64 {
76+ if i >= 0 {
77+ u. saturating_add ( i as u64 )
78+ } else {
79+ u. saturating_sub ( ( -i) as u64 )
80+ }
81+ }
82+
83+ let size = self . data . lock ( ) . await . len ( ) as u64 ;
84+ ctx. pos = match pos {
85+ SeekFrom :: Start ( x) => x,
86+ SeekFrom :: End ( x) => saturating_add_signed ( size, x) ,
87+ SeekFrom :: Current ( x) => saturating_add_signed ( ctx. pos , x) ,
88+ } ;
89+
90+ Ok ( ctx. pos )
91+ }
7392}
7493
7594pub async fn sys_memfd_create (
You can’t perform that action at this time.
0 commit comments