Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
OS-Contest-2021-Kernel-Preliminary
kcore2021-kcore
Commits
d61a1584
Commit
d61a1584
authored
4 years ago
by
LiHanChi
Browse files
Options
Download
Patches
Plain Diff
Update fs.rs
parent
03638b36
master
link-error
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
os/src/syscall/fs.rs
+70
-1
os/src/syscall/fs.rs
with
70 additions
and
1 deletion
+70
-1
os/src/syscall/fs.rs
+
70
−
1
View file @
d61a1584
// syscall/fs.rs
use
crate
::
mem
::{
UserBuffer
,
translated_byte_buffer
,
translated_refmut
,
translated_str
,
};
use
crate
::
task
::{
current_user_token
,
current_task
};
use
crate
::
fs
::{
make_pipe
,
OpenSignals
,
open_file
};
use
alloc
::
sync
::
Arc
;
pub
fn
sys_write
(
fd
:
usize
,
buf
:
*
const
u8
,
len
:
usize
)
->
isize
{
let
token
=
current_user_token
();
let
task
=
current_task
()
.unwrap
();
...
...
@@ -36,4 +47,62 @@ pub fn sys_read(fd: usize, buf: *const u8, len: uszie) -> isize {
else
{
-
1
}
}
\ No newline at end of file
}
pub
fn
sys_open
(
path
:
*
const
u8
,
signals
:
u32
)
->
isize
{
let
task
=
current_task
()
.unwrap
();
let
token
=
current_user_token
();
let
path
=
translated_str
(
token
,
path
);
if
let
Some
(
inode
)
=
open_file
(
path
.as_str
(),
OpenSignals
::
from_bits
(
signals
)
.unwrap
()
)
{
let
mut
inner
=
task
.acquire_inner_lock
();
let
fd
=
inner
.alloc_fd
();
inner
.fd_table
[
fd
]
=
Some
(
inode
);
fd
as
isize
}
else
{
-
1
}
}
pub
fn
sys_close
(
fd
:
usize
)
->
isize
{
let
task
=
current_task
()
.unwrap
();
let
mut
inner
=
task
.acquire_inner_lock
();
if
fd
>=
inner
.fd_table
.len
()
{
return
-
1
;
}
if
inner
.fd_table
[
fd
]
.is_none
()
{
return
-
1
;
}
inner
.fd_table
[
fd
]
.take
();
0
}
pub
fn
sys_pipe
(
pipe
:
*
mut
usize
)
->
isize
{
let
task
=
current_task
()
.unwrap
();
let
token
=
current_user_token
();
let
mut
inner
=
task
.acquire_inner_lock
();
let
(
pipe_read
,
pipe_write
)
=
make_pipe
();
let
read_fd
=
inner
.alloc_fd
();
inner
.fd_table
[
read_fd
]
=
Some
(
pipe_read
);
let
write_fd
=
inner
.alloc_fd
();
inner
.fd_table
[
write_fd
]
=
Some
(
pipe_write
);
*
translated_refmut
(
token
,
pipe
)
=
read_fd
;
*
translated_refmut
(
token
,
unsafe
{
pipe
.add
(
1
)
})
=
write_fd
;
0
}
pub
fn
sys_dup
(
fd
:
usize
)
->
isize
{
let
task
=
current_task
()
.unwrap
();
let
mut
inner
=
task
.acquire_inner_lock
();
if
fd
>=
inner
.fd_table
.len
()
{
return
-
1
;
}
if
inner
.fd_table
[
fd
]
.is_none
()
{
return
-
1
;
}
let
new_fd
=
inner
.alloc_fd
();
inner
.fd_table
[
new_fd
]
=
Some
(
Arc
::
clone
(
inner
.fd_table
[
fd
]
.as_ref
()
.unwrap
()));
new_fd
as
isize
}
// duplicator
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets