1
- use core:: { any:: Any , ffi:: c_int, sync:: atomic:: { AtomicUsize , Ordering } } ;
2
-
3
- use alloc:: { string:: String , sync:: { Arc , Weak } } ;
1
+ use core:: {
2
+ any:: Any ,
3
+ ffi:: c_int,
4
+ sync:: atomic:: { AtomicUsize , Ordering } ,
5
+ } ;
6
+
7
+ use alloc:: {
8
+ string:: String ,
9
+ sync:: { Arc , Weak } ,
10
+ } ;
4
11
use axerrno:: { LinuxError , LinuxResult } ;
5
12
use axfs:: fops:: DirEntry ;
6
13
use axio:: PollState ;
14
+ use axio:: SeekFrom ;
7
15
use axsync:: { Mutex , MutexGuard } ;
8
16
use linux_raw_sys:: general:: S_IFDIR ;
9
- use axio:: SeekFrom ;
10
17
11
-
12
- use super :: { get_file_like, page_cache:: { PageCache , page_cache_manager} , FileLike , Kstat } ;
18
+ use super :: {
19
+ FileLike , Kstat , get_file_like,
20
+ page_cache:: { PageCache , page_cache_manager} ,
21
+ } ;
13
22
14
23
/// File wrapper for `axfs::fops::File`.
15
24
pub struct File {
@@ -24,9 +33,9 @@ pub struct File {
24
33
impl File {
25
34
pub fn new (
26
35
inner : Option < Arc < Mutex < axfs:: fops:: File > > > ,
27
- path : String ,
36
+ path : String ,
28
37
is_direct : bool ,
29
- cache : Weak < PageCache >
38
+ cache : Weak < PageCache > ,
30
39
) -> Self {
31
40
debug ! ( "Starry-api open file {}" , path) ;
32
41
let size = {
@@ -84,7 +93,8 @@ impl File {
84
93
SeekFrom :: Start ( pos) => Some ( pos) ,
85
94
SeekFrom :: Current ( off) => offset. checked_add_signed ( off) ,
86
95
SeekFrom :: End ( off) => size. checked_add_signed ( off) ,
87
- } . unwrap ( ) ;
96
+ }
97
+ . unwrap ( ) ;
88
98
self . offset . store ( new_offset as usize , Ordering :: SeqCst ) ;
89
99
Ok ( new_offset as isize )
90
100
}
@@ -101,7 +111,7 @@ impl File {
101
111
if self . is_direct {
102
112
return Ok ( self . inner ( ) . read_at ( offset as u64 , buf) ?) ;
103
113
}
104
-
114
+
105
115
let cache = self . get_cache ( ) ;
106
116
Ok ( cache. read_at ( offset, buf) )
107
117
}
@@ -110,7 +120,7 @@ impl File {
110
120
if self . is_direct {
111
121
return Ok ( self . inner ( ) . write_at ( offset as u64 , buf) ?) ;
112
122
}
113
-
123
+
114
124
let cache = self . get_cache ( ) ;
115
125
Ok ( cache. write_at ( offset, buf) )
116
126
}
@@ -140,7 +150,7 @@ impl FileLike for File {
140
150
if self . is_direct {
141
151
return Ok ( self . inner ( ) . read ( buf) ?) ;
142
152
}
143
-
153
+
144
154
let cache = self . get_cache ( ) ;
145
155
let offset = self . offset . load ( Ordering :: SeqCst ) ;
146
156
let len = cache. write_at ( offset, buf) ;
@@ -152,7 +162,7 @@ impl FileLike for File {
152
162
if self . is_direct {
153
163
return Ok ( self . inner ( ) . write ( buf) ?) ;
154
164
}
155
-
165
+
156
166
let cache = self . get_cache ( ) ;
157
167
let offset = self . offset . load ( Ordering :: SeqCst ) ;
158
168
let len = cache. write_at ( offset, buf) ;
@@ -166,7 +176,7 @@ impl FileLike for File {
166
176
let cache = self . get_cache ( ) ;
167
177
return cache. stat ( ) ;
168
178
}
169
-
179
+
170
180
let metadata = self . inner ( ) . get_attr ( ) ?;
171
181
let ty = metadata. file_type ( ) as u8 ;
172
182
let perm = metadata. perm ( ) . bits ( ) as u32 ;
0 commit comments