4 Disc management The following sections contain some tips about disc and file management. 4.1 Formatting and verifying New discs need to be formatted before they can store data. This lays down the track and sector structure on the disc, so that data can be located and written or read. The tracks on the disc are arranged in concentric bands, each containing 10 sectors of 256 bytes. The sectors are numbered from 0 within each track, but the sectors numbers along a radius on the disc are not the same; this is because the drive takes a fixed amount of time to step between tracks, during which the disc keeps turning. A few sectors are missed while the step occurs, so the disc would have to do another revolution to get back to the first sector. The discs are arranged with a skew to avoid this, so that the first sector will be next under the drive head after the drive has stepped. The skew value is normally 3, but disc drives which step from track to track very slowly may need higher skews to perform best, and fast disc drives may be able to use a smaller skew. The built-in formatter in HDFS allows discs to be formatted double or single sided, 40 or 80 tracks, and with an HDFS catalogue or an Acorn catalogue. Double sided and 80 tracks can be used on all but a few old disc drives. The drive characteristics can be set using the keyboard links described in appendix B. Note that HDFS assumes that 80 track drives are being used, and single stepping mode should be enabled if 40 track drives are being used (see 6.11). The choice of Acorn or HDFS format catalogues depends on whether the data must be readable on a computer which is not running HDFS. Most disc filing systems support the Acorn catalogue format, and so it should be used for discs which will be used to interchange data between machines. The HDFS format should be used when a large number of files may be put on the disc, or when a larger contiguous free space is desirable, i.e. for all other discs. Never try to format a disc with more tracks or sides than it is rated for. Discs are all made by the same manufacturing process, and low density discs are simply discs which failed tests for high density storage. It is likely that discs formatted with more tracks or sides than they are rated for will lose their data. After formatting a disc, it is a good idea to verify it to check that there are no errors. A small percentage of discs will not format correctly, and may need re-formatting. If a disc fails to format after a few tries, it should be discarded. 4.2 Loading and saving All of the normal loading and saving commands used by language ROMs are supported by HDFS, as well as the operating system *SAVE and *LOAD commands. A file name must be given when using these operating system commands; no default name is assumed. 4.3 Copying and renaming Files can be copied between discs and directories or duplicated using the *COPY command. The *RENAME command is almost identical, except that it deletes the original copy of the file. These commands use the I/O processor memory as a buffer while copying files, and so should not be used if you have valuable data in memory which has not been saved. It is possible to copy files from disc to disc with one disc drive. In this case the computer will prompt for the source or destination disc each time it has finished reading or writing data. If the wrong disc is inserted, the transfer will be stopped with an error message. If this happens, or if the transfer is aborted, the disc catalogues will not be changed. It is possible to copy or move files larger than the memory buffer with *COPY and *RENAME. They load as much as possible into the memory at a time, and so require the least number of disc changes possible. There is no specific command for making backups of discs, but *COPY and *RENAME can be used to copy a set of files into a directory to achieve this end. 4.4 File handling All of the normal file opening, closing, and get and put byte commands used by language ROMs are supported, as well as the operating system OSGBPB routine for transferring blocks of data to and from files. Full random access to files is possible, using the sequential pointer. Files can be opened for input, output, or update (input and output). Files opened for input cannot be used for output, and files opened for output cannot be used for input. The HDFS only allows access for input or output if the appropriate read or write permissions are set. Acorn format discs always have read and write permission on files. The HDFS allows up to six files open simultaneously. When a new file is opened for output, it is located in the largest gap in the directory to allow it space to grow. A maximum of &4000 bytes are allocated to that file immediately, and more space can be claimed if it is available later. If more than one new file is opened, the second file will probably be allocated immediately after the first file, limiting the first file's length to &4000. If several large files are to be created by a program, the *CREATE command or OSFILE entry &7 can be used to make sure that enough space is allocated for each of them. When a file is opened for output with the same name as an existing file, an attempt is made to delete the existing file, and its space is re-used. Files which are opened for update or input must exist already. If the sequential pointer of a file is moved past the end of the file, the file will be extended as necessary by padding with zero bytes. The OSGBPB call should be used whenever possible, to reduce the overheads associated with accessing files. 4.5 Compacting and extending After a while, discs tend to get fragmented, with lots of short gaps separated by files. The space can be recovered into one contiguous block using the *COMPACT command. This shuffles all of the files and directories down so that there are no gaps between them, leaving all of the space at the end. Directories can be shrunk to fit the files that they contain using the *COMPACT command. This is especially useful when the files in a directory are not being changed at all, e.g. for program directories which are finished, or games directories. The executable directory feature of HDFS can be used to make these into self-contained applications which can be *RUN. If a file has run out of space to grow, the *EXTEND command can be used to move it into the largest gap on the disc, where it may have more space to grow. This command can be combined with *COMPACT for maximum effect; the sequence *EXTEND, *COMPACT, and then *EXTEND will ensure that the maximum amount of space left in the directory is available for the file to grow into. Both the *COMPACT and *EXTEND commands overwrite the I/O processor memory, and so should not be used if you have valuable data in memory which has not been saved.