439
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
that you wish the disk to occupy. From that, and the supplied desired max number
of files, the fd.format will work out the size of each area of the disk. Let's see this
on a real example: Supposing, you call fd.format(1300,41) -- you want the disk
to occupy 1300 sectors and store 41 file. So, what will be the size of the FRT, FAT,
and data areas?
First, the fd.format deducts 2 sectors to account for the BOOT and the END BOOT
sectors that must always be present. This leaves us with 1298 sectors.
Next, the fd.format determines the size of the FRT area: 41 is rounded to 44, then
calculates that (44/4)*2= 22 sectors are needed (this exceeds the minimum of 8,
so we do not need to correct this number). We have 998-22= 1276 sectors left.
Now, how many FAT sectors we need? 1276/128= 10. Actual amount will be
doubled, so we need 20 sectors (exceeds the minimum of 16, so we do not need to
correct this number). Therefore, we are left with 1276-20= 1256 data sectors. This
is what you will get from the
R/O property (see
).
One small caveat...
Now let us show you one trickier example. Say, you do fd.format(1301,4). You
can quickly work out that you have 1301 sector for the FAT and data areas
combined. Now, how should this be divided?
If you had 1300 sectors, then there would be no problem. Of them, 1280 would go
to the data area, and 20 will belong to the FAT. 10 "necessary" FAT sectors will
together hold 10*128= 1280 entries -- just right for the size of the data area. The
number of FAT sectors is always doubled, so FAT will get 20 sectors. Everything fits
perfectly!
Now, there is no good solution for 1301 sectors. If you give this extra one sector to
the data area, then you will need two more sectors for the FAT area -- and you
don't have those sectors. Allocating this extra sector to the FA is useless, because
you are not increasing the number of data sectors, so you don't really need an
extra FAT sector. Hence, the value of 1301 is actually not suitable to us. Same
goes for 1302. 1303 is good again, because three extra sectors allow us to give
one sector to the data area, and add two sectors to the FAT area.
Fd.format avoid falling into the trap by correcting downwards the total disk size
you request if it turns out to be one of the problematic values. So, if you do fd.
format(1302,4), then the result would be as if you did fd.format(1300,4). The
R/O property will show this to you (see
).
Why is there the END BOOT sector?
The END BOOT sector exists for one purpose -- to detect whether your application
has encroached on the flash disk. As was already
, the data area
sectors are counted from the topmost physical sector of the flash memory down.
Therefore, the END BOOT sector is the closest one to your application. Should the
application become larger and take some of the space that was previously occupied
by the flash disk, the END BOOT sector will be overwritten. The fd. object will
detect this during
and return 3- PL_FD_STATUS_FORMAT_ERR status
code.
Mounting the Flash Disk
The flash disk will not be accessible unless it is mounted using
. It can
only be mounted after the flash memory has been successfully formatted using
. The disk has to be mounted after every reboot of your device (if you
need to access it, of course). After the disk is mounted successfully, the
458
441
483
441
434
439
474
467