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
Michal Rostecki
redoxfs
Commits
946efa2f
Verified
Commit
946efa2f
authored
5 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Add sparse disk file to not require image to be sized initially.
parent
07540199
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/bin/ar.rs
+5
-4
5 additions, 4 deletions
src/bin/ar.rs
src/disk/mod.rs
+2
-0
2 additions, 0 deletions
src/disk/mod.rs
src/disk/sparse.rs
+48
-0
48 additions, 0 deletions
src/disk/sparse.rs
src/lib.rs
+1
-1
1 addition, 1 deletion
src/lib.rs
with
56 additions
and
5 deletions
src/bin/ar.rs
+
5
−
4
View file @
946efa2f
...
...
@@ -7,7 +7,7 @@ use std::io::{self, Read};
use
std
::
path
::
Path
;
use
std
::
time
::{
Duration
,
SystemTime
,
UNIX_EPOCH
};
use
redoxfs
::{
BLOCK_SIZE
,
Disk
,
Disk
Fil
e
,
Extent
,
FileSystem
,
Node
};
use
redoxfs
::{
BLOCK_SIZE
,
Disk
,
Disk
Spars
e
,
Extent
,
FileSystem
,
Node
};
use
uuid
::
Uuid
;
fn
syscall_err
(
err
:
syscall
::
Error
)
->
io
::
Error
{
...
...
@@ -72,14 +72,15 @@ fn archive<D: Disk, P: AsRef<Path>>(fs: &mut FileSystem<D>, parent_path: P, ctim
let
free_block
=
fs
.header
.1
.free
;
let
mut
free
=
fs
.node
(
free_block
)
.map_err
(
syscall_err
)
?
;
let
end_block
=
free
.1
.extents
[
0
]
.block
;
let
end_size
=
end_block
*
BLOCK_SIZE
;
free
.1
.extents
[
0
]
=
Extent
::
default
();
fs
.write_at
(
free
.0
,
&
free
.1
)
.map_err
(
syscall_err
)
?
;
fs
.header
.1
.size
=
end_
block
;
fs
.header
.1
.size
=
end_
size
;
let
header
=
fs
.header
;
fs
.write_at
(
header
.0
,
&
header
.1
)
.map_err
(
syscall_err
)
?
;
Ok
(
end_
block
*
BLOCK_SIZE
)
Ok
(
end_
size
)
}
fn
main
()
{
...
...
@@ -103,7 +104,7 @@ fn main() {
let
bootloader_path_opt
=
args
.next
();
let
disk
=
match
Disk
File
::
open
(
&
disk_path
)
{
let
disk
=
match
Disk
Sparse
::
create
(
&
disk_path
)
{
Ok
(
disk
)
=>
disk
,
Err
(
err
)
=>
{
println!
(
"redoxfs-ar: failed to open image {}: {}"
,
disk_path
,
err
);
...
...
This diff is collapsed.
Click to expand it.
src/disk/mod.rs
+
2
−
0
View file @
946efa2f
...
...
@@ -2,9 +2,11 @@ use syscall::error::Result;
pub
use
self
::
cache
::
DiskCache
;
pub
use
self
::
file
::
DiskFile
;
pub
use
self
::
sparse
::
DiskSparse
;
mod
cache
;
mod
file
;
mod
sparse
;
/// A disk
pub
trait
Disk
{
...
...
This diff is collapsed.
Click to expand it.
src/disk/sparse.rs
0 → 100644
+
48
−
0
View file @
946efa2f
use
std
::
fs
::{
File
,
OpenOptions
};
use
std
::
io
::{
Read
,
Write
,
Seek
,
SeekFrom
};
use
std
::
u64
;
use
syscall
::
error
::{
Error
,
Result
,
EIO
};
use
BLOCK_SIZE
;
use
disk
::
Disk
;
macro_rules!
try_disk
{
(
$expr:expr
)
=>
(
match
$expr
{
Ok
(
val
)
=>
val
,
Err
(
err
)
=>
{
eprintln!
(
"Disk I/O Error: {}"
,
err
);
return
Err
(
Error
::
new
(
EIO
));
}
})
}
pub
struct
DiskSparse
{
pub
file
:
File
,
}
impl
DiskSparse
{
pub
fn
create
(
path
:
&
str
)
->
Result
<
DiskSparse
>
{
let
file
=
try_disk!
(
OpenOptions
::
new
()
.read
(
true
)
.write
(
true
)
.create
(
true
)
.open
(
path
));
Ok
(
DiskSparse
{
file
})
}
}
impl
Disk
for
DiskSparse
{
fn
read_at
(
&
mut
self
,
block
:
u64
,
buffer
:
&
mut
[
u8
])
->
Result
<
usize
>
{
try_disk!
(
self
.file
.seek
(
SeekFrom
::
Start
(
block
*
BLOCK_SIZE
)));
let
count
=
try_disk!
(
self
.file
.read
(
buffer
));
Ok
(
count
)
}
fn
write_at
(
&
mut
self
,
block
:
u64
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
{
try_disk!
(
self
.file
.seek
(
SeekFrom
::
Start
(
block
*
BLOCK_SIZE
)));
let
count
=
try_disk!
(
self
.file
.write
(
buffer
));
Ok
(
count
)
}
fn
size
(
&
mut
self
)
->
Result
<
u64
>
{
Ok
(
u64
::
MAX
)
}
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
1
−
1
View file @
946efa2f
...
...
@@ -11,7 +11,7 @@ pub const SIGNATURE: &'static [u8; 8] = b"RedoxFS\0";
pub
const
VERSION
:
u64
=
3
;
pub
static
IS_UMT
:
AtomicUsize
=
AtomicUsize
::
new
(
0
);
pub
use
self
::
disk
::{
Disk
,
DiskCache
,
DiskFile
};
pub
use
self
::
disk
::{
Disk
,
DiskCache
,
DiskFile
,
DiskSparse
};
pub
use
self
::
ex_node
::
ExNode
;
pub
use
self
::
extent
::
Extent
;
pub
use
self
::
filesystem
::
FileSystem
;
...
...
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