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
2cbb4b18
Commit
2cbb4b18
authored
18 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
stop using fd to name files
parent
5692823b
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
file.c
+42
-42
42 additions, 42 deletions
file.c
pipe.c
+18
-18
18 additions, 18 deletions
pipe.c
with
60 additions
and
60 deletions
file.c
+
42
−
42
View file @
2cbb4b18
...
...
@@ -11,7 +11,7 @@
#include
"fs.h"
#include
"fsvar.h"
struct
spinlock
f
d
_table_lock
;
struct
spinlock
f
ile
_table_lock
;
struct
devsw
devsw
[
NDEV
];
struct
file
file
[
NFILE
];
...
...
@@ -19,7 +19,7 @@ struct file file[NFILE];
void
fileinit
(
void
)
{
initlock
(
&
f
d
_table_lock
,
"f
d
_table"
);
initlock
(
&
f
ile
_table_lock
,
"f
ile
_table"
);
}
// Allocate a file structure
...
...
@@ -28,34 +28,34 @@ filealloc(void)
{
int
i
;
acquire
(
&
f
d
_table_lock
);
acquire
(
&
f
ile
_table_lock
);
for
(
i
=
0
;
i
<
NFILE
;
i
++
){
if
(
file
[
i
].
type
==
FD_CLOSED
){
file
[
i
].
type
=
FD_NONE
;
file
[
i
].
ref
=
1
;
release
(
&
f
d
_table_lock
);
release
(
&
f
ile
_table_lock
);
return
file
+
i
;
}
}
release
(
&
f
d
_table_lock
);
release
(
&
f
ile
_table_lock
);
return
0
;
}
// Write to file f. Addr is kernel address.
int
filewrite
(
struct
file
*
f
d
,
char
*
addr
,
int
n
)
filewrite
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
if
(
f
d
->
writable
==
0
)
if
(
f
->
writable
==
0
)
return
-
1
;
if
(
f
d
->
type
==
FD_PIPE
){
return
pipe_write
(
f
d
->
pipe
,
addr
,
n
);
}
else
if
(
f
d
->
type
==
FD_FILE
)
{
ilock
(
f
d
->
ip
);
int
r
=
writei
(
f
d
->
ip
,
addr
,
f
d
->
off
,
n
);
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
d
->
off
+=
r
;
f
->
off
+=
r
;
}
iunlock
(
f
d
->
ip
);
iunlock
(
f
->
ip
);
return
r
;
}
else
{
panic
(
"filewrite"
);
...
...
@@ -65,18 +65,18 @@ filewrite(struct file *fd, char *addr, int n)
// Read from file f. Addr is kernel address.
int
fileread
(
struct
file
*
f
d
,
char
*
addr
,
int
n
)
fileread
(
struct
file
*
f
,
char
*
addr
,
int
n
)
{
if
(
f
d
->
readable
==
0
)
if
(
f
->
readable
==
0
)
return
-
1
;
if
(
f
d
->
type
==
FD_PIPE
){
return
pipe_read
(
f
d
->
pipe
,
addr
,
n
);
}
else
if
(
f
d
->
type
==
FD_FILE
){
ilock
(
f
d
->
ip
);
int
cc
=
readi
(
f
d
->
ip
,
addr
,
f
d
->
off
,
n
);
if
(
f
->
type
==
FD_PIPE
){
return
pipe_read
(
f
->
pipe
,
addr
,
n
);
}
else
if
(
f
->
type
==
FD_FILE
){
ilock
(
f
->
ip
);
int
cc
=
readi
(
f
->
ip
,
addr
,
f
->
off
,
n
);
if
(
cc
>
0
)
f
d
->
off
+=
cc
;
iunlock
(
f
d
->
ip
);
f
->
off
+=
cc
;
iunlock
(
f
->
ip
);
return
cc
;
}
else
{
panic
(
"fileread"
);
...
...
@@ -86,19 +86,19 @@ fileread(struct file *fd, char *addr, int n)
// Close file f. (Decrement ref count, close when reaches 0.)
void
fileclose
(
struct
file
*
f
d
)
fileclose
(
struct
file
*
f
)
{
acquire
(
&
f
d
_table_lock
);
acquire
(
&
f
ile
_table_lock
);
if
(
f
d
->
ref
<
1
||
f
d
->
type
==
FD_CLOSED
)
if
(
f
->
ref
<
1
||
f
->
type
==
FD_CLOSED
)
panic
(
"fileclose"
);
if
(
--
f
d
->
ref
==
0
){
struct
file
dummy
=
*
f
d
;
if
(
--
f
->
ref
==
0
){
struct
file
dummy
=
*
f
;
f
d
->
ref
=
0
;
f
d
->
type
=
FD_CLOSED
;
release
(
&
f
d
_table_lock
);
f
->
ref
=
0
;
f
->
type
=
FD_CLOSED
;
release
(
&
f
ile
_table_lock
);
if
(
dummy
.
type
==
FD_PIPE
){
pipe_close
(
dummy
.
pipe
,
dummy
.
writable
);
...
...
@@ -108,18 +108,18 @@ fileclose(struct file *fd)
panic
(
"fileclose"
);
}
}
else
{
release
(
&
f
d
_table_lock
);
release
(
&
f
ile
_table_lock
);
}
}
// Get metadata about file f.
int
filestat
(
struct
file
*
f
d
,
struct
stat
*
st
)
filestat
(
struct
file
*
f
,
struct
stat
*
st
)
{
if
(
f
d
->
type
==
FD_FILE
){
ilock
(
f
d
->
ip
);
stati
(
f
d
->
ip
,
st
);
iunlock
(
f
d
->
ip
);
if
(
f
->
type
==
FD_FILE
){
ilock
(
f
->
ip
);
stati
(
f
->
ip
,
st
);
iunlock
(
f
->
ip
);
return
0
;
}
else
return
-
1
;
...
...
@@ -127,11 +127,11 @@ filestat(struct file *fd, struct stat *st)
// Increment ref count for file f.
void
fileincref
(
struct
file
*
f
d
)
fileincref
(
struct
file
*
f
)
{
acquire
(
&
f
d
_table_lock
);
if
(
f
d
->
ref
<
1
||
f
d
->
type
==
FD_CLOSED
)
acquire
(
&
f
ile
_table_lock
);
if
(
f
->
ref
<
1
||
f
->
type
==
FD_CLOSED
)
panic
(
"fileincref"
);
f
d
->
ref
++
;
release
(
&
f
d
_table_lock
);
f
->
ref
++
;
release
(
&
f
ile
_table_lock
);
}
This diff is collapsed.
Click to expand it.
pipe.c
+
18
−
18
View file @
2cbb4b18
...
...
@@ -19,14 +19,14 @@ struct pipe {
};
int
pipe_alloc
(
struct
file
**
f
d1
,
struct
file
**
f
d2
)
pipe_alloc
(
struct
file
**
f
0
,
struct
file
**
f
1
)
{
*
f
d1
=
*
f
d2
=
0
;
*
f
0
=
*
f
1
=
0
;
struct
pipe
*
p
=
0
;
if
((
*
f
d1
=
filealloc
())
==
0
)
if
((
*
f
0
=
filealloc
())
==
0
)
goto
oops
;
if
((
*
f
d2
=
filealloc
())
==
0
)
if
((
*
f
1
=
filealloc
())
==
0
)
goto
oops
;
if
((
p
=
(
struct
pipe
*
)
kalloc
(
PAGE
))
==
0
)
goto
oops
;
...
...
@@ -35,25 +35,25 @@ pipe_alloc(struct file **fd1, struct file **fd2)
p
->
writep
=
0
;
p
->
readp
=
0
;
initlock
(
&
p
->
lock
,
"pipe"
);
(
*
f
d1
)
->
type
=
FD_PIPE
;
(
*
f
d1
)
->
readable
=
1
;
(
*
f
d1
)
->
writable
=
0
;
(
*
f
d1
)
->
pipe
=
p
;
(
*
f
d2
)
->
type
=
FD_PIPE
;
(
*
f
d2
)
->
readable
=
0
;
(
*
f
d2
)
->
writable
=
1
;
(
*
f
d2
)
->
pipe
=
p
;
(
*
f
0
)
->
type
=
FD_PIPE
;
(
*
f
0
)
->
readable
=
1
;
(
*
f
0
)
->
writable
=
0
;
(
*
f
0
)
->
pipe
=
p
;
(
*
f
1
)
->
type
=
FD_PIPE
;
(
*
f
1
)
->
readable
=
0
;
(
*
f
1
)
->
writable
=
1
;
(
*
f
1
)
->
pipe
=
p
;
return
0
;
oops:
if
(
p
)
kfree
((
char
*
)
p
,
PAGE
);
if
(
*
f
d1
){
(
*
f
d1
)
->
type
=
FD_NONE
;
fileclose
(
*
f
d1
);
if
(
*
f
0
){
(
*
f
0
)
->
type
=
FD_NONE
;
fileclose
(
*
f
0
);
}
if
(
*
f
d2
){
(
*
f
d2
)
->
type
=
FD_NONE
;
fileclose
(
*
f
d2
);
if
(
*
f
1
){
(
*
f
1
)
->
type
=
FD_NONE
;
fileclose
(
*
f
1
);
}
return
-
1
;
}
...
...
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