ALLOCA
TlNG
BLOCKS
Once you have written something
in
a particular sector on a diskette with the help
of
direct access commands, you may wish to mark that sector
as
"already
used",
to keep
other files from being written there. Blocks thus allocated will
be
safe until the diskette
is
validated.
FORMAT FOR BLOCK-ALLOCATE COMMAND:
PRINT#IS,"BLOCK-ALLOCATE";drive
#;
track
#;sector
#
usually abbreviated
as:
PRINT#IS,"B-A";drive
#;
track #;sector #
where
"drive
#"
is
the drive number, and
"track
#"
and "sector
#"
are the track and
sector containing the block
of
data
to
be
read into the
file
buffer.
ALTERNATE FORMAT:
PRINT#IS,"B-A:":drive
#;
track #;sector #
EXAMPLE:
If you
try
to allocate a block that isn't available, the DOS will set the error message
to number
6S,
NO BLOCK, and set the track and block numbers
in
the error message to
the next available track and block number. Therefore, before selecting a block
to
write,
try to allocate that block. If the block isn't available. read the next available block from
the error channel and allocate
it
instead. However, do not allocate data blocks
in
the
directory track. If the track number returned
is
0, the diskette
is
full.
Here
is
a program that allocates a place
to
store a message on a diskette.
100 OPENIS,8,
IS
110
OPENS,8,S,"
#"
120
PRINT#S,
"I
THINK
THEREFORE I
AM"
130
T=
I:S = I
140
PRINT#IS,"B-A";O;T;S
ISO
INPUT#IS,EN,EM$,ET,ES
160 IF
EN=O
THEN 210
170
IF
EN<>6S
THEN PRINT
EN,EM$,ET,ES:STOP
180
IF ET = 0 THEN PRINT
"DISK
FULL":STOP
190
IF
ET=
18
THEN
ET=
19:ES=O
200
T=
ET:S = ES:GOTO 140
210
PRINT#IS,"U2";S;O;T;S
220 PRINT
"STORED
AT:",T,S
230 CLOSE S:CLOSE
IS
240 END
72
Open command channel.
" direct access "
Write a message
to
buffer.
Start
at
first track & sector.
Try allocating it.
See if
it
worked.
If so, we're almost done.
"NO
BLOCK" means already allocated.
If next track
is
0, we're out
of
room.
Don't allocate the directory.
Try suggested track
& sector next.
Write buffer to allocated sector.
Say where message went
and tidy up.