-*- Text -*-
   This is the file .../info/FS.nfo, which contains info 
about the File Systems that MOOSE should be aware of to store objects and
exchange data.
   This file also contains info about the convention for partitioning hard
disks; to MOOSE, a hard disk is an object server like File Systems; only its
"files" (called partitions) are bigger, and it is difficult to reallocate them.

File: FS.nfo		Node: Top	Up:(MOOSE.nfo)

   File Systems (FS) are particular kinds of object servers. They provide
objects generally called "Directories" that themselves contain other
directories, objects called "Files" divided into "regular files" and "special
files".

* Menu:

Semantics of File Systems:	Services file systems provide
* Files::			First, what is a file ?
* Filenames & directories::	How to identify a file.
* Regular vs Special files::	Files are a generic concept.
* Disks::			On top of what is an FS built.

Known FS'es:
* Partitioning::		A Meta-FS and perhaps FS itself.
* DOS FS::			The FS from MS-DOS.
* Unsupported FS'es::		A list of FS'es not recognized (yet) by MOOSE.

See also:
* SPOS:: (SPOS.nfo).		Secure Persistent Object Server

Node: Files,	Up: Top

   Files are the standard object in all traditional OSes. A file is an object
with operations of Reading and Writing of units or blocks of data (most usually
multiples of 8 bit bytes). Standard Files verify some algebrical relations
(which in common language mean thing such as that when you write something to a
file, then read the file, you'll retrieve what you wrote), special files verify
only a restriction of these relations (and other relations instead).
   Older OSes, i.e. Unix, its clones, its sons, its bastards (CP/M then DOS)
were built all around this unique concern.


Node: Disks,	Up: Top

   A disk is a storage medium when data is recorded as magnetic variations on
the ferro-magnetic surface of a disk (or other means on optical disks).
Magnetic (Laser beam on optical disks) Heads can move radially, selecting a
circular (or spiraled) Track on which data is sequentially read or written.
   Each Track is itself divided into sectors, blocks where data is read or
written jointly. For convenience, sectors are most often choosen of uniform
length, being a power of two (128,256,512,1024,2048) in terms of the standard
memory units of the computer (8 bit-a byte standardly) actually usable by the
software. On PC's, 512 bytes is an established standard for magnetic disks.
Too small a sector size leads to too much overhead for the controller, while
too large sectors may lead to unused magnetic surface because a whole sector
does not fit some space that would be big enough for smaller sectors.
   To simplify even more the computational and mechanical apparti, concentric
circular tracks are often choosen to have the same number of sectors, even if
angular magnetic density is higher on external tracks than on internal ones.

   So to sum up things, data may be seen as organized in sectors of the same
size, where each sector is identified by its track and its position in the
track, each track is defined its head and cylinder (the height and radius of
the circular track); so a sector is defined by its sector number, its head
number, its track number (actually the number of the cylinder), numbers that
can be choosen independently (or in some cases, the maximum number of sectors
depending on the track/cylinder). To simplify even more the process, sectors
are given a global number. The sectors of the first cylinder, and the first
head are given their sector number; then sector of the second head, etc; then
you continue with the second cylinder, etc.

   If as on the PC's, there are Ncyl cylinder, Nhead heads, and Nsect sectors
on each track, cylinders and heads being numbered from 0 on, and sectors from 1
on, we have the formulae:

  Absolute_sector_number = Sector_Number + Nsect*(Head_Number+Nhead*Cyl_Number)
  Sector_Number = Absolute_sector_number mod Nsect
  Head_Number = (Absolute_sector_number div Nsect) mod Nhead
  Cyl_Number = (Absolute_sector_number div Nsect) div Nhead

  So the disk can be considered as a sequence of sectors. Sectors can be
grouped into blocks of multiple sectors to form a logically larger data
transfer unit (standard block under unix are 1K). That's how most operating
systems view disk, and it actually simplifies disk organization much.

Node: Partitioning,	Up: Top

   "Partitioning" is the name of the convention used by PC's to divide their
hard disks into several (commonly up to eight) zones, each (purposedly)
containing its own unique File System. This convention was originally designed
because DOS ancient file systems couldn't (not at all firstly, not efficiently
even now) handle harddisks whose size had grown too much; thus disks had to be
divided into partitions. Partitions prove useful to have multiple FS'es, not
all being used by DOS.

   The first sector on the hard disk contains the code for booting the system,
as well as a global data area called the "Partition Table", that allows to
reserve four (4) distinct partitions in the disk. The boot code generally
relocates itself from 0:7C00h to 0:600h, selects a bootable partition (if any)
in the partition table, then loads and execute the first sector of the
partition as if it were the boot sector. but some utilities may modify this
behavior for enhanced user-friendliness (for example, LILO, the Linux Loader).

   This first sector is called the primary partition table, and partitions
defined in it are called the primary partitions. We'll see that there can be
more partitions, called extended partitions.

* Partition sector::			How a partition sector is structured
* Extended Partition::			How to have more than 4 partitions.
* Partition restrictions::		Requirements for partitioning.
* Known partition types::		Magic bytes for identifying FS type.

Node: partition sector, Up: Partitioning

Structure of the sector:
------------------------
Address:
 000h: 8086 Boot code
 1BEh: 1st partition table entry
 1CEh: 2nd partition table entry
 1DEh: 3rd partition table entry
 1EEh: 4th partition table entry
 1FEh: Signature 0AA55h (55,AA) of valid bootable sector.

Partition table entry:
----------------------
Offset to 1?Eh:
 +00h: part. state - 0=non activated, 80h=boot partition (byte)
 +01h: Head of the first sector in the partition (DL for BIOS int 13h)
 +02h: Sector & Cylinder of the same sector (CX for BIOS int 13h)
 +04h: Type of partition, 0=empty slot (byte).
 +05h: Head of the last sector in the partition (DL for BIOS int 13h)
 +06h: Sector & Cylinder of the same sector (CX for BIOS int 13h)
 +08h: Offset (in sectors) from this partition table to the first sector of the
       partition (double word).
 +0Ch: number of sectors in the partition (double word).

Node: Extended Partition, Up: Partitioning

   When people saw that 4 partitions just wasn't enough, and that existing
partition sector with only four entries were too common to replace by sectors
with more entries, and that you couldn't use the sectors next to the partition
sector, because some utilities already used them, they found a new trick for
allowing the use of more than 4 partitions.
   
   In the primary partition sector, you create a partition with type 5, latter
called the extended partition. This partition is like a new disk with same
number of sectors per track and heads, but has less cylinders. Only its first
sector is not the first physical sector. So entries in the extended partition
table are exactly as in the main partition table. Only the boot code may be
missing (but not the AA55 boot signature), and while sector/head/cylinder
indications are absolute addresses, the offset of the partition is relative to
the extended partition sector.

   The first entry in the partition table is the actual usable extended
partition

   Thus
   It seems ok to have the chained partitions

Node: Partition restriction, Up: Partitioning

   Firstly, it is more than advised that partitions do not overlap. Some
operating systems may not see it, others may crash, better ones should only
warn you, but in any case, overlapping partitions may mostly result in data
from one partition being unvoluntarily and uncontrollably overwritten by
data from the other partition. So do not have partition overlap, unless you
are sure of what you do.

   Secondly, stubborn operating systems like DOS, OS/2 and perhaps Windows/NT,
require partitions to begin at the first sector of a cylinder/head combination
(and perhaps even the first sector of a cylinder for an extended partition
sector, and sector on next track for the actual data area of the partition).
It is better to have the actual data

Node: Known Partition types, Up: Partitioning

   This info is taken from Linux' fdisk utility and other sources.

Know partition types (hex):
---------------------------
 00 	empty slot, unused partition entry
 01	DOS 12-bit FAT, PRImary part.
 02	XENIX root filesystem
 03	XENIX usr filesystem
 04	DOS 16-bit FAT, <32MB
 05	Extended partition
 06	DOS 16-bit FAT, >=32MB
 07	OS/2 HPFS
 08	AIX
 09	AIX, bootable
 0A	OS/2 boot manager, or OPUS (?)
 40	Venix 80286
 4D	MOOSE File system ('M'=4Dh)
 51	Novell ?
 52	Microport
 63	GNU HURD
 64	Novell
 75	PC/IX
 80	Old style MINIX FS
 81	Linux/MINIX FS
 82	Linux swap partition
 83	Linux native (ext2,or ext or xiafs)
 93	Amoeba
 94	Amoeba BBT
 9e	VSTa boot fs
 9f     VSTa swap partition
 a5	386BSD McKusick-type FS
 b7	BSDI fs
 B8	BSDI swap
 c7	Syrinx
 db	CP/M 86 and Concurrent DOS (Digital Research)
 e1	DOS access
 e3	DOS R/O (?)
 f2	DOS secondary
 ff	BBT


Node: DOS FS, Up:Top

   When Macro-Shit Wrote its Dumb Obfuscating System, they designed their own
filesystem as a revamp of CP/M's.

   DOS FS Filesystems would have been perfect for floppies, had they allowed
more than the stupid 8.3 name limitation inherited from CP/M (and perhaps also
if the FAT had been layout through out the disk for minimal seek time). They
are one of the most stupid file systems ever used on a harddisk; Macro-Shit's
lack of willingness (and/or unability) to improve or replace it made a hell out
of it, as everyone eventually ended with utilities that relied on its name
limitations or its layout.

   DOS FS is very simple. The disk (or partition) is divided into two zones:
the first sectors in the disk are the system area, while the remaining is the
data area.
   The system area begins with the boot record sector, which contains useful
information about the size of the disk, etc; then possible reserved sectors
for the system (usually none); then multiple copies of the dreaded FAT area,
and finally the root directory.
   The data area follows, and is divided into clusters of 1,2,4,8,16 (or
perhaps a larger power of two) contiguous sectors. Clusters are allocated to
files, as described in the system area and the subdirectories.

* DOS FS boot sector::		Critical info lies in here.
* DOS FS FAT::			The File Allocation Tables
* DOS FS Directories::		contains the information identifying files.
* DOS FS Data area::		miscellaneous notes about it.

Node: DOS FS boot sector, Up: DOS FS

   Here is the structure of boot sectors (first sector) of DOS FS filesystems.

offset	type/size	description
00h	instr. (3bytes)	The bootstrap loader jumps here, so those 3 bytes
			should contain a jump to the rest of the boot routine
			typically, that's a short jump & a nop, or a near jump.
03h	8 chars		eight ASCII characters identifying the manufacturer.
0Bh	word		the size of a sector in bytes. Must be a power of two;
			perhaps must even be 512. Always 512 as far as I know.
0Dh	byte		number of sectors per allocation cluster. Must be a
			power of two.
0Eh	word		Number of reserved sectors. Those sectors won't be
			actually used by the system, so we can put a booting
			program here, or some FS of other nature, or we can
			skip deffective sectors so that the system area is safe
			or whatever. Up to 65535 sectors thus skipped
10h	byte		Number of copies of the FAT on the disk. Microsoft
			wants it to be 2 or a greater power of two, while
			DR-DOS or Linux accepts 1 or more.
11h	word		Number of entries in the root directory. Each entry
			is 32 bytes, so on 512 byte sectors, divide by 16 (or
			shr ,4) to know the length in sector.
13h	word		Total Num of sectors on the file system (floppy or
			hard disk partition). A problem arises if this is
			greater than 65535. If so, this field is nulled and
			field at 20h is used.
15h	byte		a media descriptor byte 0F?h. See table below.
			Isn't very useful.
16h	word		number of sectors per FAT (may have been computed
			from the above, but the code is somehow complicated,
			so storing it here is cheaper, when we know that the
			DOS boot sector will need this piece of information).
18h	word		Number of sectors per track.
1Ah	word		Number of heads of the disk drive.
			Those two help the DOS to translate logical sector
			count into sector/cylinder/head numbers.
1Ch	dword		Number of 'hidden' sectors. If the boot sector is not
			the first sector on the disk, this is the logical
			sector number (beginning at zero for the real first
			disk sector) of the boot sector.
20h	dword		Total number of sectors in the filesystem. Used if
			field 13h is zero (and perhaps if partition type is
			file system size >=32 MB ?).
24h	474 bytes	that's space for the boot code
1FEh	word		that's the boot sector signature, word 0AA55h
			(beware, that's bytes 55h,0AAh)

Beware: The BIOS numbers sectors on a track from one on. Cylinders, Heads,
 logical sector number are from zero on.

Media descriptor:
value	disk type	Heads	Tracks	Sectors/Track	size (KB)
F0h	3"1/2 floppy	2	80	18		1440
F0h	3"1/2 floppy	2	80	18		2880
F8h	Hard disk	according to the BIOS information
F9h	5"1/4 floppy	2	80	15		1200
F9h	3"1/2 floppy	2	80	9		720
FAh	5"1/4 floppy	1	80	8		320
FAh	3"1/2 floppy	1	80	8		320
FBh	5"1/4 floppy	2	80	8		640
FBh	3"1/2 floppy	2	80	8		640
FCh	5"1/4 floppy	1	40	9		180
FDh	5"1/4 floppy	2	40	9		360
FEh	5"1/4 floppy	1	40	8		160
FFh	5"1/4 floppy	2	40	8		320

Node: DOS FS FAT, Up: DOS FS

   In a DOS FS, a critical (and criticised) zone is the File Allocation Tables.
Tables is plural, because there are several hopefully identical copies of the
same data.

* nybbles are one after the other, grouped by 3 or 4, in the usual order. Thus
12 34 56 in a 16 bit FAT mean cluster 3412h then cluster ??56h, or in a 12 bit
fat, cluster 412h then 563h...
* The two first entries are a signature: they are filled with set bits, but for
the first byte, which is equal to the media descriptor byte.
* First usable cluster is thus cluster 2 and follows immediately the root
directory (beginning of the data area). There are no cluster 0 or 1.
* (0)000 means a free usable cluster
* (0)001-(F)FEF means that next cluster on file is given cluster
* (F)FF7 means a unusable cluster (has bad sectors inside).
* (F)FF0-(F)FF6 means a cluster reserved for system use.
* (F)FF8-(F)FFF means a cluster ending a file

Node: DOS FS Directories ..., Up: DOS FS

Ofs	bytes	Contents
00h	8	name (space filled right)
08h	3	extension (idem)
0Bh	1	file attributes
0Ch	10	reserved
16h	2	hour of last modification (in DOS int 21h, fun... format)
18h	2	date of ...
1Ah	2	First cluster in the file
1Ch	4	Length of the file.

Note that:
* The root dir is of fixed size, while other directories have their size
decided like files.

* fileattrs and reserved space are used by OS/2 or DR-DOS to store
additional information. In DR-DOS, that's the first letter of a deleted file's
name, a password key to use the file, etc.
* An empty file
* File Attr. format:
 bit	meaning if set
  0	Read-only file
  1	hidden file (won't appear on a usual "dir" command)
  2	system file (don't move the clusters)
  3	volume name
  4	sub-directory
  5	archiving bit (1:file has been modified since last archiving)
  6,7	reserved for DOS internal use.
* DOS sets bit 5 each time the file has been modified
* Hour format:
 bits 0-4: seconds in 2s units
 bits 5-10: minutes
 bits 11-16: hours
* Date format
 bit 0-4: day of month
 bit 5-8: month
 bit 9-15: Year (relative to 1980)

* First letter in name:
-00h last entry in directory
-05h first character in name is char. E5 (lowercase sigma in OEM font).
-2Eh (".") this is the current directory. ".." is the parent directory.
-E5h deleted file entry

Node: Unsupported FS'es, Up:Top

Here is an uncomplete list of FS'es to support as quickly as possible:
- MOOSE' SPOS		We certainly must support our own system, don't we ?
- DOS' FS		DOS is standard. We need read its floppies, so why not
			hard drives too !
- Linux' ext2 fs	Linux is great. Let's cooperate with it.
- Sun's NFS		A standard for networking.

Here are other FS'es to support one day:
- AFS			A better standard for networking
- OS/2's HPFS		Let's communicate with IBM computers
- SYSV's FS		Let's communicate with Unix computers
- GNU's HURD		GNU is Not Unix; it's better

FS'es that'll never be supported (by me)
- Linux/Minix' fs	we don't need these darn old things
- Linux' xia fs		(idem)
- Linux' ext fs		(idem)
- CP/M fs		As bad as DOS, not even standard !

