1CPM(5)                           File formats                           CPM(5)
2
3
4

NAME

6       cpm - CP/M disk and file system format
7

DESCRIPTION

9   Characteristic sizes
10       Each CP/M disk format is described by the following specific sizes:
11
12              Sector size in bytes
13              Number of tracks
14              Number of sectors
15              Block size
16              Number of directory entries
17              Logical sector skew
18              Number of reserved system tracks (optional)
19              Offset to start of volume (optional and not covered by operating
20              system, but disk driver specific)
21
22       A block is the smallest allocatable storage unit.  CP/M supports  block
23       sizes  of  1024, 2048, 4096, 8192 and 16384 bytes.  Unfortunately, this
24       format specification is not stored on the disk and there  are  lots  of
25       formats.   Accessing  a  block  is  performed by accessing its sectors,
26       which are stored with the given software skew.  cpmtools always  counts
27       sectors  starting  with 0, as it deals with logical sectors.  CP/M uses
28       physical sectors in the skew table, which often start with 1.
29
30   Device areas
31       A CP/M disk contains four areas:
32
33              Volume offset (optional and not covered by operating system, but
34              disk driver specific)
35              System tracks (optional)
36              Directory
37              Data
38
39       The  system  tracks store the boot loader and CP/M itself.  In order to
40       save disk space, there are non-bootable formats which omit those system
41       tracks.   The  term  disk capacity always excludes the space for system
42       tracks.  Note that there is no bitmap or list for  free  blocks.   When
43       accessing  a  drive for the first time, CP/M builds this bitmap in core
44       from the directory.
45
46       A hard disk can have the additional notion of a volume offset to locate
47       the  start  of the drive image (which may or may not have system tracks
48       associated with it).  The base unit for volume  offset  is  byte  count
49       from the beginning of the physical disk, but specifiers of K, M, T or S
50       may be appended to denote kilobytes, megabytes, tracks or sectors.   If
51       provided, a specifier must immediately follow the numeric value with no
52       whitespace.  For convenience upper and lower case are both accepted and
53       only  the first letter is significant, thus 2KB, 8MB, 1000trk and 16sec
54       are valid values.  The offset must appear subsequent to  track,  sector
55       and sector length values for the sector and track units to work.
56
57       Note that it is possible to reserve space between the directory and the
58       beginning of data.  Although typically data follows the directory, some
59       systems  used  this  to  store  extra data instead of using more system
60       tracks (see the fields ALV0 and ALV1 in the DPB).
61
62       There are disk formats that map multiple logical tracks onto a physical
63       track, which allows a little bit more capacity in case the system image
64       size does not match the physical track capacity well.
65
66   Directory entries
67       The directory is a sequence of directory entries (also called extents),
68       which contain 32 bytes of the following structure:
69
70              St F0 F1 F2 F3 F4 F5 F6 F7 E0 E1 E2 Xl Bc Xh Rc
71              Al Al Al Al Al Al Al Al Al Al Al Al Al Al Al Al
72
73       St is the status; possible values are:
74
75              0-15:  used  for file, status is the user number.  CP/M 2.2 only
76              documents 0-15 and CCP and PIP only offer those,  but  the  BDOS
77              allows to use 0-31.
78              16-31:  used  for  file,  status is the user number (P2DOS, CP/M
79              2.2) or used for password extent (CP/M 3 or higher)
80              32: disc label
81              33: time stamp (P2DOS)
82              0xE5: unused
83
84
85       F0-E2 are the file name and its extension.  They  may  consist  of  any
86       printable  7  bit ASCII character but: < > . , ; : = ? * [ ].  The file
87       name must not be empty, the extension may be empty.   Both  are  padded
88       with  blanks.   The  highest bit of each character of the file name and
89       extension is used as attribute.   The  attributes  have  the  following
90       meaning:
91
92              F0: requires set wheel byte (Backgrounder II)
93              F1:  public  file  (P2DOS, ZSDOS), forground-only command (Back‐
94              grounder II)
95              F2: date stamp (ZSDOS), background-only  commands  (Backgrounder
96              II)
97              F7: wheel protect (ZSDOS)
98              E0: read-only
99              E1: system file
100              E2: archived
101
102       Public files (visible under each user number) are not supported by CP/M
103       2.2, but there is a patch and some free CP/M clones support them  with‐
104       out any patches.
105
106       The  wheel  byte is (by default) the memory location at 0x4b.  If it is
107       zero, only non-privileged commands may be executed.
108
109       Xl and Xh store the extent number.  A file may use more than one direc‐
110       tory  entry,  if  it  contains more blocks than an extent can hold.  In
111       this case, more extents are allocated and each of them is numbered  se‐
112       quentially  with  an  extent  number.  If a physical extent stores more
113       than 16k, it is considered to contain multiple  logical  extents,  each
114       pointing  to  16k  data, and the extent number of the last used logical
115       extent is stored.  Note: Some formats decided to always store only  one
116       logical  extent  in a physical extent, thus wasting extent space.  CP/M
117       2.2 allows 512 extents per file, CP/M 3 and higher allow  up  to  2048.
118       Bit 5-7 of Xl are 0, bit 0-4 store the lower bits of the extent number.
119       Bit 6 and 7 of Xh are 0, bit 0-5 store the higher bits  of  the  extent
120       number.
121
122       Rc  and  Bc  determine the length of the data used by this extent.  The
123       physical extent is divided into logical extents, each of them being 16k
124       in  size (a physical extent must hold at least one logical extent, e.g.
125       a blocksize of 1024 byte with two-byte block pointers is not  allowed).
126       Rc  stores  the number of 128 byte records of the last used logical ex‐
127       tent.  Bc stores the number of bytes in  the  last  used  record.   The
128       value  0  means 128 for backward compatibility with CP/M 2.2, which did
129       not support Bc.  ISX records the number of unused instead of used bytes
130       in Bc.  This only applies to files with allocated blocks.  For an empty
131       file, no block is allocated and Bc 0 has no meaning.
132
133       Al stores block pointers.  If the disk capacity minus boot  tracks  but
134       including the directory area is less than or equal to 256 blocks, Al is
135       interpreted as  16  byte-values,  otherwise  as  8  double-byte-values.
136       Since  the  directory area is not subtracted, the directory area starts
137       with block 0 and files can never allocate block 0, which  is  why  this
138       value  can be given a new meaning: A block pointer of 0 marks a hole in
139       the file.  If a hole covers the range of a full extent, the extent will
140       not  be  allocated.  In particular, the first extent of a file does not
141       neccessarily have extent number 0.  A file may not  share  blocks  with
142       other  files, as its blocks would be freed if the other files is erased
143       without a following disk  system  reset.   CP/M  returns  EOF  when  it
144       reaches  a  hole,  whereas  UNIX  returns zero-value bytes, which makes
145       holes invisible.
146
147   Native time stamps
148       P2DOS and CP/M Plus support time  stamps,  which  are  stored  in  each
149       fourth  directory  entry.   This entry contains the time stamps for the
150       extents using the previous three directory entries.  Note that you  re‐
151       ally have time stamps for each extent, no matter if it is the first ex‐
152       tent of a file or not.  The structure of time stamp entries is:
153
154              1 byte status 0x21
155              8 bytes time stamp for third-last directory entry
156              2 bytes unused
157              8 bytes time stamp for second-last directory entry
158              2 bytes unused
159              8 bytes time stamp for last directory entry
160
161       A time stamp consists of two dates: Creation and modification date (the
162       latter  being recorded when the file is closed).  CP/M Plus further al‐
163       lows optionally to record the access instead of creation date as  first
164       time stamp.
165
166              2 bytes (little-endian) days starting with 1 at 01-01-1978
167              1 byte hour in BCD format
168              1 byte minute in BCD format
169
170       All time stamps are stored in local time.
171
172   DateStamper time stamps
173       The  DateStamper  software  added  functions to the BDOS to manage time
174       stamps by allocating a read only file with the name  "!!!TIME&.DAT"  in
175       the  very  first  directory entry, covering the very first data blocks.
176       It contains one entry per directory entry with the following  structure
177       of 16 bytes:
178
179              5 bytes create datefield
180              5 bytes access datefield
181              5 bytes modify datefield
182              1 byte magic number/checksum
183
184       The  magic  number  is  used  for  the first 7 entries of each 128-byte
185       record and contains the characters !, !, !, T, I, M and E.  The  check‐
186       sum  is  used on every 8th entry (last entry in 128-byte record) and is
187       the sum of the first 127 bytes of the record.  Each datefield has  this
188       structure:
189
190              1  byte  BCD  coded year (no century, so it is sane assuming any
191              year < 70 means 21st century)
192              1 byte BCD coded month
193              1 byte BCD coded day
194              1 byte BCD coded hour or, if the high bit is set, the high  byte
195              of a counter for systems without real time clock
196              1 byte BCD coded minute, or the low byte of the counter
197
198
199   Disc labels
200       CP/M  Plus support disc labels, which are stored in an arbitrary direc‐
201       tory entry.  The structure of disc labels is:
202
203              1 byte status 0x20
204              F0-E2 are the disc label
205              1 byte mode: bit 7 activates password protection, bit  6  causes
206              time  stamps  on  access,  but 5 causes time stamps on modifica‐
207              tions, bit 4 causes time stamps on creation and  bit  0  is  set
208              when a label exists.  Bit 4 and 6 are exclusively set.
209              1  byte  password  decode byte: To decode the password, xor this
210              byte with the password bytes in  reverse  order.   To  encode  a
211              password, add its characters to get the decode byte.
212              2 reserved bytes
213              8 password bytes
214              4 bytes label creation time stamp
215              4 bytes label modification time stamp
216
217
218   Passwords
219       CP/M  Plus  supports passwords, which are stored in an arbitrary direc‐
220       tory entry.  The structure of these entries is:
221
222              1 byte status (user number plus 16)
223              F0-E2 are the file name and its extension.
224              1 byte password mode: bit 7 means password required for reading,
225              bit 6 for writing and bit 5 for deleting.
226              1  byte  password  decode byte: To decode the password, xor this
227              byte with the password bytes in  reverse  order.   To  encode  a
228              password, add its characters to get the decode byte.
229              2 reserved bytes
230              8 password bytes
231
232

SEE ALSO

234       mkfs.cpm(1), fsck.cpm(1), fsed.cpm(1), cpmls(1)
235
236
237
238CP/M tools                     November 2, 2022                         CPM(5)
Impressum