New upstream version 2.20
[debian/cpmtools] / cpm.5.in
1 .\" Believe it or not, reportedly there are nroffs which do not know \(en
2 .if n .ds en -
3 .if t .ds en \(en
4 .TH CPM 5 "@UPDATED@" "CP/M tools" "File formats"
5 .SH NAME \"{{{roff}}}\"{{{
6 cpm \- CP/M disk and file system format
7 .\"}}}
8 .SH DESCRIPTION \"{{{
9 .SS "Characteristic sizes" \"{{{
10 Each CP/M disk format is described by the following specific sizes:
11 .RS
12 .sp
13 Sector size in bytes
14 .br
15 Number of tracks
16 .br
17 Number of sectors
18 .br
19 Block size
20 .br
21 Number of directory entries
22 .br
23 Logical sector skew
24 .br
25 Number of reserved system tracks (optional)
26 .br
27 Offset to start of volume (optional and not covered by operating system,
28 but disk driver specific)
29 .sp
30 .RE
31 A block is the smallest allocatable storage unit.  CP/M supports block
32 sizes of 1024, 2048, 4096, 8192 and 16384 bytes.  Unfortunately, this
33 format specification is not stored on the disk and there are lots of
34 formats.  Accessing a block is performed by accessing its sectors, which
35 are stored with the given software skew.
36 .\"}}}
37 .SS "Device areas" \"{{{
38 A CP/M disk contains four areas:
39 .RS
40 .sp
41 Volume offset (optional and not covered by operating system, but disk driver specific)
42 .br
43 System tracks (optional)
44 .br
45 Directory
46 .br
47 Data
48 .sp
49 .RE
50 The system tracks store the boot loader and CP/M itself.  In order to save
51 disk space, there are non-bootable formats which omit those system tracks.
52 The term \fIdisk capacity\fP always excludes the space for system tracks.
53 Note that there is no bitmap or list for free blocks.  When accessing a
54 drive for the first time, CP/M builds this bitmap in core from the directory.
55 .LP
56 A hard disk can have the additional notion of a \fIvolume offset\fP to
57 locate the start of the drive image (which may or may not have system
58 tracks associated with it).  The base unit for volume offset is byte
59 count from the beginning of the physical disk, but specifiers of
60 \fIK\fP, \fIM\fP, \fIT\fP or \fIS\fP may be appended to denote
61 kilobytes, megabytes, tracks or sectors.  If provided, a specifier
62 must immediately follow the numeric value with no whitespace.  For
63 convenience upper and lower case are both accepted and only the first
64 letter is significant, thus 2KB, 8MB, 1000trk and 16sec are valid
65 values.  The \fBoffset\fP must appear subsequent to track, sector and sector
66 length values for the sector and track units to work.
67 .\"}}}
68 .SS "Directory entries" \"{{{
69 The directory is a sequence of directory entries (also called extents),
70 which contain 32 bytes of the following structure:
71 .RS
72 .sp
73 .ta 3n 6n 9n 12n 15n 18n 21n 24n 27n 30n 33n 36n 39n 42n 45n
74 St      F0      F1      F2      F3      F4      F5      F6      F7      E0      E1      E2      Xl      Bc      Xh      Rc
75 .br
76 Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al      Al
77 .sp
78 .RE
79 .\"{{{ St     = status
80 \fBSt\fP is the status; possible values are:
81 .RS
82 .sp
83 0\*(en15: used for file, status is the user number
84 .br
85 16\*(en31: used for file, status is the user number (P2DOS)
86 or used for password extent (CP/M 3 or higher)
87 .br
88 32: disc label
89 .br
90 33: time stamp (P2DOS)
91 .br
92 0xE5: unused
93 .sp
94 .RE
95 .\"}}}
96 .LP
97 .\"{{{ F0-E2  = file name and extension
98 \fBF0\*(enE2\fP are the file name and its extension.  They may consist of
99 any printable 7 bit ASCII character but: \fB< > . , ; : = ? * [ ]\fP.
100 The file name must not be empty, the extension may be empty.  Both are
101 padded with blanks.  The highest bit of each character of the file name
102 and extension is used as attribute.  The attributes have the following
103 meaning:
104 .RS
105 .sp
106 F0: requires set wheel byte (Backgrounder II)
107 .br
108 F1: public file (P2DOS, ZSDOS), forground-only command (Backgrounder II)
109 .br
110 F2: date stamp (ZSDOS), background-only commands (Backgrounder II)
111 .br
112 F7: wheel protect (ZSDOS)
113 .br
114 E0: read-only
115 .br
116 E1: system file
117 .br
118 E2: archived
119 .sp
120 .RE
121 Public files (visible under each user number) are not supported by CP/M
122 2.2, but there is a patch and some free CP/M clones support them without
123 any patches.
124 .LP
125 The wheel byte is (by default) the memory location at 0x4b.  If it is
126 zero, only non-privileged commands may be executed.
127 .\"}}}
128 .LP
129 .\"{{{ Xl, Xh = extent number
130 \fBXl\fP and \fBXh\fP store the extent number.  A file may use more than
131 one directory entry, if it contains more blocks than an extent can hold.
132 In this case, more extents are allocated and each of them is numbered
133 sequentially with an extent number.  If a physical extent stores more than
134 16k, it is considered to contain multiple logical extents, each pointing
135 to 16k data, and the extent number of the last used logical extent
136 is stored.  Note: Some formats decided to always store only one logical
137 extent in a physical extent, thus wasting extent space.  CP/M 2.2 allows
138 512 extents per file, CP/M 3 and higher allow up to 2048.  Bit 5\*(en7 of
139 Xl are 0, bit 0\*(en4 store the lower bits of the extent number.  Bit 6
140 and 7 of Xh are 0, bit 0\*(en5 store the higher bits of the extent number.
141 .\"}}}
142 .LP
143 .\"{{{ Rc, Bc = record count, byte count
144 \fBRc\fP and \fBBc\fP determine the length of the data used by this extent.  The
145 physical extent is divided into logical extents, each of them being 16k
146 in size (a physical extent must hold at least one logical extent, e.g. a
147 blocksize of 1024 byte with two-byte block pointers is not allowed).
148 Rc stores the number of 128 byte records of the last used logical extent.
149 Bc stores the number of bytes in the last used record.  The value 0 means
150 128 for backward compatibility with CP/M 2.2, which did not support Bc.
151 ISX records the number of unused instead of used bytes in Bc.
152 .\"}}}
153 .LP
154 .\"{{{ Al     = allocated blocks
155 \fBAl\fP stores block pointers.  If the disk capacity minus boot
156 tracks but including the directory area is less than 256 blocks, Al
157 is interpreted as 16 byte-values, otherwise as 8 double-byte-values.
158 Since the directory area is not subtracted, the directory area starts
159 with block 0 and files can never allocate block 0, which is why this
160 value can be given a new meaning: A block pointer of 0 marks a hole in
161 the file.  If a hole covers the range of a full extent, the extent will
162 not be allocated.  In particular, the first extent of a file does not
163 neccessarily have extent number 0.  A file may not share blocks with other
164 files, as its blocks would be freed if the other files is erased without
165 a following disk system reset.  CP/M returns EOF when it reaches a hole,
166 whereas UNIX returns zero-value bytes, which makes holes invisible.
167 .\"}}}
168 .\"}}}
169 .SS "Native time stamps" \"{{{
170 P2DOS and CP/M Plus support time stamps, which are stored in each fourth
171 directory entry.  This entry contains the time stamps for
172 the extents using the previous three directory entries.  Note that you
173 really have time stamps for each extent, no matter if it is the first
174 extent of a file or not.  The structure of time stamp entries is:
175 .RS
176 .sp
177 1 byte status 0x21
178 .br
179 8 bytes time stamp for third-last directory entry
180 .br
181 2 bytes unused
182 .br
183 8 bytes time stamp for second-last directory entry
184 .br
185 2 bytes unused
186 .br
187 8 bytes time stamp for last directory entry
188 .sp
189 .RE
190 A time stamp consists of two dates: Creation and modification date (the
191 latter being recorded when the file is closed).  CP/M Plus further
192 allows optionally to record the access instead of creation date as first
193 time stamp.
194 .RS
195 .sp
196 2 bytes (little-endian) days starting with 1 at 01-01-1978
197 .br
198 1 byte hour in BCD format
199 .br
200 1 byte minute in BCD format
201 .sp
202 .RE
203 All time stamps are stored in local time.
204 .\"}}}
205 .SS "DateStamper time stamps" \"{{{
206 The DateStamper software added functions to the BDOS to manage
207 time stamps by allocating a read only file with the name "!!!TIME&.DAT"
208 in the very first directory entry, covering the very first data
209 blocks.  It contains one entry per directory entry with the
210 following structure of 16 bytes:
211 .RS
212 .sp
213 5 bytes create datefield
214 .br
215 5 bytes access datefield
216 .br
217 5 bytes modify datefield
218 .br
219 1 byte magic number/checksum
220 .sp
221 .RE
222 The magic number is used for the first 7 entries of each 128-byte record
223 and contains the characters \fB!\fP, \fB!\fP, \fB!\fP, \fBT\fP, \fBI\fP,
224 \fBM\fP and \fBE\fP.  The checksum is used on every 8th entry (last entry
225 in 128-byte record) and is the sum of the first 127 bytes of the record.
226 Each datefield has this structure:
227 .RS
228 .sp
229 1 byte BCD coded year (no century, so it is sane assuming any year < 70
230 means 21st century)
231 .br
232 1 byte BCD coded month
233 .br
234 1 byte BCD coded day
235 .br
236 1 byte BCD coded hour or, if the high bit is set, the high byte of a
237 counter for systems without real time clock
238 .br
239 1 byte BCD coded minute, or the low byte of the counter
240 .sp
241 .DE
242 .\"}}}
243 .SS "Disc labels" \"{{{
244 CP/M Plus support disc labels, which are stored in an arbitrary directory
245 entry.
246 The structure of disc labels is:
247 .RS
248 .sp
249 1 byte status 0x20
250 .br
251 \fBF0\*(enE2\fP are the disc label
252 .br
253 1 byte mode: bit 7 activates password protection, bit 6 causes time stamps on
254 access, but 5 causes time stamps on modifications, bit 4 causes time stamps on
255 creation and bit 0 is set when a label exists.  Bit 4 and 6 are exclusively set.
256 .br
257 1 byte password decode byte: To decode the password, xor this byte with the password
258 bytes in reverse order.  To encode a password, add its characters to get the
259 decode byte.
260 .br
261 2 reserved bytes
262 .br
263 8 password bytes
264 .br
265 4 bytes label creation time stamp
266 .br
267 4 bytes label modification time stamp
268 .sp
269 .RE
270 .\"}}}
271 .SS "Passwords" \"{{{
272 CP/M Plus supports passwords, which are stored in an arbitrary directory
273 entry.
274 The structure of these entries is:
275 .RS
276 .sp
277 1 byte status (user number plus 16)
278 .br
279 \fBF0\*(enE2\fP are the file name and its extension.
280 .br
281 1 byte password mode: bit 7 means password required for reading, bit 6 for writing
282 and bit 5 for deleting.
283 .br
284 1 byte password decode byte: To decode the password, xor this byte with the password
285 bytes in reverse order.  To encode a password, add its characters to get the
286 decode byte.
287 .br
288 2 reserved bytes
289 .br
290 8 password bytes
291 .sp
292 .RE
293 .\"}}}
294 .\"}}}
295 .SH "SEE ALSO" \"{{{
296 .IR mkfs.cpm (1),
297 .IR fsck.cpm (1),
298 .IR fsed.cpm (1),
299 .IR cpmls (1)
300 .\"}}}