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
50e514be
Commit
50e514be
authored
18 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
fd_* => file_*
parent
9936bffa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
defs.h
+8
-8
8 additions, 8 deletions
defs.h
file.c
+13
-13
13 additions, 13 deletions
file.c
main.c
+1
-1
1 addition, 1 deletion
main.c
pipe.c
+4
-4
4 additions, 4 deletions
pipe.c
proc.c
+2
-2
2 additions, 2 deletions
proc.c
sysfile.c
+13
-13
13 additions, 13 deletions
sysfile.c
with
41 additions
and
41 deletions
defs.h
+
8
−
8
View file @
50e514be
...
...
@@ -92,14 +92,14 @@ int pipe_read(struct pipe*, char*, int);
// fd.c
struct
stat
;
void
f
d_
init
(
void
);
int
fd
_u
alloc
(
void
);
struct
file
*
f
d_
alloc
(
void
);
void
f
d_
close
(
struct
file
*
);
int
f
d_
read
(
struct
file
*
,
char
*
,
int
n
);
int
f
d_
write
(
struct
file
*
,
char
*
,
int
n
);
int
f
d_
stat
(
struct
file
*
,
struct
stat
*
);
void
f
d_
incref
(
struct
file
*
);
void
f
ile
init
(
void
);
int
fdalloc
(
void
);
struct
file
*
f
ile
alloc
(
void
);
void
f
ile
close
(
struct
file
*
);
int
f
ile
read
(
struct
file
*
,
char
*
,
int
n
);
int
f
ile
write
(
struct
file
*
,
char
*
,
int
n
);
int
f
ile
stat
(
struct
file
*
,
struct
stat
*
);
void
f
ile
incref
(
struct
file
*
);
// ide.c
void
ide_init
(
void
);
...
...
This diff is collapsed.
Click to expand it.
file.c
+
13
−
13
View file @
50e514be
...
...
@@ -17,14 +17,14 @@ struct devsw devsw[NDEV];
struct
file
file
[
NFILE
];
void
f
d_
init
(
void
)
f
ile
init
(
void
)
{
initlock
(
&
fd_table_lock
,
"fd_table"
);
}
// Allocate a file descriptor number for curproc.
int
fd
_u
alloc
(
void
)
fdalloc
(
void
)
{
int
fd
;
struct
proc
*
p
=
curproc
[
cpu
()];
...
...
@@ -36,7 +36,7 @@ fd_ualloc(void)
// Allocate a file descriptor structure
struct
file
*
f
d_
alloc
(
void
)
f
ile
alloc
(
void
)
{
int
i
;
...
...
@@ -56,7 +56,7 @@ fd_alloc(void)
// Write to file descriptor;
// addr is a kernel address, pointing into some process's p->mem.
int
f
d_
write
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
f
ile
write
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
{
if
(
fd
->
writable
==
0
)
return
-
1
;
...
...
@@ -71,14 +71,14 @@ fd_write(struct file *fd, char *addr, int n)
iunlock
(
fd
->
ip
);
return
r
;
}
else
{
panic
(
"f
d_
write"
);
panic
(
"f
ile
write"
);
return
-
1
;
}
}
// Read from file descriptor.
int
f
d_
read
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
f
ile
read
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
{
if
(
fd
->
readable
==
0
)
return
-
1
;
...
...
@@ -92,19 +92,19 @@ fd_read(struct file *fd, char *addr, int n)
iunlock
(
fd
->
ip
);
return
cc
;
}
else
{
panic
(
"f
d_
read"
);
panic
(
"f
ile
read"
);
return
-
1
;
}
}
// Close file descriptor.
void
f
d_
close
(
struct
file
*
fd
)
f
ile
close
(
struct
file
*
fd
)
{
acquire
(
&
fd_table_lock
);
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
panic
(
"f
d_
close"
);
panic
(
"f
ile
close"
);
if
(
--
fd
->
ref
==
0
){
struct
file
dummy
=
*
fd
;
...
...
@@ -118,7 +118,7 @@ fd_close(struct file *fd)
}
else
if
(
dummy
.
type
==
FD_FILE
){
idecref
(
dummy
.
ip
);
}
else
{
panic
(
"f
d_
close"
);
panic
(
"f
ile
close"
);
}
}
else
{
release
(
&
fd_table_lock
);
...
...
@@ -127,7 +127,7 @@ fd_close(struct file *fd)
// Get metadata about file descriptor.
int
f
d_
stat
(
struct
file
*
fd
,
struct
stat
*
st
)
f
ile
stat
(
struct
file
*
fd
,
struct
stat
*
st
)
{
if
(
fd
->
type
==
FD_FILE
){
ilock
(
fd
->
ip
);
...
...
@@ -140,11 +140,11 @@ fd_stat(struct file *fd, struct stat *st)
// Increment file descriptor reference count.
void
f
d_
incref
(
struct
file
*
fd
)
f
ile
incref
(
struct
file
*
fd
)
{
acquire
(
&
fd_table_lock
);
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
panic
(
"f
d_
incref"
);
panic
(
"f
ile
incref"
);
fd
->
ref
++
;
release
(
&
fd_table_lock
);
}
This diff is collapsed.
Click to expand it.
main.c
+
1
−
1
View file @
50e514be
...
...
@@ -49,7 +49,7 @@ main0(void)
kinit
();
// physical memory allocator
tvinit
();
// trap vectors
idtinit
();
// this CPU's interrupt descriptor table
f
d_
init
();
f
ile
init
();
iinit
();
// i-node table
// initialize process 0
...
...
This diff is collapsed.
Click to expand it.
pipe.c
+
4
−
4
View file @
50e514be
...
...
@@ -24,9 +24,9 @@ pipe_alloc(struct file **fd1, struct file **fd2)
*
fd1
=
*
fd2
=
0
;
struct
pipe
*
p
=
0
;
if
((
*
fd1
=
f
d_
alloc
())
==
0
)
if
((
*
fd1
=
f
ile
alloc
())
==
0
)
goto
oops
;
if
((
*
fd2
=
f
d_
alloc
())
==
0
)
if
((
*
fd2
=
f
ile
alloc
())
==
0
)
goto
oops
;
if
((
p
=
(
struct
pipe
*
)
kalloc
(
PAGE
))
==
0
)
goto
oops
;
...
...
@@ -49,11 +49,11 @@ pipe_alloc(struct file **fd1, struct file **fd2)
kfree
((
char
*
)
p
,
PAGE
);
if
(
*
fd1
){
(
*
fd1
)
->
type
=
FD_NONE
;
f
d_
close
(
*
fd1
);
f
ile
close
(
*
fd1
);
}
if
(
*
fd2
){
(
*
fd2
)
->
type
=
FD_NONE
;
f
d_
close
(
*
fd2
);
f
ile
close
(
*
fd2
);
}
return
-
1
;
}
...
...
This diff is collapsed.
Click to expand it.
proc.c
+
2
−
2
View file @
50e514be
...
...
@@ -127,7 +127,7 @@ copyproc(struct proc *p)
for
(
i
=
0
;
i
<
NOFILE
;
i
++
){
np
->
ofile
[
i
]
=
p
->
ofile
[
i
];
if
(
np
->
ofile
[
i
])
f
d_
incref
(
np
->
ofile
[
i
]);
f
ile
incref
(
np
->
ofile
[
i
]);
}
np
->
cwd
=
p
->
cwd
;
...
...
@@ -329,7 +329,7 @@ proc_exit(void)
// Close all open files.
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
if
(
cp
->
ofile
[
fd
]){
f
d_
close
(
cp
->
ofile
[
fd
]);
f
ile
close
(
cp
->
ofile
[
fd
]);
cp
->
ofile
[
fd
]
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
sysfile.c
+
13
−
13
View file @
50e514be
...
...
@@ -25,10 +25,10 @@ sys_pipe(void)
if
(
pipe_alloc
(
&
rfd
,
&
wfd
)
<
0
)
goto
oops
;
if
((
f1
=
fd
_u
alloc
())
<
0
)
if
((
f1
=
fdalloc
())
<
0
)
goto
oops
;
p
->
ofile
[
f1
]
=
rfd
;
if
((
f2
=
fd
_u
alloc
())
<
0
)
if
((
f2
=
fdalloc
())
<
0
)
goto
oops
;
p
->
ofile
[
f2
]
=
wfd
;
if
(
fetcharg
(
0
,
&
fdp
)
<
0
)
...
...
@@ -41,9 +41,9 @@ sys_pipe(void)
oops:
if
(
rfd
)
f
d_
close
(
rfd
);
f
ile
close
(
rfd
);
if
(
wfd
)
f
d_
close
(
wfd
);
f
ile
close
(
wfd
);
if
(
f1
>=
0
)
p
->
ofile
[
f1
]
=
0
;
if
(
f2
>=
0
)
...
...
@@ -67,7 +67,7 @@ sys_write(void)
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
ret
=
f
d_
write
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
f
ile
write
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
}
...
...
@@ -86,7 +86,7 @@ sys_read(void)
return
-
1
;
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
ret
=
f
d_
read
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
f
ile
read
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
}
...
...
@@ -102,7 +102,7 @@ sys_close(void)
return
-
1
;
if
(
p
->
ofile
[
fd
]
==
0
)
return
-
1
;
f
d_
close
(
p
->
ofile
[
fd
]);
f
ile
close
(
p
->
ofile
[
fd
]);
p
->
ofile
[
fd
]
=
0
;
return
0
;
}
...
...
@@ -146,13 +146,13 @@ sys_open(void)
return
-
1
;
}
if
((
fd
=
f
d_
alloc
())
==
0
){
if
((
fd
=
f
ile
alloc
())
==
0
){
iput
(
ip
);
return
-
1
;
}
if
((
ufd
=
fd
_u
alloc
())
<
0
){
if
((
ufd
=
fdalloc
())
<
0
){
iput
(
ip
);
f
d_
close
(
fd
);
f
ile
close
(
fd
);
return
-
1
;
}
...
...
@@ -310,7 +310,7 @@ sys_fstat(void)
return
-
1
;
if
(
addr
+
sizeof
(
struct
stat
)
>
cp
->
sz
)
return
-
1
;
r
=
f
d_
stat
(
cp
->
ofile
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
r
=
f
ile
stat
(
cp
->
ofile
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
return
r
;
}
...
...
@@ -326,10 +326,10 @@ sys_dup(void)
return
-
1
;
if
(
cp
->
ofile
[
fd
]
==
0
)
return
-
1
;
if
((
ufd1
=
fd
_u
alloc
())
<
0
)
if
((
ufd1
=
fdalloc
())
<
0
)
return
-
1
;
cp
->
ofile
[
ufd1
]
=
cp
->
ofile
[
fd
];
f
d_
incref
(
cp
->
ofile
[
ufd1
]);
f
ile
incref
(
cp
->
ofile
[
ufd1
]);
return
ufd1
;
}
...
...
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