@@ -32,33 +32,33 @@ pub(crate) type Result<T> = std::result::Result<T, Errno>;
32
32
#[ async_trait]
33
33
pub ( crate ) trait RawFileSystem : Send + Sync {
34
34
/// Init the file system
35
- async fn init ( & self ) ;
35
+ async fn init ( & self ) -> Result < ( ) > ;
36
36
37
- /// Get the file path by file id
37
+ /// Get the file path by file id, if the file id is valid, return the file path
38
38
async fn get_file_path ( & self , file_id : u64 ) -> String ;
39
39
40
- /// Validate the file id and file handle, if the file id or file handle is invalid , return error
40
+ /// Validate the file id and file handle, if the file id and file handle is valid , return success
41
41
async fn valid_file_id ( & self , file_id : u64 , fh : u64 ) -> Result < ( ) > ;
42
42
43
- /// Get the file stat by file id
43
+ /// Get the file stat by file id. if the file id is valid, return the file stat
44
44
async fn stat ( & self , file_id : u64 ) -> Result < FileStat > ;
45
45
46
- /// Get the file stat by parent file id and file name
46
+ /// Lookup the file by parent file id and file name, if the file is exist, return the file stat
47
47
async fn lookup ( & self , parent_file_id : u64 , name : & str ) -> Result < FileStat > ;
48
48
49
- /// Read the directory by file id
49
+ /// Read the directory by file id, if the file id is a valid directory, return the file stat list
50
50
async fn read_dir ( & self , dir_file_id : u64 ) -> Result < Vec < FileStat > > ;
51
51
52
- /// Open the file by file id and flags
52
+ /// Open the file by file id and flags, if the file id is a valid file, return the file handle
53
53
async fn open_file ( & self , file_id : u64 , flags : u32 ) -> Result < FileHandle > ;
54
54
55
- /// Open the directory by file id and flags
55
+ /// Open the directory by file id and flags, if successful, return the file handle
56
56
async fn open_dir ( & self , file_id : u64 , flags : u32 ) -> Result < FileHandle > ;
57
57
58
- /// Create the file by parent file id and file name and flags
58
+ /// Create the file by parent file id and file name and flags, if successful, return the file handle
59
59
async fn create_file ( & self , parent_file_id : u64 , name : & str , flags : u32 ) -> Result < FileHandle > ;
60
60
61
- /// Create the directory by parent file id and file name
61
+ /// Create the directory by parent file id and file name, if successful, return the file id
62
62
async fn create_dir ( & self , parent_file_id : u64 , name : & str ) -> Result < u64 > ;
63
63
64
64
/// Set the file attribute by file id and file stat
@@ -70,13 +70,13 @@ pub(crate) trait RawFileSystem: Send + Sync {
70
70
/// Remove the directory by parent file id and file name
71
71
async fn remove_dir ( & self , parent_file_id : u64 , name : & str ) -> Result < ( ) > ;
72
72
73
- /// Close the file by file id and file handle
73
+ /// Close the file by file id and file handle, if successful
74
74
async fn close_file ( & self , file_id : u64 , fh : u64 ) -> Result < ( ) > ;
75
75
76
- /// Read the file content by file id, file handle, offset and size
76
+ /// Read the file content by file id, file handle, offset and size, if successful, return read result
77
77
async fn read ( & self , file_id : u64 , fh : u64 , offset : u64 , size : u32 ) -> Result < Bytes > ;
78
78
79
- /// Write the file content by file id, file handle, offset and data
79
+ /// Write the file content by file id, file handle, offset and data, if successful, return write size
80
80
async fn write ( & self , file_id : u64 , fh : u64 , offset : u64 , data : & [ u8 ] ) -> Result < u32 > ;
81
81
}
82
82
@@ -85,32 +85,32 @@ pub(crate) trait RawFileSystem: Send + Sync {
85
85
#[ async_trait]
86
86
pub ( crate ) trait PathFileSystem : Send + Sync {
87
87
/// Init the file system
88
- async fn init ( & self ) ;
88
+ async fn init ( & self ) -> Result < ( ) > ;
89
89
90
- /// Get the file stat by file path
90
+ /// Get the file stat by file path, if the file is exist, return the file stat
91
91
async fn stat ( & self , name : & str ) -> Result < FileStat > ;
92
92
93
- /// Get the file stat by parent file path and file name
93
+ /// Get the file stat by parent file path and file name, if the file is exist, return the file stat
94
94
async fn lookup ( & self , parent : & str , name : & str ) -> Result < FileStat > ;
95
95
96
- /// Read the directory by file path
96
+ /// Read the directory by file path, if the file is a valid directory, return the file stat list
97
97
async fn read_dir ( & self , name : & str ) -> Result < Vec < FileStat > > ;
98
98
99
- /// Open the file by file path and flags
99
+ /// Open the file by file path and flags, if the file is exist, return the opened file
100
100
async fn open_file ( & self , name : & str , flags : OpenFileFlags ) -> Result < OpenedFile > ;
101
101
102
- /// Open the directory by file path and flags
102
+ /// Open the directory by file path and flags, if the file is exist, return the opened file
103
103
async fn open_dir ( & self , name : & str , flags : OpenFileFlags ) -> Result < OpenedFile > ;
104
104
105
- /// Create the file by parent file path and file name and flags
105
+ /// Create the file by parent file path and file name and flags, if successful, return the opened file
106
106
async fn create_file (
107
107
& self ,
108
108
parent : & str ,
109
109
name : & str ,
110
110
flags : OpenFileFlags ,
111
111
) -> Result < OpenedFile > ;
112
112
113
- /// Create the directory by parent file path and file name
113
+ /// Create the directory by parent file path and file name, if successful, return the file stat
114
114
async fn create_dir ( & self , parent : & str , name : & str ) -> Result < FileStat > ;
115
115
116
116
/// Set the file attribute by file path and file stat
@@ -123,6 +123,7 @@ pub(crate) trait PathFileSystem: Send + Sync {
123
123
async fn remove_dir ( & self , parent : & str , name : & str ) -> Result < ( ) > ;
124
124
}
125
125
126
+ // FileSystemContext is the system environment for the fuse file system.
126
127
pub ( crate ) struct FileSystemContext {
127
128
// system user id
128
129
pub ( crate ) uid : u32 ,
@@ -140,7 +141,6 @@ pub(crate) struct FileSystemContext {
140
141
pub ( crate ) block_size : u32 ,
141
142
}
142
143
143
- // FileSystemContext is the file system context for the file system implementation.
144
144
impl FileSystemContext {
145
145
pub ( crate ) fn new ( uid : u32 , gid : u32 ) -> Self {
146
146
FileSystemContext {
@@ -153,7 +153,7 @@ impl FileSystemContext {
153
153
}
154
154
}
155
155
156
- // FileStat is the file stat for the file system.
156
+ // FileStat is the file metadata of the file
157
157
#[ derive( Clone , Debug ) ]
158
158
pub struct FileStat {
159
159
// file id for the file system.
@@ -214,8 +214,10 @@ pub struct OpenFileFlags(u32);
214
214
/// File reader interface for read file content
215
215
#[ async_trait]
216
216
pub ( crate ) trait FileReader : Sync + Send {
217
+ /// read the file content by offset and size, if successful, return the read result
217
218
async fn read ( & mut self , offset : u64 , size : u32 ) -> Result < Bytes > ;
218
219
220
+ /// close the file
219
221
async fn close ( & mut self ) -> Result < ( ) > {
220
222
Ok ( ( ) )
221
223
}
@@ -224,12 +226,15 @@ pub(crate) trait FileReader: Sync + Send {
224
226
/// File writer interface for write file content
225
227
#[ async_trait]
226
228
pub trait FileWriter : Sync + Send {
229
+ /// write the file content by offset and data, if successful, return the write size
227
230
async fn write ( & mut self , offset : u64 , data : & [ u8 ] ) -> Result < u32 > ;
228
231
232
+ /// close the file
229
233
async fn close ( & mut self ) -> Result < ( ) > {
230
234
Ok ( ( ) )
231
235
}
232
236
237
+ /// flush the file
233
238
async fn flush ( & mut self ) -> Result < ( ) > {
234
239
Ok ( ( ) )
235
240
}
0 commit comments