Skip to content

Commit 5197245

Browse files
committed
Emerald: Implemented OpenOptions and file creation
We have now full support for the rust OpenOptions, and from that, we can control read and write access as well as creating new files.
1 parent 247d5de commit 5197245

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,15 @@ dependencies = [
12121212

12131213
[[package]]
12141214
name = "emerald_kernel_user_link"
1215-
version = "0.2.9"
1215+
version = "0.2.10"
12161216
dependencies = [
12171217
"compiler_builtins",
12181218
"rustc-std-workspace-core",
12191219
]
12201220

12211221
[[package]]
12221222
name = "emerald_std"
1223-
version = "0.2.9"
1223+
version = "0.3.0"
12241224
dependencies = [
12251225
"compiler_builtins",
12261226
"emerald_kernel_user_link",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }
6161
# This is from `https://github.com/Amjad50/Emerald`, i.e. it must be run from that context
6262
# TODO: for now we are using relative path, as we are using `libm` from `git` and we can't publish
6363
# that. Fix it later
64-
emerald_std = { version = "0.2.9", features = ['rustc-dep-of-std'], path = "../../../../libraries/emerald_std" }
64+
emerald_std = { version = "0.3.0", features = ['rustc-dep-of-std'], path = "../../../../libraries/emerald_std" }
6565

6666
[features]
6767
backtrace = [

library/std/src/sys/pal/emerald/fs.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct DirEntry {
3737
}
3838

3939
#[derive(Clone, Debug)]
40-
pub struct OpenOptions {}
40+
pub struct OpenOptions(emerald_std::io::OpenOptions);
4141

4242
#[derive(Copy, Clone, Debug, Default)]
4343
pub struct FileTimes {}
@@ -217,15 +217,32 @@ impl DirEntry {
217217

218218
impl OpenOptions {
219219
pub fn new() -> OpenOptions {
220-
OpenOptions {}
220+
OpenOptions(emerald_std::io::OpenOptions::new())
221221
}
222222

223-
pub fn read(&mut self, _read: bool) {}
224-
pub fn write(&mut self, _write: bool) {}
225-
pub fn append(&mut self, _append: bool) {}
226-
pub fn truncate(&mut self, _truncate: bool) {}
227-
pub fn create(&mut self, _create: bool) {}
228-
pub fn create_new(&mut self, _create_new: bool) {}
223+
pub fn read(&mut self, read: bool) {
224+
self.0.read(read);
225+
}
226+
227+
pub fn write(&mut self, write: bool) {
228+
self.0.write(write);
229+
}
230+
231+
pub fn append(&mut self, append: bool) {
232+
self.0.append(append);
233+
}
234+
235+
pub fn truncate(&mut self, truncate: bool) {
236+
self.0.truncate(truncate);
237+
}
238+
239+
pub fn create(&mut self, create: bool) {
240+
self.0.create(create);
241+
}
242+
243+
pub fn create_new(&mut self, create_new: bool) {
244+
self.0.create_new(create_new);
245+
}
229246
}
230247

231248
impl File {
@@ -235,12 +252,11 @@ impl File {
235252
Ok(File { path: path.to_owned(), fd })
236253
}
237254

238-
fn openc(path: &CStr, _opts: &OpenOptions) -> io::Result<FileDesc> {
255+
fn openc(path: &CStr, open_options: &OpenOptions) -> io::Result<FileDesc> {
239256
let flags = 0;
240-
let access_mode = 0;
241257

242258
let fd = unsafe {
243-
emerald_std::io::syscall_open(path, access_mode, flags).map_err(syscall_to_io_error)
259+
emerald_std::io::syscall_open(path, open_options.0, flags).map_err(syscall_to_io_error)
244260
}?;
245261

246262
Ok(unsafe { FileDesc::from_raw_fd(fd as usize) })

0 commit comments

Comments
 (0)