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
7ce01cf9
Commit
7ce01cf9
authored
18 years ago
by
rtm
Browse files
Options
Downloads
Patches
Plain Diff
mknod set nlink = 1
usertests for concurrent create/delete, and read() after unlink()
parent
43572072
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fs.c
+5
-3
5 additions, 3 deletions
fs.c
usertests.c
+114
-0
114 additions, 0 deletions
usertests.c
with
119 additions
and
3 deletions
fs.c
+
5
−
3
View file @
7ce01cf9
...
...
@@ -412,6 +412,8 @@ namei(char *path, uint *ret_pinum)
pinum
=
dp
->
inum
;
iput
(
dp
);
dp
=
iget
(
dev
,
ninum
);
if
(
dp
->
type
==
0
||
dp
->
nlink
<
1
)
panic
(
"namei"
);
while
(
*
cp
==
'/'
)
cp
++
;
}
...
...
@@ -443,7 +445,7 @@ mknod(char *cp, short type, short major, short minor)
ip
->
major
=
major
;
ip
->
minor
=
minor
;
ip
->
size
=
0
;
ip
->
nlink
=
0
;
ip
->
nlink
=
1
;
iupdate
(
ip
);
// write new inode to disk
...
...
@@ -467,8 +469,8 @@ mknod(char *cp, short type, short major, short minor)
brelse
(
bp
);
dp
->
size
+=
sizeof
(
struct
dirent
);
// update directory inode
iupdate
(
dp
);
iput
(
dp
);
return
ip
;
iput
(
dp
);
return
ip
;
}
int
...
...
This diff is collapsed.
Click to expand it.
usertests.c
+
114
−
0
View file @
7ce01cf9
...
...
@@ -157,6 +157,7 @@ sharedfd()
}
}
close
(
fd
);
unlink
(
"sharedfd"
);
if
(
nc
==
1000
&&
np
==
1000
)
printf
(
1
,
"sharedfd ok
\n
"
);
else
...
...
@@ -219,14 +220,127 @@ twofiles()
}
}
unlink
(
"f1"
);
unlink
(
"f2"
);
puts
(
"twofiles ok
\n
"
);
}
// two processes create and delete files in same directory
void
createdelete
()
{
int
pid
,
i
,
fd
;
int
n
=
10
;
// for now, fit in one directory block
char
name
[
32
];
pid
=
fork
();
if
(
pid
<
0
){
puts
(
"fork failed
\n
"
);
exit
();
}
name
[
0
]
=
pid
?
'p'
:
'c'
;
name
[
2
]
=
'\0'
;
for
(
i
=
0
;
i
<
n
;
i
++
){
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
puts
(
"create failed
\n
"
);
exit
();
}
close
(
fd
);
if
(
i
>
0
&&
(
i
%
2
)
==
0
){
name
[
1
]
=
'0'
+
(
i
/
2
);
if
(
unlink
(
name
)
<
0
){
puts
(
"unlink failed
\n
"
);
exit
();
}
}
}
if
(
pid
)
wait
();
else
exit
();
for
(
i
=
0
;
i
<
n
;
i
++
){
name
[
0
]
=
'p'
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
n
/
2
)
&&
fd
<
0
){
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
}
else
if
((
i
>=
1
&&
i
<
n
/
2
)
&&
fd
>=
0
){
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
}
if
(
fd
>=
0
)
close
(
fd
);
name
[
0
]
=
'c'
;
name
[
1
]
=
'0'
+
i
;
fd
=
open
(
name
,
0
);
if
((
i
==
0
||
i
>=
n
/
2
)
&&
fd
<
0
){
printf
(
1
,
"oops createdelete %s didn't exist
\n
"
,
name
);
}
else
if
((
i
>=
1
&&
i
<
n
/
2
)
&&
fd
>=
0
){
printf
(
1
,
"oops createdelete %s did exist
\n
"
,
name
);
}
if
(
fd
>=
0
)
close
(
fd
);
}
for
(
i
=
0
;
i
<
n
;
i
++
){
name
[
0
]
=
'p'
;
name
[
1
]
=
'0'
+
i
;
unlink
(
name
);
name
[
0
]
=
'c'
;
unlink
(
name
);
}
printf
(
1
,
"createdelete ok
\n
"
);
}
// can I unlink a file and still read it?
void
unlinkread
()
{
int
fd
;
fd
=
open
(
"unlinkread"
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
puts
(
"create unlinkread failed
\n
"
);
exit
();
}
write
(
fd
,
"hello"
,
5
);
close
(
fd
);
fd
=
open
(
"unlinkread"
,
O_RDWR
);
if
(
fd
<
0
){
puts
(
"open unlinkread failed
\n
"
);
exit
();
}
if
(
unlink
(
"unlinkread"
)
!=
0
){
puts
(
"unlink unlinkread failed
\n
"
);
exit
();
}
if
(
read
(
fd
,
buf
,
sizeof
(
buf
))
!=
5
){
puts
(
"unlinkread read failed"
);
exit
();
}
if
(
write
(
fd
,
buf
,
10
)
!=
10
){
puts
(
"unlinkread write failed
\n
"
);
exit
();
}
close
(
fd
);
puts
(
"unlinkread ok
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
puts
(
"usertests starting
\n
"
);
unlinkread
();
createdelete
();
twofiles
();
sharedfd
();
pipe1
();
...
...
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