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
educg-net-28668-2608132
OSKernel2024-JTing-3602
Commits
e40ae3f9
Commit
e40ae3f9
authored
2 months ago
by
某某某
Browse files
Options
Download
Patches
Plain Diff
pwd实现
parent
5748a3b5
main
chong
develop
fb
pwd
touch
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
Makefile
+3
-2
Makefile
kernel/include/sysnum.h
+1
-0
kernel/include/sysnum.h
kernel/syscall.c
+3
-0
kernel/syscall.c
kernel/sysfile.c
+39
-0
kernel/sysfile.c
xv6-user/pwd.c
+15
-0
xv6-user/pwd.c
xv6-user/user.h
+1
-0
xv6-user/user.h
xv6-user/usys.pl
+1
-0
xv6-user/usys.pl
with
63 additions
and
2 deletions
+63
-2
Makefile
+
3
−
2
View file @
e40ae3f9
...
...
@@ -65,8 +65,8 @@ else
RUSTSBI
=
./bootloader/SBI/sbi-qemu
endif
TOOLPREFIX
:=
riscv64-unknown-elf-
#
TOOLPREFIX := riscv64-linux-gnu-
#
TOOLPREFIX := riscv64-unknown-elf-
TOOLPREFIX
:=
riscv64-linux-gnu-
CC
=
$(
TOOLPREFIX
)
gcc
AS
=
$(
TOOLPREFIX
)
gas
LD
=
$(
TOOLPREFIX
)
ld
...
...
@@ -204,6 +204,7 @@ UPROGS=\
$U
/_usertests
\
$U
/_strace
\
$U
/_mv
\
$U
/_pwd
\
# $U/_forktest\
# $U/_ln\
...
...
This diff is collapsed.
Click to expand it.
kernel/include/sysnum.h
+
1
−
0
View file @
e40ae3f9
...
...
@@ -28,5 +28,6 @@
#define SYS_readdir 24
#define SYS_getcwd 25
#define SYS_rename 26
#define SYS_pwd 27
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kernel/syscall.c
+
3
−
0
View file @
e40ae3f9
...
...
@@ -116,6 +116,7 @@ extern uint64 sys_remove(void);
extern
uint64
sys_trace
(
void
);
extern
uint64
sys_sysinfo
(
void
);
extern
uint64
sys_rename
(
void
);
extern
uint64
sys_pwd
(
void
);
static
uint64
(
*
syscalls
[])(
void
)
=
{
[
SYS_fork
]
sys_fork
,
...
...
@@ -144,6 +145,7 @@ static uint64 (*syscalls[])(void) = {
[
SYS_trace
]
sys_trace
,
[
SYS_sysinfo
]
sys_sysinfo
,
[
SYS_rename
]
sys_rename
,
[
SYS_pwd
]
sys_pwd
,
};
static
char
*
sysnames
[]
=
{
...
...
@@ -173,6 +175,7 @@ static char *sysnames[] = {
[
SYS_trace
]
"trace"
,
[
SYS_sysinfo
]
"sysinfo"
,
[
SYS_rename
]
"rename"
,
[
SYS_pwd
]
"pwd"
,
};
void
...
...
This diff is collapsed.
Click to expand it.
kernel/sysfile.c
+
39
−
0
View file @
e40ae3f9
...
...
@@ -365,6 +365,45 @@ sys_getcwd(void)
}
// get absolute cwd string
uint64
sys_pwd
(
void
)
{
uint64
addr
;
if
(
argaddr
(
0
,
&
addr
)
<
0
)
return
-
1
;
struct
dirent
*
de
=
myproc
()
->
cwd
;
char
path
[
FAT32_MAX_PATH
];
char
*
s
;
int
len
;
if
(
de
->
parent
==
NULL
)
{
s
=
"/"
;
}
else
{
s
=
path
+
FAT32_MAX_PATH
-
1
;
*
s
=
'\0'
;
while
(
de
->
parent
)
{
len
=
strlen
(
de
->
filename
);
s
-=
len
;
if
(
s
<=
path
)
// can't reach root "/"
return
-
1
;
strncpy
(
s
,
de
->
filename
,
len
);
*--
s
=
'/'
;
de
=
de
->
parent
;
}
}
// if (copyout(myproc()->pagetable, addr, s, strlen(s) + 1) < 0)
if
(
copyout2
(
addr
,
s
,
strlen
(
s
)
+
1
)
<
0
)
return
-
1
;
return
0
;
}
// Is the directory dp empty except for "." and ".." ?
static
int
isdirempty
(
struct
dirent
*
dp
)
...
...
This diff is collapsed.
Click to expand it.
xv6-user/pwd.c
0 → 100644
+
15
−
0
View file @
e40ae3f9
#include
"kernel/include/types.h"
#include
"kernel/include/stat.h"
#include
"xv6-user/user.h"
int
main
(
int
argc
,
char
*
argv
[])
{
char
buf
[
128
];
if
(
pwd
(
buf
)
<
0
)
{
fprintf
(
2
,
"pwd failed
\n
"
);
exit
(
1
);
}
printf
(
"%s
\n
"
,
buf
);
exit
(
0
);
}
This diff is collapsed.
Click to expand it.
xv6-user/user.h
+
1
−
0
View file @
e40ae3f9
...
...
@@ -33,6 +33,7 @@ int remove(char *filename);
int
trace
(
int
mask
);
int
sysinfo
(
struct
sysinfo
*
);
int
rename
(
char
*
old
,
char
*
new
);
int
pwd
(
char
*
buf
);
// ulib.c
int
stat
(
const
char
*
,
struct
stat
*
);
...
...
This diff is collapsed.
Click to expand it.
xv6-user/usys.pl
+
1
−
0
View file @
e40ae3f9
...
...
@@ -41,3 +41,4 @@ entry("remove");
entry
("
trace
");
entry
("
sysinfo
");
entry
("
rename
");
entry
("
pwd
");
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