J3 and JP file formats

J3 and JP are the types that came before J4. They have one structure: a header frame, a fixed number of group frames and, after them, frames allocated on demand. See Hashed file types for what all types share. The data files explorer draws this structure and shows it in sample J3 and JP files.

JP differs from J3 in three ways. A file offset is 8 bytes long, not 4, so a file can be larger than 4 GB. The block is 4096 bytes, not 1024. The first frame of a group carries a size hint.

Below, P is the size of a file offset: 4 in J3 and 8 in JP.

HEADER

The header is 0x78 bytes in J3 and 0x84 bytes in JP, at offset 0. The rest of the first frame is zero.

J3 offsetJP offsetSizeHolds
0x000x008JBC__HS3 in a J3 file; in a JP file the last character is P
0x080x084frame size in bytes
0x0c0x0c4secondary record size: a record body of this length or more is stored out of its group
0x100x104number of groups (the modulo)
0x140x1441 in J3, 3 in JP
0x180x184creation time, seconds since 1970
0x1c0x1c4hash method
0x200x204flags given at creation: 0x20 in a J3 file and 0x40 in a JP file made by CREATE-FILE
0x240x24Poffset of group 0, equal to the frame size
0x280x2cPoffset of the first free frame, or 0
0x2c0x344number of free frames
0x300x38Pend of the file: where the next new frame goes

CREATE-FILE name modulo,separation,secondary sets the fields as follows:

FRAMES

Every frame other than the header starts with the offsets of the next and the previous frame of its chain and a frame type. The rest of the frame header depends on the type.

OffsetSizeFrame typesHolds
0Palloffset of the next frame of the chain, or 0
PPalloffset of the previous frame, or 0
2P4allframe type
2P + 441, 2bytes used in this frame, the frame header included
2P + 841, 2sequence number of the group
2P + 1241a time; the creation time in a new file
2P + 1641number of records in the group whose body is out of the group

The frame types are:

Frame typeFrameHeader sizeIn J3In JP
1first frame of a group2P + 200x1c0x24
2overflow frame of a group2P + 120x140x1c
3frame of a record body out of its group2P + 40x0c0x14
4free frame2P + 40x0c0x14

In the first frame of a JP group the "bytes used" field holds two numbers. The low 16 bits are the bytes used. The high 16 bits are a hint for the reader: how many frames of memory to set aside for the group. It is 0 for a group of one frame, and a reader can ignore it.

GROUPS

The first frame of group n is at the offset of group 0 plus n times the frame size. It has type 1 and no previous frame. When the group does not fit in one frame, the first frame is full and points to a chain of frames of type 2. Each of them points back to the frame before it and repeats the sequence number of the first frame. A reader that finds anything else reports error 2007.

The data of a group is the used bytes of its frames after their headers, in chain order.

A new group has sequence number 0. Every write, delete and clear of the group adds 1.

RECORDS

OffsetSizeHolds
0x004key length in the low 16 bits; bit 0x10000 is set when the body is out of the group
0x044body length
0x084time of the write, seconds since 1970
0x0ckey lengththe key
10xff

When the body length is less than the secondary record size, the body follows, and then one more 0xff. Such a record takes key length + body length + 14 bytes.

Otherwise an offset of P bytes follows: the first frame of the chain that holds the body. Such a record takes key length + 13 + P bytes. A key is at most 65535 bytes long.

The body is stored in a chain of frames of type 3. Each frame gives the frame size less 2P + 4 bytes of the body. The first frame has no previous frame and the last has no next frame. The frames of a chain need not be in file order.

NOTES

The group of a key is the hash of the key modulo the number of groups, with the hash methods of J4 file format.

Free frames form a list. The header holds the offset of the first one and their number. A free frame has type 4 and the offset of the next free frame in its first P bytes.

SELECT returns the records by group number, and within a group in the order they are stored.

How a write lays out a group and in which order it takes frames from the free list is not described.