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