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
f9a06440
Commit
f9a06440
authored
15 years ago
by
Russ Cox
Browse files
Options
Downloads
Patches
Plain Diff
rearrangements and cleanup for text
parent
2de1c550
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
fs.c
+50
-49
50 additions, 49 deletions
fs.c
initcode.S
+1
-1
1 addition, 1 deletion
initcode.S
kalloc.c
+18
-22
18 additions, 22 deletions
kalloc.c
sysfile.c
+33
-35
33 additions, 35 deletions
sysfile.c
with
102 additions
and
107 deletions
fs.c
+
50
−
49
View file @
f9a06440
...
...
@@ -141,6 +141,53 @@ iinit(void)
initlock
(
&
icache
.
lock
,
"icache"
);
}
static
struct
inode
*
iget
(
uint
dev
,
uint
inum
);
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct
inode
*
ialloc
(
uint
dev
,
short
type
)
{
int
inum
;
struct
buf
*
bp
;
struct
dinode
*
dip
;
struct
superblock
sb
;
readsb
(
dev
,
&
sb
);
for
(
inum
=
1
;
inum
<
sb
.
ninodes
;
inum
++
){
// loop over inode blocks
bp
=
bread
(
dev
,
IBLOCK
(
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
inum
%
IPB
;
if
(
dip
->
type
==
0
){
// a free inode
memset
(
dip
,
0
,
sizeof
(
*
dip
));
dip
->
type
=
type
;
bwrite
(
bp
);
// mark it allocated on the disk
brelse
(
bp
);
return
iget
(
dev
,
inum
);
}
brelse
(
bp
);
}
panic
(
"ialloc: no inodes"
);
}
// Copy inode, which has changed, from memory to disk.
void
iupdate
(
struct
inode
*
ip
)
{
struct
buf
*
bp
;
struct
dinode
*
dip
;
bp
=
bread
(
ip
->
dev
,
IBLOCK
(
ip
->
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
ip
->
inum
%
IPB
;
dip
->
type
=
ip
->
type
;
dip
->
major
=
ip
->
major
;
dip
->
minor
=
ip
->
minor
;
dip
->
nlink
=
ip
->
nlink
;
dip
->
size
=
ip
->
size
;
memmove
(
dip
->
addrs
,
ip
->
addrs
,
sizeof
(
ip
->
addrs
));
bwrite
(
bp
);
brelse
(
bp
);
}
// Find the inode with number inum on device dev
// and return the in-memory copy.
static
struct
inode
*
...
...
@@ -262,51 +309,6 @@ iunlockput(struct inode *ip)
iput
(
ip
);
}
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct
inode
*
ialloc
(
uint
dev
,
short
type
)
{
int
inum
;
struct
buf
*
bp
;
struct
dinode
*
dip
;
struct
superblock
sb
;
readsb
(
dev
,
&
sb
);
for
(
inum
=
1
;
inum
<
sb
.
ninodes
;
inum
++
){
// loop over inode blocks
bp
=
bread
(
dev
,
IBLOCK
(
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
inum
%
IPB
;
if
(
dip
->
type
==
0
){
// a free inode
memset
(
dip
,
0
,
sizeof
(
*
dip
));
dip
->
type
=
type
;
bwrite
(
bp
);
// mark it allocated on the disk
brelse
(
bp
);
return
iget
(
dev
,
inum
);
}
brelse
(
bp
);
}
panic
(
"ialloc: no inodes"
);
}
// Copy inode, which has changed, from memory to disk.
void
iupdate
(
struct
inode
*
ip
)
{
struct
buf
*
bp
;
struct
dinode
*
dip
;
bp
=
bread
(
ip
->
dev
,
IBLOCK
(
ip
->
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
ip
->
inum
%
IPB
;
dip
->
type
=
ip
->
type
;
dip
->
major
=
ip
->
major
;
dip
->
minor
=
ip
->
minor
;
dip
->
nlink
=
ip
->
nlink
;
dip
->
size
=
ip
->
size
;
memmove
(
dip
->
addrs
,
ip
->
addrs
,
sizeof
(
ip
->
addrs
));
bwrite
(
bp
);
brelse
(
bp
);
}
//PAGEBREAK!
// Inode contents
//
...
...
@@ -336,7 +338,6 @@ bmap(struct inode *ip, uint bn)
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
bp
=
bread
(
ip
->
dev
,
addr
);
a
=
(
uint
*
)
bp
->
data
;
if
((
addr
=
a
[
bn
])
==
0
){
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
bwrite
(
bp
);
...
...
@@ -571,7 +572,7 @@ skipelem(char *path, char *name)
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
static
struct
inode
*
namex
(
char
*
path
,
int
parent
,
char
*
name
)
namex
(
char
*
path
,
int
namei
parent
,
char
*
name
)
{
struct
inode
*
ip
,
*
next
;
...
...
@@ -586,7 +587,7 @@ namex(char *path, int parent, char *name)
iunlockput
(
ip
);
return
0
;
}
if
(
parent
&&
*
path
==
'\0'
){
if
(
namei
parent
&&
*
path
==
'\0'
){
// Stop one level early.
iunlock
(
ip
);
return
ip
;
...
...
@@ -598,7 +599,7 @@ namex(char *path, int parent, char *name)
iunlockput
(
ip
);
ip
=
next
;
}
if
(
parent
){
if
(
namei
parent
){
iput
(
ip
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
initcode.S
+
1
−
1
View file @
f9a06440
...
...
@@ -8,7 +8,7 @@
start
:
pushl
$argv
pushl
$init
pushl
$
0
pushl
$
0
//
where
caller
pc
would
be
movl
$SYS_exec
,
%
eax
int
$T_SYSCALL
...
...
This diff is collapsed.
Click to expand it.
kalloc.c
+
18
−
22
View file @
f9a06440
...
...
@@ -22,21 +22,20 @@ struct {
// Initialize free list of physical pages.
// This code cheats by just considering one megabyte of
// pages after
_
end. Real systems would determine the
// pages after end. Real systems would determine the
// amount of memory available in the system and use it all.
void
kinit
(
void
)
{
extern
int
end
;
uint
mem
;
char
*
start
;
extern
char
end
[]
;
uint
len
;
char
*
p
;
initlock
(
&
kmem
.
lock
,
"kmem"
);
start
=
(
char
*
)
&
end
;
start
=
(
char
*
)
(((
uint
)
start
+
PAGE
)
&
~
(
PAGE
-
1
));
mem
=
256
;
// assume computer has 256 pages of RAM
cprintf
(
"mem = %d
\n
"
,
mem
*
PAGE
);
kfree
(
start
,
mem
*
PAGE
);
p
=
(
char
*
)(((
uint
)
end
+
PAGE
)
&
~
(
PAGE
-
1
));
len
=
256
*
PAGE
;
// assume computer has 256 pages of RAM, 1 MB
cprintf
(
"mem = %d
\n
"
,
len
);
kfree
(
p
,
len
);
}
// Free the len bytes of memory pointed at by v,
...
...
@@ -61,13 +60,7 @@ kfree(char *v, int len)
rend
=
(
struct
run
*
)((
char
*
)
r
+
r
->
len
);
if
(
r
<=
p
&&
p
<
rend
)
panic
(
"freeing free page"
);
if
(
pend
==
r
){
// p next to r: replace r with p
p
->
len
=
len
+
r
->
len
;
p
->
next
=
r
->
next
;
*
rp
=
p
;
goto
out
;
}
if
(
rend
==
p
){
// r next to p: replace p with r
if
(
rend
==
p
){
// r before p: expand r to include p
r
->
len
+=
len
;
if
(
r
->
next
&&
r
->
next
==
pend
){
// r now next to r->next?
r
->
len
+=
r
->
next
->
len
;
...
...
@@ -75,6 +68,12 @@ kfree(char *v, int len)
}
goto
out
;
}
if
(
pend
==
r
){
// p before r: expand p to include, replace r
p
->
len
=
len
+
r
->
len
;
p
->
next
=
r
->
next
;
*
rp
=
p
;
goto
out
;
}
}
// Insert p before r in list.
p
->
len
=
len
;
...
...
@@ -99,14 +98,11 @@ kalloc(int n)
acquire
(
&
kmem
.
lock
);
for
(
rp
=&
kmem
.
freelist
;
(
r
=*
rp
)
!=
0
;
rp
=&
r
->
next
){
if
(
r
->
len
==
n
){
*
rp
=
r
->
next
;
release
(
&
kmem
.
lock
);
return
(
char
*
)
r
;
}
if
(
r
->
len
>
n
){
if
(
r
->
len
>=
n
){
r
->
len
-=
n
;
p
=
(
char
*
)
r
+
r
->
len
;
if
(
r
->
len
==
0
)
*
rp
=
r
->
next
;
release
(
&
kmem
.
lock
);
return
p
;
}
...
...
This diff is collapsed.
Click to expand it.
sysfile.c
+
33
−
35
View file @
f9a06440
...
...
@@ -44,6 +44,20 @@ fdalloc(struct file *f)
return
-
1
;
}
int
sys_dup
(
void
)
{
struct
file
*
f
;
int
fd
;
if
(
argfd
(
0
,
0
,
&
f
)
<
0
)
return
-
1
;
if
((
fd
=
fdalloc
(
f
))
<
0
)
return
-
1
;
filedup
(
f
);
return
fd
;
}
int
sys_read
(
void
)
{
...
...
@@ -68,20 +82,6 @@ sys_write(void)
return
filewrite
(
f
,
p
,
n
);
}
int
sys_dup
(
void
)
{
struct
file
*
f
;
int
fd
;
if
(
argfd
(
0
,
0
,
&
f
)
<
0
)
return
-
1
;
if
((
fd
=
fdalloc
(
f
))
<
0
)
return
-
1
;
filedup
(
f
);
return
fd
;
}
int
sys_close
(
void
)
{
...
...
@@ -225,17 +225,15 @@ create(char *path, short type, short major, short minor)
if
((
ip
=
dirlookup
(
dp
,
name
,
&
off
))
!=
0
){
iunlockput
(
dp
);
ilock
(
ip
);
if
(
ip
->
type
!=
type
||
type
!=
T_FILE
){
iunlockput
(
ip
);
return
0
;
}
return
ip
;
}
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
0
){
iunlockput
(
dp
);
if
(
type
==
T_FILE
&&
ip
->
type
==
T_FILE
)
return
ip
;
iunlockput
(
ip
);
return
0
;
}
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
0
)
panic
(
"create: ialloc"
);
ilock
(
ip
);
ip
->
major
=
major
;
ip
->
minor
=
minor
;
...
...
@@ -298,6 +296,18 @@ sys_open(void)
return
fd
;
}
int
sys_mkdir
(
void
)
{
char
*
path
;
struct
inode
*
ip
;
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
}
int
sys_mknod
(
void
)
{
...
...
@@ -315,18 +325,6 @@ sys_mknod(void)
return
0
;
}
int
sys_mkdir
(
void
)
{
char
*
path
;
struct
inode
*
ip
;
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
}
int
sys_chdir
(
void
)
{
...
...
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