Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
kernel
Commits
2fc605a8
Commit
2fc605a8
authored
8 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Allow schemes to be listed
parent
c484241e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scheme/mod.rs
+8
-0
8 additions, 0 deletions
scheme/mod.rs
scheme/sys/mod.rs
+34
-15
34 additions, 15 deletions
scheme/sys/mod.rs
scheme/sys/scheme.rs
+18
-0
18 additions, 0 deletions
scheme/sys/scheme.rs
with
60 additions
and
15 deletions
scheme/mod.rs
+
8
−
0
View file @
2fc605a8
...
...
@@ -71,6 +71,14 @@ impl SchemeList {
}
}
pub
fn
iter
(
&
self
)
->
::
collections
::
btree_map
::
Iter
<
usize
,
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>>
{
self
.map
.iter
()
}
pub
fn
iter_name
(
&
self
)
->
::
collections
::
btree_map
::
Iter
<
Box
<
[
u8
]
>
,
usize
>
{
self
.names
.iter
()
}
/// Get the nth scheme.
pub
fn
get
(
&
self
,
id
:
usize
)
->
Option
<&
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>>
{
self
.map
.get
(
&
id
)
...
...
This diff is collapsed.
Click to expand it.
scheme/sys/mod.rs
+
34
−
15
View file @
2fc605a8
...
...
@@ -6,10 +6,11 @@ use spin::RwLock;
use
syscall
::
data
::
Stat
;
use
syscall
::
error
::{
Error
,
EBADF
,
EINVAL
,
ENOENT
,
Result
};
use
syscall
::
flag
::{
MODE_FILE
,
SEEK_CUR
,
SEEK_END
,
SEEK_SET
};
use
syscall
::
flag
::{
MODE_DIR
,
MODE_FILE
,
SEEK_CUR
,
SEEK_END
,
SEEK_SET
};
use
syscall
::
scheme
::
Scheme
;
mod
context
;
mod
scheme
;
//mod interrupt;
//mod log;
//mod memory;
...
...
@@ -36,6 +37,7 @@ impl SysScheme {
let
mut
files
:
BTreeMap
<&
'static
[
u8
],
Box
<
SysFn
>>
=
BTreeMap
::
new
();
files
.insert
(
b"context"
,
Box
::
new
(
move
||
context
::
resource
()));
files
.insert
(
b"scheme"
,
Box
::
new
(
move
||
scheme
::
resource
()));
//files.insert(b"interrupt", Box::new(move || interrupt::resource()));
//files.insert(b"log", Box::new(move || log::resource()));
//files.insert(b"memory", Box::new(move || memory::resource()));
...
...
@@ -54,18 +56,36 @@ impl Scheme for SysScheme {
let
path_utf8
=
str
::
from_utf8
(
path
)
.map_err
(|
_err
|
Error
::
new
(
ENOENT
))
?
;
let
path_trimmed
=
path_utf8
.trim_matches
(
'/'
);
//Have to iterate to get the path without allocation
for
entry
in
self
.files
.iter
()
{
if
entry
.0
==
&
path_trimmed
.as_bytes
()
{
let
id
=
self
.next_id
.fetch_add
(
1
,
Ordering
::
SeqCst
);
self
.handles
.write
()
.insert
(
id
,
Handle
{
path
:
entry
.0
,
data
:
entry
.1
()
?
,
mode
:
MODE_FILE
|
0o444
,
seek
:
0
});
return
Ok
(
id
)
if
path_trimmed
.is_empty
()
{
let
mut
data
=
Vec
::
new
();
for
entry
in
self
.files
.iter
()
{
if
!
data
.is_empty
()
{
data
.push
(
b'\n'
);
}
data
.extend_from_slice
(
entry
.0
);
}
let
id
=
self
.next_id
.fetch_add
(
1
,
Ordering
::
SeqCst
);
self
.handles
.write
()
.insert
(
id
,
Handle
{
path
:
b""
,
data
:
data
,
mode
:
MODE_DIR
|
0o444
,
seek
:
0
});
return
Ok
(
id
)
}
else
{
//Have to iterate to get the path without allocation
for
entry
in
self
.files
.iter
()
{
if
entry
.0
==
&
path_trimmed
.as_bytes
()
{
let
id
=
self
.next_id
.fetch_add
(
1
,
Ordering
::
SeqCst
);
self
.handles
.write
()
.insert
(
id
,
Handle
{
path
:
entry
.0
,
data
:
entry
.1
()
?
,
mode
:
MODE_FILE
|
0o444
,
seek
:
0
});
return
Ok
(
id
)
}
}
}
...
...
@@ -122,9 +142,8 @@ impl Scheme for SysScheme {
let
handles
=
self
.handles
.read
();
let
handle
=
handles
.get
(
&
id
)
.ok_or
(
Error
::
new
(
EBADF
))
?
;
//TODO: Copy scheme part in kernel
let
mut
i
=
0
;
let
scheme_path
=
b"
initf
s:"
;
let
scheme_path
=
b"
sy
s:"
;
while
i
<
buf
.len
()
&&
i
<
scheme_path
.len
()
{
buf
[
i
]
=
scheme_path
[
i
];
i
+=
1
;
...
...
This diff is collapsed.
Click to expand it.
scheme/sys/scheme.rs
0 → 100644
+
18
−
0
View file @
2fc605a8
use
collections
::
Vec
;
use
scheme
;
use
syscall
::
error
::
Result
;
pub
fn
resource
()
->
Result
<
Vec
<
u8
>>
{
let
mut
data
=
Vec
::
new
();
let
schemes
=
scheme
::
schemes
();
for
(
name
,
_scheme_lock
)
in
schemes
.iter_name
()
{
if
!
data
.is_empty
()
{
data
.push
(
b'\n'
);
}
data
.extend_from_slice
(
name
);
}
Ok
(
data
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment