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-lab
Commits
b3c2b90e
Commit
b3c2b90e
authored
7 months ago
by
姜继扬
Browse files
Options
Download
Patches
Plain Diff
getdents
parent
0b8ec988
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kernel/syscall.c
+3
-3
kernel/syscall.c
kernel/sysfile.c
+53
-0
kernel/sysfile.c
with
56 additions
and
3 deletions
+56
-3
kernel/syscall.c
+
3
−
3
View file @
b3c2b90e
...
...
@@ -130,7 +130,7 @@ extern uint64 sys_openat(void);
extern
uint64
sys_dup3
(
void
);
extern
uint64
sys_mount
(
void
);
extern
uint64
sys_umount2
(
void
);
//
extern uint64 sys_getdents64(void);
extern
uint64
sys_getdents64
(
void
);
static
uint64
(
*
syscalls
[])(
void
)
=
{
[
SYS_fork
]
sys_fork
,
...
...
@@ -175,7 +175,7 @@ static uint64 (*syscalls[])(void) = {
[
SYS_pipe2
]
sys_pipe
,
[
SYS_mount
]
sys_mount
,
[
SYS_umount2
]
sys_umount2
,
//
[SYS_getdents64] sys_getdents64,
[
SYS_getdents64
]
sys_getdents64
,
};
static
char
*
sysnames
[]
=
{
...
...
@@ -220,7 +220,7 @@ static char *sysnames[] = {
[
SYS_pipe2
]
"pipe2"
,
[
SYS_mount
]
"sys_mount"
,
[
SYS_umount2
]
"sys_umount2"
,
//
[SYS_getdents64] "getdents64",
[
SYS_getdents64
]
"getdents64"
,
};
void
...
...
This diff is collapsed.
Click to expand it.
kernel/sysfile.c
+
53
−
0
View file @
b3c2b90e
...
...
@@ -620,3 +620,56 @@ fail:
eput
(
src
);
return
-
1
;
}
struct
linux_dirent64
{
uint64
d_ino
;
uint32
d_off
;
unsigned
short
d_reclen
;
unsigned
char
d_type
;
char
d_name
[];
};
uint64
sys_getdents64
(
void
)
{
int
fd
,
len
;
uint64
addr
;
struct
file
*
f
;
int
nread
=
0
;
struct
dirent
de
;
int
count
=
0
;
int
ret
;
struct
linux_dirent64
tmp
;
if
(
argint
(
0
,
&
fd
)
<
0
||
argint
(
2
,
&
len
)
<
0
||
argaddr
(
1
,
&
addr
)
<
0
)
{
return
-
1
;
}
if
(
fd
<
0
||
fd
>=
NOFILE
||
(
f
=
myproc
()
->
ofile
[
fd
])
==
NULL
)
return
-
1
;
while
(
nread
+
(
int
)(
sizeof
(
tmp
))
<=
len
)
{
elock
(
f
->
ep
);
// 跳过empty slots
while
((
ret
=
enext
(
f
->
ep
,
&
de
,
f
->
off
,
&
count
))
==
0
)
{
f
->
off
+=
count
*
32
;
}
eunlock
(
f
->
ep
);
// 目录结尾
if
(
ret
==
-
1
)
return
nread
;
f
->
off
+=
count
*
32
;
safestrcpy
(
tmp
.
d_name
,
de
.
filename
,
strlen
(
de
.
filename
)
+
1
);
if
(
copyout2
(
addr
,
(
char
*
)
&
tmp
,
sizeof
(
tmp
))
<
0
)
return
-
1
;
addr
+=
sizeof
(
tmp
);
nread
+=
(
int
)(
sizeof
(
tmp
));
}
return
nread
;
}
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