1CPM(5) File formats CPM(5)
2
3
4
6 cpm - CP/M disk and file system format
7
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
19
20 A block is the smallest allocatable storage unit. CP/M supports block
21 sizes of 1024, 2048, 4096, 8192 and 16384 bytes. Unfortunately, this
22 format specification is not stored on the disk and there are lots of
23 formats. Accessing a block is performed by accessing its sectors,
24 which are stored with the given software skew.
25
26 Device areas
27 A CP/M disk contains three areas:
28
29 System tracks (optional)
30 Directory
31 Data
32
33 The system tracks store the boot loader and CP/M itself. In order to
34 save disk space, there are non-bootable formats which omit those system
35 tracks. The term disk capacity always excludes the space for system
36 tracks. Note that there is no bitmap or list for free blocks. When
37 accessing a drive for the first time, CP/M builds this bitmap in core
38 from the directory.
39
40 Directory entries
41 The directory is a sequence of directory entries (also called extents),
42 which contain 32 bytes of the following structure:
43
44 St F0 F1 F2 F3 F4 F5 F6 F7 E0 E1 E2 Xl Bc Xh Rc
45 Al Al Al Al Al Al Al Al Al Al Al Al Al Al Al Al
46
47 St is the status; possible values are:
48
49 0-15: used for file, status is the user number
50 16-31: used for file, status is the user number (P2DOS) or used
51 for password extent (CP/M 3 or higher)
52 32: disc label
53 33: time stamp (P2DOS)
54 0xE5: unused
55
56
57 F0-E2 are the file name and its extension. They may consist of any
58 printable 7 bit ASCII character but: < > . , ; : = ? * [ ]. The file
59 name must not be empty, the extension may be empty. Both are padded
60 with blanks. The highest bit of each character of the file name and
61 extension is used as attribute. The attributes have the following
62 meaning:
63
64 F0: requires set wheel byte (Backgrounder II)
65 F1: public file (P2DOS, ZSDOS), forground-only command (Back‐
66 grounder II)
67 F2: date stamp (ZSDOS), background-only commands (Backgrounder
68 II)
69 F7: wheel protect (ZSDOS)
70 E0: read-only
71 E1: system file
72 E2: archived
73
74 Public files (visible under each user number) are not supported by CP/M
75 2.2, but there is a patch and some free CP/M clones support them with‐
76 out any patches.
77
78 The wheel byte is (by default) the memory location at 0x4b. If it is
79 zero, only non-privileged commands may be executed.
80
81 Xl and Xh store the extent number. A file may use more than one direc‐
82 tory entry, if it contains more blocks than an extent can hold. In
83 this case, more extents are allocated and each of them is numbered
84 sequentially with an extent number. If a physical extent stores more
85 than 16k, it is considered to contain multiple logical extents, each
86 pointing to 16k data, and the extent number of the last used logical
87 extent is stored. Note: Some formats decided to always store only one
88 logical extent in a physical extent, thus wasting extent space. CP/M
89 2.2 allows 512 extents per file, CP/M 3 and higher allow up to 2048.
90 Bit 5-7 of Xl are 0, bit 0-4 store the lower bits of the extent number.
91 Bit 6 and 7 of Xh are 0, bit 0-5 store the higher bits of the extent
92 number.
93
94 Rc and Bc determine the length of the data used by this extent. The
95 physical extent is divided into logical extents, each of them being 16k
96 in size (a physical extent must hold at least one logical extent, e.g.
97 a blocksize of 1024 byte with two-byte block pointers is not allowed).
98 Rc stores the number of 128 byte records of the last used logical
99 extent. Bc stores the number of bytes in the last used record. The
100 value 0 means 128 for backward compatibility with CP/M 2.2, which did
101 not support Bc.
102
103 Al stores block pointers. If the disk capacity is less than 256
104 blocks, Al is interpreted as 16 byte-values, otherwise as 8 double-
105 byte-values. A block pointer of 0 marks a hole in the file. If a hole
106 covers the range of a full extent, the extent will not be allocated.
107 In particular, the first extent of a file does not neccessarily have
108 extent number 0. A file may not share blocks with other files, as its
109 blocks would be freed if the other files is erased without a following
110 disk system reset. CP/M returns EOF when it reaches a hole, whereas
111 UNIX returns zero-value bytes, which makes holes invisible.
112
113 Time stamps
114 P2DOS and CP/M Plus support time stamps, which are stored in each
115 fourth directory entry. This entry contains the time stamps for the
116 extents using the previous three directory entries. Note that you
117 really have time stamps for each extent, no matter if it is the first
118 extent of a file or not. The structure of time stamp entries is:
119
120 1 byte status 0x21
121 8 bytes time stamp for third-last directory entry
122 2 bytes unused
123 8 bytes time stamp for second-last directory entry
124 2 bytes unused
125 8 bytes time stamp for last directory entry
126
127 A time stamp consists of two dates: Creation and modification date (the
128 latter being recorded when the file is closed). CP/M Plus further
129 allows optionally to record the access instead of creation date as
130 first time stamp.
131
132 2 bytes (little-endian) days starting with 1 at 01-01-1978
133 1 byte hour in BCD format
134 1 byte minute in BCD format
135
136
137 Disc labels
138 CP/M Plus support disc labels, which are stored in an arbitrary direc‐
139 tory entry. The structure of disc labels is:
140
141 1 byte status 0x20
142 F0-E2 are the disc label
143 1 byte mode: bit 7 activates password protection, bit 6 causes
144 time stamps on access, but 5 causes time stamps on modifica‐
145 tions, bit 4 causes time stamps on creation and bit 0 is set
146 when a label exists. Bit 4 and 6 are exclusively set.
147 1 byte password decode byte: To decode the password, xor this
148 byte with the password bytes in reverse order. To encode a
149 password, add its characters to get the decode byte.
150 2 reserved bytes
151 8 password bytes
152 4 bytes label creation time stamp
153 4 bytes label modification time stamp
154
155
156 Passwords
157 CP/M Plus supports passwords, which are stored in an arbitrary direc‐
158 tory entry. The structure of these entries is:
159
160 1 byte status (user number plus 16)
161 F0-E2 are the file name and its extension.
162 1 byte password mode: bit 7 means password required for reading,
163 bit 6 for writing and bit 5 for deleting.
164 1 byte password decode byte: To decode the password, xor this
165 byte with the password bytes in reverse order. To encode a
166 password, add its characters to get the decode byte.
167 2 reserved bytes
168 8 password bytes
169
170
172 mkfs.cpm(1), fsck.cpm(1), fsed.cpm(1), cpmls(1)
173
174
175
176CP/M tools December 20, 2009 CPM(5)