2 The Filing System

What is a filing system?
Almost all computer applications need some kind of access to an external storage medium, for example a disk, to save information. The most common reason for this is that the computer does not remember what is in its memory after it has been switched off. Also, some programs may need to use large amounts of data that will not all fit into memory at the same time. To use this external data, some means of accessing it must be provided in order to retrieve or modify existing items and to create new items. The items are refered to as files. A filing system provides a convenient way of performing these tasks.

What about the DFS?
Many BBC series computers are fitted with DFS to access disks with. DFS is useful, but suffers from one major limitation. You are only allowed to have 31 files on each disk (62 if you count both sides of a disk). You could use ADFS, but that requires different hardware. HADFS allows you to use the existing DFS hardware and uses a modified DFS-format disk to provide a full hierarchial disk-based filing system.

Directories and subdirectories
HADFS is a hierarchial filing system. What this means is that the disk can contain files and directories. Directories are collections of files and can also contain more directories, or subdirectories. The structure is called a 'tree' because it looks like an upside-down tree. Everything starts at the 'root', which, being upside-down, is at the top.

				ÉÍ»
				º$º (Root directory)
				ÈÑ¼
    ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
 ÚÄÄÁÄÄ¿	ÉÍÍÏÍÍÍ»	ÉÍÍÍÍÏÍÍÍÍÍ»	ÉÍÍÍÏÍÍÍ»	ÉÍÍÏÍÍ»
 ³!Boot³	ºExtrasº	ºHFS_Manualº	ºLibraryº	ºUtilsº
 ÀÄÄÄÄÄÙ	ÈÍÍÍÍÍÍ¼	ÈÍÍÍÍÍÍÍÍÍÍ¼	ÈÍÍÍÑÍÍÍ¼	ÈÍÍÑÍÍ¼
		    		                    ³		   ³
   ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÙ       ÚÄÄÄÄÄÄÁÄÄ¿
 ÚÄÁÄÄ¿  ÚÄÄÁÄÄ¿  ÚÄÄÁÄÄ¿  ÉÏÍ»  ÚÄÄÁÄÄÄ¿  ÚÄÄÄÄÁÄÄÄ¿  ÚÄÄÄÁÄÄ¿  ÚÄÄÄÁÄÄÄ¿
 ³Copy³  ³Disks³  ³ETree³  ºlpº  ³MakeLP³  ³TreeCopy³  ³H-Edit³  ³H-Utils³
 ÀÄÄÄÄÙ  ÀÄÄÄÄÄÙ  ÀÄÄÄÄÄÙ  ÈÑÍ¼  ÀÄÄÄÄÄÄÙ  ÀÄÄÄÄÄÄÄÄÙ  ÀÄÄÄÄÄÄÙ  ÀÄÄÄÄÄÄÄÙ
			     ³
		 ÚÄÄÄÄÄÄÄÂÄÄÄÁÄÄÂÄÄÄÄÄÄÄ¿
		ÚÁÄ¿  ÚÄÄÁÄÄ¿  ÚÁÄ¿  ÚÄÄÁÄÄ¿
		³a4³  ³nlqa4³  ³66³  ³nlq66³
		ÀÄÄÙ  ÀÄÄÄÄÄÙ  ÀÄÄÙ  ÀÄÄÄÄÄÙ

The root directory is called $. This diagram, which shows part of the HADFS System disk, shows the root directory containing several subdirectories,Extras, HFS_Manual, Library and Utils. Library in turn has files and a subdirectory of its own.

When HADFS is first used, or a *MOUNT command is used, the $ directory becomes the 'Currently Selected Directory', or CSD. When you type *CAT or*. a catalogue of the CSD is displayed. You can also show other directories by giving the *. command a directory name, eg:

	*CAT Library  or
	*.Utils

Moving around the directory structure
For directories to be useful, you have to 'move around' and create new directories. The *DIR command is used to change the CSD and move around the directory tree, for example to make the root the CSD, use:

	*DIR $

You can use pathnames of any length, eg:

	*DIR $.Library.lp

If you want to move back 'up' the directory tree, you use the ^ symbol, pronounced 'up'. Suppose you had set the CSD to $.Library.lp using the above command, then 

	*DIR ^

would move you back to $.Library. You can also select another disk by starting the pathname with :, so for example

	*DIR :1

would set the CSD to $ on drive 1.

Creating directories
You can create new directories anywhere on the disk using the *CDIR command. As an example

	*CDIR $.Utils.Games

would create the directory Games inside the Utils directory. If the CSD was already set to $.Utils, you could use

	*CDIR Games

for the same effect. Once you have created a directory, you can move into it with the *DIR command and move back out of it with *DIR ^.

Libraries
When a *command is issued, the MOS and the ROMs fitted in the computer are searched to find a match. If the command cannot be found there, then it is passed on to the filing system. HADFS looks in the CSD for a file of the name. If it cannot find one, then it looks in the currently selected library directory, the LIB. By default, the LIB is set to a directory called Library on the default drive or the drive mounted on. To set the CSD to the parent of the current directory. To specify a new library, the *LIB command is used, eg:

	*LIB $.Utils

You could set the LIB to be the same as the CSD by using @, which refers to the CSD:

	*LIB @

Wildcards
A means of abbreviating long names is provided by the 'wildcard' facility. The wildcards are # and *. The * character is used to ignore eveything after the position it is used in. For instance

	*INFO Let*

would show the information on the first object that started with the letters 'Let'. If would match Letters, Lettace and Lettings. The # character matches to any character for one position only. For instance
	*INFO F##D

would match to Food, Find, Ford or Fred. It would not match to Finds, Fly or Feeding.

Access codes
Files and directories have associated with them an access code which descibes what operations can be done on them. These are:

D - Directory. This is a directory which may contain more files and directories.

R - Read. If this letter is present, the file can be read using LOAD or OPENIN, or can be run using *RUN or
	*name.

W - Write. If this letter is absent, the file cannot be written to with OPENOUT. The file can however be overwritten
	with SAVE.

L - Locked. A locked file cannot be deleted or renamed and cannot be overwritten with SAVE. Directories are
	locked by default.

E - Execute. If this option is present, the file can only be run as machine code with *name, */name or *RUN. If
	the Execute option is set, the Read option is masked out.

P - Private. This can make an entry invisible to a user that does not own the directory. By default, the whole disk is
	owned.

Each file has two sets of access codes. The ones to the left of the '/' are the owner's access code, the ones to the right are the public's access codes. In general use, you will only need to be concerned with the owner codes as the entire disk is owned by you. See Chapter 8 for more information.

The *ACCESS comand allows a file's access code to be changed:

	*ACCESS DATA LWR	Allows the file to be read and written with
				OPEN, but cannot be renamed, deleted or
				overwritten with SAVE.

	*ACCESS PROG WR/R	Allows the file to be read by anyone, but
				can be written to with OPEN only by its
				owner. It can be deleted, overwritten or
				renamed (only by its owner).

The default attributes are WR/WR for a file and L for a directory.

Deleting, renaming and copying
When a file is no longer needed, it can be deleted from the disk. This releases the space it used for use by other files. The *DELETE command removes a single named entry from a directory; the filename must not have any wildcards in it. For example:

	*DELETE Rubbish

You cannot delete a file which has been locked with the 'L' access code. To successfully delete such a file, the access must be removed, eg:

	*ACCESS data
	*DELETE data

Directories are created locked, and they must also be empty when you delete them.

Being able to rename files is very useful, as it can be used not only to change the name of a file, but to move it around the directory structure. The *RENAME command is followed by the old filename, and then the new filename. The command

	*RENAME old new

will change the file old to have the name new. Furthermore, the command

	*RENAME test $.Programs.test

actually moves the file test from the CSD to the directory $.Programs. You can also change the name of a file while moving it, so

	*RENAME OldFile ^.NewFile

will move OldFile into the directory above the CSD, and change its name toNewFile. Directories as well as files can be renamed like this. You cannot use wildcards in the newname part of a *RENAME command.

The *COPY command makes a copy of a file whilst retaining the original. The command is followed by the source filename, and the the destination filename. An example would be:

	*COPY ThisFile $.Data.ThatFile

*COPY uses as much unused shadow memory as possible to transfer the file and avoids using the program memory. If you want to copy lots of files, or copy files between different disks in the same drive or between different filing systems, the TreeCopy program should be used, see Chapter 5. In current versions of HADFS, the *COPY command is a transient command in the system Library directory.

File and disk information
HADFS knows more things about each file that is shown in the display given by *CAT. The *INFO command displays this extra information. The result of a *INFO command might look like this:

    Chapter1   FFFFFF00 FFFFFFFF   001B78   WR/WR  28/12/93  078B

The numbers shown are the load address, the execution address and the length, then the access code, date and sector address. There is also a command *EX which does a *INFO on all the entries in the specified directory.

A special instance of the *INFO command will get information on the disk. Using *INFO $ could give a display like:
	Drive 0: Letters    03/04/92	Size: 400K ID:984F Data

It shows the title of the disk, the date it was created and its size, its disk ID number and whether it is a Data disk or System disk. If it is a system disk, it shows the version of HADFS installed on it.

Disks have only a finite amount of space on them. To find out how much space is used, the *FREE command is used. A typical display would be:

	>*FREE
	01A4 Sectors =   107520 bytes free
	049C Sectors =   302808 bytes used

The first hexadecimal figures are the number of sectors free or used, the decimal number is the space in bytes.

Formatting disks
Before a new disk can be used, it must be formatted. Blank disks are like a blank piece of paper, formatting it is like drawing lines on it. Note that formatting completely erases everything that may be on a disk, so if you accidently format a disk that already has information on it, there is no way to recover its contents.

To format an HADFS disk, you use the *FORM command, followed by the number of tracks. The most common size is double-sided 80 tracks, making 160 tracks in total, so you would use:

	*FORM160 0

to format the disk in drive 0. Before formatting, you are asked to confirm the operation:

	Format drive 0
	Go? (Y/N)

You must respond by pressing Y. Anything else will abort the process. Once a disk has been formatted, it can be used immediately. Freshly formatted disks are Data disks with the title '(Untitled)'. This can be changed using *TITLE or *INSTALL. If you want the disk to be a system disk, you must install the system files with *INSTALL, for example:

	*INSTALL 0 $ NewDisk 400K

This installs the system files onto the disk in drive 0, setting its title to 'NewDisk'.

Autostart
Sometimes it is useful to make a program automatically start when you first use a disk. This can be done using a file called !Boot and the *OPT4 command. This file can be in any directory, but the most common place for it is in the $ directory. When you log on to a directory using *I AM, then the boot option set with *OPT4 is looked at and the !Boot file is loaded, run or executed. Pressing Shift-Break is the same as doing

	*I AM BOOT

If there is no $.BOOT directory, then the $ directory is logged into. Doing *I AM is similar to doing *MOUNT <drv> then *DIR <dir>.

Changing disks
An important fact to realise is that HADFS stores some disk information in memory, and that information will stay there even if the disk is removed from the drive. For example, if you take a disk out, and put a different one in the same drive and try to do

	*CAT

you will get a listing from the previous disk. If you try to write or save anything, or select another directory, a Disk changed error will occur. You have to inform the computer that you have changed the disk. You do this using *BYE and *MOUNT. *BYE closes all open files, and then goes into a 'dismounted' state. After using *BYE, all disks can be removed and replaced. *MOUNT forgets all information, and selects a new drive. If no parameter is given, then the default drive (usually drive 0) is selected. If a drive parameter is given, then that drive is selected.*BYE is the same as *CLOSE followed by *MOUNT.

Special characters
$ means 'root directory' and points to the top of the directory tree.

^ means 'parent directory' and points to the directory that is the parent of the current one. The parent of the $
	 directory is $.

% means 'library directory' and points to the directory set with *LIB or the one selected after doing *MOUNT,
	*BYE or *I AM.

@ means 'current directory', the one selected with *DIR. If a command needs a directory and you need to select the
	CSD, you use this, eg using *LIB @ makes the library directory the same as the currently selected
	directory.

: means 'drive', and is followed by a drive number. Drive numbers can be from 0 to 9, and A to V.

Commands on other systems
MSDOS disks have a similar directory structure, but the commands to move around it are slightly different. In summary:

Operation:		BBC			MSDOS
Show this directory:		*CAT or *CAT @		DIR or DIR .
Move down a directory:	*DIR name		CD name
Move up a directory:		*DIR ^			CD ..
Move to another drive:	*DIR :d			CD d:
To change a disk:		*MOUNT or *MOUNT d		<Ctrl>-C