Torch CPN Filesystem Structure ============================== http://mdfs.net/Docs/Comp/Disk/Format/Torch The Torch CPN filesystem uses 256-byte disk blocks. Blocks are addressed as C:H:S and are counted from block &0000 at the start of the filesystem. Block numbers are calculated as track*32+side*16+sector. Floppy disks are physically formatted to 10 sectors per track, and the allocation map marks all sectors &A-&F as unusable. A disk image of a 400K floppy disk will be 400K long and will not contain any data representing the nonexisting sectors. Filesystem Layout ----------------- Sector 0000-0009 Directory Sector 000A-000F Mapped out from disk Sector 0010-0015 Directory Sector 0016-0017 Allocation map Sector 0018 Test pattern Sector 0019 Other information Sector 0020-end Data Directory Layout - Sector &0000-&0015 ------------------------------------- The directory occupies all accessible sectors from &0000 to &0015. The allocation map at &0016-&0017 should be refered to find what sectors from &0000 to &0015 are usable. On 400K floppy disks sectors &000A-&000F will not exist and will be marked in the allocation map as being allocated. Directory entries are 16 bytes long. 00-01 Block number 02-03 Highest record number in this file 04 User number 05 Filename 1st character, b7=user attribute 1 06 Filename 2nd character, b7=user attribute 2 07 Filename 3rd character, b7=user attribute 3 08 Filename 4th character, b7=user attribute 4 09 Filename 5th character, b7=reserved attribute 1 0A Filename 6th character, b7=reserved attribute 2 0B Filename 7th character, b7=reserved attribute 3 0C Filename 8th character, b7=reserved attribute 4 0D Filename extension 1st character, b7=R/O flag 0E Filename extension 2nd character, b7=SYS flag 0F Filename extension 3rd character, b7=execute only flag The block number indicates whether the entry is used, and what block contains the L2 or L3 block holding the file's allocation data: &0000 - End of directory, ignore rest of directory contents &0000+n - n is sector number of L3 block &4000+n - undefined &8000+n - n is sector number of L2 block &C000+n - undefined &FFFF - Null entry Note: Documentation refers to the directory being 256 blocks of 16 bytes. On a floppy disk with sectors &000A-&000F missing this means it extends to &0015. This implies that on a disk that allows sectors &000A-&000F then the allocation map would be at &0010. However, you need to read the allocation map to see what sectors are missing. It seems that it is best to assume the directory uses all usable sectors up to &0015 rather than it being exactly 16 usable sectors. Allocation Map Layout - Sector &0016-&0017 ------------------------------------------ The allocation map is 256 16-bit words. Each 16-bit word refers to 16 sectors on the disk. Word &000 refers to sectors &0000 to &000F. b0 refers to sector 0, b15 refers to sector 15. 0=free, 1=allocated. On 400K floppy disks, bits 10-15 will always by 1 as the refered to sectors do not exist. Test Pattern - Sector &0018 --------------------------- Test pattern and other information. On examining disks this appears to be a sector filled with sequentially incremented bytes, from &D6-&FF, then &00-&D5. Other Information - Sector &0019 -------------------------------- On examining disks this is a sector of zeros, with byte &FE set to some non-zero value. File Structure -------------- CPN files consist of a number of 128-byte records. Each 256-byte sector holds two records. L2 Block -------- An L2 block is a single 256-byte sector containing 128 16-bit words. Word 'n' contains either the sector number of the L3 block for records 256n to 256n+255 or 0 if none of these records have been written to. L3 Block -------- An L3 block is a single 256-byte sector containing 128 16-bit words. Word 'n' refers to records 2n and 2n+1 within the part of the file refered to by this L3 block. Each word is: b0-b13 Sector number holding record 2n and 2n+1, or 0 if never written to b14 0=record 2n never written to, 1=record 2n written to b15 0=record 2n+1 never written to, 1=record 2n+1 written to