The OS-9 File System

Input and output refer to the data your computer system

receives and the data that it sends. OS-9 can receive (input)

data from a keyboard, disk files, modems, and other terminals. It

can send (output) data to all of these devices-except the key

board-and to a video display.


OS-9 receives and sends data in the same format, regardless of

whether the destination is a file or a device. It overcomes the dif

ferences in the devices by defining a standard for them and using

device drivers to make each device conform to the standard. The

result: a much simpler and more versatile input/output system.


Input/Output Paths

The base of OS-9's unified I/O system is an organization of

paths. Input/output paths are, in effect, software links between

files. (Remember, OS-9 thinks of all devices as files.)


Individual device drivers process data so that it conforms to the

hardware requirements of the device involved. Data transfer is in

streams of 8-bit bytes that can be either bidirectional (read/

write) or unidirectional (read only or write only), depending on

the device, how you establish the path, or both. A byte is a unit

of computer data. (A byte may contain the code for one alphabet

character.) A bit is a binary digit and has a value of either 0 or

1.


OS-9 does not require the data it manages to have any special

format or meaning. The meaning of the data is determined by

the programs that use it.


Some of the advantages of such a unified I/O system are:









OS-9 Commands Reference




Disk Directories

A directory is a storage place for other directories and files. It

contains the information about the directories and files assigned

to it so that OS-9 can easily find and access the data they

contain.


Each disk has its own directory system. For example, a typical

system diskette, diagrammed partially and simply, might look

like this:






)f )f I 11~
SYS
Startup CMDS

Errmsg



The ROOT directory of /DO the ROOT from which the rest of

the disk's file system grows-contains a file called Startup and

two directories, SYS and CMDS.


SYS and CMDS, in turn, contain files: SYS contains Errmsg,

and CMDS contains Copy, List, Dir, Del, and Format. All these

files and directories, and many more, come built into the OS-9

system.


OS-9 organizes each directory area into 32-byte records. The

first 29 bytes contain filename characters. The first byte of the

name has its sign bit (the leftmost or most significant bit) set.

When you delete a file, it is not immediately destroyed. Rather,

the deletion process sets the first character position of the record

to zero, and OS-9 no longer recognizes the record. Although the

file contents still exist, they are no longer accessible to you or

OS-9. Subsequent file creations overwrite deleted records.


2-2


The last three bytes of a record make up a 24-bit binary number

that is the logical sector number pointing to the file descriptor

record. Logical sectors are numbered with reference to the

sequence of their use, rather than their physical location on a

disk. See "Disk Files" for more information on disk organization.


You create directories using the MAKDIR command and can

identify them by the D (directory) attribute. (See "Examining

and Changing File Attributes".) MAKDIR initializes each direc

tory with two entries having the names "." and "..". These

entries contain the logical sector numbers of the directory and

its parent directory, respectively.


You cannot use the COPY and LIST commands (as described in

Getting Started With OS-9) with directories. Instead, use DSAVE

and DIR.


You cannot delete directories directly. You must first empty a

directory of files, convert it into a standard file, and then delete

it. However, the DELDIR command performs all these functions

automatically.



.i






2-3
OS-9 Commands Reference

The system stores all files as an ordered sequence of 8-bit bytes.

The file can be any size from 0 bytes to the maximum capacity

of the storage device and can be expanded or shortened as

desired.


When OS-9 creates or opens a file, it establishes a file pointer for

it. OS-9 addresses bytes within the file in the same manner it

addresses memory, and the file pointer holds the address of the

next byte to write or read. OS-9's read and write functions

always update the pointer as the system transfers data.


This pointer function lets assembly-language programmers and

high-level language programmers reposition the file pointer. To

expand a file, write past the previous end of the file. Reading up

to the last byte of a file causes the next read request to return

an end-of-file status.


OS-9's file system also uses a universal organization for all I/O

devices. This feature means that application programs can treat

each hardware device similarly. The following section gives basic

information about the physical file structure used by OS-9. (For

more information, see the OS-9 Level Two Technical Reference

manual.)


Sectors

The data contained in a file is stored in one or more sectors (disk

storage units). These file sectors have both a logical and a physi

cal arrangement. The logical arrangement numbers the sectors

in sequence. The physical arrangement can be in any order

based on the actual location of a sector on a disk's surface. For

instance, Logical Sector 1 might be located at Physical Sector

10, and Logical Sector 2 might be located at Physical Sector 19.


Each sector contains 256 data bytes. The first sector of every file

(Logical Sector Number 0 or LSN 0) is called the file descriptor.

It contains the logical and physical description of the file. The

disk driver module links sector numbers to physical track/sector

numbers on a disk.


A sector is the smallest physical unit of a file that OS-9 can

allocate for storage. On the Color Computer, a sector is also the

smallest file unit. (To increase efficiency on some larger-capacity

disk systems, OS-9 uses uniform-sized groups of sectors, called

clusters, as the smallest allocatable unit. A cluster is always an

integral power of two-2, 4, 8, and so on.)


2-4


OS-9 uses one or more sectors of each disk as a bitmap (usually

starting at LSN 1) in which each data bit corresponds to one

cluster on the disk. The system sets and clears bits to indicate

which clusters it is using, which clusters are defective, and

which clusters are free for allocation. The Color Computer

default floppy disk system uses this format:










Each OS-9 file has a directory entry that includes the filename

and the logical sector number of the file's file descriptor sector.

The file descriptor sector contains a complete description of its

file, including:












Unless the file size is 0, the file uses one or more sectors/clusters

to store data. The system groups data sectors into one or more

adjacent blocks called segments.


Text Files

Text files contain variable-length lines of ASCII characters. A

carriage return (ASCII code OD hexadecimal or 13 decimal) ter

minates each line. Text files contain such data as program

source code, procedure files, messages, and documentation.


Programs usually read text files sequentially. Almost all high

level languages (such as BASIC09) support text files.


Use LIST to examine the content of text files.


OS-9 Commands Reference

Random-Access Data Files

Random-access files consist of sequences of records, with each

record the same length. A program can find any record's begin

ning address by multiplying the record number by the number of

bytes used for each record. This feature allows direct access of

any record.


Usually, high-level languages let you subdivide records into

fields. Each field can have a fixed length and use. For example,

the first field of a record can be 25 text characters in length, the

next field can be two bytes in length and used to hold 16-bit

binary numbers, and so on.


OS-9 does not directly process records. It only provides the basic

file functions used by high-level languages to create and handle

random-access files.


Programmers use high-level languages like BASIC09, Pascal,

and C to create random-access data files. For instance, in

BASIC09 and Pascal, GET, PUT, and SEEK functions operate

on random-access files.


Procedure Files

Procedure files are disk files that contain commands. You can

use them to execute a series of commands by typing and enter

ing a single command name.


Your System Master diskette contains one procedure file named

Startup. You can create your own procedure files using the

BUILD command, copying input from the keyboard to a file, or

by using a text editor program. For instance, suppose you have

three disk drives, /D0, /D 1, and /H0. You could create three very

simple procedures to allow you to look at the directories of these

disks by typing and entering a simple two-character command.


To create a procedure file to look at the directory of /D 1, type:

    build p 1 ENTER

    display 0C ENTER


    d i r / d 1 ENTER~'~,

    display 0A ESTER

    ENTER


2-6
          The OS-9 File System / 2


The first line creates a file named P1 (print directory for Drive

/D1). When you press ENTER , a question mark appears on the

screen telling you that OS-9 is waiting for input. Type the rest

of the lines. Finally, press ENTER at the beginning of a line to

tell OS-9 that the input is complete. OS-9 closes the file.


Now, to see the contents of Drive /D 1, type p 1 ENTER . The com

mand d i 5 p 1 a y e C clears the video screen. The command

d i 5 p 1 a y 0 A causes the cursor to drop down one line on the

screen.


Use your imagination. Almost anything you can do from the key

board, you can do with a procedure file. However, remember that

OS-9 looks only in the current data directory for a procedure

file, unless you provide a full pathlist to the procedure. Also,

OS-9 must be able to find any command in the current execution

directory that is part of a procedure file. If the current execution

directory does not contain the commands you need, change it,

either from the keyboard or as part of your procedure file.


Executable Program Module Files

OS-9 program modules are executable program code, generated

by an assembler or compiled by a high-level language. A file can

contain one or more program modules.


Each module has a standard format that includes the object code

(the executable portion of the module), a module header that

describes the type and size of the module, and a CRC (Cyclic

Redundancy Checksum) value. The system stores program mod

ules in files in the same structure in which they load into mem

ory. Because OS-9 programs are position-independent, they do

not require specific memory addresses for loading.


For OS-9 to load program module(s) from a file, the file execute

attribute must be set, and each module must have a valid mod

ule header and CRC value. If you or the system alters a program

module in any way (either as a file or in memory), its CRC

check value becomes incorrect, and OS-9 cannot load the module.


If a file contains two or more modules, OS-9 treats them as a

group and assigns contiguous memory locations for them.


2-7
OS-9 Commands Reference

Using LIST on program files or any other files that contain

binary data, causes a jumbled display of random characters and

an error message.


Miscellaneous File Use

OS-9's basic file functions are so versatile that you can devise

almost unlimited numbers of special-purpose file formats for

particular applications that require formats not discussed here

(text, random-access, and so on).


The File Security System

Each file and directory has properties called ownership and attri

butes that determine who can access the file and how they can

use it.


OS-9 automatically stores the user number associated with the

creation of a file. The system considers the owner of the number

to be the owner of the file.


Security functions are based on access attributes. There are

eight attributes, each of which can be turned off or on indepen

dently. When the D (directory) attribute is on for a file, that file

is a directory. (Only MAKDIR can set the D attribute for a file.)

When the S (shareable) attribute is on, only one program or user

can access the file at a time.


2-8
The OS-9 File System / 2

The other six attributes control whether the file can be read

from, written to, or executed by either the owner or the public

(all other users.) When on, these six attributes function as

follows:


Owner read

permission

Owner write

permission

Owner execute

permission

Public read
permission

Public write
permission

Public execute
permission

For example, if a file has all permissions on except write permit

to public and read permit to public, the owner has unrestricted

access to the file. Other users can execute it but cannot read,

copy, delete, or alter it.


Examining and Changing File Attributes

You can use the DIR command, with the E (entire) option, to

examine the security permissions of all files in a particular

directory. An example of output using DIR E on the current data

directory is: _

The owner can read from the file. Use this

permission to prevent binary files from

being used as text files.


The owner can write to the file or delete it.

Use this permission to protect important

files from accidental deletion or

modification.


The owner can load the file into memory

and execute it. To be loaded, the file must

contain one or more valid OS-9 memory

modules.


Anyone can read and copy the file.

Anyone can write to or delete the file.

Anyone can execute the file.

Directory of . 10:20:44

Owner Last modified Attributes Sector Hytecount Name

0 86/07/31 1436 ----r-wr
0 86/07/31 1437 d-ewrewr
0 86/07/31 1442 d-ewrewr
0 86/07/31 1409 ------wr

A 6567 OS9Hoot
71 560 CMDS
1 H8 80 SYS
1 Hd 55 Startup

2-9
OS-9 Commands Reference

The Attributes column shows which attributes are on by listing
one or more of the following codes.
d s e w r e w r

                  L--> owner read


                  > owner write


                > owner execute


              > public read


            > public write


          > public execute


      L-> not shareable


    > directory

For example, the first file shows:

    ----r-wr


This means that (1) The file is not a directory. (2) It is share
able. (3) The public cannot execute it or (4) write to it, but can
(5) read it. (6) The owner cannot execute the file, but can (7)
write to it, and ($) can read it.

To examine the attributes of a particular file, use ATTR. Typing
ATTR followed by a filename shows you the file's current attri
butes, for example:

    a t t r f i 1 e 2 ENTER


A possible screen display is:

    ---wr-wr


To change a file's attributes use ATTR and a filename, followed
by a list of one or more attribute abbreviations. However, you
must own a file before you can change its attributes.

2-10
                    The OS-9 File System / 2


The following command enables public write and public read per

missions and removes the execute permission for both the owner

and the public:


    at t r f i 1 e2 Pw pr -a -Pe ENTER


Note: In order to protect data stored in directories, the D
attribute behaves somewhat differently from the other attri
butes. You cannot use ATTR to turn on the D attribute
only MAKDIR can do that-and you can use ATTR to turn
off D only if the directory is empty.

Record Lockout

When two or more processes use the same file simultaneously,

they might attempt to update the file at the same time, causing

unpredictable results. When you open a file in the update mode,

OS-9 eliminates the problem of simultaneous use by locking the

sections of the file. The lock covers any disk sectors containing

the bytes last read by each process accessing the file. If one pro

cess attempts to access a locked portion of a file, OS-9 puts the

process to sleep until the locked area is free.


OS-9 moves the lock and frees the area when it reads from or

writes to another area. The system removes a lock on a file when

the process associated with the lock closes its path to the file. A

process can have only one lock on a file, but it can have locks on

more than one file.


You can lock an entire file by activating its single user bit. (See

the earlier section "Examining and Changing File Attributes.")

When the single user bit is on, only one process can open a path

to the file at a time. Attempts by other processes to access the

file result in an error.


2-11
OS-9 Commands Reference

Device Names

Each physical I/O device supported by OS-9 has a unique name.
The following list describes the device names supported by the
system. Your system diskette already defines several of these
devices. You can define others using CONFIG.

    DO-35S Floppy Disk Drive /D0, single sided, 35

    cylinders.

    D 1_35S Floppy Disk Drive /D 1, single sided, 35

    cylinders.

    D2-35S Floppy Disk Drive /D2, single sided, 35

    cylinders.

    D3-35S Floppy Disk Drive /D3, single sided, 35

    cylinders.

    DDDO-35S Default Disk Drive /D0, single sided, 35

    cylinders.

    DO-40D Floppy Disk Drive /D0, double sided, 40

    cylinders.

    D 1_40D Floppy Disk Drive /D 1, double sided, 40

    cylinders.

    D2_40D Floppy Disk Drive /D2, double sided, 40

    cylinders.

    D3_40D Floppy Disk Drive /D3, double sided, 40

    cylinders.

    DDDO-40D Default Disk Drive /D0, double sided, 40

    cylinders.

    D 1_80D Floppy Disk Drive /D 1, double sided, 80

    cylinders.

    D2_80D Floppy Disk Drive /D2, double sided, 80

    cylinders.

    P a printer using the RS-232 serial port

    TERM your computer keyboard and video display

    T1 a terminal port using the standard RS-232

    port

    T2 a terminal using the optional RS-232

    communications pak _

    T3 a terminal using the optional RS-232

    communications pak

    M1 a modem using an optional 300 baud modem

    pak

    M2 a modem using an optional 300 baud modem

    pak

    W a generic window descriptor

    W 1 window device Number 1


2-12
                    The OS-9 File System / 2


    W2 window device Number 2

    W3 window device Number 3

    W4 window device Number 4

    W5 window device Number 5

    W6 window device Number 6

    W7 window device Number 7


Although OS-9 and your computer can access all these devices,

your original diskette does not configure it to do so. For informa

tion on configuring your system, see Chapter 7 of Getting

Started With OS-9.


Because device names are at the root of the file system, you can

use them only as the first part of a pathlist. Always precede the

name of a device with a slash.


When you refer to a non-disk device, for example a terminal or

printer, use only the device name. /P, for instance, is the full

allowable pathlist for a printer.


Note: An I/O device name is actually the name of an OS-9

device descriptor that you precede with a slash (/). OS-9

automatically loads device descriptors during the OS-9 boot

sequence. You can add or delete other device descriptors

while the system is running or add device descriptors to the

bootfile using CONFIG.


2-13