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
2186f88c
Commit
2186f88c
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
formatting, cleanup
parent
cce27ba9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
file.c
+55
-57
55 additions, 57 deletions
file.c
with
55 additions
and
57 deletions
file.c
+
55
−
57
View file @
2186f88c
...
...
@@ -41,75 +41,55 @@ filealloc(void)
return
0
;
}
//
Write to file f. Addr is kernel address
.
int
file
write
(
struct
file
*
f
,
char
*
addr
,
int
n
)
//
Increment ref count for file f
.
void
file
incref
(
struct
file
*
f
)
{
if
(
f
->
writable
==
0
)
return
-
1
;
if
(
f
->
type
==
FD_PIPE
){
return
pipe_write
(
f
->
pipe
,
addr
,
n
);
}
else
if
(
f
->
type
==
FD_FILE
)
{
ilock
(
f
->
ip
);
int
r
=
writei
(
f
->
ip
,
addr
,
f
->
off
,
n
);
if
(
r
>
0
)
{
f
->
off
+=
r
;
}
iunlock
(
f
->
ip
);
return
r
;
}
else
{
panic
(
"filewrite"
);
return
-
1
;
}
acquire
(
&
file_table_lock
);
if
(
f
->
ref
<
1
||
f
->
type
==
FD_CLOSED
)
panic
(
"fileincref"
);
f
->
ref
++
;
release
(
&
file_table_lock
);
}
// Read from file f. Addr is kernel address.
int
fileread
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
int
r
;
if
(
f
->
readable
==
0
)
return
-
1
;
if
(
f
->
type
==
FD_PIPE
)
{
if
(
f
->
type
==
FD_PIPE
)
return
pipe_read
(
f
->
pipe
,
addr
,
n
);
}
else
if
(
f
->
type
==
FD_FILE
){
if
(
f
->
type
==
FD_FILE
){
ilock
(
f
->
ip
);
int
cc
=
readi
(
f
->
ip
,
addr
,
f
->
off
,
n
);
if
(
cc
>
0
)
f
->
off
+=
cc
;
if
((
r
=
readi
(
f
->
ip
,
addr
,
f
->
off
,
n
))
>
0
)
f
->
off
+=
r
;
iunlock
(
f
->
ip
);
return
cc
;
}
else
{
panic
(
"fileread"
);
return
-
1
;
return
r
;
}
panic
(
"fileread"
);
}
//
Close
file f.
(Decrement ref count, close when reaches 0.)
void
file
clos
e
(
struct
file
*
f
)
//
Write to
file f.
Addr is kernel address.
int
file
writ
e
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
acquire
(
&
file_table_lock
);
if
(
f
->
ref
<
1
||
f
->
type
==
FD_CLOSED
)
panic
(
"fileclose"
);
int
r
;
if
(
--
f
->
ref
==
0
){
struct
file
dummy
=
*
f
;
f
->
ref
=
0
;
f
->
type
=
FD_CLOSED
;
release
(
&
file_table_lock
);
if
(
dummy
.
type
==
FD_PIPE
){
pipe_close
(
dummy
.
pipe
,
dummy
.
writable
);
}
else
if
(
dummy
.
type
==
FD_FILE
){
idecref
(
dummy
.
ip
);
}
else
{
panic
(
"fileclose"
);
}
}
else
{
release
(
&
file_table_lock
);
if
(
f
->
writable
==
0
)
return
-
1
;
if
(
f
->
type
==
FD_PIPE
)
return
pipe_write
(
f
->
pipe
,
addr
,
n
);
if
(
f
->
type
==
FD_FILE
){
ilock
(
f
->
ip
);
if
((
r
=
writei
(
f
->
ip
,
addr
,
f
->
off
,
n
))
>
0
)
f
->
off
+=
r
;
iunlock
(
f
->
ip
);
return
r
;
}
panic
(
"filewrite"
);
}
// Get metadata about file f.
...
...
@@ -121,17 +101,35 @@ filestat(struct file *f, struct stat *st)
stati
(
f
->
ip
,
st
);
iunlock
(
f
->
ip
);
return
0
;
}
else
return
-
1
;
}
return
-
1
;
}
//
Increment ref count for file f.
//
Close file f. (Decrement ref count, close when reaches 0.)
void
file
incref
(
struct
file
*
f
)
file
close
(
struct
file
*
f
)
{
struct
file
ff
;
acquire
(
&
file_table_lock
);
if
(
f
->
ref
<
1
||
f
->
type
==
FD_CLOSED
)
panic
(
"fileincref"
);
f
->
ref
++
;
panic
(
"fileclose"
);
if
(
--
f
->
ref
>
0
){
release
(
&
file_table_lock
);
return
;
}
ff
=
*
f
;
f
->
ref
=
0
;
f
->
type
=
FD_CLOSED
;
release
(
&
file_table_lock
);
if
(
ff
.
type
==
FD_PIPE
)
pipe_close
(
ff
.
pipe
,
ff
.
writable
);
else
if
(
ff
.
type
==
FD_FILE
)
idecref
(
ff
.
ip
);
else
panic
(
"fileclose"
);
}
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