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
04e10340
Commit
04e10340
authored
7 years ago
by
Tommie Levy
Browse files
Options
Downloads
Patches
Plain Diff
Check if current namespace exists
parent
7bfe1739
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!69
Check if current namespace exists
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scheme/mod.rs
+27
-9
27 additions, 9 deletions
src/scheme/mod.rs
with
27 additions
and
9 deletions
src/scheme/mod.rs
+
27
−
9
View file @
04e10340
...
@@ -77,6 +77,18 @@ pub const ATOMIC_SCHEMEID_INIT: AtomicSchemeId = AtomicSchemeId::default();
...
@@ -77,6 +77,18 @@ pub const ATOMIC_SCHEMEID_INIT: AtomicSchemeId = AtomicSchemeId::default();
/// Unique identifier for a file descriptor.
/// Unique identifier for a file descriptor.
int_like!
(
FileHandle
,
AtomicFileHandle
,
usize
,
AtomicUsize
);
int_like!
(
FileHandle
,
AtomicFileHandle
,
usize
,
AtomicUsize
);
pub
struct
SchemeIter
<
'a
>
{
inner
:
Option
<
::
alloc
::
btree_map
::
Iter
<
'a
,
Box
<
[
u8
]
>
,
SchemeId
>>
}
impl
<
'a
>
Iterator
for
SchemeIter
<
'a
>
{
type
Item
=
(
&
'a
Box
<
[
u8
]
>
,
&
'a
SchemeId
);
fn
next
(
&
mut
self
)
->
Option
<
Self
::
Item
>
{
self
.inner
.as_mut
()
.and_then
(|
iter
|
iter
.next
())
}
}
/// Scheme list type
/// Scheme list type
pub
struct
SchemeList
{
pub
struct
SchemeList
{
map
:
BTreeMap
<
SchemeId
,
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>>
,
map
:
BTreeMap
<
SchemeId
,
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>>
,
...
@@ -168,8 +180,10 @@ impl SchemeList {
...
@@ -168,8 +180,10 @@ impl SchemeList {
self
.map
.iter
()
self
.map
.iter
()
}
}
pub
fn
iter_name
(
&
self
,
ns
:
SchemeNamespace
)
->
::
alloc
::
btree_map
::
Iter
<
Box
<
[
u8
]
>
,
SchemeId
>
{
pub
fn
iter_name
(
&
self
,
ns
:
SchemeNamespace
)
->
SchemeIter
{
self
.names
[
&
ns
]
.iter
()
SchemeIter
{
inner
:
self
.names
.get
(
&
ns
)
.map
(|
names
|
names
.iter
())
}
}
}
/// Get the nth scheme.
/// Get the nth scheme.
...
@@ -178,19 +192,22 @@ impl SchemeList {
...
@@ -178,19 +192,22 @@ impl SchemeList {
}
}
pub
fn
get_name
(
&
self
,
ns
:
SchemeNamespace
,
name
:
&
[
u8
])
->
Option
<
(
SchemeId
,
&
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>
)
>
{
pub
fn
get_name
(
&
self
,
ns
:
SchemeNamespace
,
name
:
&
[
u8
])
->
Option
<
(
SchemeId
,
&
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>
)
>
{
if
let
Some
(
&
id
)
=
self
.names
[
&
ns
]
.get
(
name
)
{
if
let
Some
(
names
)
=
self
.names
.get
(
&
ns
)
{
self
.get
(
id
)
.map
(|
scheme
|
(
id
,
sche
me
)
)
if
let
Some
(
&
id
)
=
names
.get
(
na
me
)
{
}
else
{
return
self
.get
(
id
)
.map
(|
scheme
|
(
id
,
scheme
));
None
}
}
}
return
None
;
}
}
/// Create a new scheme.
/// Create a new scheme.
pub
fn
insert
<
F
>
(
&
mut
self
,
ns
:
SchemeNamespace
,
name
:
Box
<
[
u8
]
>
,
scheme_fn
:
F
)
->
Result
<
SchemeId
>
pub
fn
insert
<
F
>
(
&
mut
self
,
ns
:
SchemeNamespace
,
name
:
Box
<
[
u8
]
>
,
scheme_fn
:
F
)
->
Result
<
SchemeId
>
where
F
:
Fn
(
SchemeId
)
->
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>
where
F
:
Fn
(
SchemeId
)
->
Arc
<
Box
<
Scheme
+
Send
+
Sync
>>
{
{
if
self
.names
[
&
ns
]
.contains_key
(
&
name
)
{
if
let
Some
(
names
)
=
self
.names
.get
(
&
ns
)
{
return
Err
(
Error
::
new
(
EEXIST
));
if
names
.contains_key
(
&
name
)
{
return
Err
(
Error
::
new
(
EEXIST
));
}
}
}
if
self
.next_id
>=
SCHEME_MAX_SCHEMES
{
if
self
.next_id
>=
SCHEME_MAX_SCHEMES
{
...
@@ -216,7 +233,8 @@ impl SchemeList {
...
@@ -216,7 +233,8 @@ impl SchemeList {
if
let
Some
(
ref
mut
names
)
=
self
.names
.get_mut
(
&
ns
)
{
if
let
Some
(
ref
mut
names
)
=
self
.names
.get_mut
(
&
ns
)
{
assert!
(
names
.insert
(
name
,
id
)
.is_none
());
assert!
(
names
.insert
(
name
,
id
)
.is_none
());
}
else
{
}
else
{
panic!
(
"scheme namespace not found"
);
// Nonexistent namespace, posssibly null namespace
return
Err
(
Error
::
new
(
ENODEV
));
}
}
Ok
(
id
)
Ok
(
id
)
}
}
...
...
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