From http://www.fship.com/dbfspecs.txt ---------------------------------------------------------------------------- General format of .dbf files in Xbase languages 12-Apr-2011 ---------------------------------------------------------------------------- Applies for / supported by: FS = FlagShip D3 = dBaseIII+ Fb = FoxBase D4 = dBaseIV Fp = FoxPro D5 = dBaseV CL = Clipper 1. DBF Structure ================ Byte Description ------+-------------------------------------- 0..n .dbf header (see 2 for size, byte 8) n+1 1st record of fixed length (see 2&3) \\\ 2nd record (see 2 for size, byte 10) \ if dbf is ... / not empty last record /// last optional: 0x1a (eof byte) 2. DBF Header (variable size, depending on field count) ======================================================= Byte Size Contents Description Applies for (supported by) ----+----+--------+----------------------------+----------------------------- 00 1 0x03 plain .dbf FS, D3, D4, D5, Fb, Fp, CL 0x04 plain .dbf D4, D5 (FS) 0x05 plain .dbf D5, Fp (FS) 0x83 with .dbt (M memo fields) FS, D3, D4, D5, Fb, Fp, CL 0x13 with .dbv (V* fields) FS 0x23 with 2/4/8 fields FS 0x33 with .dbv (V*) + 2/4/8 FS 0x93 with .dbt + .dbv (M + V*) FS 0xB3 with .dbt + .dbv + 2/4/8 FS 0x8B with .dbt memo in D4 format D4, D5 (FS msg) 0x8E with SQL table D4, D5 0xF5 with .fpt memo Fp, CL 01 3 YYMMDD Last modification =LUPDATE() all YY = 00..0x63 (= 1900..1999) D3 = 00..0xFF (= 1900..2155) FS, D4, CL, Fp 04 4 ulong Number of records in file all 08 2 ushort Header size in bytes all 10 2 ushort Record size in bytes all 12 2 0,0 Reserved all 14 1 0x01 Begin transaction D4, D5 0x00 End Transaction D4, D5 0x00 ignored FS, D3, Fb, Fp, CL 15 1 0x01 Encryptpted D4, D5 0x00 normal visible all 16 12 0 (1) multi-user environment use D4,D5 28 1 0x01 production index exists Fp, D4, D5 0x00 index upon demand all 29 1 n language driver ID D4, D5 0x01 codepage 437 DOS USA Fp 0x02 codepage 850 DOS Multi ling Fp 0x03 codepage 1251 Windows ANSI Fp 0xC8 codepage 1250 Windows EE Fp 0x00 ignored FS, D3, Fb, Fp, CL 30 1 0x00 reserved all 31 1 n update/integrity count FS 0x00 ignored D3, D4, D5, Fb, Fp, CL 32 n*32 Field Descriptor, see (2a) all +1 1 0x0D Header Record Terminator all 2a. Field descriptor array in dbf header (fix 32 bytes for each field) ======================================== Byte Size Contents Description Applies for (supported by) ----+----+--------+----------------------------+----------------------------- 0 11 ASCI field name, 0x00 termin. all 11 1 ASCI field type (see 2b) all 12 4 n,n,n,n fld address in memory D3 n,n,0,0 offset from record begin Fp 0,0,0,0 ignored FS, D4, D5, Fb, CL 16 1 byte Field length, bin (see 2b) all \ FS,CL: for C field type, 17 1 byte decimal count, bin all / both used for fld lng 18 2 0,0 reserved all 20 1 byte Work area ID D4, D5 0x00 unused FS, D3, Fb, Fp, CL 21 2 n,n multi-user dBase D3, D4, D5 0,0 ignored FS, Fb, Fp, CL 23 1 0x01 Set Fields D3, D4, D5 0x00 ignored FS, Fb, Fp, CL 24 7 0..0 reserved all 31 1 0x01 Field is in .mdx index D4, D5 0x00 ignored FS, D3, Fb, Fp, CL 2b. Field type and size in dbf header, field descriptor (1 byte) ======================================================= Size Type Description/Storage Applies for (supported by) ------+---------+------------------------------+----------------------------- C 1..n Char ASCII (OEM code page chars) all rest= space, not \0 term. n = 1..64kb (using deci count) FS n = 1..32kb (using deci count) Fp, CL n = 1..254 all D 8 Date 8 Ascii digits (0..9) in the all YYYYMMDD format F 1..n Numeric Ascii digits (-.0123456789) FS, D4, D5, Fp variable pos. of float.point n = 1..20 N 1..n Numeric Ascii digits (-.0123456789) all fix posit/no float.point n = 1..20 FS, Fp, CL n = 1..18 D3, D4, D5, Fb L 1 Logical Ascii chars (YyNnTtFf space) FS, D3, Fb, Fp, CL Ascii chars (YyNnTtFf ?) D4, D5 (FS) M 10 Memo 10 digits repres. the start all block posit. in .dbt file, or 10spaces if no entry in memo V* 10 Variable Variable, bin/asc data in .dbv FS (.dbf type = 0x13,0x33,0x93,0xB3) 4bytes bin= start pos in memo 4bytes bin= block size 1byte = subtype 1byte = reserved (0x1a) 10spaces if no entry in .dbv P 10 Picture binary data in .ftp Fp (.dbf type = 0x?5) structure like M B 10 Binary binary data in .dbt D5 (.dbf type = 0x?5) structure like M G 10 General OLE objects D5, Fp (.dbf type = 0x?5) structure like M 2 2 short int binary int max +/- 32767 FS (.dbf type = 0x23,0x33,0xB3) 4 4 long int binary int max +/- 2147483647 FS (.dbf type = 0x23,0x33,0xB3) 8 8 double binary signed double IEEE FS (.dbf type = 0x23,0x33,0xB3) V* fields are VC, VCZ, VB, VBZ 3. Each Dbf record (fix length) ================== Byte Size Description Applies for (supported by) ------+----+--------------------------------------+-------------------------- 0 1 deleted flag "*" or not deleted " " all 1..n 1.. x-times contents of fields, fixed all length, unterminated. For n, see (2) byte 10..11 FlagShip version 6 and newer supports .dbf file size larger than 2 Gigabytes (up to 16 Terabytes, system specific), all other DBMS supports .dbf up to 2GB only. The maximum record number is 2 billion (2,147,483,647), whereby all DBMS except FlagShip limits it further by locking scheme. 4. .dbt file structure (FS, D3, D4, D5, Fb, CL) ====================== When field type 'M' is specified in the database structure of .dbf, the DBMS creates same named file with extension .dbt (in addition to .dbf file). In this .dbt file, "memo" data (usually plain ascii text) are stored for each database record, if such aditional data are available. In FlagShip, you may store also binary data (containing 0x00 and 0x1A) within the .dbt (memo field) by using MemoCode() function (or ChrPack() from FS2). The 10 bytes of M-field in .dbf contains block start address in the .dbt file or 10 spaces (20202020202020202020 hex) if no memory data are available for this record. The block address is coded in ascii, i.e. " 25" ascii or 20202020202020203235 hex points to 25th text block. Every block is 512 bytes long. Data within the text block are terminated by 0x1A, rest of the block (behind 0x1A) is unused. Data longer than 512 continues in subsequent block(s), until 0x1A (or 0x00 in some systems) terminates it. There is also internal zero-block in the .dbt file, containing only pointer to next unused block (here in binary, not ascii). When the memo data get changed, and the new data fits in available block(s), the same block (or block sequence) is re-used. If the new data does not fit in available block(s), a new block (or block sequence) is assigned, leaving previously used block(s) as garbage. This may result in growing the size of .dbt file. Compressing the .dbt file, i.e. removing unused blocks is done by PACK, ZAP or COPY FILE..TO.. commands or associated functions. FlagShip version 6 and newer supports .dbt file size larger than 2 Gigabytes (up to 16 Terabytes, system specific), all other DBMS supports .dbt up to 2GB. 5. .dbv file structure (FS only) ====================== When field type 'V*' is specified in the database structure of .dbf, the DBMS creates same named file with extension .dbv (in addition to .dbf file). In this .dbv file, variable data fields (any text or binary data) are stored for each database record, if such aditional data are available. The .dbv file has 32 bytes header, where the first 16 bytes stores last modification date and time in ascii format (YYYYMMDDhh:mm:ss) and 16 bytes of internal data. Blocks of variable-data-records follows. Every block in the .dbv file has header of 8 bytes + data. The first 4 bytes (binary, normalized) of the block header specify the data length, the second 4 bytes are reserved for future use. If the data starts with 0xEF + 0xEF, the record is compressed, and the 3rd byte says how (0x01 = RLL with preserved \0, 0x02 = RLL, 0x03 = LZH with preserved \0, 0x04 = LZH). At the time of storing data, FlagShip determines the best storage method by considering the V?Z data type and current set(_SET_COMPRESS) flag. In the .dbf file, the 10 bytes of V* field for each record are either 10* 0x00 if there is no additional data allocated, otherwise the value contain 4 bytes (binary, normalized): start address of data block (header) in .dbv 4 bytes (binary, normalized): length of data (w/o header) 1 byte: subtype, usually 0x43 = 'C' or 0x42 = 'B' 1 byte: always 0x1A When the memo data get changed, and the new data fits in available space, the same data block is re-used. If the new data does not fit in available block space, new block is assigned, the old block may be re-used later. Compressing the .dbv file, i.e. removing unused blocks is done by PACK, ZAP or COPY FILE..TO.. commands or associated functions. The size of each data block can be up to 2 GB. FlagShip version 6 and newer supports .dbv file size larger than 2 Gigabytes (up to 16 Terabytes, system specific). ---------------------------------------------------------------------------- .idx Index file of FlagShip 5.x, 6.x and 7.x 12-Apr-11 ---------------------------------------------------------------------------- FlagShip version 6 and newer supports .idx file size larger than 2 Gigabytes (up to 16 Terabytes, system specific). a. INDEX HEADER (1024 bytes) Byte Size Type Default Description ----+----+------+----------+-------------------------------------------------- 00 1 uchar 0x52 index type, version 01 1 uchar 0 index status (unique=1, descend=2, uniq+desc=3) 02 1 uchar 0 if num key: number of digits incl deci \ (KLEN) 03 1 uchar 0 - num key: number of deci places / (KLEN) 1..255 - other key types: current key length (KLEN) 04 1 uchar C,D,N,L,I index key type 05 1 uchar 0..255 max tree depth 06 1 uchar 0..255 number of header pages 07 1 uchar 1..255 update/integrity count vs. dbf 08 2 ushort 1..655345 page length 10 2 ushort 1..655345 update/integrity count index 12 4 ulong 0..4GB number of index entries in file 16 4 ulong 0..4GB root index position 20 4 ulong 0..4GB first available page number 24 4 ulong 0..4GB maximal number of keys in page (NKPP) 28 4 ulong 0..4GB next page to use if none free 32 50 uchar 0 reserved 82 430 uchar 1..255,0 expression for indexing (max 429 chars) 512 1 uchar 0x52 fix 513 5 uchar 0 reserved 518 20 uchar 1..255,0 first 20 chars of dbf name without path 538 200 uchar 1..255,0 FOR condition string (max 199 chars) 738 20 uchar 1..255,0 name of the sorting order file 758 10 uchar 0 reserved 768 256 uchar 0..255 sort table at index creation (C type only) b. INDEX PAGES ea 1024 bytes (balanced binary tree) Byte Size Type Default Description ----+-----+------+--------+-------------------------------------------------- 00 4 ulong 0..NKPP number of keys in current page 04 4*NKPP ulong 0.. child page, repeats NKPP times n1 4*NKPP ulong 1.. record number, repeats NKPP times n2 KLEN*NKPP key value, repeats NKPP times n1 = (page * 1024) + (NKPP * 4) + 8 n2 = n1 + (NKPP * 4) ---------------------------------------------------------------------------- .idx Index file of FlagShip 4.4x 16-Apr-97 ---------------------------------------------------------------------------- a. INDEX HEADER (1024 bytes) Byte Size Type Default Description ----+----+------+--------+-------------------------------------------------- 00 1 uchar 0x81 index type, version 01 1 uchar 0 index status (unique=1, descend=2, uniq+desc=3) 02 1 uchar 0 if num key: number of digits incl deci point 03 1 uchar 0 - num key: number of deci places 1..255 - other key types: current key length 04 4 ulong 0..n number of keys in file 08 4 ulong 0..n page no of the root page 12 4 ulong 0..n page no of the list of free pages 16 4 ulong 0..n page no behind eof 20 1 uchar C,D,N,L index key type 21 1 uchar reserved 22 2 ushort 512 size of each index page (in bytes) 24 4 ulong 1..238 key length (in bytes) incl 4byte alignment 28 4 ulong 2..41 max no of keys per page 32 420 char xxx\0 string of the index key expression + \0 452 60 char reserved 512 1 char reserved 513 1 uchar 0..255 data integrity check against dbf 514 4 uchar reserved 518 20 char xxx\0 first 19 chars of dbf name without path + \0 538 230 char 0 FOR condition as string + \0 768 256 char sorting table active during the index creation b. INDEX PAGES ea 512 bytes (binary tree) Byte Size Type Default Description ----+----+------+--------+-------------------------------------------------- 00 4 ulong 0..n number of keys in current page 04 4 ulong 0..n page no of the parent page 08 2 ushort 0..n ordinal no of the parent key in the parent page 10 2 ushort reserved -- ------- 12 4 ulong 0..n page no of child page \ 16 4 ulong 1..n record no in the dbf \ 20 8 double key = numeric + n-times ea page 4 ulong key = date / see byte 28 in header n char key = char, logical / -- ------- .