Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Krishna Vinnakota
CSEP551
Commits
d15f0d10
Commit
d15f0d10
authored
18 years ago
by
kaashoek
Browse files
Options
Downloads
Patches
Plain Diff
start on mkdir
stat
parent
e4bcd2a3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
ls.c
+12
-6
12 additions, 6 deletions
ls.c
syscall.c
+28
-0
28 additions, 0 deletions
syscall.c
syscall.h
+1
-0
1 addition, 0 deletions
syscall.h
ulib.c
+16
-0
16 additions, 0 deletions
ulib.c
user.h
+2
-1
2 additions, 1 deletion
user.h
userfs.c
+13
-0
13 additions, 0 deletions
userfs.c
usys.S
+1
-0
1 addition, 0 deletions
usys.S
with
73 additions
and
7 deletions
ls.c
+
12
−
6
View file @
d15f0d10
...
...
@@ -4,7 +4,7 @@
#include
"fs.h"
char
buf
[
512
];
struct
stat
st
at
;
struct
stat
st
;
struct
dirent
dirent
;
int
...
...
@@ -23,20 +23,26 @@ main(int argc, char *argv[])
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
if
(
fstat
(
fd
,
&
st
at
)
<
0
)
{
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
if
(
st
at
.
st_type
!=
T_DIR
)
{
if
(
st
.
st_type
!=
T_DIR
)
{
printf
(
2
,
"ls: . is not a dir
\n
"
);
}
for
(
off
=
0
;
off
<
stat
.
st_size
;
off
+=
sizeof
(
struct
dirent
))
{
cprintf
(
"size %d
\n
"
,
st
.
st_size
);
for
(
off
=
0
;
off
<
st
.
st_size
;
off
+=
sizeof
(
struct
dirent
))
{
if
(
read
(
fd
,
&
dirent
,
sizeof
(
struct
dirent
))
!=
sizeof
(
struct
dirent
))
{
printf
(
2
,
"ls: read error
\n
"
);
exit
();
}
if
(
dirent
.
inum
!=
0
)
printf
(
1
,
"%s
\n
"
,
dirent
.
name
);
if
(
dirent
.
inum
!=
0
)
{
if
(
stat
(
dirent
.
name
,
&
st
)
<
0
)
printf
(
2
,
"stat: failed
\n
"
);
printf
(
1
,
"%s t %d
\n
"
,
dirent
.
name
,
st
.
st_type
);
}
}
close
(
fd
);
...
...
This diff is collapsed.
Click to expand it.
syscall.c
+
28
−
0
View file @
d15f0d10
...
...
@@ -289,6 +289,31 @@ sys_mknod(void)
return
(
nip
==
0
)
?
-
1
:
0
;
}
int
sys_mkdir
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
inode
*
nip
;
uint
arg0
;
int
l
;
if
(
fetcharg
(
0
,
&
arg0
)
<
0
)
return
-
1
;
if
((
l
=
checkstring
(
arg0
))
<
0
)
return
-
1
;
if
(
l
>=
DIRSIZ
)
return
-
1
;
nip
=
mknod
(
cp
->
mem
+
arg0
,
T_DIR
,
0
,
0
);
// XXX put . and .. in
iput
(
nip
);
return
(
nip
==
0
)
?
-
1
:
0
;
}
int
sys_unlink
(
void
)
{
...
...
@@ -561,6 +586,9 @@ syscall(void)
case
SYS_link
:
ret
=
sys_link
();
break
;
case
SYS_mkdir
:
ret
=
sys_mkdir
();
break
;
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
...
...
This diff is collapsed.
Click to expand it.
syscall.h
+
1
−
0
View file @
d15f0d10
...
...
@@ -13,4 +13,5 @@
#define SYS_unlink 16
#define SYS_fstat 17
#define SYS_link 18
#define SYS_mkdir 19
This diff is collapsed.
Click to expand it.
ulib.c
+
16
−
0
View file @
d15f0d10
#include
"types.h"
#include
"stat.h"
#include
"fcntl.h"
#include
"user.h"
int
...
...
@@ -54,3 +57,16 @@ gets(char *buf, int max)
buf
[
i
]
=
'\0'
;
return
buf
;
}
int
stat
(
char
*
n
,
struct
stat
*
st
)
{
int
fd
=
open
(
n
,
O_RDONLY
);
int
r
;
if
(
fd
<
0
)
return
-
1
;
r
=
fstat
(
fd
,
st
);
close
(
fd
);
return
r
;
}
This diff is collapsed.
Click to expand it.
user.h
+
2
−
1
View file @
d15f0d10
...
...
@@ -14,9 +14,10 @@ int exec(char *, char **);
int
open
(
char
*
,
int
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
unlink
(
char
*
);
struct
stat
;
int
fstat
(
int
fd
,
struct
stat
*
stat
);
int
link
(
char
*
,
char
*
);
int
mkdir
(
char
*
);
int
stat
(
char
*
,
struct
stat
*
stat
);
int
puts
(
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
...
...
This diff is collapsed.
Click to expand it.
userfs.c
+
13
−
0
View file @
d15f0d10
...
...
@@ -65,7 +65,13 @@ main(void)
printf
(
stdout
,
"read failed
\n
"
);
}
close
(
fd
);
printf
(
stdout
,
"unlink doesnotexist
\n
"
);
unlink
(
"doesnotexist"
);
printf
(
stdout
,
"many creates, followed by unlink
\n
"
);
name
[
0
]
=
'a'
;
name
[
2
]
=
'\0'
;
for
(
i
=
0
;
i
<
52
;
i
++
)
{
...
...
@@ -80,6 +86,13 @@ main(void)
unlink
(
name
);
}
printf
(
stdout
,
"mkdir
\n
"
);
if
(
mkdir
(
"dir0"
)
<
0
)
printf
(
stdout
,
"mkdir failed
\n
"
);
// unlink("dir0");
//exec("echo", echo_args);
printf
(
stdout
,
"about to do exec
\n
"
);
exec
(
"cat"
,
cat_args
);
...
...
This diff is collapsed.
Click to expand it.
usys.S
+
1
−
0
View file @
d15f0d10
...
...
@@ -23,3 +23,4 @@ STUB(mknod)
STUB
(
unlink
)
STUB
(
fstat
)
STUB
(
link
)
STUB
(
mkdir
)
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