Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redoxfs
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
James Matlik
redoxfs
Commits
702bef44
Commit
702bef44
authored
9 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Path handling
parent
799a847f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scheme/main.rs
+36
-11
36 additions, 11 deletions
scheme/main.rs
with
36 additions
and
11 deletions
scheme/main.rs
+
36
−
11
View file @
702bef44
...
@@ -11,7 +11,7 @@ use std::mem::size_of;
...
@@ -11,7 +11,7 @@ use std::mem::size_of;
use
image
::
Image
;
use
image
::
Image
;
use
redoxfs
::
FileSystem
;
use
redoxfs
::
{
FileSystem
,
Node
}
;
use
system
::
error
::{
Error
,
Result
,
ENOENT
,
EBADF
,
EINVAL
};
use
system
::
error
::{
Error
,
Result
,
ENOENT
,
EBADF
,
EINVAL
};
use
system
::
scheme
::{
Packet
,
Scheme
};
use
system
::
scheme
::{
Packet
,
Scheme
};
...
@@ -26,10 +26,10 @@ struct FileResource {
...
@@ -26,10 +26,10 @@ struct FileResource {
}
}
impl
FileResource
{
impl
FileResource
{
fn
new
(
path
:
&
str
)
->
FileResource
{
fn
new
(
path
:
&
str
,
data
:
Vec
<
u8
>
)
->
FileResource
{
FileResource
{
FileResource
{
path
:
path
.to_string
(),
path
:
path
.to_string
(),
data
:
Vec
::
new
()
,
data
:
data
,
seek
:
0
,
seek
:
0
,
}
}
}
}
...
@@ -105,17 +105,47 @@ impl FileScheme {
...
@@ -105,17 +105,47 @@ impl FileScheme {
files
:
BTreeMap
::
new
()
files
:
BTreeMap
::
new
()
}
}
}
}
fn
path_node
(
&
mut
self
,
path
:
&
str
)
->
Result
<
(
u64
,
Node
)
>
{
let
mut
block
=
self
.fs.header
.1
.root
;
for
part
in
path
.split
(
'/'
)
{
if
!
part
.is_empty
()
{
let
next
=
try
!
(
self
.fs
.find_node
(
part
,
block
));
block
=
next
.0
;
}
}
self
.fs
.node
(
block
)
}
}
}
impl
Scheme
for
FileScheme
{
impl
Scheme
for
FileScheme
{
fn
open
(
&
mut
self
,
path
:
&
str
,
flags
:
usize
,
mode
:
usize
)
->
Result
<
usize
>
{
fn
open
(
&
mut
self
,
url
:
&
str
,
flags
:
usize
,
mode
:
usize
)
->
Result
<
usize
>
{
println!
(
"open {:X} = {}, {:X}, {:X}"
,
path
.as_ptr
()
as
usize
,
path
,
flags
,
mode
);
let
path
=
url
.split
(
':'
)
.nth
(
1
)
.unwrap_or
(
""
)
.trim_matches
(
'/'
);
let
node
=
try
!
(
self
.path_node
(
path
));
let
mut
data
=
Vec
::
new
();
if
node
.1
.is_dir
()
{
let
mut
children
=
Vec
::
new
();
try
!
(
self
.fs
.child_nodes
(
&
mut
children
,
node
.0
));
for
child
in
children
.iter
()
{
if
let
Ok
(
name
)
=
child
.1
.name
()
{
if
!
data
.is_empty
()
{
data
.push
(
'\n'
as
u8
);
}
data
.extend_from_slice
(
&
name
.as_bytes
());
}
}
}
else
{
data
.extend_from_slice
(
&
format!
(
"{:#?}"
,
node
)
.as_bytes
());
}
let
id
=
self
.next_id
as
usize
;
let
id
=
self
.next_id
as
usize
;
self
.next_id
+=
1
;
self
.next_id
+=
1
;
if
self
.next_id
<
0
{
if
self
.next_id
<
0
{
self
.next_id
=
1
;
self
.next_id
=
1
;
}
}
self
.files
.insert
(
id
,
FileResource
::
new
(
p
at
h
));
self
.files
.insert
(
id
,
FileResource
::
new
(
url
,
d
at
a
));
Ok
(
id
)
Ok
(
id
)
}
}
...
@@ -134,7 +164,6 @@ impl Scheme for FileScheme {
...
@@ -134,7 +164,6 @@ impl Scheme for FileScheme {
/* Resource operations */
/* Resource operations */
#[allow(unused_variables)]
#[allow(unused_variables)]
fn
read
(
&
mut
self
,
id
:
usize
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
>
{
fn
read
(
&
mut
self
,
id
:
usize
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
>
{
println!
(
"read {}, {:X}, {}"
,
id
,
buf
.as_mut_ptr
()
as
usize
,
buf
.len
());
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
file
.read
(
buf
)
file
.read
(
buf
)
}
else
{
}
else
{
...
@@ -144,7 +173,6 @@ impl Scheme for FileScheme {
...
@@ -144,7 +173,6 @@ impl Scheme for FileScheme {
#[allow(unused_variables)]
#[allow(unused_variables)]
fn
write
(
&
mut
self
,
id
:
usize
,
buf
:
&
[
u8
])
->
Result
<
usize
>
{
fn
write
(
&
mut
self
,
id
:
usize
,
buf
:
&
[
u8
])
->
Result
<
usize
>
{
println!
(
"write {}, {:X}, {}"
,
id
,
buf
.as_ptr
()
as
usize
,
buf
.len
());
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
file
.write
(
buf
)
file
.write
(
buf
)
}
else
{
}
else
{
...
@@ -154,7 +182,6 @@ impl Scheme for FileScheme {
...
@@ -154,7 +182,6 @@ impl Scheme for FileScheme {
#[allow(unused_variables)]
#[allow(unused_variables)]
fn
seek
(
&
mut
self
,
id
:
usize
,
pos
:
usize
,
whence
:
usize
)
->
Result
<
usize
>
{
fn
seek
(
&
mut
self
,
id
:
usize
,
pos
:
usize
,
whence
:
usize
)
->
Result
<
usize
>
{
println!
(
"seek {}, {}, {}"
,
id
,
pos
,
whence
);
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
file
.seek
(
pos
,
whence
)
file
.seek
(
pos
,
whence
)
}
else
{
}
else
{
...
@@ -164,7 +191,6 @@ impl Scheme for FileScheme {
...
@@ -164,7 +191,6 @@ impl Scheme for FileScheme {
#[allow(unused_variables)]
#[allow(unused_variables)]
fn
fpath
(
&
self
,
id
:
usize
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
>
{
fn
fpath
(
&
self
,
id
:
usize
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
>
{
println!
(
"fpath {}, {:X}, {}"
,
id
,
buf
.as_mut_ptr
()
as
usize
,
buf
.len
());
if
let
Some
(
file
)
=
self
.files
.get
(
&
id
)
{
if
let
Some
(
file
)
=
self
.files
.get
(
&
id
)
{
file
.path
(
buf
)
file
.path
(
buf
)
}
else
{
}
else
{
...
@@ -199,7 +225,6 @@ impl Scheme for FileScheme {
...
@@ -199,7 +225,6 @@ impl Scheme for FileScheme {
}
}
fn
close
(
&
mut
self
,
id
:
usize
)
->
Result
<
usize
>
{
fn
close
(
&
mut
self
,
id
:
usize
)
->
Result
<
usize
>
{
println!
(
"close {}"
,
id
);
if
self
.files
.remove
(
&
id
)
.is_some
()
{
if
self
.files
.remove
(
&
id
)
.is_some
()
{
Ok
(
0
)
Ok
(
0
)
}
else
{
}
else
{
...
...
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