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
d2a07378
Commit
d2a07378
authored
9 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Add unlink and creat
parent
702bef44
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
+77
-28
77 additions, 28 deletions
scheme/main.rs
with
77 additions
and
28 deletions
scheme/main.rs
+
77
−
28
View file @
d2a07378
...
...
@@ -13,9 +13,9 @@ use image::Image;
use
redoxfs
::{
FileSystem
,
Node
};
use
system
::
error
::{
Error
,
Result
,
ENOENT
,
EBADF
,
EINVAL
};
use
system
::
error
::{
Error
,
Result
,
EISDIR
,
EPERM
,
ENOENT
,
EBADF
,
EINVAL
};
use
system
::
scheme
::{
Packet
,
Scheme
};
use
system
::
syscall
::{
Stat
,
SEEK_SET
,
SEEK_CUR
,
SEEK_END
};
use
system
::
syscall
::{
Stat
,
O_CREAT
,
SEEK_SET
,
SEEK_CUR
,
SEEK_END
};
pub
mod
image
;
...
...
@@ -106,39 +106,75 @@ impl FileScheme {
}
}
fn
path_node
(
&
mut
self
,
path
:
&
str
)
->
Result
<
(
u64
,
Node
)
>
{
fn
path_node
s
(
&
mut
self
,
path
:
&
str
,
nodes
:
&
mut
Vec
<
(
u64
,
Node
)
>
)
->
Result
<
(
u64
,
Node
)
>
{
let
mut
block
=
self
.fs.header
.1
.root
;
nodes
.push
(
try
!
(
self
.fs
.node
(
block
)));
for
part
in
path
.split
(
'/'
)
{
if
!
part
.is_empty
()
{
let
next
=
try
!
(
self
.fs
.find_node
(
part
,
block
));
block
=
next
.0
;
let
node
=
try
!
(
self
.fs
.find_node
(
part
,
block
));
block
=
node
.0
;
nodes
.push
(
node
);
}
}
self
.fs
.node
(
block
)
Ok
(
nodes
.pop
()
.unwrap
()
)
}
}
impl
Scheme
for
FileScheme
{
fn
open
(
&
mut
self
,
url
:
&
str
,
flags
:
usize
,
mode
:
usize
)
->
Result
<
usize
>
{
let
path
=
url
.split
(
':'
)
.nth
(
1
)
.unwrap_or
(
""
)
.trim_matches
(
'/'
);
let
node
=
try
!
(
self
.path_node
(
path
));
let
mut
nodes
=
Vec
::
new
();
let
node_result
=
self
.path_nodes
(
path
,
&
mut
nodes
);
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
);
match
node_result
{
Ok
(
node
)
=>
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
());
},
Err
(
err
)
=>
if
err
.errno
==
ENOENT
&&
flags
&
O_CREAT
==
O_CREAT
{
let
mut
last_part
=
String
::
new
();
for
part
in
path
.split
(
'/'
)
{
if
!
part
.is_empty
()
{
last_part
=
part
.to_string
();
}
}
if
!
last_part
.is_empty
()
{
if
let
Some
(
parent
)
=
nodes
.last
()
{
try
!
(
self
.fs
.create_node
(
Node
::
MODE_FILE
,
&
last_part
,
parent
.0
));
}
else
{
return
Err
(
Error
::
new
(
EPERM
));
}
data
.extend_from_slice
(
&
name
.as_bytes
());
}
else
{
return
Err
(
Error
::
new
(
EPERM
));
}
}
else
{
return
Err
(
err
);
}
}
/*
if let Some(arg) = args.next() {
match {
Ok(node) => println!("{}: {:#?}", node.0, node.1),
Err(err) => println!("mk: failed to create {}: {}", arg, err)
}
} else {
data
.extend_from_slice
(
&
format!
(
"{:#?}"
,
node
)
.as_bytes
()
);
println!("mk <file>"
);
}
*/
let
id
=
self
.next_id
as
usize
;
self
.next_id
+=
1
;
...
...
@@ -149,17 +185,36 @@ impl Scheme for FileScheme {
Ok
(
id
)
}
#[allow(unused_variables)]
fn
unlink
(
&
mut
self
,
path
:
&
str
)
->
Result
<
usize
>
{
println!
(
"unlink {}"
,
path
);
fn
mkdir
(
&
mut
self
,
path
:
&
str
,
mode
:
usize
)
->
Result
<
usize
>
{
println!
(
"mkdir {}, {:X}"
,
path
,
mode
);
Err
(
Error
::
new
(
ENOENT
))
}
#[allow(unused_variables)]
fn
m
k
dir
(
&
mut
self
,
path
:
&
str
,
mode
:
usize
)
->
Result
<
usize
>
{
println!
(
"m
k
dir {}
, {:X}
"
,
path
,
mode
);
/*
fn
r
mdir(&mut self, path: &str) -> Result<usize> {
println!("
r
mdir {}", path);
Err(Error::new(ENOENT))
}
*/
fn
unlink
(
&
mut
self
,
url
:
&
str
)
->
Result
<
usize
>
{
let
path
=
url
.split
(
':'
)
.nth
(
1
)
.unwrap_or
(
""
)
.trim_matches
(
'/'
);
let
mut
nodes
=
Vec
::
new
();
let
child
=
try
!
(
self
.path_nodes
(
path
,
&
mut
nodes
));
if
let
Some
(
parent
)
=
nodes
.last
()
{
if
!
child
.1
.is_dir
()
{
if
let
Ok
(
child_name
)
=
child
.1
.name
()
{
self
.fs
.remove_node
(
Node
::
MODE_FILE
,
child_name
,
parent
.0
)
.and
(
Ok
(
0
))
}
else
{
Err
(
Error
::
new
(
ENOENT
))
}
}
else
{
Err
(
Error
::
new
(
EISDIR
))
}
}
else
{
Err
(
Error
::
new
(
EPERM
))
}
}
/* Resource operations */
#[allow(unused_variables)]
...
...
@@ -171,7 +226,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
write
(
&
mut
self
,
id
:
usize
,
buf
:
&
[
u8
])
->
Result
<
usize
>
{
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
file
.write
(
buf
)
...
...
@@ -180,7 +234,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
seek
(
&
mut
self
,
id
:
usize
,
pos
:
usize
,
whence
:
usize
)
->
Result
<
usize
>
{
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
file
.seek
(
pos
,
whence
)
...
...
@@ -189,7 +242,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
fpath
(
&
self
,
id
:
usize
,
buf
:
&
mut
[
u8
])
->
Result
<
usize
>
{
if
let
Some
(
file
)
=
self
.files
.get
(
&
id
)
{
file
.path
(
buf
)
...
...
@@ -198,7 +250,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
fstat
(
&
self
,
id
:
usize
,
stat
:
&
mut
Stat
)
->
Result
<
usize
>
{
println!
(
"fstat {}, {:X}"
,
id
,
stat
as
*
mut
Stat
as
usize
);
if
let
Some
(
file
)
=
self
.files
.get
(
&
id
)
{
...
...
@@ -208,7 +259,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
fsync
(
&
mut
self
,
id
:
usize
)
->
Result
<
usize
>
{
println!
(
"fsync {}"
,
id
);
if
let
Some
(
mut
file
)
=
self
.files
.get_mut
(
&
id
)
{
...
...
@@ -218,7 +268,6 @@ impl Scheme for FileScheme {
}
}
#[allow(unused_variables)]
fn
ftruncate
(
&
mut
self
,
id
:
usize
,
len
:
usize
)
->
Result
<
usize
>
{
println!
(
"ftruncate {}, {}"
,
id
,
len
);
Err
(
Error
::
new
(
EBADF
))
...
...
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