Q2 The Filing Systemq									DWhat is a filing system?d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 Efilese. A Efiling systeme provides a convenientway of performing these tasks.DWhat about DFS?d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.DDirectories and subdirectoriesd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º	ºManualº	ºLibraryº	ºUtilsº ÀÄÄÄÄÄÙ	ÈÍÍÍÍÍÍ¼	ÈÍÍÍÍÍÍ¼	ÈÍÍÍÑÍÍÍ¼	ÈÍÍÑÍÍ¼		    		                    ³		   ³   ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÙ       ÚÄÄÄÄÄÄÁÄÄ¿ ÚÄÁÄÄ¿  ÚÄÄÁÄÄ¿  ÚÄÄÁÄÄ¿  ÉÏÍ»  ÚÄÄÁÄÄÄ¿  ÚÄÄÄÄÁÄÄÄ¿  ÚÄÄÄÁÄ¿   ÚÄÄÄÁÄÄ¿ ³Copy³  ³Disks³  ³ETree³  ºlpº  ³MakeLP³  ³TreeCopy³  ³HEdit³   ³HUtils³ ÀÄÄÄÄÙ  ÀÄÄÄÄÄÙ  ÀÄÄÄÄÄÙ  ÈÑÍ¼  ÀÄÄÄÄÄÄÙ  ÀÄÄÄÄÄÄÄÄÙ  ÀÄÄÄÄÄÙ   ÀÄÄÄÄÄÄÙ			     ³		 ÚÄÄÄÄÄÄÄÂÄÄÄÁÄÄÂÄÄÄÄÄÄÄ¿		ÚÁÄ¿  ÚÄÄÁÄÄ¿  ÚÁÄ¿  ÚÄÄÁÄÄ¿		³a4³  ³nlqa4³  ³66³  ³nlq66³		ÀÄÄÙ  ÀÄÄÄÄÄÙ  ÀÄÄÙ  ÀÄÄÄÄÄÙThe root directory is called I$i. This diagram, which shows part of theHADFS System disk, shows the root directory containing severalsubdirectories, IExtrasi, IManuali, ILibraryi and IUtilsi. ILibraryi and IUtilsiin turn each have files and subdirectories of their own.When HADFS is first used, or a B*MOUNTb command is used, the I$i directorybecomes the 'Currently Selected Directory', or CSD. When you type B*CATbor B*.b a catalogue of the CSD is displayed. You can also show otherdirectories by giving the B*.b command a directory name, eg:	B*CAT Libraryb  or	B*.UtilsbDMoving around the directory structuredFor directories to be useful, you have to 'move around' and create newdirectories. The B*DIRb command is used to change the CSD and move aroundthe directory tree, for example to make the root the CSD, use:	B*DIR $bYou can use pathnames of any length, eg:	B*DIR $.Library.lpbIf you want to move back 'up' the directory tree, you use the B^b symbol,pronounced 'up'. Suppose you had set the CSD to I$.Library.lpi using theabove command, then 	B*DIR ^bwould move you back to I$.Libraryi. You can also select another disk bystarting the pathname with B:b, so for example	B*DIR :1bwould set the CSD to B$b on drive 1.DCreating directoriesdYou can create new directories anywhere on the disk using the B*CDIRbcommand. As an example	B*CDIR $.Utils.Gamesbwould create the directory IGamesi inside the IUtilsi directory. If theCSD was already set to I$.Utilsi, you could use	B*CDIR Gamesbfor the same effect. Once you have created a directory, you can move intoit with the B*DIRb command and move back out of it with B*DIR ^b.DLibrariesdWhen a B*bcommand is issued, the MOS and sideways 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 ILibraryi 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 B*LIBb command is used, eg:	B*LIB $.UtilsbYou could set the LIB to be the same as the CSD by using B@b, which refersto the CSD:	B*LIB @bDWildcardsdA means of abbreviating long names is provided by the 'wildcard' facility. The wildcards are B#b and B*b. The B*b character is used to ignore everythingafter the position it is used in. For instance	B*INFO Let*bwould show the information on the first object that started with theletters 'Let'. If would match ILettersi, ILettacei and ILettingsi. The B#bcharacter matches to any character for one position only. For instance	B*INFO F##Dbwould match to IFoodi, IFindi, IFordi or IFredi. It would not match to IFindsi, IFlyior IFeedingi.DAccess codesd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 B*RUNb or B*nameb.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 B*nameb, B*/nameb or B*RUNb. 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 B*ACCESSb comand allows a file's access code to be changed:	B*ACCESS DATA LWRb	Allows the file to be read and written with				OPEN, but cannot be renamed, deleted or				overwritten with SAVE.	B*ACCESS PROG WR/Rb	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 BWR/wrb for a file and BLb for a directory.DDeleting, renaming and copyingd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 B*DELETEb commandremoves a single named entry from a directory; the filename must not haveany wildcards in it. For example:	B*DELETE RubbishbYou cannot delete a file which has been locked with the 'BLb' access code. To successfully delete such a file, the access must be removed, eg:	B*ACCESS datab	B*DELETE datab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 B*RENAMEb command is followed by the old filename, and then the newfilename. The command	B*RENAME old newbwill change the file Ioldi to have the name Inewi. Furthermore, the command	B*RENAME test $.Programs.testbactually moves the file Itesti from the CSD to the directory I$.Programsi. You can also change the name of a file while moving it, so	B*RENAME OldFile ^.NewFilebwill move IOldFilei into the directory above the CSD, and change its nameto INewFilei. Directories as well as files can be renamed like this. Youcannot use wildcards in the newname part of a B*RENAMEb command and youcannot rename a directory into a subdirectory of itself.The B*COPYb 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:	B*COPY ThisFile $.Data.ThatFilebB*COPYb 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 ITreeCopyi program should be used, see Chapter 5. Incurrent versions of HADFS, the B*COPYb command is a transient command inthe system ILibraryi directory.DFile and disk informationdHADFS knows more things about each file that is shown in the display givenby B*CATb. The B*INFOb command displays this extra information. The resultof a B*INFOb command might look like this:     BChapter1   FFFFFF00 FFFFFFFF   001B78   WR/WR  28/12/1993  00078Bb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 B*EXb which does a B*INFOb on all the entries in the specifieddirectory.A special instance of the B*INFOb command will get information on the disk. Using B*INFO $b could give a display like:	BDrive 0: Letters    03/04/1992	Size: 400K ID: 984F Datab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 available, the B*FREEb command is used. A typical display would be:	B>*FREE	0001A4 Sectors =   107,520 bytes free	00049C Sectors =   302,808 bytes usedbThe first hexadecimal figures are the number of sectors free or used, thedecimal number is the space in bytes.DFormatting disksd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 B*FORMb 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:	B*FORM160 0bto format the disk in drive 0. Before formatting, you are asked to confirmthe operation:	BFormat drive 0	Go? (Y/N)bYou must respond by pressing BYb. 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 B*TITLEb or B*INSTALLb. If you want the disk to be a systemdisk, you must copy the IHADFSROMi file into the root directory, or useB*INSTALLb, for example:	B*INSTALL 0 $ NewDisk 400KbThis installs the system files onto the disk in drive 0, setting its titleto 'NewDisk'.Non-floppy disks, such as hard drives and RAM disks, usually do not needformatting or will be supplied with a program to format them. You thenjust need to initialise the drive with the B*INSTALLb command. For instance,to install HADFS on a 16M hard disk in drive 4, use:	B*INSTALL 4 $ IDEDisk4 16384KbDAutostartdSometimes it is useful to make a program automatically start when youfirst use a disk. This can be done using a file called I!Booti and theB*OPT4b command. This file can be in any directory, but the most commonplace for it is in the B$b directory. When you log on to a directory usingB*I AMb, then the boot option set with B*OPT4b is looked at and the I!Bootifile is loaded, run or executed. Pressing Shift-Break is the same as doing	B*I AM BOOTbIf there is no I$.BOOTi directory, then the I$i directory is logged into. Doing B*I AMb is similar to doing B*MOUNT <drv>b then B*DIR <dir>b.DChanging disksd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	B*CATbyou will get a listing from the previous disk. If you try to write or saveanything, or select another directory, a BDisk changedb error will occur.You have to inform the computer that you have changed the disk.  You dothis using B*BYEb and B*MOUNTb. B*BYEb closes all open files, and then goes intoa 'dismounted' state. After using B*BYEb, all disks can be removed andreplaced. B*MOUNTb 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. B*BYEb is thesame as B*CLOSEb followed by B*MOUNTb.DSpecial charactersdB$b means 'root directory' and points to the top of the directory tree.B^b means 'parent directory' and points to the directory that is the	parent of the current one. The parent of the I$i directory is I$i.B%b means 'library directory' and points to the directory set with B*LIBb	or the one selected after doing B*MOUNTb, B*BYEb or B*I AMb.B@b means 'current directory', the one selected with B*DIRb. If a command	needs a directory and you need to select the CSD, you use this, eg	using B*LIB @b makes the library directory the same as the	currently selected directory.B:b means 'drive', and is followed by a drive number. Drive numbers can	be from 0 to 9, and A to V.DCommands on other systemsd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:	B*CATb or B*CAT @b		BDIRb or BDIR .bMove down a directory:	B*DIRb Inamei		BCDb InameiMove up a directory:	B*DIR ^			CD ..bMove to another drive:	B*DIR :bIdi			BCD bIdiB:bTo change a disk:	B*MOUNTb or B*MOUNTb Idi	<Ctrl>-C