one
takes
the
it
biggest
gap
Here
the
justification
is
the
unused
piece
can
hopefully
be
used
for
another
file
end
itemize
First
fit
is
obviously
the
fastest
of
these
methods
But
empirical
values
show
that
with
respect
to
memory
utilization
first
fit
is
not
worse
than
best
fit
and
significantly
better
than
worst
fit
Now
what
about
the
mapping
logical
longrightarrow
linear
that
we
need
for
the
non
consecutive
storage
model
There
are
many
possible
solutions
Here
are
a
few
that
are
actually
used
begin
enumerate
item
CP
M
stores
the
numbers
of
the
linear
blocks
directly
in
the
directory
entry
for
the
file
If
they
do
not
all
child
process
and
copies
the
entry
of
the
parent
into
it
Then
the
refcnt
fields
of
all
involved
file
table
entries
are
incremented
This
procedure
leads
to
the
situation
we
saw
earlier
aaa
unitlength
mm
begin
picture
put
indexblk
put
indexblk
put
indexblk
put
indexblk
put
makebox
vdots
put
makebox
ft
index
put
makebox
file
put
makebox
table
put
makebox
ft
index
put
makebox
proc
put
makebox
A
put
makebox
proc
put
makebox
B
put
vector
put
vector
put
makebox
end
picture
aaa
Usually
the
child
process
immediately
closes
most
of
the
open
files
and
overwrites
itself
with
another
program
system
call
exec
So
far
we
have
not
seen
any
places
in
FM
where
thrd
sleep
and
thrd
wakeup
were
called
except
in
buffer
c
That
is
simply
because
we
did
not
show
but
rather
only
described
the
routines
where
such
calls
to
thrd
sleep
etc
occur
So
that
the
reader
may
see
how
thrd
sleep
and
thrd
wakeup
are
used
we
now
look
at
a
couple
of
such
places
In
inode
c
it
can
happen
that
an
inode
that
is
needed
is
currently
locked
another
process
also
needed
it
In
this
case
our
thread
must
sleep
and
wait
for
the
inode
to
be
unlocked
That
looks
as
follows
begin
verbatim
for
if
inode
in
hash
list
if
inode
locked
sleep
on
event
inode
not
locked
continue
go
back
to
square
one
end
verbatim
The
last
line
of
ino
put
is
then
correspondingly
begin
verbatim
wakeup
all
procs
waiting
for
inode
not
locked
end
verbatim
The
access
to
the
free
list
for
data
blocks
is
managed
with
a
different
mechanism
In
the
super
block
in
main
memory
there
is
a
field
b
lock
that
can
take
boolean
values
TRUE
locked
and
FALSE
unlocked
In
the
routine
sup
alloc
that
allocates
a
free
data
block
one
then
has
begin
verbatim
while
super
block
locked
sleep
on
event
super
block
not
locked
if
it
was
last
block
lock
super
block
copy
contents
of
block
into
array
of
free
blocks
unlock
super
block
wakeup
all
threads
waiting
for
super
block
not
locked
end
verbatim
This
illustrates
nicely
the
use
of
thrd
sleep
and
thrd
wakeup
section
Testing
the
File
Manager
Once
one
has
finished
building
the
File
Manager
one
is
faced
with
the
problem
of
testing
it
As
we
saw
at
the
beginning
of
this
chapter
the
File
Manager
does
not
depend
on
the
other
system
processes
so
we
do
not
need
to
wait
for
them
to
be
finished
before
testing
FM
Indeed
we
should
be
reasonably
sure
that
FM
is
working
correctly
before
building
the
Memory
Manager
for
example
because
MM
needs
certain
services
of
FM
The
File
Manager
does
appear
to
need
the
kernel
and
at
least
the
driver
for
the
hard
disk
both
of
which
we
do
not
yet
have
How
do
we
get
around
this
problem
Let
us
address
the
problem
of
the
disk
driver
first
FM
contains
a
module
devcall
c
which
implements
the
calls
to
the
disk
driver
These
are
the
calls
that
request
the
driver
to
read
or
write
one
or
more
linear
blocks
In
the
final
version
of
course
these
calls
will
be
implemented
by
building
t
messages
and
sending
them
to
the
driver
process
But
for
the
time
being
the
simplest
solution
would
be
to
let
these
calls
emulate
the
hard
disk
We
implement
the
hard
disk
with
a
large
sc
Unix
file
Then
dev
read
does
an
lseek
to
the
desired
linear
block
in
the
file
and
uses
the
sc
Unix
read
call
to
read
one
block
And
dev
write
does
the
same
with
the
sc
Unix
every
data
block
belongs
to
exactly
one
inode
or
else
is
in
the
free
list
item
Check
that
every
inode
in
the
free
list
is
really
free
i
e
has
a
in
its
mode
link
field
item
Check
that
the
numbers
are
correct
i
e
that
an
inode
with
link
number
n
is
mentioned
in
exactly
n
directory
entries
item
Check
that
the
file
sizes
as
given
in
the
inodes
are
consistent
with
the
data
blocks
assigned
to
the
inodes
end
itemize
This
program
fsck
is
particularly
in
the
important
as
long
as
FM
is
development
stage
We
must
check
regularly
to
make
sure
FM
has
not
destroyed
one
of
its
file
systems
Now
we
need
one
further
utility
program
It
must
be
able
to
copy
the
complete
contents
of
a
sc
Unix
directory
tree
into
a
sc
Tunix
directory
tree
in
a
sc
Tunix
file
system
Building
a
large
directory
tree
by
hand
would
be
too
tedious
And
we
need
non
trivial
directory
trees
in
order
to
check
that
FM
is
really
working
properly
One
can
check
a
great
many
of
the
functions
of
FM
by
simply
using
the
pseudo
shell
For
example
we
can
test
whether
enumerate

