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
13ae8808
Commit
13ae8808
authored
15 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
tidy fs.c; bmap callers always expected allocation
parent
f12551b5
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
fs.c
+15
-24
15 additions, 24 deletions
fs.c
with
15 additions
and
24 deletions
fs.c
+
15
−
24
View file @
13ae8808
...
...
@@ -316,38 +316,28 @@ iupdate(struct inode *ip)
// listed in the block ip->addrs[INDIRECT].
// Return the disk block address of the nth block in inode ip.
// If there is no such block,
alloc controls whether one is allocated
.
// If there is no such block,
bmap allocates one
.
static
uint
bmap
(
struct
inode
*
ip
,
uint
bn
,
int
alloc
)
bmap
(
struct
inode
*
ip
,
uint
bn
)
{
uint
addr
,
*
a
;
struct
buf
*
bp
;
if
(
bn
<
NDIRECT
){
if
((
addr
=
ip
->
addrs
[
bn
])
==
0
){
if
(
!
alloc
)
return
-
1
;
if
((
addr
=
ip
->
addrs
[
bn
])
==
0
)
ip
->
addrs
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
}
return
addr
;
}
bn
-=
NDIRECT
;
if
(
bn
<
NINDIRECT
){
// Load indirect block, allocating if necessary.
if
((
addr
=
ip
->
addrs
[
NDIRECT
])
==
0
){
if
(
!
alloc
)
return
-
1
;
if
((
addr
=
ip
->
addrs
[
NDIRECT
])
==
0
)
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
}
bp
=
bread
(
ip
->
dev
,
addr
);
a
=
(
uint
*
)
bp
->
data
;
if
((
addr
=
a
[
bn
])
==
0
){
if
(
!
alloc
){
brelse
(
bp
);
return
-
1
;
}
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
bwrite
(
bp
);
}
...
...
@@ -422,7 +412,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
n
=
ip
->
size
-
off
;
for
(
tot
=
0
;
tot
<
n
;
tot
+=
m
,
off
+=
m
,
dst
+=
m
){
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
,
0
));
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
));
m
=
min
(
n
-
tot
,
BSIZE
-
off
%
BSIZE
);
memmove
(
dst
,
bp
->
data
+
off
%
BSIZE
,
m
);
brelse
(
bp
);
...
...
@@ -444,13 +434,13 @@ writei(struct inode *ip, char *src, uint off, uint n)
return
devsw
[
ip
->
major
].
write
(
ip
,
src
,
n
);
}
if
(
off
+
n
<
off
)
if
(
off
>
ip
->
size
||
off
+
n
<
off
)
return
-
1
;
if
(
off
+
n
>
MAXFILE
*
BSIZE
)
n
=
MAXFILE
*
BSIZE
-
off
;
for
(
tot
=
0
;
tot
<
n
;
tot
+=
m
,
off
+=
m
,
src
+=
m
){
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
,
1
));
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
));
m
=
min
(
n
-
tot
,
BSIZE
-
off
%
BSIZE
);
memmove
(
bp
->
data
+
off
%
BSIZE
,
src
,
m
);
bwrite
(
bp
);
...
...
@@ -487,7 +477,7 @@ dirlookup(struct inode *dp, char *name, uint *poff)
panic
(
"dirlookup not DIR"
);
for
(
off
=
0
;
off
<
dp
->
size
;
off
+=
BSIZE
){
bp
=
bread
(
dp
->
dev
,
bmap
(
dp
,
off
/
BSIZE
,
0
));
bp
=
bread
(
dp
->
dev
,
bmap
(
dp
,
off
/
BSIZE
));
for
(
de
=
(
struct
dirent
*
)
bp
->
data
;
de
<
(
struct
dirent
*
)(
bp
->
data
+
BSIZE
);
de
++
){
...
...
@@ -507,9 +497,9 @@ dirlookup(struct inode *dp, char *name, uint *poff)
return
0
;
}
// Write a new directory entry (name, in
o
) into the directory dp.
// Write a new directory entry (name, in
um
) into the directory dp.
int
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
in
o
)
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
in
um
)
{
int
off
;
struct
dirent
de
;
...
...
@@ -530,7 +520,7 @@ dirlink(struct inode *dp, char *name, uint ino)
}
strncpy
(
de
.
name
,
name
,
DIRSIZ
);
de
.
inum
=
in
o
;
de
.
inum
=
in
um
;
if
(
writei
(
dp
,
(
char
*
)
&
de
,
off
,
sizeof
(
de
))
!=
sizeof
(
de
))
panic
(
"dirlink"
);
...
...
@@ -549,6 +539,7 @@ dirlink(struct inode *dp, char *name, uint ino)
// Examples:
// skipelem("a/bb/c", name) = "bb/c", setting name = "a"
// skipelem("///a//bb", name) = "bb", setting name = "a"
// skipelem("a", name) = "", setting name = "a"
// skipelem("", name) = skipelem("////", name) = 0
//
static
char
*
...
...
@@ -580,7 +571,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
*
_
name
i
(
char
*
path
,
int
parent
,
char
*
name
)
name
x
(
char
*
path
,
int
parent
,
char
*
name
)
{
struct
inode
*
ip
,
*
next
;
...
...
@@ -618,11 +609,11 @@ struct inode*
namei
(
char
*
path
)
{
char
name
[
DIRSIZ
];
return
_
name
i
(
path
,
0
,
name
);
return
name
x
(
path
,
0
,
name
);
}
struct
inode
*
nameiparent
(
char
*
path
,
char
*
name
)
{
return
_
name
i
(
path
,
1
,
name
);
return
name
x
(
path
,
1
,
name
);
}
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